[PATCH next 14/14] test_bits: include some invalid input tests for GENMASK_INPUT_CHECK()

david.laight.linux@gmail.com posted 14 patches 2 weeks, 3 days ago
[PATCH next 14/14] test_bits: include some invalid input tests for GENMASK_INPUT_CHECK()
Posted by david.laight.linux@gmail.com 2 weeks, 3 days ago
From: David Laight <david.laight.linux@gmail.com>

The check for invalid 'compile time constant' parameters can easily be
changed to return 'failed' rather than generating a compile time error.
Add some tests for negative, swapped and overlarge values.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 lib/tests/test_bits.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
index 4d3a895f490c..9642c55f5487 100644
--- a/lib/tests/test_bits.c
+++ b/lib/tests/test_bits.c
@@ -144,6 +144,22 @@ static void genmask_input_check_test(struct kunit *test)
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0);
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0);
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0);
+
+	/*
+	 * Invalid input
+	 * Change GENMASK_INPUT_CHECK() return 'fail' rather than
+	 * generating a compile-time error.
+	 */
+#define GENMASK_INPUT_CHECK_FAIL() 1
+	z = 0;
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 31, -1, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 0, 1, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 8, 0, 8) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 16, 0, 16) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 32, 0, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 64, 0, 64) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 128, 0, 128) == 0);
+#undef GENMASK_INPUT_CHECK_FAIL
 }
 
 
-- 
2.39.5