summaryrefslogtreecommitdiff
path: root/tools/perf/tests/builtin-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/builtin-test.c')
-rw-r--r--tools/perf/tests/builtin-test.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index c4b888f18e9c..5e6242576236 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -26,6 +26,7 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <subcmd/exec-cmd.h>
+#include <linux/zalloc.h>
static bool dont_fork;
@@ -510,8 +511,8 @@ static const char *shell_test__description(char *description, size_t size,
return description ? strim(description + 1) : NULL;
}
-#define for_each_shell_test(dir, base, ent) \
- while ((ent = readdir(dir)) != NULL) \
+#define for_each_shell_test(entlist, nr, base, ent) \
+ for (int __i = 0; __i < nr && (ent = entlist[__i]); __i++) \
if (!is_directory(base, ent) && ent->d_name[0] != '.')
static const char *shell_tests__dir(char *path, size_t size)
@@ -538,8 +539,9 @@ static const char *shell_tests__dir(char *path, size_t size)
static int shell_tests__max_desc_width(void)
{
- DIR *dir;
+ struct dirent **entlist;
struct dirent *ent;
+ int n_dirs, e;
char path_dir[PATH_MAX];
const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
int width = 0;
@@ -547,11 +549,11 @@ static int shell_tests__max_desc_width(void)
if (path == NULL)
return -1;
- dir = opendir(path);
- if (!dir)
+ n_dirs = scandir(path, &entlist, NULL, alphasort);
+ if (n_dirs == -1)
return -1;
- for_each_shell_test(dir, path, ent) {
+ for_each_shell_test(entlist, n_dirs, path, ent) {
char bf[256];
const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name);
@@ -563,7 +565,9 @@ static int shell_tests__max_desc_width(void)
}
}
- closedir(dir);
+ for (e = 0; e < n_dirs; e++)
+ zfree(&entlist[e]);
+ free(entlist);
return width;
}
@@ -578,7 +582,10 @@ static int shell_test__run(struct test *test, int subdir __maybe_unused)
char script[PATH_MAX];
struct shell_test *st = test->priv;
- path__join(script, sizeof(script), st->dir, st->file);
+ path__join(script, sizeof(script) - 3, st->dir, st->file);
+
+ if (verbose)
+ strncat(script, " -v", sizeof(script) - strlen(script) - 1);
err = system(script);
if (!err)
@@ -589,8 +596,9 @@ static int shell_test__run(struct test *test, int subdir __maybe_unused)
static int run_shell_tests(int argc, const char *argv[], int i, int width)
{
- DIR *dir;
+ struct dirent **entlist;
struct dirent *ent;
+ int n_dirs, e;
char path_dir[PATH_MAX];
struct shell_test st = {
.dir = shell_tests__dir(path_dir, sizeof(path_dir)),
@@ -599,14 +607,14 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
if (st.dir == NULL)
return -1;
- dir = opendir(st.dir);
- if (!dir) {
+ n_dirs = scandir(st.dir, &entlist, NULL, alphasort);
+ if (n_dirs == -1) {
pr_err("failed to open shell test directory: %s\n",
st.dir);
return -1;
}
- for_each_shell_test(dir, st.dir, ent) {
+ for_each_shell_test(entlist, n_dirs, st.dir, ent) {
int curr = i++;
char desc[256];
struct test test = {
@@ -623,7 +631,9 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
test_and_print(&test, false, -1);
}
- closedir(dir);
+ for (e = 0; e < n_dirs; e++)
+ zfree(&entlist[e]);
+ free(entlist);
return 0;
}
@@ -722,19 +732,20 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
static int perf_test__list_shell(int argc, const char **argv, int i)
{
- DIR *dir;
+ struct dirent **entlist;
struct dirent *ent;
+ int n_dirs, e;
char path_dir[PATH_MAX];
const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
if (path == NULL)
return -1;
- dir = opendir(path);
- if (!dir)
+ n_dirs = scandir(path, &entlist, NULL, alphasort);
+ if (n_dirs == -1)
return -1;
- for_each_shell_test(dir, path, ent) {
+ for_each_shell_test(entlist, n_dirs, path, ent) {
int curr = i++;
char bf[256];
struct test t = {
@@ -745,9 +756,12 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
continue;
pr_info("%2d: %s\n", i, t.desc);
+
}
- closedir(dir);
+ for (e = 0; e < n_dirs; e++)
+ zfree(&entlist[e]);
+ free(entlist);
return 0;
}