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: log iwd output for --shell

This will allow the user to see the iwd output in /tmp/iwd.log.

execute_program was extended to take a 'log' flag. If true, this
will cause the programs output to be stored in /tmp/<name>.log.
This is only useful when using the --shell command as this file
will go away once the VM stops. The verbose flag always overrides
the logging functionality.

For now only iwd output is logged when using --shell.
This commit is contained in:
James Prestwood 2019-08-05 11:17:47 -07:00 committed by Denis Kenzior
parent 5af5498aa9
commit d2639e5d4e

View File

@ -490,7 +490,7 @@ static bool start_qemu(void)
return true;
}
static pid_t execute_program(char *argv[], bool wait, bool verbose)
static pid_t execute_program(char *argv[], bool wait, bool verbose, bool log)
{
int status;
pid_t pid, child_pid;
@ -511,7 +511,16 @@ static pid_t execute_program(char *argv[], bool wait, bool verbose)
if (child_pid == 0) {
if (!verbose) {
int fd = open("/dev/null", O_WRONLY);
int fd;
char log_file[PATH_MAX];
if (!log)
fd = open("/dev/null", O_WRONLY);
else {
sprintf(log_file, "/tmp/%s.log", argv[0]);
fd = open(log_file, O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR);
}
dup2(fd, 1);
dup2(fd, 2);
@ -617,7 +626,7 @@ static bool start_dbus_daemon(void)
if (check_verbosity("dbus"))
setenv("DBUS_VERBOSE", "1", true);
pid = execute_program(argv, false, check_verbosity("dbus"));
pid = execute_program(argv, false, check_verbosity("dbus"), false);
if (pid < 0)
return false;
@ -628,7 +637,7 @@ static bool start_dbus_daemon(void)
argv[0] = "dbus-monitor";
argv[1] = "--system";
argv[2] = NULL;
execute_program(argv, false, true);
execute_program(argv, false, true, false);
}
l_debug("D-Bus is running");
@ -644,7 +653,7 @@ static bool start_haveged(void)
argv[0] = "haveged";
argv[1] = NULL;
pid = execute_program(argv, true, false);
pid = execute_program(argv, true, false, false);
if (pid < 0)
return false;
@ -666,7 +675,7 @@ static bool set_interface_state(const char *if_name, bool isUp)
argv[2] = state;
argv[3] = NULL;
pid = execute_program(argv, true, false);
pid = execute_program(argv, true, false, false);
if (pid < 0)
return false;
@ -688,7 +697,7 @@ static bool create_interface(const char *if_name, const char *phy_name)
argv[7] = "managed";
argv[8] = NULL;
pid = execute_program(argv, true, false);
pid = execute_program(argv, true, false, false);
if (pid < 0)
return false;
@ -706,7 +715,7 @@ static bool delete_interface(const char *if_name)
argv[3] = "del";
argv[4] = NULL;
pid = execute_program(argv, true, false);
pid = execute_program(argv, true, false, false);
if (pid < 0)
return false;
@ -722,7 +731,7 @@ static bool list_interfaces(void)
argv[1] = "-a";
argv[2] = NULL;
pid = execute_program(argv, true, true);
pid = execute_program(argv, true, true, false);
if (pid < 0)
return false;
@ -738,7 +747,7 @@ static bool list_hwsim_radios(void)
argv[1] = "--list";
argv[2] = NULL;
pid = execute_program(argv, true, true);
pid = execute_program(argv, true, true, false);
if (pid < 0)
return false;
@ -786,7 +795,7 @@ static int create_hwsim_radio(const char *radio_name,
argv[idx] = NULL;
pid = execute_program(argv, true, check_verbosity(BIN_HWSIM));
pid = execute_program(argv, true, check_verbosity(BIN_HWSIM), false);
if (pid < 0)
return -1;
@ -805,7 +814,7 @@ static bool destroy_hwsim_radio(int radio_id)
argv[1] = destroy_param;
argv[2] = NULL;
pid = execute_program(argv, true, false);
pid = execute_program(argv, true, false, false);
if (pid < 0)
return false;
@ -825,7 +834,7 @@ static pid_t register_hwsim_as_trans_medium(void)
argv[idx++] = BIN_HWSIM;
argv[idx++] = NULL;
return execute_program(argv, false, check_verbosity(BIN_HWSIM));
return execute_program(argv, false, check_verbosity(BIN_HWSIM), false);
}
static void terminate_medium(pid_t medium_pid)
@ -849,13 +858,13 @@ static void start_loopback(void)
argv[2] = "127.0.0.1";
argv[3] = "up";
argv[4] = NULL;
execute_program(argv, false, false);
execute_program(argv, false, false, false);
argv[0] = "route";
argv[1] = "add";
argv[2] = "127.0.0.1";
argv[3] = NULL;
execute_program(argv, false, false);
execute_program(argv, false, false, false);
loopback_started = true;
}
@ -874,7 +883,7 @@ static pid_t start_phonesim(void)
setenv("OFONO_PHONESIM_CONFIG", "/tmp/phonesim.conf", true);
return execute_program(argv, false, false);
return execute_program(argv, false, false, false);
}
static void stop_phonesim(pid_t pid)
@ -900,7 +909,7 @@ static pid_t start_ofono(void)
start_loopback();
return execute_program(argv, false, verbose);
return execute_program(argv, false, verbose, false);
}
static void stop_ofono(pid_t pid)
@ -955,7 +964,7 @@ static pid_t start_hostapd(char **config_files, struct wiphy **wiphys)
argv[idx++] = NULL;
}
pid = execute_program(argv, false, verbose);
pid = execute_program(argv, false, verbose, false);
if (pid < 0) {
goto exit;
}
@ -1404,7 +1413,7 @@ static pid_t start_iwd(const char *config_dir, struct l_queue *wiphy_list,
argv[idx++] = "-c";
argv[idx++] = (char *) config_dir;
if (check_verbosity(BIN_IWD))
if (check_verbosity(BIN_IWD) || shell)
argv[idx++] = "-d";
argv[idx] = NULL;
@ -1445,7 +1454,7 @@ static pid_t start_iwd(const char *config_dir, struct l_queue *wiphy_list,
argv[idx++] = (char *)ext_options;
argv[idx] = NULL;
ret = execute_program(argv, false, check_verbosity(BIN_IWD));
ret = execute_program(argv, false, check_verbosity(BIN_IWD), shell);
if (iwd_phys)
l_free(iwd_phys);
@ -1700,7 +1709,7 @@ start_next_test:
print_test_status(py_test, TEST_STATUS_STARTED, 0);
test_exec_pid = execute_program(argv, false,
check_verbosity("pytests"));
check_verbosity("pytests"), false);
gettimeofday(&time_before, NULL);
@ -1841,7 +1850,7 @@ static void set_reg_domain(const char *domain)
argv[3] = (char *) domain;
argv[4] = NULL;
execute_program(argv, false, false);
execute_program(argv, false, false, false);
}
static void wiphy_up(void *data, void *user_data)
@ -2310,7 +2319,7 @@ static void run_unit_tests(void)
argv[0] = unit_test_abs_path;
argv[1] = NULL;
execute_program(argv, true, check_verbosity("unit"));
execute_program(argv, true, check_verbosity("unit"), false);
l_free(unit_test_abs_path);
}