Re: [PATCH v2] selftests/mm: Drop duplicate test_seal_mprotect_two_vma_with_gap() call

Hongfu Li <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm
Message-ID <[email protected]>
> > ---
> > v2:
> > - update ksft_set_plan(88) to 87 to match the actual number of tests
> >   after removing the duplicate call.
> 
> I wonder if there could be an automated way for this.  Obviously not a question
> to the author but just my loud thought.

Glad you brought this up, I totally agree with your thought.

Something like the below refactor could achieve that automation:

+typedef void (*test_fn)(void);
+typedef void (*test_fn_seal)(bool seal);
+
+static const struct {
+    test_fn_seal fn;
+    bool seal;
+} tests_seal[] = {
+    { test_seal_mprotect, false },
+    { test_seal_mprotect, true },
...
+};
+
+static const test_fn tests[] = {
+    test_seal_addseal,
+    test_seal_unmapped_start,
...
+};
+
+
 int main(void)
 {
...
-       ksft_set_plan(87);
+       ksft_set_plan(ARRAY_SIZE(tests) + ARRAY_SIZE(tests_seal));
+       for (size_t i = 0; i < ARRAY_SIZE(tests); i++)
+               tests[i]();
+       for (size_t i = 0; i < ARRAY_SIZE(tests_seal); i++)
+        tests_seal[i].fn(tests_seal[i].seal);

Though I'm still unsure whether this extra complexity is really worthwhile.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.