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

Petr Vorel pvorel@suse.cz
Fri Jan 7 10:05:20 CET 2022


Hi all,

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

LGTM. NOTE: Cyril suggested strchr() with loop, maybe he thought about even
simpler solution.

> 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.
Maybe use '|' as the default? That's very unlikely to be used
(but I'd still have TST_NEEDS_KCONFIGS_IFS).

Kind regards,
Petr


More information about the ltp mailing list