Skip to content

Commit

Permalink
ledctl: add tests to verify log_level and log_path
Browse files Browse the repository at this point in the history
Add function to print configuration for test_params option.

Signed-off-by: Pawel Piatkowski <[email protected]>
  • Loading branch information
pawpiatko committed Dec 11, 2023
1 parent 6b77fba commit 99956af
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/ledctl/ledctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,34 @@ static led_status_t _init_ledctl_conf(void)
return ledmon_init_conf(&conf, LED_LOG_LEVEL_WARNING, LEDCTL_DEF_LOG_FILE);
}

static const char *getLogLevelName(enum led_log_level_enum log_level)
{
switch (log_level) {
case LED_LOG_LEVEL_UNDEF:
return "UNDEF";
case LED_LOG_LEVEL_QUIET:
return "QUIET";
case LED_LOG_LEVEL_ERROR:
return "ERROR";
case LED_LOG_LEVEL_WARNING:
return "WARNING";
case LED_LOG_LEVEL_INFO:
return "INFO";
case LED_LOG_LEVEL_DEBUG:
return "DEBUG";
case LED_LOG_LEVEL_ALL:
return "ALL";
default:
return "UNDEF";
}
}

static void print_configuration(void)
{
printf("Log level: %s\n", getLogLevelName(conf.log_level));
printf("Log path: %s\n", conf.log_path);
}

/**
* @brief Propagate the configuration setting to the library settings
*/
Expand Down Expand Up @@ -1127,8 +1155,10 @@ int main(int argc, char *argv[])
_unset_unused_options();

status = _cmdline_parse(argc, argv, &req);
if (status != LED_STATUS_SUCCESS || test_params)
if (status != LED_STATUS_SUCCESS || test_params) {
print_configuration();
exit(status);
}

status = log_open(&conf);
if (status != LED_STATUS_SUCCESS)
Expand Down
46 changes: 46 additions & 0 deletions tests/ledctl/parameters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,49 @@ def test_ibpi_parameters_are_valid_short_test_flag(ledctl_binary, valid_ibpi_com
cmd = LedctlCmd(ledctl_binary)
cmd.is_test_flag_enabled()
cmd.run_ledctl_cmd(valid_ibpi_commands.split())

@pytest.mark.parametrize("valid_warning_level_commands", [
"--list-controllers --log-level=warning -T",
"-P -n vmd --warning -T",
"normal=/dev/nvme0n1 --listed-only --log-level=warning -T",
"normal=/dev/nvme0n1 --listed-only --warning -T",
],)
def test_parameters_log_level_warning(ledctl_binary, valid_warning_level_commands):
cmd = LedctlCmd(ledctl_binary)
cmd.is_test_flag_enabled()
output = cmd.run_ledctl_cmd_decode(valid_warning_level_commands.split())
assert "Log level: WARNING" in output

@pytest.mark.parametrize("valid_debug_level_commands", [
"--list-controllers --log-level=debug -T",
"-P -n vmd --debug -T",
"normal=/dev/nvme0n1 --listed-only --log-level=debug -T",
"normal=/dev/nvme0n1 --listed-only --debug -T",
],)
def test_parameters_log_level_debug(ledctl_binary, valid_debug_level_commands):
cmd = LedctlCmd(ledctl_binary)
cmd.is_test_flag_enabled()
output = cmd.run_ledctl_cmd_decode(valid_debug_level_commands.split())
assert "Log level: DEBUG" in output

@pytest.mark.parametrize("valid_all_level_commands", [
"--list-controllers --log-level=all -T",
"-P -n vmd --all -T",
"normal=/dev/nvme0n1 --listed-only --log-level=all -T",
"normal=/dev/nvme0n1 --listed-only --all -T",
],)
def test_parameters_log_level_all(ledctl_binary, valid_all_level_commands):
cmd = LedctlCmd(ledctl_binary)
cmd.is_test_flag_enabled()
output = cmd.run_ledctl_cmd_decode(valid_all_level_commands.split())
assert "Log level: ALL" in output

@pytest.mark.parametrize("log_path_commands", [
"--list-controllers --log=/root/test.log -T",
"normal=/dev/nvme0n1 --listed-only -l /root/test.log -T",
],)
def test_parameters_log_path(ledctl_binary, log_path_commands):
cmd = LedctlCmd(ledctl_binary)
cmd.is_test_flag_enabled()
output = cmd.run_ledctl_cmd_decode(log_path_commands.split())
assert "Log path: /root/test.log" in output

0 comments on commit 99956af

Please sign in to comment.