All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 1/2] lib: Refactor construction of unique tokens
@ 2021-10-05 22:29 Ashutosh Dixit
  2021-10-05 22:29 ` [igt-dev] [PATCH i-g-t 2/2] lib: Typechecking minmax Ashutosh Dixit
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ashutosh Dixit @ 2021-10-05 22:29 UTC (permalink / raw)
  To: igt-dev; +Cc: Petri Latvala, Zbigniew Kempczynski, Chris Wilson

From: Chris Wilson <chris.p.wilson@intel.com>

Wrap all the igt_tokencat(prefix, __LINE) into its own igt_unique() to
reduce the clutter and make it easier to generate unique tokens for other
common macros.

Signed-off-by: Chris Wilson <chris.p.wilson@intel.com>
---
 lib/igt_core.h | 54 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/lib/igt_core.h b/lib/igt_core.h
index 8d433fc1655..6b8dbf348d8 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -147,12 +147,12 @@ __noreturn void __igt_fixture_end(void);
  * enumeration (e.g. when enumerating on systems without an intel gpu) such
  * blocks should be annotated with igt_fixture.
  */
-#define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \
-			 igt_tokencat(__tmpint,__LINE__) < 1 && \
+#define igt_fixture for (volatile int igt_unique(__tmpint) = 0; \
+			 igt_unique(__tmpint) < 1 && \
 			 (STATIC_ANALYSIS_BUILD || \
 			 (__igt_fixture() && \
 			 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0))); \
-			 igt_tokencat(__tmpint,__LINE__) ++, \
+			 igt_unique(__tmpint) ++, \
 			 __igt_fixture_complete())
 
 /* subtest infrastructure */
@@ -203,6 +203,16 @@ bool __igt_run_dynamic_subtest(const char *dynamic_subtest_name);
  */
 #define igt_tokencat(x, y) __igt_tokencat2(x, y)
 
+/**
+ * igt_unique:
+ * @prefix: local identifier
+ *
+ * C preprocessor helper to generate a custom 'unique' token by appending
+ * the line number onto the token.
+ */
+#define igt_unique(prefix) \
+	igt_tokencat(igt_tokencat(__igt_unique__, prefix), __LINE__)
+
 /**
  * igt_subtest:
  * @name: name of the subtest
@@ -238,7 +248,7 @@ bool __igt_run_dynamic_subtest(const char *dynamic_subtest_name);
  * static string.
  */
 #define igt_subtest_f(f...) \
-	__igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f)
+	__igt_subtest_f(igt_unique(__tmpchar), f)
 
 /**
  * igt_subtest_with_dynamic:
@@ -315,7 +325,7 @@ bool __igt_run_dynamic_subtest(const char *dynamic_subtest_name);
  * format string instead of a static string.
  */
 #define igt_subtest_with_dynamic_f(f...) \
-	__igt_subtest_with_dynamic_f(igt_tokencat(__tmpchar, __LINE__), f)
+	__igt_subtest_with_dynamic_f(igt_unique(__tmpchar), f)
 
 /**
  * igt_dynamic:
@@ -358,7 +368,7 @@ bool __igt_run_dynamic_subtest(const char *dynamic_subtest_name);
  * instead of a static string.
  */
 #define igt_dynamic_f(f...) \
-	__igt_dynamic_f(igt_tokencat(__tmpchar, __LINE__), f)
+	__igt_dynamic_f(igt_unique(__tmpchar), f)
 
 const char *igt_subtest_name(void);
 bool igt_only_list_subtests(void);
@@ -380,15 +390,15 @@ void __igt_subtest_group_restore(int, int);
  * clauses. If any common setup in a fixture fails, only the subtests in this
  * group will fail or skip. Subtest groups can be arbitrarily nested.
  */
-#define igt_subtest_group for (int igt_tokencat(__tmpint,__LINE__) = 0, \
-			       igt_tokencat(__save,__LINE__) = 0, \
-			       igt_tokencat(__desc,__LINE__) = 0; \
-			       igt_tokencat(__tmpint,__LINE__) < 1 && \
-			       (__igt_subtest_group_save(& igt_tokencat(__save,__LINE__), \
-							 & igt_tokencat(__desc,__LINE__) ), true); \
-			       igt_tokencat(__tmpint,__LINE__) ++, \
-			       __igt_subtest_group_restore(igt_tokencat(__save,__LINE__), \
-							   igt_tokencat(__desc,__LINE__)))
+#define igt_subtest_group for (int igt_unique(__tmpint) = 0, \
+			       igt_unique(__save) = 0, \
+			       igt_unique(__desc) = 0; \
+			       igt_unique(__tmpint) < 1 && \
+			       (__igt_subtest_group_save(& igt_unique(__save), \
+							 & igt_unique(__desc) ), true); \
+			       igt_unique(__tmpint) ++, \
+			       __igt_subtest_group_restore(igt_unique(__save), \
+							   igt_unique(__desc)))
 
 /**
  * igt_main_args:
@@ -404,15 +414,15 @@ void __igt_subtest_group_restore(int, int);
  * #igt_subtest_init_parse_opts.
  */
 #define igt_main_args(short_opts, long_opts, help_str, opt_handler, handler_data) \
-	static void igt_tokencat(__real_main, __LINE__)(void); \
+	static void igt_unique(__real_main)(void); \
 	int main(int argc, char **argv) { \
 		igt_subtest_init_parse_opts(&argc, argv, \
 					    short_opts, long_opts, help_str, \
 					    opt_handler, handler_data); \
-		igt_tokencat(__real_main, __LINE__)(); \
+		igt_unique(__real_main)(); \
 		igt_exit(); \
 	} \
-	static void igt_tokencat(__real_main, __LINE__)(void) \
+	static void igt_unique(__real_main)(void) \
 
 
 /**
@@ -460,15 +470,15 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
  * #igt_simple_init_parse_opts.
  */
 #define igt_simple_main_args(short_opts, long_opts, help_str, opt_handler, handler_data) \
-	static void igt_tokencat(__real_main, __LINE__)(void); \
+	static void igt_unique(__real_main)(void); \
 	int main(int argc, char **argv) { \
 		igt_simple_init_parse_opts(&argc, argv, \
 					   short_opts, long_opts, help_str, \
 					   opt_handler, handler_data);	\
-		igt_tokencat(__real_main, __LINE__)(); \
+		igt_unique(__real_main)(); \
 		igt_exit(); \
 	} \
-	static void igt_tokencat(__real_main, __LINE__)(void) \
+	static void igt_unique(__real_main)(void) \
 
 
 /**
@@ -490,7 +500,7 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
  */
 #define igt_constructor \
 	__attribute__((constructor)) \
-	static void igt_tokencat(__igt_constructor_l, __LINE__)(void)
+	static void igt_unique(__igt_constructor_l)(void)
 
 __noreturn __attribute__((format(printf, 1, 2)))
 void igt_skip(const char *f, ...);
-- 
2.33.0

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

end of thread, other threads:[~2021-10-06 20:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 22:29 [igt-dev] [PATCH i-g-t 1/2] lib: Refactor construction of unique tokens Ashutosh Dixit
2021-10-05 22:29 ` [igt-dev] [PATCH i-g-t 2/2] lib: Typechecking minmax Ashutosh Dixit
2021-10-06 18:11   ` Zbigniew Kempczyński
2021-10-06 20:26   ` Zbigniew Kempczyński
2021-10-05 23:16 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] lib: Refactor construction of unique tokens Patchwork
2021-10-06  3:46 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2021-10-06  8:01 ` [igt-dev] [PATCH i-g-t 1/2] " Zbigniew Kempczyński

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.