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

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Fri Jan 7 10:22:48 CET 2022


Hi Petr
> 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).
No, look test_kconfig01.c, we use '|' for a valid or operation.

Best Rgards
Yang Xu
>
> Kind regards,
> Petr


More information about the ltp mailing list