aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/resctrl/resctrl_tests.c
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2023-09-04 12:53:37 +0300
committerShuah Khan <skhan@linuxfoundation.org>2023-10-13 14:28:55 -0600
commite33cb5702a9f287d829b0e9e6abe57f6a4aba6d2 (patch)
treedf1886ccbab01a2f9f337e551dadfc65a0869255 /tools/testing/selftests/resctrl/resctrl_tests.c
parentselftests/resctrl: Reorder resctrl FS prep code and benchmark_cmd init (diff)
downloadwireguard-linux-e33cb5702a9f287d829b0e9e6abe57f6a4aba6d2.tar.xz
wireguard-linux-e33cb5702a9f287d829b0e9e6abe57f6a4aba6d2.zip
selftests/resctrl: Make benchmark command const and build it with pointers
Benchmark command is used in multiple tests so it should not be mutated by the tests but CMT test alters span argument. Due to the order of tests (CMT test runs last), mutating the span argument in CMT test does not trigger any real problems currently. Mark benchmark_cmd strings as const and setup the benchmark command using pointers. Because the benchmark command becomes const, the input arguments can be used directly. Besides being simpler, using the input arguments directly also removes the internal size restriction. CMT test has to create a copy of the benchmark command before altering the benchmark command. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/resctrl/resctrl_tests.c')
-rw-r--r--tools/testing/selftests/resctrl/resctrl_tests.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index f105e00d6099..89edde416f07 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -10,9 +10,6 @@
*/
#include "resctrl.h"
-#define BENCHMARK_ARGS 64
-#define BENCHMARK_ARG_SIZE 64
-
static int detect_vendor(void)
{
FILE *inf = fopen("/proc/cpuinfo", "r");
@@ -70,7 +67,7 @@ void tests_cleanup(void)
cat_test_cleanup();
}
-static void run_mbm_test(char **benchmark_cmd, int cpu_no)
+static void run_mbm_test(const char * const *benchmark_cmd, int cpu_no)
{
int res;
@@ -96,7 +93,7 @@ umount:
umount_resctrlfs();
}
-static void run_mba_test(char **benchmark_cmd, int cpu_no)
+static void run_mba_test(const char * const *benchmark_cmd, int cpu_no)
{
int res;
@@ -120,7 +117,7 @@ umount:
umount_resctrlfs();
}
-static void run_cmt_test(char **benchmark_cmd, int cpu_no)
+static void run_cmt_test(const char * const *benchmark_cmd, int cpu_no)
{
int res;
@@ -173,11 +170,12 @@ umount:
int main(int argc, char **argv)
{
bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true;
- char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE];
int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0;
- char *benchmark_cmd[BENCHMARK_ARGS];
+ const char *benchmark_cmd[BENCHMARK_ARGS];
int ben_ind, ben_count, tests = 0;
+ char *span_str = NULL;
bool cat_test = true;
+ int ret;
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0) {
@@ -265,23 +263,19 @@ int main(int argc, char **argv)
ksft_exit_fail_msg("Too long benchmark command.\n");
/* Extract benchmark command from command line. */
- for (i = ben_ind; i < argc; i++) {
- benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i];
- if (strlen(argv[i]) >= BENCHMARK_ARG_SIZE)
- ksft_exit_fail_msg("Too long benchmark command argument.\n");
- sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]);
- }
+ for (i = 0; i < argc - ben_ind; i++)
+ benchmark_cmd[i] = argv[i + ben_ind];
benchmark_cmd[ben_count] = NULL;
} else {
/* If no benchmark is given by "-b" argument, use fill_buf. */
- for (i = 0; i < 5; i++)
- benchmark_cmd[i] = benchmark_cmd_area[i];
-
- strcpy(benchmark_cmd[0], "fill_buf");
- sprintf(benchmark_cmd[1], "%u", DEFAULT_SPAN);
- strcpy(benchmark_cmd[2], "1");
- strcpy(benchmark_cmd[3], "0");
- strcpy(benchmark_cmd[4], "false");
+ benchmark_cmd[0] = "fill_buf";
+ ret = asprintf(&span_str, "%u", DEFAULT_SPAN);
+ if (ret < 0)
+ ksft_exit_fail_msg("Out of memory!\n");
+ benchmark_cmd[1] = span_str;
+ benchmark_cmd[2] = "1";
+ benchmark_cmd[3] = "0";
+ benchmark_cmd[4] = "false";
benchmark_cmd[5] = NULL;
}
@@ -299,5 +293,6 @@ int main(int argc, char **argv)
if (cat_test)
run_cat_test(cpu_no, no_of_bits);
+ free(span_str);
ksft_finished();
}