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

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Fri Jan 7 09:28:08 CET 2022


Hi Li
> 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:
Yes, it works well. Thanks.

I checked the kernel config, it seems comma can not meet the CONFIG_LSM 
situation (Petr mention it but I don't notice before).
CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"

so I think we may TST_NEEDS_KCONFIGS_IFS variable and default value is 
comma.

Best Regards
Yang Xu
>
> ---------------------------
>          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;
>          }
>          ...
>
>
>


More information about the ltp mailing list