3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

test-runner: make verbose option -v application specific

The existing verbose option would turn on debug logging for most
processes in the test-runner framework. This change makes the verbose
option more granular. The --verbose or -v option should now be
followed by a comma separated list of the test-runner processes you
want to see debug logging from. Currently iwd, hwsim, ofonod, and
hostapd are valid options to pass to the verbose flag e.g.

-v iwd,hwsim,ofonod,hostapd

Or any single/combination of the above applications.
This commit is contained in:
James Prestwood 2018-01-23 15:28:18 -08:00 committed by Denis Kenzior
parent 973b7b4555
commit 802a8f86ff

View File

@ -57,6 +57,8 @@
#define BIN_HWSIM "hwsim" #define BIN_HWSIM "hwsim"
#define BIN_OFONO "ofonod" #define BIN_OFONO "ofonod"
#define BIN_PHONESIM "phonesim" #define BIN_PHONESIM "phonesim"
#define BIN_HOSTAPD "hostapd"
#define BIN_IWD "iwd"
#define HWSIM_RADIOS_MAX 100 #define HWSIM_RADIOS_MAX 100
#define TEST_MAX_EXEC_TIME_SEC 20 #define TEST_MAX_EXEC_TIME_SEC 20
@ -69,7 +71,8 @@ static enum action {
static const char *own_binary; static const char *own_binary;
static char **test_argv; static char **test_argv;
static int test_argc; static int test_argc;
static bool verbose_out; static char **verbose_apps;
static char *verbose_opt;
static bool enable_debug; static bool enable_debug;
const char *debug_filter; const char *debug_filter;
static const char *qemu_binary; static const char *qemu_binary;
@ -152,6 +155,20 @@ struct wiphy {
char *hostapd_config; char *hostapd_config;
}; };
static bool check_verbosity(const char *app)
{
char **apps = verbose_apps;
while (*apps) {
if (!strcmp(app, *apps))
return true;
apps++;
}
return false;
}
static bool path_exist(const char *path_name) static bool path_exist(const char *path_name)
{ {
struct stat st; struct stat st;
@ -355,10 +372,10 @@ static void start_qemu(void)
"rootflags=trans=virtio,version=9p2000.u " "rootflags=trans=virtio,version=9p2000.u "
"acpi=off pci=noacpi noapic quiet ro " "acpi=off pci=noacpi noapic quiet ro "
"mac80211_hwsim.radios=0 init=%s TESTHOME=%s " "mac80211_hwsim.radios=0 init=%s TESTHOME=%s "
"TESTVERBOUT=%u DEBUG_FILTER=\'%s\'" "TESTVERBOUT=\'%s\' DEBUG_FILTER=\'%s\'"
"TEST_ACTION=%u TEST_ACTION_PARAMS=\'%s\' " "TEST_ACTION=%u TEST_ACTION_PARAMS=\'%s\' "
"TESTARGS=\'%s\' PATH=\'%s\'", "TESTARGS=\'%s\' PATH=\'%s\'",
initcmd, cwd, verbose_out, initcmd, cwd, verbose_opt,
enable_debug ? debug_filter : "", enable_debug ? debug_filter : "",
test_action, test_action,
test_action_params ? test_action_params : "", test_action_params ? test_action_params : "",
@ -388,9 +405,6 @@ static void set_output_visibility(void)
{ {
int fd; int fd;
if (verbose_out)
return;
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
dup2(fd, 1); dup2(fd, 1);
@ -399,7 +413,7 @@ static void set_output_visibility(void)
close(fd); close(fd);
} }
static pid_t execute_program(char *argv[], bool wait) static pid_t execute_program(char *argv[], bool wait, bool verbose)
{ {
int status; int status;
pid_t pid, child_pid; pid_t pid, child_pid;
@ -419,7 +433,8 @@ static pid_t execute_program(char *argv[], bool wait)
} }
if (child_pid == 0) { if (child_pid == 0) {
set_output_visibility(); if (!verbose)
set_output_visibility();
execvp(argv[0], argv); execvp(argv[0], argv);
@ -514,7 +529,7 @@ static bool start_dbus_daemon(void)
argv[1] = "--system"; argv[1] = "--system";
argv[2] = NULL; argv[2] = NULL;
pid = execute_program(argv, false); pid = execute_program(argv, false, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -534,7 +549,7 @@ static bool start_haveged(void)
argv[0] = "haveged"; argv[0] = "haveged";
argv[1] = NULL; argv[1] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -556,7 +571,7 @@ static bool set_interface_state(const char *if_name, bool isUp)
argv[2] = state; argv[2] = state;
argv[3] = NULL; argv[3] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -578,7 +593,7 @@ static bool create_interface(const char *if_name, const char *phy_name)
argv[7] = "managed"; argv[7] = "managed";
argv[8] = NULL; argv[8] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -596,7 +611,7 @@ static bool delete_interface(const char *if_name)
argv[3] = "del"; argv[3] = "del";
argv[4] = NULL; argv[4] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -612,7 +627,7 @@ static bool list_interfaces(void)
argv[1] = "-a"; argv[1] = "-a";
argv[2] = NULL; argv[2] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, true);
if (pid < 0) if (pid < 0)
return false; return false;
@ -628,7 +643,7 @@ static bool list_hwsim_radios(void)
argv[1] = "--list"; argv[1] = "--list";
argv[2] = NULL; argv[2] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, true);
if (pid < 0) if (pid < 0)
return false; return false;
@ -657,7 +672,7 @@ static int create_hwsim_radio(const char *radio_name,
argv[4] = "--nointerface"; argv[4] = "--nointerface";
argv[5] = NULL; argv[5] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return -1; return -1;
@ -676,7 +691,7 @@ static bool destroy_hwsim_radio(int radio_id)
argv[1] = destroy_param; argv[1] = destroy_param;
argv[2] = NULL; argv[2] = NULL;
pid = execute_program(argv, true); pid = execute_program(argv, true, false);
if (pid < 0) if (pid < 0)
return false; return false;
@ -690,7 +705,7 @@ static pid_t register_hwsim_as_trans_medium(void)
argv[0] = BIN_HWSIM; argv[0] = BIN_HWSIM;
argv[1] = NULL; argv[1] = NULL;
return execute_program(argv, false); return execute_program(argv, false, false);
} }
static void terminate_medium(pid_t medium_pid) static void terminate_medium(pid_t medium_pid)
@ -714,13 +729,13 @@ static void start_loopback(void)
argv[2] = "127.0.0.1"; argv[2] = "127.0.0.1";
argv[3] = "up"; argv[3] = "up";
argv[4] = NULL; argv[4] = NULL;
execute_program(argv, false); execute_program(argv, false, false);
argv[0] = "route"; argv[0] = "route";
argv[1] = "add"; argv[1] = "add";
argv[2] = "127.0.0.1"; argv[2] = "127.0.0.1";
argv[3] = NULL; argv[3] = NULL;
execute_program(argv, false); execute_program(argv, false, false);
loopback_started = true; loopback_started = true;
} }
@ -739,7 +754,7 @@ static pid_t start_phonesim(void)
setenv("OFONO_PHONESIM_CONFIG", "/tmp/phonesim.conf", true); setenv("OFONO_PHONESIM_CONFIG", "/tmp/phonesim.conf", true);
return execute_program(argv, false); return execute_program(argv, false, false);
} }
static void stop_phonesim(pid_t pid) static void stop_phonesim(pid_t pid)
@ -750,12 +765,13 @@ static void stop_phonesim(pid_t pid)
static pid_t start_ofono(void) static pid_t start_ofono(void)
{ {
char *argv[5]; char *argv[5];
bool verbose = check_verbosity(BIN_OFONO);
argv[0] = BIN_OFONO; argv[0] = BIN_OFONO;
argv[1] = "-n"; argv[1] = "-n";
argv[2] = "--plugin=atmodem,phonesim"; argv[2] = "--plugin=atmodem,phonesim";
if (verbose_out) if (verbose)
argv[3] = "-d"; argv[3] = "-d";
else else
argv[3] = NULL; argv[3] = NULL;
@ -764,7 +780,7 @@ static pid_t start_ofono(void)
start_loopback(); start_loopback();
return execute_program(argv, false); return execute_program(argv, false, verbose);
} }
static void stop_ofono(pid_t pid) static void stop_ofono(pid_t pid)
@ -775,18 +791,25 @@ static void stop_ofono(pid_t pid)
static pid_t start_hostapd(const char *config_file, const char *interface_name, static pid_t start_hostapd(const char *config_file, const char *interface_name,
const char *ctrl_interface) const char *ctrl_interface)
{ {
char *argv[7]; char *argv[8];
pid_t pid; pid_t pid;
bool verbose = check_verbosity(BIN_HOSTAPD);
argv[0] = "hostapd"; argv[0] = BIN_HOSTAPD;
argv[1] = "-g"; argv[1] = "-g";
argv[2] = (char *) ctrl_interface; argv[2] = (char *) ctrl_interface;
argv[3] = "-i"; argv[3] = "-i";
argv[4] = (char *) interface_name; argv[4] = (char *) interface_name;
argv[5] = (char *) config_file; argv[5] = (char *) config_file;
argv[6] = NULL;
pid = execute_program(argv, false); if (verbose) {
argv[6] = "-d";
argv[7] = NULL;
} else {
argv[6] = NULL;
}
pid = execute_program(argv, false, verbose);
if (pid < 0) { if (pid < 0) {
goto exit; goto exit;
} }
@ -1183,7 +1206,7 @@ static pid_t start_iwd(const char *config_dir, struct l_queue *wiphy_list,
pid_t ret; pid_t ret;
int idx = 0; int idx = 0;
argv[idx++] = "iwd"; argv[idx++] = BIN_IWD;
argv[idx++] = "-c"; argv[idx++] = "-c";
argv[idx++] = (char *) config_dir; argv[idx++] = (char *) config_dir;
argv[idx] = NULL; argv[idx] = NULL;
@ -1218,7 +1241,7 @@ static pid_t start_iwd(const char *config_dir, struct l_queue *wiphy_list,
argv[idx++] = (char *)ext_options; argv[idx++] = (char *)ext_options;
argv[idx] = NULL; argv[idx] = NULL;
ret = execute_program(argv, false); ret = execute_program(argv, false, check_verbosity(BIN_IWD));
if (iwd_phys) if (iwd_phys)
l_free(iwd_phys); l_free(iwd_phys);
@ -1326,9 +1349,7 @@ static void print_test_status(char *test_name, enum test_status ts,
case TEST_STATUS_STARTED: case TEST_STATUS_STARTED:
color_str = CONSOLE_LN_RESET; color_str = CONSOLE_LN_RESET;
status_str = "STARTED "; status_str = "STARTED ";
line_end = "\n";
if (verbose_out)
line_end = "\n";
break; break;
case TEST_STATUS_PASSED: case TEST_STATUS_PASSED:
@ -1482,7 +1503,7 @@ start_next_test:
argv[2] = NULL; argv[2] = NULL;
print_test_status(py_test, TEST_STATUS_STARTED, 0); print_test_status(py_test, TEST_STATUS_STARTED, 0);
test_exec_pid = execute_program(argv, false); test_exec_pid = execute_program(argv, false, false);
gettimeofday(&time_before, NULL); gettimeofday(&time_before, NULL);
@ -1699,7 +1720,7 @@ static void create_network_and_run_tests(const void *key, void *value,
if (medium_pid < 0) if (medium_pid < 0)
goto exit_hwsim; goto exit_hwsim;
if (verbose_out) { if (check_verbosity("hwsim")) {
list_hwsim_radios(); list_hwsim_radios();
list_interfaces(); list_interfaces();
} }
@ -1946,6 +1967,7 @@ static void run_auto_tests(void)
l_queue_destroy(test_stat_queue, test_stat_queue_entry_destroy); l_queue_destroy(test_stat_queue, test_stat_queue_entry_destroy);
exit: exit:
l_strfreev(verbose_apps);
l_strfreev(test_config_dirs); l_strfreev(test_config_dirs);
l_hashmap_destroy(test_config_map, NULL); l_hashmap_destroy(test_config_map, NULL);
} }
@ -1971,7 +1993,7 @@ static void run_unit_tests(void)
argv[0] = unit_test_abs_path; argv[0] = unit_test_abs_path;
argv[1] = NULL; argv[1] = NULL;
execute_program(argv, true); execute_program(argv, true, false);
l_free(unit_test_abs_path); l_free(unit_test_abs_path);
} }
@ -2029,13 +2051,6 @@ static void run_tests(void)
*ptr = '\0'; *ptr = '\0';
ptr = strstr(cmdline, "TESTVERBOUT=1");
if (ptr) {
l_info("Enable verbose output");
verbose_out = true;
}
ptr = strstr(cmdline, "TEST_ACTION_PARAMS="); ptr = strstr(cmdline, "TEST_ACTION_PARAMS=");
if (ptr) { if (ptr) {
@ -2087,6 +2102,24 @@ static void run_tests(void)
} }
} }
ptr = strstr(cmdline, "TESTVERBOUT=");
if (ptr) {
verbose_opt = ptr + 13;
ptr = strchr(verbose_opt, '\'');
if (!ptr) {
l_error("Malformed verbose parameter");
return;
}
*ptr = '\0';
l_info("Enable verbose output for %s", verbose_opt);
verbose_apps = l_strsplit(verbose_opt, ',');
}
ptr = strstr(cmdline, "TESTHOME="); ptr = strstr(cmdline, "TESTHOME=");
if (ptr) { if (ptr) {
@ -2125,7 +2158,9 @@ static void usage(void)
l_info("Options:\n" l_info("Options:\n"
"\t-q, --qemu <path> QEMU binary\n" "\t-q, --qemu <path> QEMU binary\n"
"\t-k, --kernel <image> Kernel image (bzImage)\n" "\t-k, --kernel <image> Kernel image (bzImage)\n"
"\t-v, --verbose Enable verbose output\n" "\t-v, --verbose <apps> Comma separated list of "
"applications to enable\n"
"\t\t\t\tverbose output\n"
"\t-h, --help Show help options\n"); "\t-h, --help Show help options\n");
l_info("Commands:\n" l_info("Commands:\n"
"\t-A, --auto-tests <dirs> Comma separated list of the " "\t-A, --auto-tests <dirs> Comma separated list of the "
@ -2140,7 +2175,7 @@ static const struct option main_options[] = {
{ "unit-tests", required_argument, NULL, 'U' }, { "unit-tests", required_argument, NULL, 'U' },
{ "qemu", required_argument, NULL, 'q' }, { "qemu", required_argument, NULL, 'q' },
{ "kernel", required_argument, NULL, 'k' }, { "kernel", required_argument, NULL, 'k' },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", required_argument, NULL, 'v' },
{ "debug", optional_argument, NULL, 'd' }, { "debug", optional_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ } { }
@ -2167,7 +2202,7 @@ int main(int argc, char *argv[])
for (;;) { for (;;) {
int opt; int opt;
opt = getopt_long(argc, argv, "A:U:q:k:vdh", main_options, opt = getopt_long(argc, argv, "A:U:q:k:v:dh", main_options,
NULL); NULL);
if (opt < 0) if (opt < 0)
break; break;
@ -2182,7 +2217,6 @@ int main(int argc, char *argv[])
test_action = ACTION_UNIT_TEST; test_action = ACTION_UNIT_TEST;
test_action_params = optarg; test_action_params = optarg;
actions++; actions++;
verbose_out = true;
break; break;
case 'q': case 'q':
qemu_binary = optarg; qemu_binary = optarg;
@ -2201,7 +2235,7 @@ int main(int argc, char *argv[])
l_debug_enable(debug_filter); l_debug_enable(debug_filter);
break; break;
case 'v': case 'v':
verbose_out = true; verbose_opt = optarg;
break; break;
case 'h': case 'h':
usage(); usage();