[PATCH] add testcases for type comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sparse, as an extension and with a special syntax, supports the
direct comparison of types, either equality modulo qualifiers for
'==' and '!=', or size comparison for '<', '>', '<=' and '>='.

Add some testcases to avoid possible regressions here.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 validation/type-compare.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 validation/type-compare.c

diff --git a/validation/type-compare.c b/validation/type-compare.c
new file mode 100644
index 000000000..1adcd7040
--- /dev/null
+++ b/validation/type-compare.c
@@ -0,0 +1,76 @@
+#define __user		__attribute__((address_space(1)))
+#define __safe		__attribute__((safe))
+#define __nocast	__attribute__((nocast))
+#define __bitwise	__attribute__((bitwise))
+#define __noderef	__attribute__((noderef))
+
+int test(void)
+{
+	if ([int] != [int]) return 1;
+	if (!([int] == [int])) return 1;
+
+	if ([int] == [long]) return 1;
+	if (!([int] != [long])) return 1;
+
+	if ([int] == [unsigned int]) return 1;
+	if (!([int] != [unsigned int])) return 1;
+
+	if ([int] != [int]) return 1;
+	if ([typeof(int)] != [int]) return 1;
+	if ([int] != [typeof(int)]) return 1;
+	if ([typeof(int)] != [typeof(int)]) return 1;
+
+	if ([char] > [short]) return 1;
+	if ([short] < [char]) return 1;
+	if (!([char] <= [short])) return 1;
+	if (!([short] >= [char])) return 1;
+
+	if ([short] > [int]) return 1;
+	if ([int] < [short]) return 1;
+	if (!([short] <= [int])) return 1;
+	if (!([int] >= [short])) return 1;
+
+	if ([int] > [long]) return 1;
+	if ([long] < [int]) return 1;
+	if (!([int] <= [long])) return 1;
+	if (!([long] >= [int])) return 1;
+
+	if ([long] > [long long]) return 1;
+	if ([long long] < [long]) return 1;
+	if (!([long] <= [long long])) return 1;
+	if (!([long long] >= [long])) return 1;
+
+	if ([int *] != [int *]) return 1;
+	if ([int *] == [void *]) return 1;
+
+	// qualifiers are ignored
+	if ([int] != [const int]) return 1;
+	if ([int] != [volatile int]) return 1;
+
+	// but others modifiers are significant
+	if ([int] == [int __nocast]) return 1;
+	if ([int] == [int __bitwise]) return 1;
+
+	//
+	if ([int *] == [const int *]) return 1;
+	if ([int *] == [volatile int *]) return 1;
+	if ([int *] == [int __user *]) return 1;
+	if ([int *] == [int __safe *]) return 1;
+	if ([int *] == [int __nocast *]) return 1;
+	if ([int *] == [int __bitwise *]) return 1;
+	if ([int *] == [int __noderef *]) return 1;
+
+	return 0;
+}
+
+/*
+ * check-name: type-as-first-class comparison
+ * check-description: This test the sparse extension making
+ *	types first class citizens which can be compared
+ *	for equality (or size for <, >, <=, >=).
+ *	See expand.c:compare_types().
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
-- 
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux