All of lore.kernel.org
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Li Wang <liwang@redhat.com>, Cyril Hrubis <chrubis@suse.cz>,
	Petr Vorel <pvorel@suse.cz>
Cc: LTP List <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 3/4] shell: add kconfig parse api
Date: Fri, 7 Jan 2022 04:08:58 +0000	[thread overview]
Message-ID: <61D7BD03.4040200@fujitsu.com> (raw)
In-Reply-To: <CAEemH2ddfS3v-v62vWjMGzr34-NfT=OBt1s-x6+dCSQD4p0YEg@mail.gmail.com>

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
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-01-07  4:09 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  6:57 [LTP] [PATCH v1 1/3] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-04  6:57 ` [LTP] [PATCH v1 2/3] shell: add kconfig parse api Yang Xu
2022-01-04 11:04   ` Petr Vorel
2022-01-05  7:15     ` xuyang2018.jy
2022-01-05 14:34       ` Petr Vorel
2022-01-06  5:59         ` xuyang2018.jy
2022-01-06  8:16           ` xuyang2018.jy
2022-01-06  9:25         ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-06  9:25           ` [LTP] [PATCH v2 2/4] lib: Introduce LTP_KCONFIG_DISABLE environment variables Yang Xu
2022-01-06  9:49             ` Petr Vorel
2022-01-06  9:52             ` Petr Vorel
2022-01-06 11:07             ` Cyril Hrubis
2022-01-06 11:50               ` Petr Vorel
2022-01-06 13:59                 ` Cyril Hrubis
2022-01-06 17:41                   ` Petr Vorel
2022-01-07  2:00                   ` xuyang2018.jy
2022-01-06  9:25           ` [LTP] [PATCH v2 3/4] shell: add kconfig parse api Yang Xu
2022-01-06 10:40             ` Petr Vorel
2022-01-06 11:19             ` Cyril Hrubis
2022-01-07  3:54               ` Li Wang
2022-01-07  4:08                 ` xuyang2018.jy [this message]
2022-01-07  7:04                   ` Li Wang
2022-01-07  8:28                     ` xuyang2018.jy
2022-01-07  8:41                       ` Li Wang
2022-01-07  9:46                         ` Cyril Hrubis
2022-01-07  9:56                           ` xuyang2018.jy
2022-01-07  9:05                       ` Petr Vorel
2022-01-07  9:22                         ` xuyang2018.jy
2022-01-07 12:07                           ` Petr Vorel
2022-01-07  7:33                 ` Petr Vorel
2022-01-06  9:25           ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-06 11:20             ` Cyril Hrubis
2022-01-10  1:49               ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-10  1:49                 ` [LTP] [PATCH v3 2/4] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
2022-01-10  8:14                   ` Li Wang
2022-01-10 12:20                   ` Cyril Hrubis
2022-01-11  1:38                     ` xuyang2018.jy
2022-01-10  1:49                 ` [LTP] [PATCH v3 3/4] shell: add kconfig parse api Yang Xu
2022-01-10  8:26                   ` Li Wang
2022-01-10  8:46                     ` xuyang2018.jy
2022-01-10  9:13                       ` Li Wang
2022-01-10 13:43                   ` Cyril Hrubis
2022-01-11  5:29                     ` xuyang2018.jy
2022-01-11  6:10                     ` [LTP] [PATCH v4 1/5] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Yang Xu
2022-01-11  6:10                       ` [LTP] [PATCH v4 2/5] lib: Introduce KCONFIG_SKIP_CHECK environment variable Yang Xu
2022-01-13 11:09                         ` Petr Vorel
2022-01-14  5:36                           ` xuyang2018.jy
2022-01-11  6:10                       ` [LTP] [PATCH v4 3/5] shell: add kconfig parse api Yang Xu
2022-01-11  7:52                         ` Li Wang
2022-01-11  8:37                           ` xuyang2018.jy
2022-01-13  9:15                             ` xuyang2018.jy
2022-01-13  9:42                               ` Li Wang
2022-01-13 15:51                             ` Cyril Hrubis
2022-01-14  6:26                               ` xuyang2018.jy
2022-01-14  9:19                                 ` xuyang2018.jy
2022-01-14  9:49                                   ` Petr Vorel
2022-01-11  6:10                       ` [LTP] [PATCH v4 4/5] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-13 10:53                         ` Petr Vorel
2022-01-13 16:06                           ` Petr Vorel
2022-01-13 15:54                         ` Cyril Hrubis
2022-01-11  6:10                       ` [LTP] [PATCH v4 5/5] runtest.sh: add test_kconfig.sh into ltp c test target Yang Xu
2022-01-13 11:25                         ` Petr Vorel
2022-01-13 15:54                         ` Cyril Hrubis
2022-01-10  1:49                 ` [LTP] [PATCH v3 4/4] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu
2022-01-10  8:30                   ` Li Wang
2022-01-10 14:15                   ` Cyril Hrubis
2022-01-11  5:34                     ` xuyang2018.jy
2022-01-10  8:10                 ` [LTP] [PATCH v3 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Li Wang
2022-01-10 12:18                 ` Cyril Hrubis
2022-01-10  5:45               ` [LTP] [PATCH v2 4/4] sysctl/sysctl02.sh: Use kconfig shell api xuyang2018.jy
2022-01-06  9:54           ` [LTP] [PATCH v2 1/4] lib/tst_kconfig: Modify the return type of tst_kconfig_check function Petr Vorel
2022-01-06 10:57           ` Cyril Hrubis
2022-01-07  1:25             ` xuyang2018.jy
2022-01-04  6:57 ` [LTP] [PATCH v1 3/3] sysctl/sysctl02.sh: Use kconfig shell api Yang Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61D7BD03.4040200@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=chrubis@suse.cz \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.