diff mbox series

[v2,01/14] testsuite: test predef macros on LP32/LP64/LLP64

Message ID 20181212164554.43133-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series predefined macros for intmax_t/intptr_t/... | expand

Commit Message

Luc Van Oostenryck Dec. 12, 2018, 4:45 p.m. UTC
Now these tests should succeed and be meaningful on
all archs.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/preprocessor/predef-char-bit.c | 16 ---------
 validation/preprocessor/predef-llp64.c    | 10 ++++++
 validation/preprocessor/predef-lp32.c     |  9 +++++
 validation/preprocessor/predef-lp64.c     |  9 +++++
 validation/preprocessor/predef-max.c      | 18 ----------
 validation/preprocessor/predef-sizeof.c   | 25 --------------
 validation/preprocessor/predef.c          | 42 +++++++++++++++++++++++
 7 files changed, 70 insertions(+), 59 deletions(-)
 delete mode 100644 validation/preprocessor/predef-char-bit.c
 create mode 100644 validation/preprocessor/predef-llp64.c
 create mode 100644 validation/preprocessor/predef-lp32.c
 create mode 100644 validation/preprocessor/predef-lp64.c
 delete mode 100644 validation/preprocessor/predef-max.c
 delete mode 100644 validation/preprocessor/predef-sizeof.c
 create mode 100644 validation/preprocessor/predef.c
diff mbox series

Patch

diff --git a/validation/preprocessor/predef-char-bit.c b/validation/preprocessor/predef-char-bit.c
deleted file mode 100644
index fed0166e4..000000000
--- a/validation/preprocessor/predef-char-bit.c
+++ /dev/null
@@ -1,16 +0,0 @@ 
-#define TEST_BIT(X, T)	if (__ ## X ## _BIT__  != 8 * sizeof(T)) return 1
-
-int test(void)
-{
-	TEST_BIT(CHAR, char);
-
-	return 0;
-}
-
-/*
- * check-name: predefined __<type>_BIT__
- * check-command: test-linearize -Wno-decl $file
- * check-output-ignore
- *
- * check-output-contains: ret\\..*\\$0
- */
diff --git a/validation/preprocessor/predef-llp64.c b/validation/preprocessor/predef-llp64.c
new file mode 100644
index 000000000..a34b51b3a
--- /dev/null
+++ b/validation/preprocessor/predef-llp64.c
@@ -0,0 +1,10 @@ 
+#include "predef.c"
+
+/*
+ * check-name: predefined macros for LLP64
+ * check-command: test-linearize -Wno-decl -msize-llp64 $file
+ * check-known-to-fail
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
diff --git a/validation/preprocessor/predef-lp32.c b/validation/preprocessor/predef-lp32.c
new file mode 100644
index 000000000..8fa2846c2
--- /dev/null
+++ b/validation/preprocessor/predef-lp32.c
@@ -0,0 +1,9 @@ 
+#include "predef.c"
+
+/*
+ * check-name: predefined macros for LP32
+ * check-command: test-linearize -Wno-decl -m32 $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
diff --git a/validation/preprocessor/predef-lp64.c b/validation/preprocessor/predef-lp64.c
new file mode 100644
index 000000000..0173ca40d
--- /dev/null
+++ b/validation/preprocessor/predef-lp64.c
@@ -0,0 +1,9 @@ 
+#include "predef.c"
+
+/*
+ * check-name: predefined macros for LP64
+ * check-command: test-linearize -Wno-decl -m64 $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
diff --git a/validation/preprocessor/predef-max.c b/validation/preprocessor/predef-max.c
deleted file mode 100644
index ad4b7eaf1..000000000
--- a/validation/preprocessor/predef-max.c
+++ /dev/null
@@ -1,18 +0,0 @@ 
-#define TEST_MAX(X, Z)	if (X != ((~ Z) >> 1))	return 1
-
-int test_max(void)
-{
-	TEST_MAX(__INT_MAX__, 0U);
-	TEST_MAX(__LONG_MAX__, 0UL);
-	TEST_MAX(__LONG_LONG_MAX__, 0ULL);
-
-	return 0;
-}
-
-/*
- * check-name: predefined __<type>_MAX__
- * check-command: test-linearize -Wno-decl $file
- * check-output-ignore
- *
- * check-output-contains: ret\\..*\\$0
- */
diff --git a/validation/preprocessor/predef-sizeof.c b/validation/preprocessor/predef-sizeof.c
deleted file mode 100644
index 12be2dd1d..000000000
--- a/validation/preprocessor/predef-sizeof.c
+++ /dev/null
@@ -1,25 +0,0 @@ 
-#define TEST(X, T)	if (__SIZEOF_ ## X ## __ != sizeof(T))	return 1
-
-int test_sizeof(void)
-{
-	TEST(SHORT, short);
-	TEST(INT, int);
-	TEST(LONG, long);
-	TEST(LONG_LONG, long long);
-	TEST(INT128, __int128);
-	TEST(SIZE_T, __SIZE_TYPE__);
-	TEST(POINTER, void*);
-	TEST(FLOAT, float);
-	TEST(DOUBLE, double);
-	TEST(LONG_DOUBLE, long double);
-
-	return 0;
-}
-
-/*
- * check-name: predefined __SIZEOF_<type>__
- * check-command: test-linearize -Wno-decl $file
- * check-output-ignore
- *
- * check-output-contains: ret\\..*\\$0
- */
diff --git a/validation/preprocessor/predef.c b/validation/preprocessor/predef.c
new file mode 100644
index 000000000..ccb5d3619
--- /dev/null
+++ b/validation/preprocessor/predef.c
@@ -0,0 +1,42 @@ 
+#define BITS(T)		(sizeof(T) * 8)
+#define SIGN_BIT(T)	(1ULL << (BITS(T) - 1))
+#define SMASK(T)	(SIGN_BIT(T) - 1)
+#define UMASK(T)	(SIGN_BIT(T) | SMASK(T))
+
+int test(void);
+int test(void)
+{
+#define TEST_BIT(X, T)	if (__ ## X ## _BIT__  != BITS(T)) return 1
+	TEST_BIT(CHAR, char);
+
+#define TEST_MAX(X, M)	if (__ ## X ## _MAX__ != M) return 1
+#define TEST_SMAX(X, T)	TEST_MAX(X, SMASK(T))
+#define TEST_UMAX(X, T)	TEST_MAX(X, UMASK(T))
+	TEST_SMAX(SCHAR, signed char);
+	TEST_SMAX(SHRT, short);
+	TEST_SMAX(INT, int);
+	TEST_SMAX(LONG, long);
+	TEST_SMAX(LONG_LONG, long long);
+
+#define TEST_SIZEOF(X, T) if (__SIZEOF_ ## X ## __ != sizeof(T)) return 1
+	TEST_SIZEOF(SHORT, short);
+	TEST_SIZEOF(INT, int);
+	TEST_SIZEOF(LONG, long);
+	TEST_SIZEOF(LONG_LONG, long long);
+	TEST_SIZEOF(INT128, __int128);
+	TEST_SIZEOF(SIZE_T, __SIZE_TYPE__);
+	TEST_SIZEOF(POINTER, void*);
+	TEST_SIZEOF(FLOAT, float);
+	TEST_SIZEOF(DOUBLE, double);
+	TEST_SIZEOF(LONG_DOUBLE, long double);
+
+	return 0;
+}
+
+/*
+ * check-name: predefined macros: __SIZEOF_<type>__, ...
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */