Skip to content

Commit

Permalink
FW: Test mgmt refactor: Use global state to keep the test count.
Browse files Browse the repository at this point in the history
Signed-off-by: Arzhan Kinzhalin <arzhan.i.kinzhalin@intel.com>
  • Loading branch information
busykai committed Apr 9, 2024
1 parent cc8b4f8 commit be87b1f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
7 changes: 3 additions & 4 deletions framework/logging.cpp
Expand Up @@ -2599,19 +2599,18 @@ void YamlLogger::print_tests_header(TestHeaderTime mode)

/// prints the results from running the test \c{test} (test number \c{tc})
/// and returns the effective test result
TestResult logging_print_results(std::span<const ChildExitStatus> status, int *tc, const struct test *test)
TestResult logging_print_results(std::span<const ChildExitStatus> status, const struct test *test)
{
int n = ++*tc;
switch (current_output_format()) {
case SandstoneApplication::OutputFormat::key_value: {
KeyValuePairLogger l(test, status);
l.print(n);
l.print(sApp->current_test_count);
return l.testResult;
}

case SandstoneApplication::OutputFormat::tap: {
TapFormatLogger l(test, status);
l.print(n);
l.print(sApp->current_test_count);
return l.testResult;
}

Expand Down
42 changes: 22 additions & 20 deletions framework/sandstone.cpp
Expand Up @@ -1591,7 +1591,7 @@ struct ChildrenList
};
} // unnamed namespace

static void wait_for_children(ChildrenList &children, int *tc, const struct test *test)
static void wait_for_children(ChildrenList &children, const struct test *test)
{
Duration remaining = test_timeout(sApp->current_test_duration);
int children_left = children.handles.size();
Expand Down Expand Up @@ -1756,7 +1756,7 @@ static void wait_for_children(ChildrenList &children, int *tc, const struct test
// (child has likely not been able to write results)
int exit_code = 128 | ret;

logging_print_results(children.results, tc, test);
logging_print_results(children.results, test);
exit_code = cleanup_global(exit_code, {});

// now exit with the same signal
Expand Down Expand Up @@ -2077,7 +2077,7 @@ static int slices_for_test(const struct test *test)
return plan.size();
}

static void run_one_test_children(ChildrenList &children, int *tc, const struct test *test)
static void run_one_test_children(ChildrenList &children, const struct test *test)
{
int child_count = slices_for_test(test);
if (sApp->current_fork_mode() != SandstoneApplication::exec_each_test) {
Expand Down Expand Up @@ -2109,12 +2109,14 @@ static void run_one_test_children(ChildrenList &children, int *tc, const struct
}

/* wait for the children */
wait_for_children(children, tc, test);
wait_for_children(children, test);
}

static TestResult run_one_test_once(int *tc, const struct test *test)
static TestResult run_one_test_once(const struct test *test)
{
ChildrenList children;

sApp->current_test_count++;
if (uint64_t missing = (test->minimum_cpu | test->compiler_minimum_cpu) & ~cpu_features) {
init_per_thread_data();

Expand All @@ -2125,11 +2127,11 @@ static TestResult run_one_test_once(int *tc, const struct test *test)

children.results.emplace_back(ChildExitStatus{ TestResult::Skipped });
} else {
run_one_test_children(children, tc, test);
run_one_test_children(children, test);
}

// print results and find out if the test failed
TestResult testResult = logging_print_results(children.results, tc, test);
TestResult testResult = logging_print_results(children.results, test);
switch (testResult) {
case TestResult::Passed:
case TestResult::Skipped:
Expand Down Expand Up @@ -2158,7 +2160,7 @@ static TestResult run_one_test_once(int *tc, const struct test *test)
return testResult;
}

static void analyze_test_failures(int tc, const struct test *test, int fail_count, int attempt_count,
static void analyze_test_failures(const struct test *test, int fail_count, int attempt_count,
const SandstoneApplication::PerCpuFailures &per_cpu_failures)
{
logging_printf(LOG_LEVEL_VERBOSE(1), "# Test failed %d out of %d times"
Expand Down Expand Up @@ -2271,7 +2273,7 @@ static void analyze_test_failures(int tc, const struct test *test, int fail_coun
}
}

TestResult run_one_test(int *tc, const struct test *test, SandstoneApplication::PerCpuFailures &per_cpu_fails)
TestResult run_one_test(const struct test *test, SandstoneApplication::PerCpuFailures &per_cpu_fails)
{
TestResult state = TestResult::Skipped;
int fail_count = 0;
Expand Down Expand Up @@ -2335,7 +2337,7 @@ TestResult run_one_test(int *tc, const struct test *test, SandstoneApplication::
sApp->shmem->current_test_endtime =
calculate_wallclock_deadline(sApp->current_test_duration - runtime,
&sApp->current_test_starttime);
state = run_one_test_once(tc, test);
state = run_one_test_once(test);
runtime += MonotonicTimePoint::clock::now() - sApp->current_test_starttime;

cleanup_internal(test);
Expand Down Expand Up @@ -2389,14 +2391,14 @@ TestResult run_one_test(int *tc, const struct test *test, SandstoneApplication::
sApp->shmem->current_test_endtime =
calculate_wallclock_deadline(sApp->current_test_duration,
&sApp->current_test_starttime);
state = run_one_test_once(tc, test);
state = run_one_test_once(test);
cleanup_internal(test);

if (state > TestResult::Passed)
mark_up_per_cpu_fail(iterations);
}

analyze_test_failures(*tc, test, fail_count, iterations, per_cpu_fails);
analyze_test_failures(test, fail_count, iterations, per_cpu_fails);
state = TestResult::Failed;
}

Expand Down Expand Up @@ -2514,13 +2516,13 @@ static struct test *get_next_test_iteration(void)
return RESTART_OF_TESTS;
}

static struct test *get_next_test(SandstoneTestSet::TestSetIterator &it, int tc)
static struct test *get_next_test(SandstoneTestSet::TestSetIterator &it)
{
if (sApp->shmem->use_strict_runtime && wallclock_deadline_has_expired(sApp->endtime))
return nullptr;

if constexpr (InterruptMonitor::InterruptMonitorWorks) {
if (sApp->mce_check_period && tc % sApp->mce_check_period == sApp->mce_check_period - 1
if (sApp->mce_check_period && sApp->current_test_count % sApp->mce_check_period == sApp->mce_check_period - 1
&& test_set->is_disabled(mce_test.id))
return &mce_test;
}
Expand Down Expand Up @@ -2617,7 +2619,7 @@ static vector<int> run_triage(vector<const struct test *> &triage_tests)
do {
int test_count = 1;
for (auto &t: triage_tests) {
ret = test_result_to_exit_code(run_one_test(&test_count, t, per_cpu_failures));
ret = test_result_to_exit_code(run_one_test(t, per_cpu_failures));
if (ret > EXIT_SUCCESS) break; // EXIT_SKIP is OK
test_count++;
}
Expand Down Expand Up @@ -3195,7 +3197,6 @@ int main(int argc, char **argv)
const char *seed = nullptr;
int max_cores_per_slice = 0;
int opt;
int tc = 0;
int total_failures = 0;
int total_successes = 0;
int total_skips = 0;
Expand Down Expand Up @@ -3797,13 +3798,14 @@ int main(int argc, char **argv)
vector<const struct test *> triage_tests;

bool restarting = true;
sApp->current_test_count = 0;
int total_tests_run = 0;
TestResult lastTestResult = TestResult::Skipped;
auto it = test_set->begin();

for (struct test *test = get_next_test(it, tc); test; test = get_next_test(it, tc)) {
for (struct test *test = get_next_test(it); test; test = get_next_test(it)) {
if (restarting){
tc = 0;
sApp->current_test_count = 0;
logging_print_iteration_start();
initialize_smi_counts(); // used by smi_count test
} else if (lastTestResult != TestResult::Skipped) {
Expand Down Expand Up @@ -3832,7 +3834,7 @@ int main(int argc, char **argv)
continue;
}

lastTestResult = run_one_test(&tc, test, per_cpu_failures);
lastTestResult = run_one_test(test, per_cpu_failures);

total_tests_run++;
if (lastTestResult == TestResult::Failed) {
Expand All @@ -3855,7 +3857,7 @@ int main(int argc, char **argv)
// Run the mce_test at the end of all tests to make sure no MCE errors fired
if constexpr (InterruptMonitor::InterruptMonitorWorks) {
if (total_failures == 0 && !test_set->is_disabled(mce_test.id)) {
if (run_one_test(&tc, &mce_test, per_cpu_failures) == TestResult::Failed)
if (run_one_test(&mce_test, per_cpu_failures) == TestResult::Failed)
++total_failures;
else
++total_successes;
Expand Down
3 changes: 2 additions & 1 deletion framework/sandstone_p.h
Expand Up @@ -381,6 +381,7 @@ struct SandstoneApplication : public InterruptMonitor, public test_the_test_data
int max_test_count = INT_MAX;
int max_test_loop_count = 0;
int current_iteration_count; // iterations of the same test (positive for fracture; negative for retest)
int current_test_count;
MonotonicTimePoint starttime = MonotonicTimePoint::clock::now();
MonotonicTimePoint endtime;
MonotonicTimePoint current_test_starttime;
Expand Down Expand Up @@ -674,7 +675,7 @@ void logging_init(const struct test *test);
void logging_init_child_preexec();
void logging_finish();
LoggingStream logging_user_messages_stream(int thread_num, int level);
TestResult logging_print_results(std::span<const ChildExitStatus> status, int *tc, const struct test *test);
TestResult logging_print_results(std::span<const ChildExitStatus> status, const struct test *test);

/* random.cpp */
void random_init_global(const char *argument);
Expand Down

0 comments on commit be87b1f

Please sign in to comment.