Skip to contentSkip to conversation

Add support for kconfig strings

PATCH Superseded Cyril Hrubis 2 participants 5 messages Nov 12, 2020 – Nov 18, 2020 Library code

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for kconfig strings

We add a support for strings into the boolean tokenizer and also validator for kconfig variables into the kconfig parser so that we find most of the typos even before we attempt to evaluate the expressions.

Cyril Hrubis (2):
lib: tst_bool_expr: Add support for strings
lib/tst_kconfig: Validate variables

 lib/newlib_tests/.gitignore       |   1 +
 lib/newlib_tests/config01         |   1 +
 lib/newlib_tests/config02         |   1 +
 lib/newlib_tests/config03         |   1 +
 lib/newlib_tests/config04         |   1 +
 lib/newlib_tests/config05         |   1 +
 lib/newlib_tests/test_kconfig.c   |   1 +
 lib/newlib_tests/test_kconfig02.c |  29 +++++++++
 lib/newlib_tests/tst_bool_expr.c  |   3 +
 lib/tst_bool_expr.c               |   7 ++
 lib/tst_kconfig.c                 | 102 ++++++++++++++++++++++++++++++
 11 files changed, 148 insertions(+)
 create mode 100644 lib/newlib_tests/test_kconfig02.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/2 lib: tst_bool_expr: Add support for strings

There are cases where special characters, e.g. parentesis appear in the value of a kernel config variable, so in order to be able to parse boolean variables such as "CONFIG_DEFAULT_HOSTNAME=\"(none)\"" the tokenizer must be able to parse strings.

The implementation is easy, when in string we do not split the input into tokens.

---
 lib/newlib_tests/config01        | 1 +
 lib/newlib_tests/config02        | 1 +
 lib/newlib_tests/config03        | 1 +
 lib/newlib_tests/config04        | 1 +
 lib/newlib_tests/config05        | 1 +
 lib/newlib_tests/test_kconfig.c  | 1 +
 lib/newlib_tests/tst_bool_expr.c | 3 +++
 lib/tst_bool_expr.c              | 7 +++++++
 8 files changed, 16 insertions(+)
lib/newlib_tests/config01 +1 -0
index 96d68d836..1d94d810a 100644
@@ -2,3 +2,4 @@
 CONFIG_MMU=y
 CONFIG_EXT4_FS=m
 CONFIG_PGTABLE_LEVELS=4
+CONFIG_DEFAULT_HOSTNAME="(none)"
lib/newlib_tests/config02 +1 -0
index 2de45cff8..e1b0e8086 100644
@@ -2,3 +2,4 @@
 # CONFIG_MMU is not set
 CONFIG_EXT4_FS=m
 CONFIG_PGTABLE_LEVELS=4
+CONFIG_DEFAULT_HOSTNAME="(none)"
lib/newlib_tests/config03 +1 -0
index 1a3b9e648..05c8e194a 100644
@@ -2,3 +2,4 @@
 CONFIG_MMU=y
 CONFIG_EXT4_FS=m
 CONFIG_PGTABLE_LEVELS=44
+CONFIG_DEFAULT_HOSTNAME="(none)"
lib/newlib_tests/config04 +1 -0
index cce7051ae..da01579b6 100644
@@ -2,3 +2,4 @@
 CONFIG_MMU=y
 CONFIG_EXT4_FS=y
 CONFIG_PGTABLE_LEVELS=4
+CONFIG_DEFAULT_HOSTNAME="(none)"
lib/newlib_tests/config05 +1 -0
index a9d7bab4d..490f94fa6 100644
@@ -1,3 +1,4 @@
 # Everything is wrong
 CONFIG_EXT4_FS=y
 CONFIG_PGTABLE_LEVELS=44
+CONFIG_DEFAULT_HOSTNAME=""
lib/newlib_tests/test_kconfig.c +1 -0
index 1f659b95a..9280f07ca 100644
@@ -16,6 +16,7 @@ static const char *kconfigs[] = {
 	"CONFIG_PGTABLE_LEVELS=4",
 	"CONFIG_MMU & CONFIG_EXT4_FS=m",
 	"CONFIG_EXT4_FS=m | CONFIG_MMU",
+	"CONFIG_DEFAULT_HOSTNAME=\"(none)\"",
 	NULL
 };
 
lib/newlib_tests/tst_bool_expr.c +3 -0
index f9bb1780d..8f0929d35 100644
@@ -102,6 +102,9 @@ static void do_test(void)
 	do_eval_test("False & A", 1, 0, 0, 0);
 	do_eval_test("! Undefined", 0, 0, 0, -1);
 
+	do_eval_test("\"(none)\"", 0, 0, 0, -1);
+	do_eval_test("\"(none)\" & \" \"", 0, 0, 0, -1);
+
 	parse_fail("A!");
 	parse_fail("A &");
 	parse_fail("A B");
lib/tst_bool_expr.c +7 -0
index dd147cde3..387c38b91 100644
@@ -81,6 +81,13 @@ static unsigned int tokenize(const char *expr, struct tst_expr_tok *last)
 			token_cnt += new_tok(&last, &expr[j], i - j);
 			j = i+1;
 		break;
+		case '"':
+			while (expr[i+1] != '"' && expr[i+1])
+				i++;
+
+			if (expr[i+1] == '"')
+				i++;
+		break;
 		default:
 		break;
 		}
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/2 lib/tst_kconfig: Validate variables

In reply to Cyril Hrubis

Add variable validation so that we catch typos even before we attempt to evaluate the expressions.

---
 lib/newlib_tests/.gitignore       |   1 +
 lib/newlib_tests/test_kconfig02.c |  29 +++++++++
 lib/tst_kconfig.c                 | 102 ++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 lib/newlib_tests/test_kconfig02.c
lib/newlib_tests/.gitignore +1 -0
index 89de61cf7..ac1d19be0 100644
@@ -32,6 +32,7 @@ test_exec
 test_exec_child
 test_kconfig
 test_kconfig01
+test_kconfig02
 variant
 test_guarded_buf
 tst_bool_expr
lib/newlib_tests/test_kconfig02.c new file +29 -0
new file mode 100644
index 000000000..176929222
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <[email protected]>
+ *
+ * Invalid boolean expression test.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TPASS, "Test passed!");
+}
+
+static const char *kconfigs[] = {
+	"\"CONFIG_FOO=val\"",
+	"CONFIG_a=1",
+	"CONFIG_FOO=",
+	"CONFIG_DEFAULT_HOSTNAME=\"(none",
+	"CONFIG_DEFAULT_HOSTNAME=\"(none)\"a",
+	"CONFIG_BROKEN=a\" | CONFIG_FOO",
+	"CONFIG_BROKEN=a=",
+	NULL
+};
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_kconfigs = kconfigs,
+};
lib/tst_kconfig.c +102 -0

114 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

v2 cover Add support for kconfig strings

In reply to Cyril Hrubis

Hello,

Quoted 8 lines · Cyril Hrubis

We add a support for strings into the boolean tokenizer and also validator for kconfig variables into the kconfig parser so that we find most of the typos even before we attempt to evaluate the expressions.

Cyril Hrubis (2):
lib: tst_bool_expr: Add support for strings
lib/tst_kconfig: Validate variables

Quoted 16 lines
 lib/newlib_tests/.gitignore       |   1 +
 lib/newlib_tests/config01         |   1 +
 lib/newlib_tests/config02         |   1 +
 lib/newlib_tests/config03         |   1 +
 lib/newlib_tests/config04         |   1 +
 lib/newlib_tests/config05         |   1 +
 lib/newlib_tests/test_kconfig.c   |   1 +
 lib/newlib_tests/test_kconfig02.c |  29 +++++++++
 lib/newlib_tests/tst_bool_expr.c  |   3 +
 lib/tst_bool_expr.c               |   7 ++
 lib/tst_kconfig.c                 | 102 ++++++++++++++++++++++++++++++
 11 files changed, 148 insertions(+)
 create mode 100644 lib/newlib_tests/test_kconfig02.c
Signature · 1 line
2.26.2

LGTM

Signature · 2 lines
Thank you,
Richard.