public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Richard Palethorpe <io@richiejp.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/3] Add support for mixing C and shell code
Date: Mon, 26 Aug 2024 16:51:28 +0200	[thread overview]
Message-ID: <ZsyWcCGmjaWWe7fK@yuki.lan> (raw)
In-Reply-To: <87wmkksafr.fsf@richiejp.com>

Hi!
> In general I like the idea except that it will encourage more shell
> usage, but I'm guessing that is a battle that has already been
> lost.

Indeed. However messy shell is we are not going to get rid of it.

> Also if a suitable embedded scripting language were found this is
> a starting point for that.

My hopes are not that high, LTP targets embedded, so we are quite
limited in what we can do here and having python or perl as a dependency
is a no-go. Perhaps there is a minimalistic scripting language that
integrated into UNIX well out there, but I'm not aware of any. So as far
as I can tell we are stuck with shell for the foreseeable future.

> > 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                   | 11 ++++
> >  testcases/lib/tests/.gitignore               |  6 ++
> >  testcases/lib/tests/Makefile                 | 11 ++++
> >  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 ++++++
> >  testcases/lib/tests/shell_test_brk.sh        |  6 ++
> >  testcases/lib/tests/shell_test_check_argv.sh | 23 ++++++++
> >  testcases/lib/tests/shell_test_checkpoint.sh |  7 +++
> >  testcases/lib/tests/shell_test_pass.sh       |  6 ++
> >  testcases/lib/tst_env.sh                     | 21 +++++++
> >  testcases/lib/tst_res_.c                     | 58 ++++++++++++++++++++
> >  19 files changed, 362 insertions(+), 2 deletions(-)
> >  create mode 100755 testcases/lib/run_tests.sh
> >  create mode 100644 testcases/lib/tests/.gitignore
> >  create mode 100644 testcases/lib/tests/Makefile
> >  create mode 100644 testcases/lib/tests/shell_test01.c
> >  create mode 100644 testcases/lib/tests/shell_test02.c
> >  create mode 100644 testcases/lib/tests/shell_test03.c
> >  create mode 100644 testcases/lib/tests/shell_test04.c
> >  create mode 100644 testcases/lib/tests/shell_test05.c
> >  create mode 100644 testcases/lib/tests/shell_test06.c
> >  create mode 100755 testcases/lib/tests/shell_test_brk.sh
> >  create mode 100755 testcases/lib/tests/shell_test_check_argv.sh
> >  create mode 100755 testcases/lib/tests/shell_test_checkpoint.sh
> >  create mode 100755 testcases/lib/tests/shell_test_pass.sh
> >  create mode 100644 testcases/lib/tst_env.sh
> >  create mode 100644 testcases/lib/tst_res_.c
> >
> > diff --git a/include/tst_test.h b/include/tst_test.h
> > index 6c76f043d..a334195ac 100644
> > --- a/include/tst_test.h
> > +++ b/include/tst_test.h
> > @@ -331,6 +331,8 @@ struct tst_fs {
> >   * @child_needs_reinit: Has to be set if the test needs to call tst_reinit()
> >   *                      from a process started by exec().
> >   *
> > + * @runs_script: Implies child_needs_reinit and forks_child at the moment.
> > + *
> >   * @needs_devfs: If set the devfs is mounted at tst_test.mntpoint. This is
> >   *               needed for tests that need to create device files since tmpfs
> >   *               at /tmp is usually mounted with 'nodev' option.
> > @@ -518,6 +520,7 @@ struct tst_fs {
> >  	unsigned int mount_device:1;
> >  	unsigned int needs_rofs:1;
> >  	unsigned int child_needs_reinit:1;
> > +	unsigned int runs_script:1;
> 
> This could be a string constant instead of a flag if you want to future
> proof against multiple scripting languages or you could change it to runs_shell.

Heh, Martin Doucha requtested runs_shell to be changed to runs_script,
and that was a rightful request, since there is actually nothing shell
specific in the test library, it just sets up env variables and passes
command line option to something that is executed by execvpe(). All that
is missing for any other scripting language is a bit of glue code that
would interface the shared memory passed down in LTP_IPC_ENV.

So quite contrary the tst_run_shell() function should be renamed to
tst_run_script() as well, which I will do in v3.

> > +	int pid;
> > +	unsigned int i, params_len = params_array_len(params);
> > +	char *argv[params_len + 2];
> > +
> > +	if (!tst_test->runs_script)
> > +		tst_brk(TBROK, "runs_script flag must be set!");
> > +
> > +	argv[0] = script_name;
> maybe you'd have to cast it here or something, but IMO worth it

Hmm, I was expecting that we would have to copy the data, but casting
seems to work, will do.

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2024-08-26 14:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  9:20 [LTP] [PATCH 0/3] Shell test library v3 Cyril Hrubis
2024-07-31  9:20 ` [LTP] [PATCH 1/3] Add support for mixing C and shell code Cyril Hrubis
2024-08-13 15:35   ` Richard Palethorpe
2024-08-26 14:51     ` Cyril Hrubis [this message]
2024-07-31  9:20 ` [LTP] [PATCH 2/3] libs: Vendor ujson library Cyril Hrubis
2024-08-13 15:38   ` Richard Palethorpe
2024-07-31  9:20 ` [LTP] [PATCH 3/3] testcaes/lib: Add shell loader Cyril Hrubis
2024-08-13 16:15   ` Richard Palethorpe
2024-08-26 15:10     ` Cyril Hrubis
2024-07-31 10:06 ` [LTP] [PATCH 0/3] Shell test library v3 Cyril Hrubis

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=ZsyWcCGmjaWWe7fK@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=io@richiejp.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox