selftests/resctrl: Move cleanups out of individual tests
authorMaciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Tue, 27 Feb 2024 07:21:43 +0000 (08:21 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 6 May 2024 19:57:19 +0000 (13:57 -0600)
Every test calls its cleanup function at the end of it's test function.
After the cleanup function pointer is added to the test framework this
can be simplified to executing the callback function at the end of the
generic test running function.

Make test cleanup functions static and call them from the end of
run_single_test() from the resctrl_test's cleanup function pointer.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/cat_test.c
tools/testing/selftests/resctrl/cmt_test.c
tools/testing/selftests/resctrl/mba_test.c
tools/testing/selftests/resctrl/mbm_test.c
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_tests.c

index 8fa4348ab4611d492da2cb609c8c11cbbe0e676b..c7686fb6641a7155f36fc9107beed4e1e13f4330 100644 (file)
@@ -128,7 +128,7 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type
        return fail;
 }
 
-void cat_test_cleanup(void)
+static void cat_test_cleanup(void)
 {
        remove(RESULT_FILE_NAME);
 }
@@ -284,13 +284,10 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
 
        ret = cat_test(test, uparams, &param, span, start_mask);
        if (ret)
-               goto out;
+               return ret;
 
        ret = check_results(&param, test->resource,
                            cache_total_size, full_cache_mask, start_mask);
-out:
-       cat_test_cleanup();
-
        return ret;
 }
 
index a01ccf86e6ced8e5ae27a9712cb341fa30ea5f4c..a44e6fcd37b73578cfa1d58b549a0ca59f230ea1 100644 (file)
@@ -91,7 +91,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of
                                 MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true);
 }
 
-void cmt_test_cleanup(void)
+static void cmt_test_cleanup(void)
 {
        remove(RESULT_FILE_NAME);
 }
@@ -161,7 +161,6 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
                ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
 
 out:
-       cmt_test_cleanup();
        free(span_str);
 
        return ret;
index 189fbe20dc7bc5917b979c8f46fbf376d6ec7e7d..5d6af9e8afedd1d39156ce6118fac1c46d17e945 100644 (file)
@@ -137,7 +137,7 @@ static int check_results(void)
        return show_mba_info(bw_imc, bw_resc);
 }
 
-void mba_test_cleanup(void)
+static void mba_test_cleanup(void)
 {
        remove(RESULT_FILE_NAME);
 }
@@ -158,13 +158,10 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
 
        ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
        if (ret)
-               goto out;
+               return ret;
 
        ret = check_results();
 
-out:
-       mba_test_cleanup();
-
        return ret;
 }
 
index 73d6a8b989f571a172f8295b7a779f63a8747615..3059ccc51a5ab027c144ebb21e3e89e8fac7da2a 100644 (file)
@@ -105,7 +105,7 @@ static int mbm_setup(const struct resctrl_test *test,
        return ret;
 }
 
-void mbm_test_cleanup(void)
+static void mbm_test_cleanup(void)
 {
        remove(RESULT_FILE_NAME);
 }
@@ -126,15 +126,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
 
        ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
        if (ret)
-               goto out;
+               return ret;
 
        ret = check_results(DEFAULT_SPAN);
        if (ret && (get_vendor() == ARCH_INTEL))
                ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
 
-out:
-       mbm_test_cleanup();
-
        return ret;
 }
 
index bc486f92aceb785e8e7cbd9207dd24844741c69b..00d51fa7531cea4d660a6758fe95eaaf9456dacb 100644 (file)
@@ -158,8 +158,6 @@ int resctrl_val(const struct resctrl_test *test,
                const struct user_params *uparams,
                const char * const *benchmark_cmd,
                struct resctrl_val_param *param);
-void mbm_test_cleanup(void);
-void mba_test_cleanup(void);
 unsigned long create_bit_mask(unsigned int start, unsigned int len);
 unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
 int get_full_cbm(const char *cache_type, unsigned long *mask);
@@ -169,9 +167,7 @@ int resource_info_unsigned_get(const char *resource, const char *filename, unsig
 void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
 int signal_handler_register(const struct resctrl_test *test);
 void signal_handler_unregister(void);
-void cat_test_cleanup(void);
 unsigned int count_bits(unsigned long n);
-void cmt_test_cleanup(void);
 
 void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
 void perf_event_initialize_read_format(struct perf_event_read *pe_read);
index 0590daec2f44a7101c5c908b195acc15249de04c..348d17cb2a84a760d1abd3447d931f37921b805a 100644 (file)
@@ -100,8 +100,10 @@ static int test_prepare(const struct resctrl_test *test)
        return 0;
 }
 
-static void test_cleanup(void)
+static void test_cleanup(const struct resctrl_test *test)
 {
+       if (test->cleanup)
+               test->cleanup();
        umount_resctrlfs();
        signal_handler_unregister();
 }
@@ -143,7 +145,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
        ksft_test_result(!ret, "%s: test\n", test->name);
 
 cleanup:
-       test_cleanup();
+       test_cleanup(test);
 }
 
 static void init_user_params(struct user_params *uparams)