Commit caaaa554 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf test: Avoid shell test description infinite loop



for_each_shell_test() is already strict in expecting tests to be files
and executable. It is sometimes possible when it iterates over all files
that it finds one that is executable and lacks a newline character. When
this happens the loop never terminates as it doesn't check for EOF.

Add the EOF check to make this loop at least bounded by the file size.

If the description is returned as NULL then also skip the test.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Marco Elver <elver@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20220517204144.645913-1-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 01b28e4a
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -279,6 +279,7 @@ static const char *shell_test__description(char *description, size_t size,
{
{
	FILE *fp;
	FILE *fp;
	char filename[PATH_MAX];
	char filename[PATH_MAX];
	int ch;


	path__join(filename, sizeof(filename), path, name);
	path__join(filename, sizeof(filename), path, name);
	fp = fopen(filename, "r");
	fp = fopen(filename, "r");
@@ -286,7 +287,9 @@ static const char *shell_test__description(char *description, size_t size,
		return NULL;
		return NULL;


	/* Skip shebang */
	/* Skip shebang */
	while (fgetc(fp) != '\n');
	do {
		ch = fgetc(fp);
	} while (ch != EOF && ch != '\n');


	description = fgets(description, size, fp);
	description = fgets(description, size, fp);
	fclose(fp);
	fclose(fp);
@@ -417,7 +420,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width,
			.priv = &st,
			.priv = &st,
		};
		};


		if (!perf_test__matches(test_suite.desc, curr, argc, argv))
		if (test_suite.desc == NULL ||
		    !perf_test__matches(test_suite.desc, curr, argc, argv))
			continue;
			continue;


		st.file = ent->d_name;
		st.file = ent->d_name;