Skip to content

Commit

Permalink
selftests/resctrl: Allow ->setup() to return errors
Browse files Browse the repository at this point in the history
resctrl_val() assumes ->setup() always returns either 0 to continue
tests or < 0 in case of the normal termination of tests after x runs.
The latter overlaps with normal error returns.

Define END_OF_TESTS (=1) to differentiate the normal termination of
tests and return errors as negative values. Alter callers of ->setup()
to handle errors properly.

Fixes: 790bf58 ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest")
Fixes: ecdbb91 ("selftests/resctrl: Add MBM test")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Ilpo Järvinen authored and Shuah Khan committed Apr 10, 2023
1 parent c90b3b5 commit fa10366
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tools/testing/selftests/resctrl/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ int cat_val(struct resctrl_val_param *param)
while (1) {
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
ret = param->setup(1, param);
if (ret) {
if (ret == END_OF_TESTS) {
ret = 0;
break;
}
if (ret < 0)
break;
ret = reset_enable_llc_perf(bm_pid, param->cpu_no);
if (ret)
break;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static int cat_setup(int num, ...)

/* Run NUM_OF_RUNS times */
if (p->num_of_runs >= NUM_OF_RUNS)
return -1;
return END_OF_TESTS;

if (p->num_of_runs == 0) {
sprintf(schemata, "%lx", p->mask);
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/resctrl/cmt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int cmt_setup(int num, ...)

/* Run NUM_OF_RUNS times */
if (p->num_of_runs >= NUM_OF_RUNS)
return -1;
return END_OF_TESTS;

p->num_of_runs++;

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/resctrl/mba_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static int mba_setup(int num, ...)
return 0;

if (allocation < ALLOCATION_MIN || allocation > ALLOCATION_MAX)
return -1;
return END_OF_TESTS;

sprintf(allocation_str, "%d", allocation);

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/resctrl/mbm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int mbm_setup(int num, ...)

/* Run NUM_OF_RUNS times */
if (num_of_runs++ >= NUM_OF_RUNS)
return -1;
return END_OF_TESTS;

va_start(param, num);
p = va_arg(param, struct resctrl_val_param *);
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/resctrl/resctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define ARCH_INTEL 1
#define ARCH_AMD 2

#define END_OF_TESTS 1

#define PARENT_EXIT(err_msg) \
do { \
perror(err_msg); \
Expand Down
4 changes: 3 additions & 1 deletion tools/testing/selftests/resctrl/resctrl_val.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,12 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
/* Test runs until the callback setup() tells the test to stop. */
while (1) {
ret = param->setup(1, param);
if (ret) {
if (ret == END_OF_TESTS) {
ret = 0;
break;
}
if (ret < 0)
break;

if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
Expand Down

0 comments on commit fa10366

Please sign in to comment.