Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] lib/igt_core: add helper for srandom seed initialization
@ 2023-05-24 15:04 Kamil Konieczny
  2023-05-24 16:30 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Kamil Konieczny @ 2023-05-24 15:04 UTC (permalink / raw)
  To: igt-dev

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-26 12:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-24 15:04 [igt-dev] [PATCH i-g-t] lib/igt_core: add helper for srandom seed initialization Kamil Konieczny
2023-05-24 16:30 ` [igt-dev] ✓ Fi.CI.BAT: success for " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox