Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/resctrl: Modularize resctrl test suite main() function

Resctrl test suite main() function does the following things
1. Parses command line arguments passed by user
2. Some setup checks
3. Logic that calls into each unit test
4. Print result and clean up after running each unit test

Introduce wrapper functions for steps 3 and 4 to modularize the main()
function. Adding these wrapper functions makes it easier to add any logic
to each individual test.

Please note that this is a preparatory patch for the next one and no
functional changes are intended.

Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Fenghua Yu and committed by
Shuah Khan
c9fb4e7c 09a67934

+57 -31
+57 -31
tools/testing/selftests/resctrl/resctrl_tests.c
··· 54 54 cat_test_cleanup(); 55 55 } 56 56 57 + static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span, 58 + int cpu_no, char *bw_report) 59 + { 60 + int res; 61 + 62 + ksft_print_msg("Starting MBM BW change ...\n"); 63 + if (!has_ben) 64 + sprintf(benchmark_cmd[5], "%s", MBA_STR); 65 + res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd); 66 + ksft_test_result(!res, "MBM: bw change\n"); 67 + mbm_test_cleanup(); 68 + } 69 + 70 + static void run_mba_test(bool has_ben, char **benchmark_cmd, int span, 71 + int cpu_no, char *bw_report) 72 + { 73 + int res; 74 + 75 + ksft_print_msg("Starting MBA Schemata change ...\n"); 76 + if (!has_ben) 77 + sprintf(benchmark_cmd[1], "%d", span); 78 + res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd); 79 + ksft_test_result(!res, "MBA: schemata change\n"); 80 + mba_test_cleanup(); 81 + } 82 + 83 + static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no) 84 + { 85 + int res; 86 + 87 + ksft_print_msg("Starting CMT test ...\n"); 88 + if (!has_ben) 89 + sprintf(benchmark_cmd[5], "%s", CMT_STR); 90 + res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd); 91 + ksft_test_result(!res, "CMT: test\n"); 92 + cmt_test_cleanup(); 93 + } 94 + 95 + static void run_cat_test(int cpu_no, int no_of_bits) 96 + { 97 + int res; 98 + 99 + ksft_print_msg("Starting CAT test ...\n"); 100 + res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); 101 + ksft_test_result(!res, "CAT: test\n"); 102 + cat_test_cleanup(); 103 + } 104 + 57 105 int main(int argc, char **argv) 58 106 { 59 107 bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true; 60 - int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 0; 108 + int c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 0; 61 109 char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64]; 62 110 char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; 63 111 int ben_ind, ben_count, tests = 0; ··· 218 170 219 171 ksft_set_plan(tests ? : 4); 220 172 221 - if (!is_amd && mbm_test) { 222 - ksft_print_msg("Starting MBM BW change ...\n"); 223 - if (!has_ben) 224 - sprintf(benchmark_cmd[5], "%s", MBA_STR); 225 - res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd); 226 - ksft_test_result(!res, "MBM: bw change\n"); 227 - mbm_test_cleanup(); 228 - } 173 + if (!is_amd && mbm_test) 174 + run_mbm_test(has_ben, benchmark_cmd, span, cpu_no, bw_report); 229 175 230 - if (!is_amd && mba_test) { 231 - ksft_print_msg("Starting MBA Schemata change ...\n"); 232 - if (!has_ben) 233 - sprintf(benchmark_cmd[1], "%d", span); 234 - res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd); 235 - ksft_test_result(!res, "MBA: schemata change\n"); 236 - mba_test_cleanup(); 237 - } 176 + if (!is_amd && mba_test) 177 + run_mba_test(has_ben, benchmark_cmd, span, cpu_no, bw_report); 238 178 239 - if (cmt_test) { 240 - ksft_print_msg("Starting CMT test ...\n"); 241 - if (!has_ben) 242 - sprintf(benchmark_cmd[5], "%s", CMT_STR); 243 - res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd); 244 - ksft_test_result(!res, "CMT: test\n"); 245 - cmt_test_cleanup(); 246 - } 179 + if (cmt_test) 180 + run_cmt_test(has_ben, benchmark_cmd, cpu_no); 247 181 248 - if (cat_test) { 249 - ksft_print_msg("Starting CAT test ...\n"); 250 - res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); 251 - ksft_test_result(!res, "CAT: test\n"); 252 - cat_test_cleanup(); 253 - } 182 + if (cat_test) 183 + run_cat_test(cpu_no, no_of_bits); 254 184 255 185 return ksft_exit_pass(); 256 186 }