From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] lib/igt_core: add helper for srandom seed initialization
Date: Wed, 24 May 2023 17:04:03 +0200 [thread overview]
Message-ID: <20230524150403.31460-1-kamil.konieczny@linux.intel.com> (raw)
From: Łukasz Łaguna <lukasz.laguna@intel.com>
It allows to set specific value with IGT_SRANDOM environment variable.
Cc: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Signed-off-by: Łukasz Łaguna <lukasz.laguna@intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny@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
next reply other threads:[~2023-05-24 15:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 15:04 Kamil Konieczny [this message]
2023-05-24 16:30 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_core: add helper for srandom seed initialization Patchwork
2023-05-25 5:22 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-05-25 21:17 ` Kamil Konieczny
2023-05-26 12:20 ` Yedireswarapu, SaiX Nandan
2023-05-25 6:08 ` [igt-dev] [PATCH i-g-t] " Zbigniew Kempczyński
2023-05-26 12:06 ` [igt-dev] ✓ Fi.CI.IGT: success for " Patchwork
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=20230524150403.31460-1-kamil.konieczny@linux.intel.com \
--to=kamil.konieczny@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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