All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [RFC PATCH 1/2] Add support for mixing C and shell code
Date: Thu, 18 Jul 2024 14:57:09 +0200	[thread overview]
Message-ID: <20240718125709.GB738326@pevik> (raw)
In-Reply-To: <20240716153604.22984-2-chrubis@suse.cz>

Hi Cyril,

> This is a proof of a concept of a seamless C and shell integration. The
> idea is that with this you can mix shell and C code as much as as you
> wish to get the best of the two worlds.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  include/tst_test.h                           | 38 +++++++++++++
>  lib/tst_test.c                               | 51 +++++++++++++++++
>  testcases/lib/.gitignore                     |  1 +
>  testcases/lib/Makefile                       |  4 +-
>  testcases/lib/run_tests.sh                   | 10 ++++
>  testcases/lib/tests/.gitignore               |  6 ++
>  testcases/lib/tests/Makefile                 | 11 ++++
>  testcases/lib/tests/shell_loader.sh          |  5 ++
>  testcases/lib/tests/shell_test01.c           | 17 ++++++
>  testcases/lib/tests/shell_test02.c           | 18 ++++++
>  testcases/lib/tests/shell_test03.c           | 25 +++++++++
>  testcases/lib/tests/shell_test04.c           | 18 ++++++
>  testcases/lib/tests/shell_test05.c           | 27 +++++++++
>  testcases/lib/tests/shell_test06.c           | 16 ++++++
FYI we have shell tests for new library in lib/newlib_tests (C tests) and
lib/newlib_tests/shell/ (shell tests), is it necessary to add new location? Or,
if you prefer this, we should move existing tests from lib/newlib_tests/shell/
to this new location.

Also, we have lib/newlib_tests/runtest.sh script, which runs currently only te
tests which exit 0 (TPASS or TCONF). Here are LTP_SHELL_API_TESTS listed.

Also we have test-shell target in the top level Makefile.

=> these tests (currently only these which exits 0) should be run by test-shell
and thus in CI.

Generally the approach LGTM.

>  	unsigned int needs_hugetlbfs:1;
> @@ -607,6 +612,39 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
>   */
>  void tst_reinit(void);

> +/**
> + * tst_run_shell() - Prepare the environment and execute a shell script.
> + *
> + * @script_name: A filename of the script.
> + * @params: A NULL terminated array of shell script parameters, pass NULL if
> + *          none are needed. This what is passed starting from argv[1].
> + *
> + * The shell script is executed with LTP_IPC_PATH in environment so that the
> + * binary helpers such as tst_res_ or tst_checkpoint work properly when executed
> + * from the script. This also means that the tst_test.runs_shell flag needs to
> + * be set.
> + *
> + * The shell script itself has to source the tst_env.sh shell script at the
> + * start and after that it's free to use tst_res in the same way C code would
> + * use.
> + *
> + * Example shell script that reports success::
nit: double :

> + *
> + *   #!/bin/sh
> + *   . tst_env.sh
> + *
> + *   tst_res TPASS "Example test works"
> + *
> + * The call returns a pid in a case that you want to examine the return value
> + * of the script yourself. If you do not need to check the return value
> + * yourself you can use tst_reap_children() to wait for the completion. Or let
> + * the test library collect the child automatically, just be wary that the
> + * script and the test both runs concurently at the same time in this case.
> + *
> + * Return: A pid of the shell process.
> + */
> +int tst_run_shell(char *script_name, char *const params[]);
> +
>  unsigned int tst_multiply_timeout(unsigned int timeout);

>  /*
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index e5bc5bf4d..fa0907353 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -173,6 +173,52 @@ void tst_reinit(void)
>  	SAFE_CLOSE(fd);
>  }
...

> +int tst_run_shell(char *script_name, char *const params[])
> +{
> +	int pid;
> +	unsigned int i, params_len = params_array_len(params);
> +	char *argv[params_len + 2] = {};
As I noted, this is a problem for old gcc 7 (still used in 15-SP6).

Kind regards,
Petr

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

  parent reply	other threads:[~2024-07-18 12:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 15:36 [LTP] [RFC PATCH 0/2] Shell test library v3 Cyril Hrubis
2024-07-16 15:36 ` [LTP] [RFC PATCH 1/2] Add support for mixing C and shell code Cyril Hrubis
2024-07-17  8:33   ` Li Wang
2024-07-17  8:41     ` Cyril Hrubis
2024-07-17 10:07       ` Li Wang
2024-07-17  8:52     ` Cyril Hrubis
2024-07-17 10:21       ` Li Wang
2024-07-17 17:51         ` Petr Vorel
2024-07-17 17:55         ` Petr Vorel
2024-07-17 18:13           ` Cyril Hrubis
2024-07-18 12:43   ` Petr Vorel
2024-07-18 13:03     ` Cyril Hrubis
2024-07-18 12:57   ` Petr Vorel [this message]
2024-07-18 13:07     ` Cyril Hrubis
2024-07-18 13:15       ` Petr Vorel
2024-07-24  9:37   ` Martin Doucha
2024-07-24  9:47     ` Cyril Hrubis
2024-07-24  9:53       ` Martin Doucha
2024-07-24 10:05         ` Cyril Hrubis
2024-07-30  9:49     ` Cyril Hrubis
2024-07-16 15:36 ` [LTP] [RFC PATCH 2/2] testcaes/lib: Add shell loader Cyril Hrubis
2024-07-24 12:54   ` Martin Doucha
2024-07-25 11:02     ` Petr Vorel
2024-07-25 16:01       ` Martin Doucha
2024-07-25 21:44         ` Petr Vorel

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=20240718125709.GB738326@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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.