diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-10-01 00:26:52 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-10-01 02:13:34 +0100 |
commit | c037100747a1a224160cb12defb600ddfe1ba927 (patch) | |
tree | 8332a7d288116b802866e1ed98d1b950425206f7 /testing/hstox/test_main.c | |
parent | 1977d56caaff40ea9bbf6754b69bec9539a5a969 (diff) |
Import the hstox SUT interface from hstox.
We'll maintain it in the c-toxcore repo, where it belongs.
Diffstat (limited to 'testing/hstox/test_main.c')
-rw-r--r-- | testing/hstox/test_main.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/hstox/test_main.c b/testing/hstox/test_main.c new file mode 100644 index 00000000..7ac18da0 --- /dev/null +++ b/testing/hstox/test_main.c | |||
@@ -0,0 +1,72 @@ | |||
1 | #include "driver.h" | ||
2 | #include "errors.h" | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | |||
7 | // The msgpack-rpc test port expected by the test runner. | ||
8 | #define PORT 1234 | ||
9 | |||
10 | // Timeout in seconds after which the driver shuts down. Currently, a complete | ||
11 | // test run takes about 7 seconds. The timeout of 2 minutes is a guess so it | ||
12 | // keeps working for a while, even on a very slow computer. | ||
13 | #define TIMEOUT 120 | ||
14 | |||
15 | static char const *error_desc(int code) | ||
16 | { | ||
17 | switch (code) { | ||
18 | case E_OK: | ||
19 | return "Success"; | ||
20 | |||
21 | case E_NOMEM: | ||
22 | return "Error: Out of memory"; | ||
23 | |||
24 | case E_SOCKET: | ||
25 | return "Error: socket creation failed"; | ||
26 | |||
27 | case E_BIND: | ||
28 | return "Error: bind failed"; | ||
29 | |||
30 | case E_LISTEN: | ||
31 | return "Error: listen failed"; | ||
32 | |||
33 | case E_ACCEPT: | ||
34 | return "Error: accept failed"; | ||
35 | |||
36 | case E_PARSE: | ||
37 | return "Error: unable to parse msgpack input"; | ||
38 | |||
39 | case E_OPEN: | ||
40 | return "Error: open failed"; | ||
41 | |||
42 | case E_READ: | ||
43 | return "Error: read failed"; | ||
44 | |||
45 | case E_WRITE: | ||
46 | return "Error: write failed"; | ||
47 | |||
48 | case E_SODIUM: | ||
49 | return "Error: libsodium initialisation failed"; | ||
50 | } | ||
51 | |||
52 | return "Unknown error code"; | ||
53 | } | ||
54 | |||
55 | #ifdef __GLASGOW_HASKELL__ | ||
56 | #define main test_main | ||
57 | #endif | ||
58 | int main(void) | ||
59 | { | ||
60 | struct settings cfg = {true, true}; | ||
61 | uint32_t result = network_main(cfg, PORT, TIMEOUT); | ||
62 | int line = result >> 16; | ||
63 | int error = (result >> 8) & 0xff; | ||
64 | int code = result & 0xff; | ||
65 | |||
66 | if (code != E_OK) { | ||
67 | printf("%s, errno=%d, line=%d\n", error_desc(code), error, line); | ||
68 | return EXIT_FAILURE; | ||
69 | } | ||
70 | |||
71 | return EXIT_SUCCESS; | ||
72 | } | ||