| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "test.h" |
| 20 |
|
| 21 |
#include <pj/string.h> |
| 22 |
#include <pj/sock.h> |
| 23 |
#include <pj/log.h> |
| 24 |
#include <pj/unittest.h> |
| 25 |
#include <stdio.h> |
| 26 |
|
| 27 |
|
| 28 |
#if 0 |
| 29 |
#include <windows.h> |
| 30 |
static void boost(void) |
| 31 |
{ |
| 32 |
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); |
| 33 |
} |
| 34 |
#else |
| 35 |
#define boost() |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
static void usage() |
| 40 |
{ |
| 41 |
puts("Usage:"); |
| 42 |
puts(" pjlib-test [OPTION] [test_to_run] [..]"); |
| 43 |
puts(""); |
| 44 |
puts("where OPTIONS:"); |
| 45 |
puts(""); |
| 46 |
puts(" -h, --help Show this help screen"); |
| 47 |
|
| 48 |
ut_usage(); |
| 49 |
|
| 50 |
puts(" --skip-e Skip essential tests"); |
| 51 |
puts(" -i Ask ENTER before quitting"); |
| 52 |
puts(" -p PORT Use port PORT for echo port"); |
| 53 |
puts(" -s SERVER Use SERVER as ech oserver"); |
| 54 |
puts(" -t ucp,tcp Set echo socket type to UDP or TCP"); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
int main(int argc, char *argv[]) |
| 59 |
{ |
| 60 |
int rc; |
| 61 |
int interractive = 0; |
| 62 |
|
| 63 |
boost(); |
| 64 |
ut_app_init0(&test_app.ut_app); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
if (pj_argparse_get_bool(&argc, argv, "-h") || |
| 70 |
pj_argparse_get_bool(&argc, argv, "--help")) |
| 71 |
{ |
| 72 |
usage(); |
| 73 |
return 0; |
| 74 |
} |
| 75 |
interractive = pj_argparse_get_bool(&argc, argv, "-i"); |
| 76 |
if (pj_argparse_get_int(&argc, argv, "-p", &test_app.param_echo_port)) { |
| 77 |
usage(); |
| 78 |
return 1; |
| 79 |
} |
| 80 |
if (pj_argparse_get_str(&argc, argv, "-s", |
| 81 |
(char**)&test_app.param_echo_server)) |
| 82 |
{ |
| 83 |
usage(); |
| 84 |
return 1; |
| 85 |
} |
| 86 |
|
| 87 |
if (pj_argparse_exists(argv, "-t")) { |
| 88 |
char *sock_type; |
| 89 |
if (pj_argparse_get_str(&argc, argv, "-t", &sock_type)==PJ_SUCCESS) { |
| 90 |
if (pj_ansi_stricmp(sock_type, "tcp")==0) |
| 91 |
test_app.param_echo_sock_type = pj_SOCK_STREAM(); |
| 92 |
else if (pj_ansi_stricmp(sock_type, "udp")==0) |
| 93 |
test_app.param_echo_sock_type = pj_SOCK_DGRAM(); |
| 94 |
else { |
| 95 |
printf("Error: unknown socket type %s for -t option\n", |
| 96 |
sock_type); |
| 97 |
usage(); |
| 98 |
return 1; |
| 99 |
} |
| 100 |
} else { |
| 101 |
usage(); |
| 102 |
return 1; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
if (ut_parse_args(&test_app.ut_app, &argc, argv)) { |
| 107 |
usage(); |
| 108 |
return 1; |
| 109 |
} |
| 110 |
test_app.param_skip_essentials = pj_argparse_get_bool(&argc, argv, |
| 111 |
"--skip-e"); |
| 112 |
|
| 113 |
|
| 114 |
if (pj_argparse_peek_next_option(argv)) { |
| 115 |
printf("Error: unknown argument %s\n", |
| 116 |
pj_argparse_peek_next_option(argv)); |
| 117 |
usage(); |
| 118 |
return 1; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
rc = test_main(argc, argv); |
| 123 |
|
| 124 |
if (interractive) { |
| 125 |
char s[10]; |
| 126 |
puts(""); |
| 127 |
puts("Press <ENTER> to exit"); |
| 128 |
if (!fgets(s, sizeof(s), stdin)) |
| 129 |
return rc; |
| 130 |
} |
| 131 |
|
| 132 |
return rc; |
| 133 |
} |
| 134 |
|