unit-tests: Allow configuring log levels for individual groups

This commit is contained in:
Tobias Brunner 2021-07-27 18:37:26 +02:00
parent 35edbc4048
commit 23b0220b1c
2 changed files with 47 additions and 5 deletions

View File

@ -300,17 +300,33 @@ METHOD(exchange_test_helper_t, add_listener, void,
*/
static void initialize_logging()
{
int level = LEVEL_SILENT;
char *verbosity;
char buf[BUF_LEN], *verbosity;
level_t level;
debug_t group;
lib->settings->set_default_str(lib->settings, "%s.filelog.stderr.default",
"-1", lib->ns);
verbosity = getenv("TESTS_VERBOSITY");
if (verbosity)
{
level = atoi(verbosity);
lib->settings->set_int(lib->settings, "%s.filelog.stderr.default",
level, lib->ns);
}
for (group = 0; group < DBG_MAX; group++)
{
snprintf(buf, sizeof(buf), "TESTS_VERBOSITY_%s",
enum_to_name(debug_names, group));
verbosity = getenv(buf);
if (verbosity)
{
level = atoi(verbosity);
lib->settings->set_int(lib->settings, "%s.filelog.stderr.%N",
level, lib->ns, debug_lower_names, group);
}
}
lib->settings->set_int(lib->settings, "%s.filelog.stderr.default",
lib->settings->get_int(lib->settings, "%s.filelog.stderr.default",
level, lib->ns), lib->ns);
lib->settings->set_bool(lib->settings, "%s.filelog.stderr.ike_name", TRUE,
lib->ns);
charon->load_loggers(charon);

View File

@ -735,6 +735,30 @@ static bool run_suite(test_suite_t *suite, test_runner_init_t init, char *cfg,
return FALSE;
}
/**
* Configure log levels for specific groups
*/
static void setup_log_levels(level_t *base)
{
char buf[BUF_LEN], *verbosity;
debug_t group;
level_t level;
for (group = 0; group < DBG_MAX; group++)
{
snprintf(buf, sizeof(buf), "TESTS_VERBOSITY_%s",
enum_to_name(debug_names, group));
verbosity = getenv(buf);
if (verbosity)
{
level = atoi(verbosity);
dbg_default_set_level_group(group, level);
*base = max(*base, level);
}
}
}
/**
* See header.
*/
@ -772,6 +796,8 @@ int test_runner_run(const char *name, test_configuration_t configs[],
}
dbg_default_set_level(level);
setup_log_levels(&level);
fprintf(stderr, "Running %u '%s' test suites:\n", array_count(suites), name);
enumerator = array_create_enumerator(suites);