Skip to contentSkip to conversation

lib/test_bitops: Do the full test during module init

PATCH Applied Geert Uytterhoeven 2 participants 3 messages Jul 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib/test_bitops: Do the full test during module init

Currently, the bitops test consists of two parts: one part is executed during module load, the second part during module unload. This is cumbersome for the user, as he has to perform two steps to execute all tests, and is different from most (all?) other tests.

Merge the two parts, so both are executed during module load.

---
v2:
- Keep a dummy module_exit() function to support module unloading.

---
 lib/test_bitops.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/test_bitops.c +10 -8
index ced25e3a779baf96..471141ddd6913724 100644
@@ -52,9 +52,9 @@ static unsigned long order_comb_long[][2] = {
 
 static int __init test_bitops_startup(void)
 {
-	int i;
+	int i, bit_set;
 
-	pr_warn("Loaded test module\n");
+	pr_info("Starting bitops test\n");
 	set_bit(BITOPS_4, g_bitmap);
 	set_bit(BITOPS_7, g_bitmap);
 	set_bit(BITOPS_11, g_bitmap);
@@ -81,12 +81,8 @@ static int __init test_bitops_startup(void)
 				       order_comb_long[i][0]);
 	}
 #endif
-	return 0;
-}
 
-static void __exit test_bitops_unstartup(void)
-{
-	int bit_set;
+	barrier();
 
 	clear_bit(BITOPS_4, g_bitmap);
 	clear_bit(BITOPS_7, g_bitmap);
@@ -98,7 +94,13 @@ static void __exit test_bitops_unstartup(void)
 	if (bit_set != BITOPS_LAST)
 		pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
 
-	pr_warn("Unloaded test module\n");
+	pr_info("Completed bitops test\n");
+
+	return 0;
+}
+
+static void __exit test_bitops_unstartup(void)
+{
 }
 
 module_init(test_bitops_startup);
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Geert Uytterhoeven

Currently, the bitops test consists of two parts: one part is executed during module load, the second part during module unload. This is cumbersome for the user, as he has to perform two steps to execute all tests, and is different from most (all?) other tests.

Merge the two parts, so both are executed during module load.

I think it's right way to go, sorry, I didn't notice this during module submission.

One question though, is compiler barrier enough to prevent potential ordering issues?

Quoted 56 lines

---
v2:
- Keep a dummy module_exit() function to support module unloading.

---
 lib/test_bitops.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/test_bitops.c +10 -8
index ced25e3a779baf96..471141ddd6913724 100644
@@ -52,9 +52,9 @@ static unsigned long order_comb_long[][2] = {
 
 static int __init test_bitops_startup(void)
 {
-	int i;
+	int i, bit_set;
 
-	pr_warn("Loaded test module\n");
+	pr_info("Starting bitops test\n");
 	set_bit(BITOPS_4, g_bitmap);
 	set_bit(BITOPS_7, g_bitmap);
 	set_bit(BITOPS_11, g_bitmap);
@@ -81,12 +81,8 @@ static int __init test_bitops_startup(void)
 				       order_comb_long[i][0]);
 	}
 #endif
-	return 0;
-}
 
-static void __exit test_bitops_unstartup(void)
-{
-	int bit_set;
+	barrier();
 
 	clear_bit(BITOPS_4, g_bitmap);
 	clear_bit(BITOPS_7, g_bitmap);
@@ -98,7 +94,13 @@ static void __exit test_bitops_unstartup(void)
 	if (bit_set != BITOPS_LAST)
 		pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
 
-	pr_warn("Unloaded test module\n");
+	pr_info("Completed bitops test\n");
+
+	return 0;
+}
+
+static void __exit test_bitops_unstartup(void)
+{
 }
 
 module_init(test_bitops_startup);
Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

Hi Andy,

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven

Currently, the bitops test consists of two parts: one part is executed during module load, the second part during module unload. This is cumbersome for the user, as he has to perform two steps to execute all tests, and is different from most (all?) other tests.

Quoted 6 lines
Quoted 1 line

Merge the two parts, so both are executed during module load.

I think it's right way to go, sorry, I didn't notice this during module submission.

Thanks!

Quoted 1 line

One question though, is compiler barrier enough to prevent potential ordering issues?

I think so, that's why I used barrier().
You may still be subject to CPU instruction reordering, though :-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds