[LTP] [PATCH v2 2/2] tst_common.h: Move struct pair definition from tst_res to include/tst_common.h to avoid duplicate code

Kushal Chand kushalkataria5@gmail.com
Tue Jan 18 06:57:46 CET 2022


This patch moves definition of struct pair from tst_res.c to include/tst_common.h
to avoid code duplication as struct pair is also used by tst_taint.c.

---
 include/tst_common.h | 15 +++++++++++++++
 lib/tst_res.c        | 15 ---------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/tst_common.h b/include/tst_common.h
index fd7a900d4..cd85d6053 100644
--- a/include/tst_common.h
+++ b/include/tst_common.h
@@ -83,4 +83,19 @@
 #define TST_RES_SUPPORTS_TCONF_TFAIL_TINFO_TPASS_TWARN(condition) \
 	TST_BUILD_BUG_ON(condition)
 
+struct pair {
+	const char *name;
+	int val;
+};
+
+#define PAIR(def) [def] = {.name = #def, .val = def},
+#define STRPAIR(key, value) [key] = {.name = value, .val = key},
+
+#define PAIR_LOOKUP(pair_arr, idx) do {                       \
+	if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \
+	    pair_arr[idx].name == NULL)                       \
+		return "???";                                 \
+	return pair_arr[idx].name;                            \
+} while (0)
+
 #endif /* TST_COMMON_H__ */
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 8d86b48a4..c41f3a2a2 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -124,21 +124,6 @@ extern char *TCID;		/* Test case identifier from the test source */
 extern int TST_TOTAL;		/* Total number of test cases from the test */
 
 
-struct pair {
-	const char *name;
-	int val;
-};
-
-#define PAIR(def) [def] = {.name = #def, .val = def},
-#define STRPAIR(key, value) [key] = {.name = value, .val = key},
-
-#define PAIR_LOOKUP(pair_arr, idx) do {                       \
-	if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \
-	    pair_arr[idx].name == NULL)                       \
-		return "???";                                 \
-	return pair_arr[idx].name;                            \
-} while (0)
-
 const char *strttype(int ttype)
 {
 	static const struct pair ttype_pairs[] = {
-- 
2.25.1



More information about the ltp mailing list