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

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Fri Jan 7 05:08:58 CET 2022


Hi Li, Cyril, Petr
> Hi all,
>
> On Thu, Jan 6, 2022 at 7:17 PM Cyril Hrubis<chrubis@suse.cz>  wrote:
>
>>> +| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
>
>>> +| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
>>> +                             default value is comma.
>
>
>>> +     for kconfig_i in $(seq $kconfig_max); do
>>> +             eval "local kconfig$kconfig_i"
>>> +             eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
>>> +     done
>>
>> This part is a bit ugly, I guess that it may as well be easier to
>> process in C. A long as we pass it as:
>>
>> tst_check_kconfigs "$TST_NEEDS_KCONFIGS_IFS" "$TST_NEEDS_KCONFIGS"
>>
>> We can easily split the TST_NEEDS_KCONFIGS with strchr() and single
>> loop.
>
> +1
>
In fact, I used the c code(use strtok_r) in the beginning when I wrote 
this patch
code as below:

// 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.

It seems also increase calculated complexity...

That is why I switch to filter them in shell.

If you want to use C, I will swich to use C for filter strings.
> I even don't think we need that 'TST_NEEDS_KCONFIGS_IFS'
> variable for users. More flexible means more complicated to some
> degree, if achieve a C process,  we can handle that by accepting
> whatever the delimiter.
>
> But strictly usage with a comma is enough for current kernel configs
> parsing I guess.
+1

Best Regards
Yang Xu
>


More information about the ltp mailing list