aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2012-11-02 10:22:27 -0500
committerJoel Martin <github@martintribe.org>2013-01-08 17:36:36 -0600
commit6297b4173cd0481b71df333215d03c60c2e1e85b (patch)
treea17ea5e774ca2d044e6d2e77b2cec18d002df126 /tests
parent4379d19dc217376bb11e9c4172c84ac194409c3c (diff)
Support read/write on socket file descriptors.
Add test_websockets_bi_fileops to test using read and write instead of recv and send respectively. Uses same source files with USE_FILE_OPS define.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py20
-rw-r--r--tests/websockets_bi.c16
-rw-r--r--tests/websockets_bi_side.c7
3 files changed, 27 insertions, 16 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 7a68070c..e4616f49 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10335,20 +10335,22 @@ elif 'browser' in str(sys.argv):
def test_websockets_bi(self):
for datagram in [0,1]:
- try:
- with self.WebsockHarness(8992, self.make_relay_server(8992, 8994)):
- with self.WebsockHarness(8994, no_server=True):
- Popen([PYTHON, EMCC, path_from_root('tests', 'websockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=8995', '-DTEST_DGRAM=%d' % datagram]).communicate()
- self.btest('websockets_bi.c', expected='2499', args=['-DTEST_DGRAM=%d' % datagram])
- finally:
- self.clean_pids()
+ for fileops in [0,1]:
+ try:
+ print >> sys.stderr, 'test_websocket_bi datagram %d, fileops %d' % (datagram, fileops)
+ with self.WebsockHarness(8992, self.make_relay_server(8992, 8994)):
+ with self.WebsockHarness(8994, no_server=True):
+ Popen([PYTHON, EMCC, path_from_root('tests', 'websockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=8995', '-DTEST_DGRAM=%d' % datagram]).communicate()
+ self.btest('websockets_bi.c', expected='2499', args=['-DSOCKK=8993', '-DTEST_DGRAM=%d' % datagram, '-DTEST_FILE_OPS=%s' % fileops])
+ finally:
+ self.clean_pids()
def test_websockets_bi_listen(self):
try:
with self.WebsockHarness(6992, self.make_relay_server(6992, 6994)):
with self.WebsockHarness(6994, no_server=True):
Popen([PYTHON, EMCC, path_from_root('tests', 'websockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=6995']).communicate()
- self.btest('websockets_bi_listener.c', expected='2499')
+ self.btest('websockets_bi_listener.c', expected='2499', args=['-DSOCKK=6993'])
finally:
self.clean_pids()
@@ -10364,7 +10366,7 @@ elif 'browser' in str(sys.argv):
with self.WebsockHarness(3992, self.make_relay_server(3992, 3994)):
with self.WebsockHarness(3994, no_server=True):
Popen([PYTHON, EMCC, path_from_root('tests', 'websockets_bi_side_bigdata.c'), '-o', 'side.html', '-DSOCKK=3995', '-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests')]).communicate()
- self.btest('websockets_bi_bigdata.c', expected='0', args=['-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests')])
+ self.btest('websockets_bi_bigdata.c', expected='0', args=['-DSOCKK=3993', '-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests')])
finally:
self.clean_pids()
diff --git a/tests/websockets_bi.c b/tests/websockets_bi.c
index c2dbb7da..24b84d49 100644
--- a/tests/websockets_bi.c
+++ b/tests/websockets_bi.c
@@ -14,6 +14,10 @@
#define EXPECTED_BYTES 28
+#ifndef SOCKK
+#define SOCKK 8992
+#endif
+
int SocketFD;
unsigned int get_all_buf(int sock, char* output, unsigned int maxsize)
@@ -25,7 +29,11 @@ unsigned int get_all_buf(int sock, char* output, unsigned int maxsize)
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)
{
@@ -96,13 +104,7 @@ int main(void)
memset(&stSockAddr, 0, sizeof(stSockAddr));
stSockAddr.sin_family = AF_INET;
- stSockAddr.sin_port = htons(
-#if EMSCRIPTEN
- 8993
-#else
- 8992
-#endif
- );
+ stSockAddr.sin_port = htons(SOCKK);
Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr);
if (0 > Res) {
diff --git a/tests/websockets_bi_side.c b/tests/websockets_bi_side.c
index 12b790fd..1d557ed8 100644
--- a/tests/websockets_bi_side.c
+++ b/tests/websockets_bi_side.c
@@ -54,10 +54,17 @@ int main(void)
exit(EXIT_FAILURE);
}
+#if TEST_FILE_OPS
+ printf("write..\n");
+
+ char data[] = "hello from the other siide (fileops)\n";
+ write(SocketFD, data, sizeof(data));
+#else
printf("send..\n");
char data[] = "hello from the other siide\n";
send(SocketFD, data, sizeof(data), 0);
+#endif
printf("stall..\n");