igt_core: add igt_constructor
PATCH v2 1/1 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.
Changes since v1:
- Add the line number into the name of the constructor function so that multiple constructors may be used per-file.
--- configure.ac | 1 + lib/igt_core.h | 13 +++++++++++++ 2 files changed, 14 insertions(+)
configure.ac +1 -0
@@ -65,6 +65,7 @@ AC_CHECK_TYPES([sighandler_t],[],[],[AC_INCLUDES_DEFAULT #include <signal.h>]) AC_CHECK_FUNCS([swapctl]) AC_CHECK_FUNCS([asprintf]) +AX_GCC_FUNC_ATTRIBUTE([constructor]) dnl Check for POSIX timers AC_CHECK_FUNCS(timer_create, [], [
lib/igt_core.h +13 -0
@@ -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)))
Signature · 6 lines
2.9.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 9 lines · Lyude
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 <[email protected]>Changes since v1:
- Add the line number into the name of the constructor function so that multiple constructors may be used per-file.
Works for me,
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Em Qua, 2016-12-21 às 15:50 -0500, Lyude escreveu:
Quoted 4 lines
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.
IGT doesn't compile anymore here. Reverting this patch fixes it for me.
On a brand new git clone, if I just run autogen.sh, I get this:
./configure: line 6319: syntax error near unexpected token `constructor'
./configure: line 6319: `AX_GCC_FUNC_ATTRIBUTE(constructor)'
The gcc/autoconf/etc versions are from Fedora 24.
I'm not sure what I'm missing here...
Quoted 49 lines
Signed-off-by Lyude <[email protected]>Changes since v1:
- Add the line number into the name of the constructor function so that
multiple constructors may be used per-file.
---
configure.ac | 1 +
lib/igt_core.h | 13 +++++++++++++2 files changed, 14 insertions(+)configure.ac +0
-0@@ -65,6 +65,7 @@
AC_CHECK_TYPES([sighandler_t],[],[],[AC_INCLUDES_DEFAULT #include <signal.h>])AC_CHECK_FUNCS([swapctl])AC_CHECK_FUNCS([asprintf])+AX_GCC_FUNC_ATTRIBUTE([constructor])
dnl Check for POSIX timers AC_CHECK_FUNCS(timer_create, [], [lib/igt_core.h +0
-0@@ -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.
+ */lib/igt_core.h +3
-0+#define igt_constructor \ + __attribute__((constructor)) \ + static void igt_tokencat(__igt_constructor_l,
Quoted 5 lines
__LINE__)(void)
+
__attribute__((format(printf, 1, 2)))
voidigt_skip(const char *f, ...)__attribute__((noreturn));__attribute__((format(printf, 5, 6)))
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 10 lines · Paulo Zanoni
Em Qua, 2016-12-21 às 15:50 -0500, Lyude escreveu:
Quoted 4 lines
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.IGT doesn't compile anymore here. Reverting this patch fixes it for me.
On a brand new git clone, if I just run
autogen.sh, I get this:
Quoted 7 lines
./configure: line 6319: syntax error near unexpected token `constructor'
./configure: line 6319: `AX_GCC_FUNC_ATTRIBUTE(constructor)'The gcc/autoconf/etc versions are from Fedora 24.
I'm not sure what I'm missing here...
m4/ax_gcc_func_attribute.m4
Now supplied for us luddites.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx