From: Cyril Hrubis <chrubis@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] save_restore: Introduce new struct field for flags
Date: Wed, 16 Nov 2022 16:46:32 +0100 [thread overview]
Message-ID: <Y3UF2Jgkf0Svj7lm@yuki> (raw)
In-Reply-To: <20221116145411.21299-1-mdoucha@suse.cz>
Hi!
> +* 'TST_SR_TBROK_MISSING' – End test with 'TBROK' if the file does not exist
> +* 'TST_SR_TCONF_MISSING' – End test with 'TCONF' if the file does not exist
> +* 'TST_SR_SKIP_MISSING' – Continue without saving the file if it does not exist
> +* 'TST_SR_TBROK_RO' – End test with 'TBROK' if the file is read-only
> +* 'TST_SR_TCONF_RO' – End test with 'TCONF' if the file is read-only
> +* 'TST_SR_SKIP_RO' – Continue without saving the file if it is read-only
> +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the file
> +
> +Common flag combinations also have shortcuts:
> +
> +* 'TST_SR_TCONF' – Equivalent to 'TST_SR_TCONF_MISSING | TST_SR_TCONF_RO'
> +* 'TST_SR_TBROK' – Equivalent to 'TST_SR_TBROK_MISSING | TST_SR_TBROK_RO'
> +* 'TST_SR_SKIP' – Equivalent to 'TST_SR_SKIP_MISSING | TST_SR_SKIP_RO'
This looks good now, great work!
> 'restore' is always strict and will TWARN if it encounters any error.
>
> [source,c]
> -------------------------------------------------------------------------------
> -static void setup(void)
> -{
> - FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath");
> - SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
> -}
> -
> static struct tst_test test = {
> ...
> .setup = setup,
> .save_restore = (const struct tst_path_val[]) {
> - {"/proc/sys/kernel/core_pattern", NULL},
> - {"?/proc/sys/user/max_user_namespaces", NULL},
> - {"!/sys/kernel/mm/ksm/run", "1"},
> + {"/proc/sys/kernel/core_pattern", NULL, TST_SR_TCONF},
> + {"/proc/sys/user/max_user_namespaces", NULL, TST_SR_SKIP},
> + {"/sys/kernel/mm/ksm/run", "1", TST_SR_TBROK},
> {}
> },
> };
> diff --git a/include/tst_sys_conf.h b/include/tst_sys_conf.h
> index b7bbe36fc..4c85767be 100644
> --- a/include/tst_sys_conf.h
> +++ b/include/tst_sys_conf.h
> @@ -5,14 +5,26 @@
> #ifndef TST_SYS_CONF_H__
> #define TST_SYS_CONF_H__
>
> +#define TST_SR_TCONF_MISSING 0x0
> +#define TST_SR_TBROK_MISSING 0x1
> +#define TST_SR_SKIP_MISSING 0x2
> +#define TST_SR_TCONF_RO 0x0
> +#define TST_SR_TBROK_RO 0x4
> +#define TST_SR_SKIP_RO 0x8
> +#define TST_SR_IGNORE_ERR 0x10
> +
> +#define TST_SR_TCONF (TST_SR_TCONF_MISSING | TST_SR_TCONF_RO)
> +#define TST_SR_TBROK (TST_SR_TBROK_MISSING | TST_SR_TBROK_RO)
> +#define TST_SR_SKIP (TST_SR_SKIP_MISSING | TST_SR_SKIP_RO)
> +
> struct tst_path_val {
> const char *path;
> const char *val;
> + unsigned int flags;
> };
>
> -int tst_sys_conf_save_str(const char *path, const char *value);
> -int tst_sys_conf_save(const char *path);
> -void tst_sys_conf_set(const char *path, const char *value);
> +void tst_sys_conf_save_str(const char *path, const char *value);
> +int tst_sys_conf_save(const struct tst_path_val *conf);
> void tst_sys_conf_restore(int verbose);
> void tst_sys_conf_dump(void);
>
> diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
> index 003698825..78ed577e2 100644
> --- a/lib/tst_sys_conf.c
> +++ b/lib/tst_sys_conf.c
> @@ -20,6 +20,14 @@ struct tst_sys_conf {
>
> static struct tst_sys_conf *save_restore_data;
>
> +static void print_error(int info_only, const char *err, const char *path)
> +{
> + if (info_only)
> + tst_res(TINFO | TERRNO, err, path);
> + else
> + tst_brk(TBROK | TERRNO, err, path);
> +}
If I remmeber correctly I did ask for this to become a macro or pass
__LINE__ so that we have a correct lines in the error output and you
haven't commented on that.
Otherwise the rest looks good to me.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-11-16 15:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 14:54 [LTP] [PATCH v4] save_restore: Introduce new struct field for flags Martin Doucha
2022-11-16 15:46 ` Cyril Hrubis [this message]
2022-11-16 15:51 ` Martin Doucha
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=Y3UF2Jgkf0Svj7lm@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=mdoucha@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.