tipc_test: allow connecting to arbitrary services
Add an option to specify a service name. Currently only the "connect" test supports this, and will try to connect to the named service instead of the echo and datasink services. Also fix the built-in help text, as it was missing the "burst" option, and didn't mention that the "connect" test connects to both the echo and datasink services. Bug: 200034376 Test: run Change-Id: I3903f94c16320f8e07ac4bfb69e3bb45329138c0
This commit is contained in:
parent
6aaac7cad9
commit
0aae5be54f
1 changed files with 46 additions and 28 deletions
|
@ -45,13 +45,14 @@ static const char *closer3_name = "com.android.ipc-unittest.srv.closer3";
|
|||
static const char *main_ctrl_name = "com.android.ipc-unittest.ctrl";
|
||||
static const char* receiver_name = "com.android.trusty.memref.receiver";
|
||||
|
||||
static const char *_sopts = "hsvD:t:r:m:b:";
|
||||
static const char* _sopts = "hsvDS:t:r:m:b:";
|
||||
/* clang-format off */
|
||||
static const struct option _lopts[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"silent", no_argument, 0, 's'},
|
||||
{"variable",no_argument, 0, 'v'},
|
||||
{"dev", required_argument, 0, 'D'},
|
||||
{"srv", required_argument, 0, 'S'},
|
||||
{"repeat", required_argument, 0, 'r'},
|
||||
{"burst", required_argument, 0, 'b'},
|
||||
{"msgsize", required_argument, 0, 'm'},
|
||||
|
@ -59,24 +60,25 @@ static const struct option _lopts[] = {
|
|||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const char *usage =
|
||||
"Usage: %s [options]\n"
|
||||
"\n"
|
||||
"options:\n"
|
||||
" -h, --help prints this message and exit\n"
|
||||
" -D, --dev name device name\n"
|
||||
" -t, --test name test to run\n"
|
||||
" -r, --repeat cnt repeat count\n"
|
||||
" -m, --msgsize size max message size\n"
|
||||
" -v, --variable variable message size\n"
|
||||
" -s, --silent silent\n"
|
||||
"\n"
|
||||
;
|
||||
static const char* usage =
|
||||
"Usage: %s [options]\n"
|
||||
"\n"
|
||||
"options:\n"
|
||||
" -h, --help prints this message and exit\n"
|
||||
" -D, --dev name device name\n"
|
||||
" -S, --srv name service name\n"
|
||||
" -t, --test name test to run\n"
|
||||
" -r, --repeat cnt repeat count\n"
|
||||
" -b, --burst cnt burst count\n"
|
||||
" -m, --msgsize size max message size\n"
|
||||
" -v, --variable variable message size\n"
|
||||
" -s, --silent silent\n"
|
||||
"\n";
|
||||
|
||||
static const char* usage_long =
|
||||
"\n"
|
||||
"The following tests are available:\n"
|
||||
" connect - connect to datasink service\n"
|
||||
" connect - connect to specified service, defaults to echo+datasink\n"
|
||||
" connect_foo - connect to non existing service\n"
|
||||
" burst_write - send messages to datasink service\n"
|
||||
" echo - send/receive messages to echo service\n"
|
||||
|
@ -98,6 +100,7 @@ static uint opt_msgsize = 32;
|
|||
static uint opt_msgburst = 32;
|
||||
static bool opt_variable = false;
|
||||
static bool opt_silent = false;
|
||||
static char* srv_name = NULL;
|
||||
|
||||
static void print_usage_and_exit(const char *prog, int code, bool verbose)
|
||||
{
|
||||
|
@ -120,6 +123,10 @@ static void parse_options(int argc, char **argv)
|
|||
dev_name = strdup(optarg);
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
srv_name = strdup(optarg);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
test_name = strdup(optarg);
|
||||
break;
|
||||
|
@ -159,26 +166,37 @@ static int connect_test(uint repeat)
|
|||
uint i;
|
||||
int echo_fd;
|
||||
int dsink_fd;
|
||||
int custom_fd;
|
||||
|
||||
if (!opt_silent) {
|
||||
printf("%s: repeat = %u\n", __func__, repeat);
|
||||
}
|
||||
|
||||
for (i = 0; i < repeat; i++) {
|
||||
echo_fd = tipc_connect(dev_name, echo_name);
|
||||
if (echo_fd < 0) {
|
||||
fprintf(stderr, "Failed to connect to '%s' service\n", "echo");
|
||||
}
|
||||
dsink_fd = tipc_connect(dev_name, datasink_name);
|
||||
if (dsink_fd < 0) {
|
||||
fprintf(stderr, "Failed to connect to '%s' service\n", "datasink");
|
||||
}
|
||||
if (srv_name) {
|
||||
custom_fd = tipc_connect(dev_name, srv_name);
|
||||
if (custom_fd < 0) {
|
||||
fprintf(stderr, "Failed to connect to '%s' service\n", srv_name);
|
||||
}
|
||||
if (custom_fd >= 0) {
|
||||
tipc_close(custom_fd);
|
||||
}
|
||||
} else {
|
||||
echo_fd = tipc_connect(dev_name, echo_name);
|
||||
if (echo_fd < 0) {
|
||||
fprintf(stderr, "Failed to connect to '%s' service\n", "echo");
|
||||
}
|
||||
dsink_fd = tipc_connect(dev_name, datasink_name);
|
||||
if (dsink_fd < 0) {
|
||||
fprintf(stderr, "Failed to connect to '%s' service\n", "datasink");
|
||||
}
|
||||
|
||||
if (echo_fd >= 0) {
|
||||
tipc_close(echo_fd);
|
||||
}
|
||||
if (dsink_fd >= 0) {
|
||||
tipc_close(dsink_fd);
|
||||
if (echo_fd >= 0) {
|
||||
tipc_close(echo_fd);
|
||||
}
|
||||
if (dsink_fd >= 0) {
|
||||
tipc_close(dsink_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue