Skip to contentSkip to conversation

list: test: Mending tests for list_cut_position()

PATCH RESEND Applied I Hsin Cheng 2 participants 2 messages Sep 10, 2024 – Sep 18, 2024

Subsystems (3)

v2 of 3 Applied 1/1 Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 list: test: Mending tests for list_cut_position()

Mending test for list_cut_position*() for the missing check of integer "i" after the second loop. The variable should be checked for second time to make sure both lists after the cut operation are formed as expected.

---
 lib/list-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/list-test.c +6 -0
index 37cbc33e9fdb..8d1d47a9fe9e 100644
@@ -404,10 +404,13 @@ static void list_test_list_cut_position(struct kunit *test)
 
 	KUNIT_EXPECT_EQ(test, i, 2);
 
+	i = 0;
 	list_for_each(cur, &list1) {
 		KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]);
 		i++;
 	}
+
+	KUNIT_EXPECT_EQ(test, i, 1);
 }
 
 static void list_test_list_cut_before(struct kunit *test)
@@ -432,10 +435,13 @@ static void list_test_list_cut_before(struct kunit *test)
 
 	KUNIT_EXPECT_EQ(test, i, 1);
 
+	i = 0;
 	list_for_each(cur, &list1) {
 		KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]);
 		i++;
 	}
+
+	KUNIT_EXPECT_EQ(test, i, 2);
 }
 
 static void list_test_list_splice(struct kunit *test)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · I Hsin Cheng

Mending test for list_cut_position*() for the missing check of integer "i" after the second loop. The variable should be checked for second time to make sure both lists after the cut operation are formed as expected.

---

Alas, this breaks the list test, as we're comparing the entries we get from list_for_each() with entries[i], so changing the value of 'i' will compare against the wrong elements.

You could either update the KUNIT_EXPECT_EQ at the bottom to verify the _total_ number of elements (which should be fine, as we already verify the value of i after the first loop), or compare each entry against, e.g., &entries[2 + i].

This is causing a test failure on -next:
https://lore.kernel.org/all/[email protected]/

Could we remove this from mm-nonmm pending a fix?

Cheers,
-- David

Quoted 8 lines
 lib/list-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/list-test.c +0 -0
index 37cbc33e9fdb..8d1d47a9fe9e 100644

lib/list-test.c static void list_test_list_cut_position(struct kunit *test) · line 409

Quoted 6 lines
lib/list-test.c +1 -0
@@ -404,10 +404,13 @@ static void list_test_list_cut_position(struct kunit *test)
 
        KUNIT_EXPECT_EQ(test, i, 2);
 
+       i = 0;
        list_for_each(cur, &list1) {
                KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]);

Either change this to &entries[2 + i], or...

lib/list-test.c static void list_test_list_cut_position(struct kunit *test) · line 413

Quoted 4 lines
lib/list-test.c +2 -0
                i++;
        }
+
+       KUNIT_EXPECT_EQ(test, i, 1);

This to expect i == 3

lib/list-test.c static void list_test_list_cut_before(struct kunit *test) · line 440

Quoted 10 lines
lib/list-test.c +1 -0
 }
 
 static void list_test_list_cut_before(struct kunit *test)
@@ -432,10 +435,13 @@ static void list_test_list_cut_before(struct kunit *test)
 
        KUNIT_EXPECT_EQ(test, i, 1);
 
+       i = 0;
        list_for_each(cur, &list1) {
                KUNIT_EXPECT_PTR_EQ(test, cur, &entries[i]);

Either change this to &entries[1 + i], or...

lib/list-test.c static void list_test_list_cut_before(struct kunit *test) · line 444

Quoted 4 lines
lib/list-test.c +2 -0
                i++;
        }
+
+       KUNIT_EXPECT_EQ(test, i, 2);

This to expect i == 3.

Quoted 6 lines
lib/list-test.c +0 -1
 }
 
 static void list_test_list_splice(struct kunit *test)
--

2.43.0