diff mbox series

[v1,04/17] selftests/nolibc: fix up kernel parameters support

Message ID 8e3e44492c986f691a778322e3eaf483e1734e90.1687344643.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series selftests/nolibc: allow run with minimal kernel config | expand

Commit Message

Zhangjin Wu June 21, 2023, 12:57 p.m. UTC
kernel parameters allow pass two types of strings, one type is like
'noapic', another type is like 'panic=5', the first type is passed as
arguments of the init program, the second type is passed as environment
variables of the init program.

when users pass kernel parameters like this:

    noapic NOLIBC_TEST=syscall

our nolibc-test program will ignore the NOLIBC_TEST environment
variable.

Let's verify the first type (from arguments), if it is invalid, get the
test setting from NOLIBC_TEST environment variable instead.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index d43116553288..ebec948ec808 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -951,6 +951,7 @@  int main(int argc, char **argv, char **envp)
 	int ret = 0;
 	int err;
 	int idx;
+	int len, valid = 0;
 	char *test;
 
 	environ = envp;
@@ -969,7 +970,19 @@  int main(int argc, char **argv, char **envp)
 	 *    syscall:5-15[:.*],stdlib:8-10
 	 */
 	test = argv[1];
-	if (!test)
+
+	/* verify the test setting from argv[1] */
+	if (test) {
+		for (idx = 0; test_names[idx].name; idx++) {
+			len = strlen(test_names[idx].name);
+			if (strncmp(test, test_names[idx].name, len) == 0) {
+				valid = 1;
+				break;
+			}
+		}
+	}
+
+	if (!valid)
 		test = getenv("NOLIBC_TEST");
 
 	if (test) {