summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLyude <lyude@redhat.com>2016-12-21 14:00:54 -0500
committerLyude <lyude@redhat.com>2017-01-03 13:56:22 -0500
commit31811f4b6c5a95de82e47ddf1f37739c3b2cfc58 (patch)
tree45740db84fce7d3739d49878e48387311b7c29bb /lib
parentc7c581a6843644343c15e964eddacab4a6c77769 (diff)
igt_core: add igt_constructor
This is a simple macro for executing a block of code at the beginning of intel-gpu-tools, before any tests have been ran. Useful for initialization of global resources used in IGT libraries. Signed-off-by: Lyude <lyude@redhat.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Changes since v1: - Add the line number into the name of the constructor function so that multiple constructors may be used per-file.
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_core.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 661a6343..b669de3e 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -281,6 +281,19 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
} \
static void igt_tokencat(__real_main, __LINE__)(void) \
+/**
+ * igt_constructor:
+ *
+ * Convenience macro to run the provided code block when igt first starts,
+ * before any tests have been run. This should be used for parts of the igt
+ * library that require initialization of objects with global context.
+ *
+ * This code block will be executed exactly once.
+ */
+#define igt_constructor \
+ __attribute__((constructor)) \
+ static void igt_tokencat(__igt_constructor_l, __LINE__)(void)
+
__attribute__((format(printf, 1, 2)))
void igt_skip(const char *f, ...) __attribute__((noreturn));
__attribute__((format(printf, 5, 6)))