From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 1/4] lib/tst_kconfig.c: add any kconfig with or without expected value function
Date: Wed, 29 Jan 2020 17:19:57 +0100 [thread overview]
Message-ID: <20200129161957.GF22477@rei.lan> (raw)
In-Reply-To: <20191220092529.3239-1-pengfei.xu@intel.com>
Hi!
> for (i = 0; i < cnt; i++) {
> const char *val = strchr(kconfigs[i], '=');
> @@ -176,12 +177,9 @@ void tst_kconfig_read(const char *const *kconfigs,
> tst_brk(TBROK, "Invalid config string '%s'", kconfigs[i]);
>
> matches[i].match = 0;
> - matches[i].len = strlen(kconfigs[i]);
>
> - if (val) {
> + if (val)
> matches[i].val = val + 1;
> - matches[i].len -= strlen(val);
> - }
>
> results[i].match = 0;
> results[i].value = NULL;
> @@ -193,17 +191,29 @@ void tst_kconfig_read(const char *const *kconfigs,
>
> while (fgets(buf, sizeof(buf), fp)) {
> for (i = 0; i < cnt; i++) {
> - if (match(&matches[i], kconfigs[i], &results[i], buf)) {
> - for (j = 0; j < cnt; j++) {
> - if (matches[j].match)
> - break;
> + memset(kconfig_multi, 0, sizeof(kconfig_multi));
> + /* strtok_r will split kconfigs[i] to multi string, so copy it */
> + memcpy(kconfig_multi, kconfigs[i], strlen(kconfigs[i]));
> + kconfig_token = strtok_r(kconfig_multi, "|=", &p_left);
> +
> + while (kconfig_token != NULL) {
> + if (strncmp("CONFIG_", kconfig_token, 7))
> + tst_brk(TBROK, "Invalid config string '%s'", kconfig_token);
> + matches[i].len = strlen(kconfig_token);
> + if (match(&matches[i], kconfig_token, &results[i], buf)) {
> + for (j = 0; j < cnt; j++) {
> + if (matches[j].match)
> + break;
> + }
> + if (j == cnt)
> + goto exit;
I do not think that this actually works correctly. One of the problems I
see is that we do match only the CONFIG_FOO part in the
tst_kconfig_read() and the result value is evaluated later on. This
means that if we had something as "CONFIG_FOO=5|CONFIG_FOO=4" the code
will pick up only the first occurence of the = and we would end up doing
strcmp("4", "5|CONFIG_FOO=4") which would fail as well.
If we wanted to have proper solution for logic statements inside of the
kconfig parser we would have to isolate the CONFIG_FOO names first, pass
them to the tst_kconfig_read() function, that would get us values for
all config variables we need, then we could split the configs strings
greadily on | and evaluate them one after another.
So the first function would have to be able to get arrays of strings and
return another array of strings isolating the CONFIG_FOO variables. That
would be passed to tst_kconfig_read() that would yield results[] array,
for all interesting variables. From that point we can split the kconfig
strings by | and evaluate one after another until we get match or end of
the string.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-01-29 16:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-20 9:25 [LTP] [PATCH v5 1/4] lib/tst_kconfig.c: add any kconfig with or without expected value function Pengfei Xu
2019-12-20 9:25 ` [LTP] [PATCH v5 2/4] lib: add any kconfig with or without expected value into kconfig test Pengfei Xu
2019-12-20 9:25 ` [LTP] [PATCH v5 3/4] lib: add usage that any kconfig with or without expected value in document Pengfei Xu
2019-12-20 9:25 ` [LTP] [PATCH v5 4/4] umip_basic_test.c: improve kconfig verification to avoid umip wrong abort case Pengfei Xu
2020-05-25 21:24 ` Petr Vorel
2020-05-26 2:32 ` Pengfei Xu
2020-05-26 9:23 ` Petr Vorel
2020-05-26 9:27 ` Petr Vorel
2020-05-26 10:07 ` Pengfei Xu
2020-05-26 10:11 ` Petr Vorel
2020-05-26 10:37 ` Pengfei Xu
2020-05-27 1:22 ` Xu, Pengfei
2020-05-27 6:26 ` Petr Vorel
2020-05-27 12:24 ` Xu, Pengfei
2020-01-29 16:19 ` Cyril Hrubis [this message]
2020-01-30 10:00 ` [LTP] [PATCH v5 1/4] lib/tst_kconfig.c: add any kconfig with or without expected value function Pengfei Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200129161957.GF22477@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox