Add support for kconfig strings
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 2/2 lib/tst_kconfig: Validate variables
In reply to Cyril HrubisAdd 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
@@ -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
@@ -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
v2 cover Add support for kconfig strings
In reply to Cyril HrubisHello,
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.cSignature · 1 line
2.26.2
LGTM
Signature · 2 lines
Thank you, Richard.
v2 cover Add support for kconfig strings
Hi!
Quoted 3 lines
LGTM
Reviewed-by Richard Palethorpe <[email protected]>
Thanks for the review, pushed.
Signature · 2 lines
Cyril Hrubis [email protected]