[LTP] [PATCH v3 3/4] shell: add kconfig parse api

Li Wang liwang@redhat.com
Mon Jan 10 10:13:19 CET 2022


On Mon, Jan 10, 2022 at 4:48 PM xuyang2018.jy@fujitsu.com
<xuyang2018.jy@fujitsu.com> wrote:
>
> Hi Li
> > On Mon, Jan 10, 2022 at 2:26 PM Yang Xu<xuyang2018.jy@fujitsu.com>  wrote:
> >
> >> +1.7 Parsing kernel .config
> >> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> +The shell library provides an implementation of the kconfig parsing interface
> >> +compatible with the C version.
> >
> >   ^ consistent with the C version.
> Yes.
> >
> >> +++ b/testcases/lib/tst_check_kconfigs.c
> >> @@ -0,0 +1,54 @@
> >> +// SPDX-License-Identifier: GPL-2.0-or-later
> >> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
> >> +
> >> +#include<stdio.h>
> >> +#include<string.h>
> >> +#include<limits.h>
> >> +#include<stdlib.h>
> >> +#include "tst_kconfig.h"
> >> +
> >> +int main(int argc, const char *argv[])
> >> +{
> >> +       char delim[2];
> >> +       char str[PATH_MAX];
> >> +       char *result = NULL;
> >> +       char *next = NULL;
> >> +       int i = 0, j = 0, ret = 0;
> >> +
> >> +       if (argc<  3) {
> >> +               fprintf(stderr, "Please provide kernel kconfig list and delims\n");
> >> +               return 1;
> >> +       }
> >> +
> >> +       if (strlen(argv[2]) != 1) {
> >> +               fprintf(stderr, "The delim must be a single character\n");
> >> +               return 1;
> >> +       }
> >> +
> >> +       strcpy(str, argv[1]);
> >> +       strcpy(delim, argv[2]);
> >> +
> >> +       result = strtok_r(str, delim,&next);
> >> +       for (i = 0; result != NULL; i++)
> >> +               result = strtok_r(NULL, delim,&next);
> >> +
> >> +       strcpy(str, argv[1]);
> >> +       char **kconfigs = (char **)malloc(++i * sizeof(char *));

And, I also think that if traverse the number of delim, then
we will avoid doing strcpy twice here. But that's not important,
I have no strong insist on this way.

i.e.

       strcpy(str, argv[1]);
       strcpy(delim, argv[2]);

       for (next = str, i = 1; next[j] != '\0'; j++)
               if (next[j] == delim[0])
                       i++;
       char **kconfigs = (char **)malloc(++i * sizeof(char *));


> We can modify those when maintainer merges it.

Sure.

-- 
Regards,
Li Wang



More information about the ltp mailing list