Skip to content

Commit 6cd3689

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Move cleanups out of individual tests
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 <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent e648723 commit 6cd3689

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

tools/testing/selftests/resctrl/cat_test.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type
128128
return fail;
129129
}
130130

131-
void cat_test_cleanup(void)
131+
static void cat_test_cleanup(void)
132132
{
133133
remove(RESULT_FILE_NAME);
134134
}
@@ -284,13 +284,10 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
284284

285285
ret = cat_test(test, uparams, &param, span, start_mask);
286286
if (ret)
287-
goto out;
287+
return ret;
288288

289289
ret = check_results(&param, test->resource,
290290
cache_total_size, full_cache_mask, start_mask);
291-
out:
292-
cat_test_cleanup();
293-
294291
return ret;
295292
}
296293

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of
9191
MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true);
9292
}
9393

94-
void cmt_test_cleanup(void)
94+
static void cmt_test_cleanup(void)
9595
{
9696
remove(RESULT_FILE_NAME);
9797
}
@@ -161,7 +161,6 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
161161
ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
162162

163163
out:
164-
cmt_test_cleanup();
165164
free(span_str);
166165

167166
return ret;

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int check_results(void)
137137
return show_mba_info(bw_imc, bw_resc);
138138
}
139139

140-
void mba_test_cleanup(void)
140+
static void mba_test_cleanup(void)
141141
{
142142
remove(RESULT_FILE_NAME);
143143
}
@@ -158,13 +158,10 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
158158

159159
ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
160160
if (ret)
161-
goto out;
161+
return ret;
162162

163163
ret = check_results();
164164

165-
out:
166-
mba_test_cleanup();
167-
168165
return ret;
169166
}
170167

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int mbm_setup(const struct resctrl_test *test,
105105
return ret;
106106
}
107107

108-
void mbm_test_cleanup(void)
108+
static void mbm_test_cleanup(void)
109109
{
110110
remove(RESULT_FILE_NAME);
111111
}
@@ -126,15 +126,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
126126

127127
ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
128128
if (ret)
129-
goto out;
129+
return ret;
130130

131131
ret = check_results(DEFAULT_SPAN);
132132
if (ret && (get_vendor() == ARCH_INTEL))
133133
ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
134134

135-
out:
136-
mbm_test_cleanup();
137-
138135
return ret;
139136
}
140137

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ int resctrl_val(const struct resctrl_test *test,
158158
const struct user_params *uparams,
159159
const char * const *benchmark_cmd,
160160
struct resctrl_val_param *param);
161-
void mbm_test_cleanup(void);
162-
void mba_test_cleanup(void);
163161
unsigned long create_bit_mask(unsigned int start, unsigned int len);
164162
unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
165163
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
169167
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
170168
int signal_handler_register(const struct resctrl_test *test);
171169
void signal_handler_unregister(void);
172-
void cat_test_cleanup(void);
173170
unsigned int count_bits(unsigned long n);
174-
void cmt_test_cleanup(void);
175171

176172
void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
177173
void perf_event_initialize_read_format(struct perf_event_read *pe_read);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ static int test_prepare(const struct resctrl_test *test)
100100
return 0;
101101
}
102102

103-
static void test_cleanup(void)
103+
static void test_cleanup(const struct resctrl_test *test)
104104
{
105+
if (test->cleanup)
106+
test->cleanup();
105107
umount_resctrlfs();
106108
signal_handler_unregister();
107109
}
@@ -143,7 +145,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
143145
ksft_test_result(!ret, "%s: test\n", test->name);
144146

145147
cleanup:
146-
test_cleanup();
148+
test_cleanup(test);
147149
}
148150

149151
static void init_user_params(struct user_params *uparams)

0 commit comments

Comments
 (0)