mbox series

[v3,0/3] selftests/resctrl: Simplify test cleanup functions

Message ID cover.1708599491.git.maciej.wieczor-retman@intel.com
Headers show
Series selftests/resctrl: Simplify test cleanup functions | expand

Message

Maciej Wieczor-Retman Feb. 22, 2024, 12:06 p.m. UTC
Cleaning up after tests is implemented separately for individual tests
and called at the end of each test execution. Since these functions are
very similar and a more generalized test framework was introduced a
function pointer in the resctrl_test struct can be used to reduce the
amount of function calls.

These functions are also all called in the ctrl-c handler because the
handler isn't aware which test is currently running. Since the handler
is implemented with a sigaction no function parameters can be passed
there but information about what test is currently running can be passed
with a global variable.

Changelog v3:
- Make current_test static.
- Add callback NULL check to the ctrl-c handler.

Changelog v2:
- Make current_test a const pointer limited in scope to resctrl_val
  file.
- Remove tests_cleanup from resctrl.h.
- Cleanup 'goto out' path and labels in individual test functions.

Older versions of this series:
[v1] https://lore.kernel.org/all/cover.1708434017.git.maciej.wieczor-retman@intel.com/
[v2] https://lore.kernel.org/all/cover.1708596015.git.maciej.wieczor-retman@intel.com/

Maciej Wieczor-Retman (3):
  selftests/resctrl: Add cleanup function to test framework
  selftests/resctrl: Simplify cleanup in ctrl-c handler
  selftests/resctrl: Move cleanups out of individual tests

 tools/testing/selftests/resctrl/cat_test.c      |  8 +++-----
 tools/testing/selftests/resctrl/cmt_test.c      |  4 ++--
 tools/testing/selftests/resctrl/mba_test.c      |  8 +++-----
 tools/testing/selftests/resctrl/mbm_test.c      |  8 +++-----
 tools/testing/selftests/resctrl/resctrl.h       |  9 +++------
 tools/testing/selftests/resctrl/resctrl_tests.c | 16 +++++-----------
 tools/testing/selftests/resctrl/resctrl_val.c   |  7 +++++--
 7 files changed, 24 insertions(+), 36 deletions(-)

Comments

Reinette Chatre Feb. 23, 2024, 9:18 p.m. UTC | #1
Hi Maciej,

On 2/22/2024 4:07 AM, Maciej Wieczor-Retman wrote:
> diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
> index 161f5365b4f0..bae08d1221ec 100644
> --- a/tools/testing/selftests/resctrl/resctrl_tests.c
> +++ b/tools/testing/selftests/resctrl/resctrl_tests.c
> @@ -134,6 +134,8 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
>  	}
>  
>  	ret = test->run_test(test, uparams);
> +	if (test->cleanup)
> +		test->cleanup();
>  	ksft_test_result(!ret, "%s: test\n", test->name);
>  
>  cleanup:

I think this can be potentially confusing to do cleanup here and
then follow it with a test_cleanup(). Could this test specific
cleanup perhaps be called from the general test_cleanup() instead?

Reinette