diff options
author | Sergey Kudryashov <[email protected]> | 2014-08-04 18:11:55 +0400 |
---|---|---|
committer | Rickard Green <[email protected]> | 2014-08-05 20:22:28 +0200 |
commit | b29fa5a40e04f4243c15391b70c37ebce0198fc1 (patch) | |
tree | 179b1eb14331aa22739871bc5f3316c66616a108 /erts/emulator/test/async_ports_SUITE_data | |
parent | 961cfeb7b30d721ac8264261d89bb7a4bd3182e5 (diff) | |
download | otp-b29fa5a40e04f4243c15391b70c37ebce0198fc1.tar.gz otp-b29fa5a40e04f4243c15391b70c37ebce0198fc1.tar.bz2 otp-b29fa5a40e04f4243c15391b70c37ebce0198fc1.zip |
Add async_ports test
Diffstat (limited to 'erts/emulator/test/async_ports_SUITE_data')
-rw-r--r-- | erts/emulator/test/async_ports_SUITE_data/Makefile.src | 5 | ||||
-rw-r--r-- | erts/emulator/test/async_ports_SUITE_data/cport.c | 65 |
2 files changed, 70 insertions, 0 deletions
diff --git a/erts/emulator/test/async_ports_SUITE_data/Makefile.src b/erts/emulator/test/async_ports_SUITE_data/Makefile.src new file mode 100644 index 0000000000..17e6a6ee6a --- /dev/null +++ b/erts/emulator/test/async_ports_SUITE_data/Makefile.src @@ -0,0 +1,5 @@ +all: busy_drv@dll@ hard_busy_drv@dll@ soft_busy_drv@dll@ scheduling_drv@dll@ + +@SHLIB_RULES@ + +cport@obj@: cport.c diff --git a/erts/emulator/test/async_ports_SUITE_data/cport.c b/erts/emulator/test/async_ports_SUITE_data/cport.c new file mode 100644 index 0000000000..179cdc4b8b --- /dev/null +++ b/erts/emulator/test/async_ports_SUITE_data/cport.c @@ -0,0 +1,65 @@ +#include <stdlib.h> +#include <stdio.h> +#include <malloc.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> + +typedef unsigned char byte; + +int read_cmd(byte *buf) +{ + int len; + if (read_exact(buf, 4) != 4) + return(-1); + + len = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + return read_exact(buf, len); +} + +int write_cmd(byte *buf, int len) +{ + byte li[4]; + li[0] = (len >> 24) & 0xff; + li[1] = (len >> 16) & 0xff; + li[2] = (len >> 8) & 0xff; + li[3] = len & 0xff; + write_exact(&li, 4); + + return write_exact(buf, len); +} + +int read_exact(byte *buf, int len) +{ + int i, got=0; + do { + if ((i = read(0, buf+got, len-got)) <= 0) + { + return(i); + } + got += i; + } while (got<len); + return len; +} + +int write_exact(byte *buf, int len) +{ + int i, wrote = 0; + do { + if ((i = write(1, buf+wrote, len-wrote)) < 0) + return (i); + wrote += i; + } while (wrote<len); + return len; +} + +int main(int argc, char **argv) { + int sleep_time = atoi(argv[1]); + int fn, arg, res; + byte *buf = malloc(31457280); // 30 mb + int len = 0; + while ((len = read_cmd(buf)) > 0) { + usleep(sleep_time); + write_cmd(buf, len); + } +} |