[LTP] [PATCH] lib: TST_EXP_FAIL: Add array variants
Petr Vorel
pvorel@suse.cz
Thu Jan 4 13:53:34 CET 2024
Hi Cyril,
> For certain cases there is a possibility of a failure with more than one
> errno, for instance testcases with invalid fd may return either EINVAL
> or EBADFD and in many cases either one is fine, at least that was the
> feedback from kernel devs.
> This change also adds a tst_errno_in_set() function that is now the
> single place to validate errno for all TST_EXP_FAIL*() variants. That is
> intentional since this allows us to implement code to relax the
> conditions if needed, e.g. we had requests to allow additional errnos
> for systems with SELinux where failures may be caused by the SELinux
> policies and the errors may differ.
+1, this should be merged before release.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Also thanks for starting docs in tst_test_macros.h (I wanted to add more but
haven't done it yet).
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
> include/tst_test_macros.h | 65 ++++++++++++++++++++++++++------
> lib/newlib_tests/test_macros02.c | 11 ++++++
> lib/tst_test_macros.c | 36 ++++++++++++++++++
> 3 files changed, 101 insertions(+), 11 deletions(-)
> create mode 100644 lib/tst_test_macros.c
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index bd0c491c1..5687d0904 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -186,7 +186,18 @@ extern void *TST_RET_PTR;
> TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
> } while (0) \
> -#define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...) \
> +/*
> + * Returns true if err is in the exp_err array.
> + */
> +int tst_errno_in_set(int err, const int *exp_errs, int exp_errs_cnt);
nit: we already use bool in fuzzy sync header and tst_af_alg.h. We could use it
here as well (it's immediately obvious it's true/false, not e.g. count).
...
> diff --git a/lib/tst_test_macros.c b/lib/tst_test_macros.c
> new file mode 100644
> index 000000000..a36abbea3
> --- /dev/null
> +++ b/lib/tst_test_macros.c
> @@ -0,0 +1,36 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
nit: maybe 2024?
> + */
> +
> +#include <stdio.h>
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +#include "tst_test_macros.h"
> +
> +int tst_errno_in_set(int err, const int *exp_errs, int exp_errs_cnt)
> +{
> + int i;
> +
> + for (i = 0; i < exp_errs_cnt; i++) {
> + if (err == exp_errs[i])
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> +const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt)
> +{
> + int i;
> + char *cb = buf;
> +
> + for (i = 0; i < exp_errs_cnt-1; i++)
> + cb += sprintf(cb, "%s, ", tst_strerrno(exp_errs[i]));
> +
> + cb += sprintf(cb, "%s", tst_strerrno(exp_errs[i]));
> +
> + *cb = 0;
very nit: \0 is for me more readable.
Kind regards,
Petr
> +
> + return buf;
> +}
More information about the ltp
mailing list