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

From: Zhangjin Wu
Date: Wed Jun 21 2023 - 08:58:09 EST


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@xxxxxxxxxxx>
---
tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

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) {
--
2.25.1