[igt-dev] [PATCH i-g-t] lib/igt_core: add helper for srandom seed initialization
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Thu May 25 06:08:11 UTC 2023
On Wed, May 24, 2023 at 05:04:03PM +0200, Kamil Konieczny wrote:
> From: Łukasz Łaguna <lukasz.laguna at intel.com>
>
> It allows to set specific value with IGT_SRANDOM environment variable.
>
> Cc: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
> Signed-off-by: Łukasz Łaguna <lukasz.laguna at intel.com>
> Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
> ---
> lib/igt_core.c | 16 ++++++++++++++++
> lib/igt_core.h | 2 ++
> 2 files changed, 18 insertions(+)
>
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index eff3d4272..cd9c2002d 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -3367,6 +3367,22 @@ err:
> return -1;
> }
>
> +/**
> + * igt_srandom:
> + *
> + * It initializes seed for random number generator.
> + * If specific value is needed it can be set with IGT_SRANDOM environment
> + * variable.
> + */
> +void igt_srandom(void)
> +{
> + const char *param = getenv("IGT_SRANDOM");
> + int seed = param ? atoi(param) : time(NULL);
> +
> + srandom(seed);
> + igt_info("Using IGT_SRANDOM=%d for randomisation\n", seed);
> +}
> +
> /* IGT wrappers around libpciaccess init/cleanup functions */
>
> static void pci_system_exit_handler(int sig)
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 5d5593e05..ef6bed6a5 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -1448,6 +1448,8 @@ int igt_system_quiet(const char *command);
> free(buf); \
> } while (0)
>
> +void igt_srandom(void);
> +
> /**
> * igt_trace:
> * @format: printf-style format string with optional args
> --
> 2.39.2
>
Patch looks good for me. Have you thought to add this to constructor
section?
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
--
Zbigniew
More information about the igt-dev
mailing list