[LTP] [PATCH v2 3/4] shell: add kconfig parse api
Li Wang
liwang@redhat.com
Fri Jan 7 08:04:02 CET 2022
xuyang2018.jy@fujitsu.com <xuyang2018.jy@fujitsu.com> wrote:
> // SPDX-License-Identifier: GPL-2.0-or-later
> /* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.*/
>
> #include <stdio.h>
> #include <string.h>
> #include "tst_kconfig.h"
>
>
> int main(int argc, const char *argv[])
> {
> char delims[] = ",";
> char kconfig[PATH_MAX];
> char str[PATH_MAX];
> char *result = NULL;
> char *next = NULL;
> int i = 0;
>
> if (argc < 2) {
> fprintf(stderr, "Please provide kernel kconfig list\n");
> return 1;
> }
>
> strcpy(str, argv[1]);
> result = strtok_r(str, delims, &next);
>
> while (result != NULL) {
> strcpy(kconfig, result);
> printf("%s %s %d\n", kconfig,result, i);
> const char *const kconfigs[] = {
> kconfig,
> NULL
> };
> if (tst_kconfig_check(kconfigs)) {
> fprintf(stderr, "Kernel config doesn't meet
> test's requirement!\n");
> return 1;
> }
>
> i++;
> result = strtok_r(NULL, delims, &next);
> }
>
> return 0;
> }
>
> But it must call tst_kconfig_check for every kconfig expression and
> print many info "Parsing kernel config ..." because we need to create a
> NULL terminated array for tst_kconfig_check.
Maybe we can combine the arguments into one kconfigs struct and
just do once check? something like:
---------------------------
strcpy(str, argv[1]);
result = strtok_r(str, delims, &next);
const char *kconfigs[64];
for (i = 0; result != NULL; i++) {
kconfigs[i] = result;
result = strtok_r(NULL, delims, &next);
}
kconfigs[++i] = NULL;
if (tst_kconfig_check(kconfigs)) {
fprintf(stderr, "Kernel config doesn't meet test's
requirement!\n");
return 1;
}
...
--
Regards,
Li Wang
More information about the ltp
mailing list