diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-16 11:21:40 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-17 12:44:21 -0700 |
commit | 87830ba9c03cd445583e148183a38e1345a4a0bd (patch) | |
tree | 0125834f37eb0939ad7dc69e308121916540afd5 /tests | |
parent | 5e2d3c4595aa28199a9f60c7cbd8cc699abbd32e (diff) |
add non-working websockets test for large amounts of 'random' data
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 10 | ||||
-rw-r--r-- | tests/websockets_bi_bigdata.c | 137 | ||||
-rw-r--r-- | tests/websockets_bi_side_bigdata.c | 69 | ||||
-rw-r--r-- | tests/websockets_bigdata.h | 20 |
4 files changed, 236 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 8e1eaeba..de8acaef 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -9015,6 +9015,7 @@ elif 'browser' in str(sys.argv): def websockify_func(q): print >> sys.stderr, 'running websockify on %d, forward to tcp %d' % (self.port+1, self.port) proc = Popen([path_from_root('third_party', 'websockify', 'other', 'websockify'), '-vvv', str(self.port+1), '127.0.0.1:' + str(self.port)]) + #proc = Popen([path_from_root('third_party', 'websockify', 'websockify.py'), '-vvv', str(self.port+1), '127.0.0.1:' + str(self.port)]) q.put(proc.pid) proc.communicate() @@ -9074,6 +9075,15 @@ elif 'browser' in str(sys.argv): finally: self.clean_pids() + def zzztest_zz_websockets_bi_bigdata(self): + try: + 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')]) + finally: + self.clean_pids() + def zzztest_zz_enet(self): try_delete(self.in_dir('enet')) shutil.copytree(path_from_root('tests', 'enet'), self.in_dir('enet')) diff --git a/tests/websockets_bi_bigdata.c b/tests/websockets_bi_bigdata.c new file mode 100644 index 00000000..9e8635e3 --- /dev/null +++ b/tests/websockets_bi_bigdata.c @@ -0,0 +1,137 @@ +#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 <sys/ioctl.h> +#if EMSCRIPTEN +#include <emscripten.h> +#endif + +#include "websockets_bigdata.h" + +#define EXPECTED_BYTES DATA_SIZE + +int SocketFD; + +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!"); exit(EXIT_FAILURE); } + memcpy(output+offset, buffer, n); + offset += n; + } + } + + if(n < 0) { + fprintf(stderr, "error in get_all_buf!"); + exit(EXIT_FAILURE); + } + return offset; +} + +int done = 0; + +void iter(void *arg) { + /* perform read write operations ... */ + static char out[EXPECTED_BYTES]; + static int pos = 0; + printf("so far %d, expecting up to %d\n", pos, EXPECTED_BYTES-pos); + int n = get_all_buf(SocketFD, out+pos, EXPECTED_BYTES-pos); + if (n) printf("read! %d\n", n); + pos += n; + if (pos >= EXPECTED_BYTES) { + shutdown(SocketFD, SHUT_RDWR); + + close(SocketFD); + + done = 1; + + emscripten_cancel_main_loop(); + +#if EMSCRIPTEN + 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]); + } + } + REPORT_RESULT(); +#endif + } +} + +int main(void) +{ + printf("hello from main page\n"); + + struct sockaddr_in stSockAddr; + int Res; + SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (-1 == SocketFD) + { + perror("cannot create socket"); + exit(EXIT_FAILURE); + } + + memset(&stSockAddr, 0, sizeof(stSockAddr)); + + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons( +#if EMSCRIPTEN + 3993 +#else + 3992 +#endif + ); + Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr); + + if (0 > Res) { + perror("error: first parameter is not a valid address family"); + close(SocketFD); + exit(EXIT_FAILURE); + } else if (0 == Res) { + perror("char string (second parameter does not contain valid ipaddress)"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { + perror("connect failed"); + close(SocketFD); + exit(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, 1, 0); +#else + while (!done) iter(NULL); +#endif + + return EXIT_SUCCESS; +} + diff --git a/tests/websockets_bi_side_bigdata.c b/tests/websockets_bi_side_bigdata.c new file mode 100644 index 00000000..9b67fe4c --- /dev/null +++ b/tests/websockets_bi_side_bigdata.c @@ -0,0 +1,69 @@ +#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 <sys/ioctl.h> +#if EMSCRIPTEN +#include <emscripten.h> +#endif + +#include "websockets_bigdata.h" + +#define EXPECTED_BYTES 5 + +void stall(void *arg) { +} + +int main(void) +{ + struct sockaddr_in stSockAddr; + int Res; + int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (-1 == SocketFD) + { + perror("cannot create socket"); + exit(EXIT_FAILURE); + } + + memset(&stSockAddr, 0, sizeof(stSockAddr)); + + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(SOCKK); + Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr); + + if (0 > Res) { + perror("error: first parameter is not a valid address family"); + close(SocketFD); + exit(EXIT_FAILURE); + } else if (0 == Res) { + perror("char string (second parameter does not contain valid ipaddress)"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + printf("connect..\n"); + + if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { + perror("connect failed"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + printf("send..\n"); + + char *data = generateData(); + send(SocketFD, data, DATA_SIZE, 0); + + printf("stall..\n"); + + emscripten_set_main_loop(stall, 1, 0); + + return EXIT_SUCCESS; +} + diff --git a/tests/websockets_bigdata.h b/tests/websockets_bigdata.h new file mode 100644 index 00000000..fa1a6b17 --- /dev/null +++ b/tests/websockets_bigdata.h @@ -0,0 +1,20 @@ + +#include <stdlib.h> + +#define DATA_SIZE 1250 +// 1500 fails + +char *generateData() { + char *ret = malloc(65536*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; +} + |