<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 31, 2025 at 11:58 AM Dan Carpenter <<a href="mailto:dan.carpenter@linaro.org" target="_blank">dan.carpenter@linaro.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Marie,<br>
<br>
kernel test robot noticed the following build warnings:<br>
<br>
<a href="https://git-scm.com/docs/git-format-patch#_base_tree_information" rel="noreferrer" target="_blank">https://git-scm.com/docs/git-format-patch#_base_tree_information</a>]<br>
<br>
url:    <a href="https://github.com/intel-lab-lkp/linux/commits/Marie-Zhussupova/kunit-Add-parent-kunit-for-parameterized-test-context/20250730-033818" rel="noreferrer" target="_blank">https://github.com/intel-lab-lkp/linux/commits/Marie-Zhussupova/kunit-Add-parent-kunit-for-parameterized-test-context/20250730-033818</a><br>
base:   <a href="https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git" rel="noreferrer" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git</a> kunit<br>
patch link:    <a href="https://lore.kernel.org/r/20250729193647.3410634-7-marievic%40google.com" rel="noreferrer" target="_blank">https://lore.kernel.org/r/20250729193647.3410634-7-marievic%40google.com</a><br>
patch subject: [PATCH 6/9] kunit: Enable direct registration of parameter arrays to a KUnit test<br>
config: nios2-randconfig-r072-20250731 (<a href="https://download.01.org/0day-ci/archive/20250731/202507310854.pZvIcswn-lkp@intel.com/config" rel="noreferrer" target="_blank">https://download.01.org/0day-ci/archive/20250731/202507310854.pZvIcswn-lkp@intel.com/config</a>)<br>
compiler: nios2-linux-gcc (GCC) 8.5.0<br>
<br>
If you fix the issue in a separate patch/commit (i.e. not just a new version of<br>
the same patch/commit), kindly add following tags<br>
| Reported-by: kernel test robot <<a href="mailto:lkp@intel.com" target="_blank">lkp@intel.com</a>><br>
| Reported-by: Dan Carpenter <<a href="mailto:dan.carpenter@linaro.org" target="_blank">dan.carpenter@linaro.org</a>><br>
| Closes: <a href="https://lore.kernel.org/r/202507310854.pZvIcswn-lkp@intel.com/" rel="noreferrer" target="_blank">https://lore.kernel.org/r/202507310854.pZvIcswn-lkp@intel.com/</a><br>
<br>
New smatch warnings:<br>
lib/kunit/test.c:723 kunit_run_tests() error: we previously assumed 'test_case->generate_params' could be null (see line 714)<br>
<br>
vim +723 lib/kunit/test.c<br>
<br>
914cc63eea6fbe Brendan Higgins     2019-09-23  681  int kunit_run_tests(struct kunit_suite *suite)<br>
914cc63eea6fbe Brendan Higgins     2019-09-23  682  {<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  683      char param_desc[KUNIT_PARAM_DESC_SIZE];<br>
914cc63eea6fbe Brendan Higgins     2019-09-23  684      struct kunit_case *test_case;<br>
acd8e8407b8fcc David Gow           2021-08-03  685      struct kunit_result_stats suite_stats = { 0 };<br>
acd8e8407b8fcc David Gow           2021-08-03  686      struct kunit_result_stats total_stats = { 0 };<br>
8631cd2cf5fbf2 Marie Zhussupova    2025-07-29  687      const void *curr_param;<br>
914cc63eea6fbe Brendan Higgins     2019-09-23  688  <br>
c272612cb4a2f7 David Gow           2022-07-01  689      /* Taint the kernel so we know we've run tests. */<br>
c272612cb4a2f7 David Gow           2022-07-01  690      add_taint(TAINT_TEST, LOCKDEP_STILL_OK);<br>
c272612cb4a2f7 David Gow           2022-07-01  691  <br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  692      if (suite->suite_init) {<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  693              suite->suite_init_err = suite->suite_init(suite);<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  694              if (suite->suite_init_err) {<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  695                      kunit_err(suite, KUNIT_SUBTEST_INDENT<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  696                                "# failed to initialize (%d)", suite->suite_init_err);<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  697                      goto suite_end;<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  698              }<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  699      }<br>
1cdba21db2ca31 Daniel Latypov      2022-04-29  700  <br>
cae56e1740f559 Daniel Latypov      2022-04-29  701      kunit_print_suite_start(suite);<br>
914cc63eea6fbe Brendan Higgins     2019-09-23  702  <br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  703      kunit_suite_for_each_test_case(suite, test_case) {<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  704              struct kunit test = { .param_value = NULL, .param_index = 0 };<br>
acd8e8407b8fcc David Gow           2021-08-03  705              struct kunit_result_stats param_stats = { 0 };<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  706  <br>
887d85a0736ff3 Rae Moar            2023-03-08  707              kunit_init_test(&test, test_case->name, test_case->log);<br>
03806177fa4cbb Marie Zhussupova    2025-07-29  708              __kunit_init_parent_test(test_case, &test);<br>
03806177fa4cbb Marie Zhussupova    2025-07-29  709  <br>
529534e8cba3e6 Rae Moar            2023-07-25  710              if (test_case->status == KUNIT_SKIPPED) {<br>
529534e8cba3e6 Rae Moar            2023-07-25  711                      /* Test marked as skip */<br>
529534e8cba3e6 Rae Moar            2023-07-25  712                      test.status = KUNIT_SKIPPED;<br>
529534e8cba3e6 Rae Moar            2023-07-25  713                      kunit_update_stats(&param_stats, test.status);<br>
44c50ed8e59936 Marie Zhussupova    2025-07-29 @714              } else if (!test_case->generate_params && !test.params_data.params) {<br>
                                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
Imagine ->generate_parms is NULL but test.params_data.params is<br>
non-NULL.</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
37dbb4c7c7442d David Gow           2021-11-02  715                      /* Non-parameterised test. */<br>
529534e8cba3e6 Rae Moar            2023-07-25  716                      test_case->status = KUNIT_SKIPPED;<br>
37dbb4c7c7442d David Gow           2021-11-02  717                      kunit_run_case_catch_errors(suite, test_case, &test);<br>
37dbb4c7c7442d David Gow           2021-11-02  718                      kunit_update_stats(&param_stats, test.status);<br>
03806177fa4cbb Marie Zhussupova    2025-07-29  719              } else if (test_case->status != KUNIT_FAILURE) {<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  720                      /* Get initial param. */<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  721                      param_desc[0] = '\0';<br>
8631cd2cf5fbf2 Marie Zhussupova    2025-07-29  722                      /* TODO: Make generate_params try-catch */<br>
13ee0c64bd88a3 Marie Zhussupova    2025-07-29 @723                      curr_param = test_case->generate_params(&test, NULL, param_desc);<br>
                                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
Then this could crash.<br>
<br>
I suspect that this is fine, but I bet that in the previous<br>
condition, just testing one would probably have been sufficient<br>
or maybe we could have change && to ||.<br></blockquote><div><br></div><div>Hello Dan,</div><div><br></div><div>As of now, test.params_data.params can only be populated in a param_init</div><div>function, which can only be used if we register the test case with a </div><div>KUNIT_CASE_PARAM_WITH_INIT macro. That macro auto populates </div><div>test_case->generate_params with a function called kunit_get_next_param_and_desc() </div><div>(which iterates over the parameter array) if the test user didn't provide their </div><div>own generator function. So, there shouldn't be a case where </div><div>test_case->generate_params is NULL but test.params_data.params is NON-NULL. </div><div><br></div><div>However, to be robust, we could add a NULL check  before calling </div><div>test_case->generate_params on line 723.</div><div><br></div><div>Thank you!</div><div>-Marie</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
529534e8cba3e6 Rae Moar            2023-07-25  724                      test_case->status = KUNIT_SKIPPED;<br>
6c738b52316c58 Rae Moar            2022-11-23  725                      kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT<br>
6c738b52316c58 Rae Moar            2022-11-23  726                                "KTAP version 1\n");<br>
44b7da5fcd4c99 David Gow           2021-11-02  727                      kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT<br>
44b7da5fcd4c99 David Gow           2021-11-02  728                                "# Subtest: %s", test_case->name);<br>
fadb08e7c7501e Arpitha Raghunandan 2020-11-16  729  <br>
8631cd2cf5fbf2 Marie Zhussupova    2025-07-29  730                      while (curr_param) {<br>
<br>
-- <br>
0-DAY CI Kernel Test Service<br>
<a href="https://github.com/intel/lkp-tests/wiki" rel="noreferrer" target="_blank">https://github.com/intel/lkp-tests/wiki</a><br>
<br>
</blockquote></div></div>
</div>
</div>
</div>