- removed test_sockets_bi_*
 - removed soon to be redundant test_sockets_select_server_closes_connection
This commit is contained in:
Anthony Pesch 2013-08-09 20:21:24 -07:00
Родитель fec4930b0e
Коммит c6e5e9c375
8 изменённых файлов: 1 добавлений и 774 удалений

Просмотреть файл

@ -12450,11 +12450,8 @@ elif 'browser' in str(sys.argv):
i = sys.argv.index('browser')
sys.argv = sys.argv[:i] + sys.argv[i+1:]
sys.argv += [
'browser.test_sockets_bi',
'browser.test_sockets_gethostbyname',
'browser.test_sockets_bi_bigdata',
'browser.test_sockets_select_server_down',
'browser.test_sockets_select_server_closes_connection',
'browser.test_sockets_select_server_closes_connection_rw',
'browser.test_enet'
]
@ -14075,10 +14072,6 @@ Press any key to continue.'''
# always run these tests last
# make sure to use different ports in each one because it takes a while for the processes to be cleaned up
def test_sockets(self):
with self.WebsockHarness(8990):
self.btest('sockets/test_sockets.c', expected='571', args=['-DSOCKK=8991'])
def test_sockets_partial(self):
def partial(q):
import socket
@ -14111,25 +14104,10 @@ Press any key to continue.'''
proc.communicate()
return relay_server
def test_sockets_bi(self):
for datagram in [0,1]:
for fileops in [0,1]:
print >> sys.stderr, 'test_websocket_bi datagram %d, fileops %d' % (datagram, fileops)
with self.WebsockHarness(6992, self.make_relay_server(6992, 6994)):
with self.WebsockHarness(6994, no_server=True):
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets/test_sockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=6995', '-DTEST_DGRAM=%d' % datagram]).communicate()
self.btest('sockets/test_sockets_bi.c', expected='2499', args=['-DSOCKK=6993', '-DTEST_DGRAM=%d' % datagram, '-DTEST_FILE_OPS=%s' % fileops])
def test_sockets_gethostbyname(self):
with self.WebsockHarness(7000):
self.btest('sockets/test_sockets_gethostbyname.c', expected='571', args=['-O2', '-DSOCKK=7001'])
def test_sockets_bi_bigdata(self):
with self.WebsockHarness(3992, self.make_relay_server(3992, 3994)):
with self.WebsockHarness(3994, no_server=True):
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets/test_sockets_bi_side_bigdata.c'), '-o', 'side.html', '-DSOCKK=3995', '-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests/sockets')]).communicate()
self.btest('sockets/test_sockets_bi_bigdata.c', expected='0', args=['-DSOCKK=3993', '-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests/sockets')])
def test_sockets_select_server_down(self):
def closedServer(q):
import socket
@ -14140,23 +14118,6 @@ Press any key to continue.'''
with self.WebsockHarness(8994, closedServer):
self.btest('sockets/test_sockets_select.c', expected='266', args=['-DSOCKK=8995'])
def test_sockets_select_server_closes_connection(self):
def closingServer(q):
import socket
q.put(None) # No sub-process to start
ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock.bind(("127.0.0.1", 8994))
ssock.listen(2)
while True:
csock, addr = ssock.accept()
print "Connection from %s" % repr(addr)
csock.send("1234567")
csock.close()
with self.WebsockHarness(8994, closingServer):
self.btest('sockets/test_sockets_select_server_closes_connection.c', expected='266', args=['-DSOCKK=8995'])
def test_sockets_select_server_closes_connection_rw(self):
def closingServer_rw(q):
import socket

Просмотреть файл

@ -1,143 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <assert.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#define EXPECTED_BYTES 5
int sockfd;
int not_always_data = 0;
void finish(int result) {
close(sockfd);
#if EMSCRIPTEN
REPORT_RESULT();
#endif
exit(result);
}
unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) {
// select check for IO
fd_set sett;
FD_ZERO(&sett);
assert(select(64, &sett, NULL, NULL, NULL) == 0); // empty set
FD_SET(sock, &sett);
assert(select(0, &sett, NULL, NULL, NULL) == 0); // max FD to check is 0
assert(FD_ISSET(sock, &sett) == 0);
FD_SET(sock, &sett);
int select_says_yes = select(64, &sett, NULL, NULL, NULL);
// ioctl check for IO
int bytes;
if (ioctl(sock, FIONREAD, &bytes) || bytes == 0) {
not_always_data = 1;
printf("ioctl says 0, FD_ISSET says %ld\n", FD_ISSET(sock, &sett));
assert(FD_ISSET(sock, &sett) == 0);
return 0;
}
assert(FD_ISSET(sock, &sett));
assert(select_says_yes); // ioctl must agree with select
char buffer[1024];
int n;
unsigned int offset = 0;
while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) ||
errno == EINTR) {
if(n > 0) {
if (((unsigned int) n)+offset > maxsize) {
fprintf(stderr, "too much data!");
finish(EXIT_FAILURE);
}
memcpy(output+offset, buffer, n);
offset += n;
}
}
if (n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
fprintf(stderr, "error in get_all_buf! %d", errno);
finish(EXIT_FAILURE);
}
return offset;
}
void iter(void *arg) {
static char out[1024*2];
static int pos = 0;
fd_set fdr;
int res;
// make sure that sockfd is ready to read
FD_ZERO(&fdr);
FD_SET(sockfd, &fdr);
res = select(64, &fdr, NULL, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
} else if (!FD_ISSET(sockfd, &fdr)) {
return;
}
// perform read write operations ...
int n = get_all_buf(sockfd, out+pos, 1024-pos);
if (n) printf("read! %d\n", n);
pos += n;
if (pos >= EXPECTED_BYTES) {
int i, sum = 0;
for (i=0; i < pos; i++) {
printf("%x\n", out[i]);
sum += out[i];
}
shutdown(sockfd, SHUT_RDWR);
close(sockfd);
printf("sum: %d\n", sum);
finish(sum);
}
}
void main() {
struct sockaddr_in addr;
int res;
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == -1) {
perror("cannot create socket");
finish(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
#if EMSCRIPTEN
emscripten_set_main_loop(iter, 0, 0);
#else
while (1) iter(NULL);
#endif
}

Просмотреть файл

@ -1,138 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#define EXPECTED_BYTES 28
int sockfd;
void finish(int result) {
close(sockfd);
#if EMSCRIPTEN
REPORT_RESULT();
#endif
exit(result);
}
unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) {
int bytes;
if (ioctl(sock, FIONREAD, &bytes)) return 0;
if (bytes == 0) return 0;
char buffer[1024];
int n;
unsigned int offset = 0;
#if TEST_FILE_OPS
while((errno = 0, (n = read(sock, buffer, sizeof(buffer)))>0) ||
#else
while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) ||
#endif
errno == EINTR) {
if(n > 0) {
if (((unsigned int) n)+offset > maxsize) {
fprintf(stderr, "too much data!");
finish(EXIT_FAILURE);
}
memcpy(output+offset, buffer, n);
offset += n;
}
}
if(n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
fprintf(stderr, "error in get_all_buf!");
finish(EXIT_FAILURE);
}
return offset;
}
void iter(void *arg) {
static char out[1024*2];
static int pos = 0;
fd_set fdr;
int res;
// make sure that sockfd is ready to read
FD_ZERO(&fdr);
FD_SET(sockfd, &fdr);
res = select(64, &fdr, NULL, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
} else if (!FD_ISSET(sockfd, &fdr)) {
return;
}
// perform read write operations ...
int n = get_all_buf(sockfd, out+pos, 1024-pos);
if (n) printf("read! %d\n", n);
pos += n;
if (pos >= EXPECTED_BYTES) {
int i, sum = 0;
for (i=0; i < pos; i++) {
printf("%x\n", out[i]);
sum += out[i];
}
shutdown(sockfd, SHUT_RDWR);
close(sockfd);
printf("sum: %d\n", sum);
finish(sum);
}
}
int main() {
struct sockaddr_in addr;
int res;
printf("hello from main page\n");
#if !TEST_DGRAM
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
#else
sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
if (sockfd == -1) {
perror("cannot create socket");
finish(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
#if EMSCRIPTEN
emscripten_run_script("console.log('adding iframe');"
"var iframe = document.createElement('iframe');"
"iframe.src = 'side.html';"
"document.body.appendChild(iframe);"
"console.log('added.');");
emscripten_set_main_loop(iter, 0, 0);
#else
while (1) iter(NULL);
#endif
return EXIT_SUCCESS;
}

Просмотреть файл

@ -1,138 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#include "test_sockets_bigdata.h"
#define EXPECTED_BYTES DATA_SIZE
int sockfd;
void finish(int result) {
close(sockfd);
#if EMSCRIPTEN
REPORT_RESULT();
#endif
exit(result);
}
unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) {
int bytes;
if (ioctl(sock, FIONREAD, &bytes)) return 0;
if (bytes == 0) return 0;
char buffer[EXPECTED_BYTES];
int n;
unsigned int offset = 0;
while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) ||
errno == EINTR) {
if (n > 0) {
if (((unsigned int) n)+offset > maxsize) {
fprintf(stderr, "too much data!");
finish(EXIT_FAILURE);
}
memcpy(output+offset, buffer, n);
offset += n;
}
}
if (n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
fprintf(stderr, "error in get_all_buf!");
finish(EXIT_FAILURE);
}
return offset;
}
void iter(void *arg) {
static char out[EXPECTED_BYTES];
static int pos = 0;
fd_set fdr;
int res;
// make sure that sockfd has finished connecting and is ready to read
FD_ZERO(&fdr);
FD_SET(sockfd, &fdr);
res = select(64, &fdr, NULL, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
return;
} else if (!FD_ISSET(sockfd, &fdr)) {
return;
}
// perform read write operations ...
printf("so far %d, expecting up to %d\n", pos, EXPECTED_BYTES-pos);
res = get_all_buf(sockfd, out+pos, EXPECTED_BYTES-pos);
if (res) printf("read! %d\n", res);
pos += res;
if (pos >= EXPECTED_BYTES) {
shutdown(sockfd, SHUT_RDWR);
close(sockfd);
char *comp = generateData();
int result = strcmp(comp, out);
if (result != 0) {
for (int i = 0; i < DATA_SIZE; i++) {
printf("%d:%d\n", comp[i], out[i]);
}
}
finish(result);
}
}
int main() {
struct sockaddr_in addr;
int res;
printf("hello from main page\n");
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == -1) {
perror("cannot create socket");
finish(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
#if EMSCRIPTEN
emscripten_run_script("console.log('adding iframe');"
"var iframe = document.createElement('iframe');"
"iframe.src = 'side.html';"
"iframe.width = '100%';"
"iframe.width = '40%';"
"document.body.appendChild(iframe);"
"console.log('added.');");
emscripten_set_main_loop(iter, 3, 0);
#else
while (1) iter(NULL);
#endif
return EXIT_SUCCESS;
}

Просмотреть файл

@ -1,93 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#define EXPECTED_BYTES 5
int sockfd = -1;
void finish(int result) {
close(sockfd);
exit(result);
}
void loop() {
fd_set fdw;
int res;
// Make sure that sockfd has actually finished connecting
// and is ready to read.
FD_ZERO(&fdw);
FD_SET(sockfd, &fdw);
res = select(64, NULL, &fdw, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
} else if (!FD_ISSET(sockfd, &fdw)) {
return;
}
char data[] = "hello from the other siide\n";
printf("send..\n");
#if TEST_FILE_OPS
res = write(sockfd, data, sizeof(data));
#else
res = send(sockfd, data, sizeof(data), 0);
#endif
if (res == -1) {
if (errno != EAGAIN) {
perror("send error");
finish(EXIT_FAILURE);
}
return;
}
finish(EXIT_SUCCESS);
}
int main() {
struct sockaddr_in addr;
int res;
#if !TEST_DGRAM
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
#else
sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
if (sockfd == -1) {
perror("cannot create socket");
finish(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
emscripten_set_main_loop(loop, 0, 0);
return EXIT_SUCCESS;
}

Просмотреть файл

@ -1,90 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#include "test_sockets_bigdata.h"
#define EXPECTED_BYTES 5
int sockfd = -1;
char *data = NULL;
void finish(int result) {
close(sockfd);
exit(result);
}
void loop() {
fd_set fdw;
int res;
// make sure that sockfd has finished connecting and is ready to write
FD_ZERO(&fdw);
FD_SET(sockfd, &fdw);
res = select(64, NULL, &fdw, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
return;
} else if (!FD_ISSET(sockfd, &fdw)) {
return;
}
printf("send..\n");
res = send(sockfd, data, DATA_SIZE, 0);
if (res == -1) {
if (errno != EAGAIN) {
perror("send error");
finish(EXIT_FAILURE);
}
return;
}
finish(EXIT_SUCCESS);
}
int main() {
struct sockaddr_in addr;
int res;
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == -1) {
perror("cannot create socket");
exit(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
printf("connect..\n");
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
data = generateData();
emscripten_set_main_loop(loop, 1, 0);
return EXIT_SUCCESS;
}

Просмотреть файл

@ -1,20 +0,0 @@
#include <stdlib.h>
#define DATA_SIZE (256*256*2)
// 1500 fails
char *generateData() {
char *ret = malloc(256*256*2);
char *curr = ret;
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
*curr = i;
curr++;
*curr = j;
curr++;
}
}
return ret;
}

Просмотреть файл

@ -1,112 +0,0 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <assert.h>
#if EMSCRIPTEN
#include <emscripten.h>
#endif
#define EXPECTED_BYTES 5
int sockfd = -1;
void finish(int result) {
close(sockfd);
#if EMSCRIPTEN
REPORT_RESULT();
#endif
exit(result);
}
void iter(void *arg) {
static char readbuf[1024];
static int readPos = 0;
fd_set sett;
FD_ZERO(&sett);
FD_SET(sockfd, &sett);
int res = select(64, &sett, NULL, NULL, NULL);
if (res == -1) {
perror("select failed");
finish(EXIT_FAILURE);
} else if (res == 0) {
return;
} else if (res > 0) {
assert(FD_ISSET(sockfd, &sett));
int bytesRead = recv(sockfd, readbuf+readPos, 7-readPos, 0);
if (bytesRead == -1) {
if (errno != EAGAIN) {
perror("recv error");
finish(EXIT_FAILURE);
}
// try again
return;
}
if (readPos < 7) {
readPos += bytesRead;
} else {
if (!bytesRead) {
perror("Connection to websocket server was closed as expected");
finish(266);
} else {
perror("Connection to websocket server was not closed");
finish(EXIT_FAILURE);
}
}
}
return;
}
// Scenario: the server sends data and closes the connection after 7 bytes.
// This test should provoke the situation in which the underlying
// tcp connection has been torn down already but there is still data
// in the queue. The select call has to succeed as long the queue
// still contains data and only then start to throw errors.
int main() {
struct sockaddr_in addr;
int res;
sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == -1) {
perror("cannot create socket");
finish(EXIT_FAILURE);
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKK);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
perror("inet_pton failed");
finish(EXIT_FAILURE);
}
// This call should succeed (even if the server port is closed)
res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1 && errno != EINPROGRESS) {
perror("connect failed");
finish(EXIT_FAILURE);
}
#if EMSCRIPTEN
emscripten_set_main_loop(iter, 0, 0);
#else
while (1) iter(NULL);
#endif
return EXIT_FAILURE;
}