Skip to contentSkip to conversation

kunit: fix: kunit_binary_assert_format() only prints signed int

PATCH In review Vitor Massaru Iha 2 participants 5 messages Aug 19, 2020

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

PATCH 1/1 kunit: fix: kunit_binary_assert_format() only prints signed int

Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print.

---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/kunit/assert.c +13 -2
index 202f9fdeed0e..3ae90c09986a 100644
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
 				  binary_assert->left_text,
 				  binary_assert->operation,
 				  binary_assert->right_text);
-		string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+		if (binary_assert->left_value - 1 < 0) {
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+				  binary_assert->left_text,
+				  binary_assert->left_value);
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+				  binary_assert->right_text,
+				  binary_assert->right_value);
+		}
+		else {
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
 				  binary_assert->left_text,
 				  binary_assert->left_value);
-		string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+			string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
 				  binary_assert->right_text,
 				  binary_assert->right_value);
+		}
 	}
 	kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158

Signature · 1 line
2.26.2
#1 lore raw
Quoted 27 lines · Vitor Massaru Iha

Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print.

---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/kunit/assert.c +8 -1
index 202f9fdeed0e..3ae90c09986a 100644
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
                                  binary_assert->left_text,
                                  binary_assert->operation,
                                  binary_assert->right_text);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+               if (binary_assert->left_value - 1 < 0) {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+                                 binary_assert->left_text,
+                                 binary_assert->left_value);
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                                 binary_assert->right_text,
+                                 binary_assert->right_value);

lib/kunit/assert.c void kunit_binary_assert_format(const struct kunit_assert *assert, · line 123

Quoted 10 lines
lib/kunit/assert.c +5 -1
+               }
+               else {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
                                  binary_assert->left_text,
                                  binary_assert->left_value);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
                                  binary_assert->right_text,
                                  binary_assert->right_value);
+               }

I agree that you found a bug here; however, I disagree that this is the correct fix. Given that the value is stored as a long long; isn't the value always stored as a signed value? So if the value overflows, won't it still not pass the check you have here?

Quoted 9 lines
lib/kunit/assert.c +0 -0
        }
        kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158 --
2.26.2

#2 lore raw
Quoted 6 lines · Brendan Higgins
Quoted 4 lines · Vitor Massaru Iha

Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print.

Oops, Thanks!
I'll fix it.

Quoted 48 lines
Quoted 23 lines
---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/kunit/assert.c +8 -1
index 202f9fdeed0e..3ae90c09986a 100644
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
                                  binary_assert->left_text,
                                  binary_assert->operation,
                                  binary_assert->right_text);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+               if (binary_assert->left_value - 1 < 0) {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+                                 binary_assert->left_text,
+                                 binary_assert->left_value);
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                                 binary_assert->right_text,
+                                 binary_assert->right_value);

lib/kunit/assert.c void kunit_binary_assert_format(const struct kunit_assert *assert, · line 123

Quoted 10 lines
lib/kunit/assert.c +5 -1
+               }
+               else {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
                                  binary_assert->left_text,
                                  binary_assert->left_value);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
                                  binary_assert->right_text,
                                  binary_assert->right_value);
+               }

I agree that you found a bug here; however, I disagree that this is the correct fix. Given that the value is stored as a long long; isn't the value always stored as a signed value? So if the value overflows, won't it still not pass the check you have here?

Quoted 9 lines
lib/kunit/assert.c +0 -0
        }
        kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158 --
2.26.2

#3 lore raw

Hi Brendan,

Actually https://patchwork.kernel.org/patch/11724995/
solves my problem with unsigned int, since I can customize the Expected message with this patch.

I think you can ignore this patch :)

Quoted 61 lines · Vitor Massaru Iha
Quoted 6 lines · Brendan Higgins
Quoted 4 lines · Vitor Massaru Iha

Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print.

Oops, Thanks!
I'll fix it.

Quoted 48 lines
Quoted 23 lines
---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/kunit/assert.c +8 -1
index 202f9fdeed0e..3ae90c09986a 100644
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
                                  binary_assert->left_text,
                                  binary_assert->operation,
                                  binary_assert->right_text);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+               if (binary_assert->left_value - 1 < 0) {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+                                 binary_assert->left_text,
+                                 binary_assert->left_value);
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                                 binary_assert->right_text,
+                                 binary_assert->right_value);

lib/kunit/assert.c void kunit_binary_assert_format(const struct kunit_assert *assert, · line 123

Quoted 10 lines
lib/kunit/assert.c +5 -1
+               }
+               else {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
                                  binary_assert->left_text,
                                  binary_assert->left_value);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
                                  binary_assert->right_text,
                                  binary_assert->right_value);
+               }

I agree that you found a bug here; however, I disagree that this is the correct fix. Given that the value is stored as a long long; isn't the value always stored as a signed value? So if the value overflows, won't it still not pass the check you have here?

Quoted 9 lines
lib/kunit/assert.c +0 -0
        }
        kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158 --
2.26.2

#4 lore raw
Quoted 8 lines · Vitor Massaru Iha

Hi Brendan,

Actually https://patchwork.kernel.org/patch/11724995/
solves my problem with unsigned int, since I can customize the Expected message with this patch.

I think you can ignore this patch :)

Got it. Sounds good :-)

Quoted 62 lines · Vitor Massaru Iha
Quoted 61 lines
Quoted 6 lines · Brendan Higgins
Quoted 4 lines · Vitor Massaru Iha

Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print.

Oops, Thanks!
I'll fix it.

Quoted 48 lines
Quoted 23 lines
---
 lib/kunit/assert.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/kunit/assert.c +8 -1
index 202f9fdeed0e..3ae90c09986a 100644
@@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
                                  binary_assert->left_text,
                                  binary_assert->operation,
                                  binary_assert->right_text);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+
+               if (binary_assert->left_value - 1 < 0) {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n",
+                                 binary_assert->left_text,
+                                 binary_assert->left_value);
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                                 binary_assert->right_text,
+                                 binary_assert->right_value);

lib/kunit/assert.c void kunit_binary_assert_format(const struct kunit_assert *assert, · line 123

Quoted 10 lines
lib/kunit/assert.c +5 -1
+               }
+               else {
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n",
                                  binary_assert->left_text,
                                  binary_assert->left_value);
-               string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld",
+                       string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu",
                                  binary_assert->right_text,
                                  binary_assert->right_value);
+               }

I agree that you found a bug here; however, I disagree that this is the correct fix. Given that the value is stored as a long long; isn't the value always stored as a signed value? So if the value overflows, won't it still not pass the check you have here?

Quoted 9 lines
lib/kunit/assert.c +0 -0
        }
        kunit_assert_print_msg(assert, stream);
 }

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158 --
2.26.2