public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Brendan Higgins <brendanhiggins@google.com>,
	Rae Moar <rmr167@gmail.com>, Daniel Latypov <dlatypov@google.com>,
	Shuah Khan <skhan@linuxfoundation.org>
Cc: David Gow <davidgow@google.com>,
	kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 3/4] kunit: Don't crash if no parameters are generated
Date: Wed, 27 Oct 2021 23:41:53 -0700	[thread overview]
Message-ID: <20211028064154.2301049-3-davidgow@google.com> (raw)
In-Reply-To: <20211028064154.2301049-1-davidgow@google.com>

It's possible that a parameterised test could end up with zero
parameters. At the moment, the test function will nevertheless be called
with NULL as the parameter. Instead, don't try to run the test code, and
just mark the test as SKIPped.

Reported-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: David Gow <davidgow@google.com>
---

Changes since v2:
https://lore.kernel.org/linux-kselftest/20211027013702.2039566-3-davidgow@google.com/
- Rework to not share the loop between the parameterised and
  non-parameterised test cases.
  - Suggested by Daniel Latypov.
  - Avoids using a magic non-zero pointer value.

 lib/kunit/test.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 3bd741e50a2d..dfe1127aacfd 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -508,12 +508,12 @@ int kunit_run_tests(struct kunit_suite *suite)
 			/* Get initial param. */
 			param_desc[0] = '\0';
 			test.param_value = test_case->generate_params(NULL, param_desc);
-		}
+			kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT
+				  "# Subtest: %s", test_case->name);
 
-		do {
-			kunit_run_case_catch_errors(suite, test_case, &test);
+			while (test.param_value) {
+				kunit_run_case_catch_errors(suite, test_case, &test);
 
-			if (test_case->generate_params) {
 				if (param_desc[0] == '\0') {
 					snprintf(param_desc, sizeof(param_desc),
 						 "param-%d", test.param_index);
@@ -530,11 +530,15 @@ int kunit_run_tests(struct kunit_suite *suite)
 				param_desc[0] = '\0';
 				test.param_value = test_case->generate_params(test.param_value, param_desc);
 				test.param_index++;
-			}
 
+				kunit_update_stats(&param_stats, test.status);
+			}
+		} else {
+			/* Non-parameterised test. */
+			kunit_run_case_catch_errors(suite, test_case, &test);
 			kunit_update_stats(&param_stats, test.status);
+		}
 
-		} while (test.param_value);
 
 		kunit_print_test_stats(&test, param_stats);
 
-- 
2.33.0.1079.g6e70778dc9-goog


  parent reply	other threads:[~2021-10-28  6:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28  6:41 [PATCH v3 1/4] kunit: tool: Do not error on tests without test plans David Gow
2021-10-28  6:41 ` [PATCH v3 2/4] kunit: tool: Report an error if any test has no subtests David Gow
2021-10-28 22:36   ` Daniel Latypov
2021-10-28  6:41 ` David Gow [this message]
2021-10-28 22:21   ` [PATCH v3 3/4] kunit: Don't crash if no parameters are generated Daniel Latypov
2021-10-28  6:41 ` [PATCH v3 4/4] kunit: Report test parameter results as (K)TAP subtests David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211028064154.2301049-3-davidgow@google.com \
    --to=davidgow@google.com \
    --cc=brendanhiggins@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmr167@gmail.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox