summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/resctrl/resctrl_tests.c
diff options
context:
space:
mode:
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();
}