On Thu, 12 Nov 2020 20:07:32 +0200 Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Test get_option() for a starter which is provided by cmdline.c.
...
lib/cmdline_kunit.c | 98 +++++++++++++++++++++++++++++++++++++++++++++
The spectacular warning storm which this produces makes me wonder if you sent the correct version? I mean, the cmdline_test_values[] definition wasn't even close.
This fixes it all for me:
--- a/lib/cmdline_kunit.c~lib-cmdline_kunit-add-a-new-test-suite-for-cmdline-api-fix +++ a/lib/cmdline_kunit.c @@ -13,19 +13,19 @@ static const char *cmdline_test_strings[ "+," , "--", ",,", "''" , """,", "","", "-""", """, };
-static const char *cmdline_test_values[] = { +static const char cmdline_test_values[] = { 1, 1, 1, 1, 2, 3, 2, 3, 1, 3, 2, 1, 1, 1, 3, 1, };
-static void cmdline_do_one_test(struct kunit *test, char *in, int rc, int offset) +static void cmdline_do_one_test(struct kunit *test, const char *in, int rc, int offset) { const char *fmt = "Pattern: %s"; - char *out = in; + const char *out = in; int dummy; int ret;
- ret = get_option(&out, &dummy); + ret = get_option((char **)&out, &dummy);
KUNIT_EXPECT_EQ_MSG(test, ret, rc, fmt, in); KUNIT_EXPECT_PTR_EQ_MSG(test, out, in + offset, fmt, in); _
but it sucks that get_option()'s first arg isn't `const char **str'. I was too lazy to look at addressing that.
lib/cmdline_kunit.c:17:2: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:2: note: (near initialization for ‘cmdline_test_values[0]’) lib/cmdline_kunit.c:17:5: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:5: note: (near initialization for ‘cmdline_test_values[1]’) lib/cmdline_kunit.c:17:8: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:8: note: (near initialization for ‘cmdline_test_values[2]’) lib/cmdline_kunit.c:17:11: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:11: note: (near initialization for ‘cmdline_test_values[3]’) lib/cmdline_kunit.c:17:14: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:14: note: (near initialization for ‘cmdline_test_values[4]’) lib/cmdline_kunit.c:17:17: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:17: note: (near initialization for ‘cmdline_test_values[5]’) lib/cmdline_kunit.c:17:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:20: note: (near initialization for ‘cmdline_test_values[6]’) lib/cmdline_kunit.c:17:23: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 1, 1, 1, 2, 3, 2, 3, ^ lib/cmdline_kunit.c:17:23: note: (near initialization for ‘cmdline_test_values[7]’) lib/cmdline_kunit.c:18:2: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:2: note: (near initialization for ‘cmdline_test_values[8]’) lib/cmdline_kunit.c:18:5: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:5: note: (near initialization for ‘cmdline_test_values[9]’) lib/cmdline_kunit.c:18:8: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:8: note: (near initialization for ‘cmdline_test_values[10]’) lib/cmdline_kunit.c:18:11: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:11: note: (near initialization for ‘cmdline_test_values[11]’) lib/cmdline_kunit.c:18:14: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:14: note: (near initialization for ‘cmdline_test_values[12]’) lib/cmdline_kunit.c:18:17: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:17: note: (near initialization for ‘cmdline_test_values[13]’) lib/cmdline_kunit.c:18:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:20: note: (near initialization for ‘cmdline_test_values[14]’) lib/cmdline_kunit.c:18:23: warning: initialization makes pointer from integer without a cast [-Wint-conversion] 1, 3, 2, 1, 1, 1, 3, 1, ^ lib/cmdline_kunit.c:18:23: note: (near initialization for ‘cmdline_test_values[15]’) lib/cmdline_kunit.c: In function ‘cmdline_test_noint’: lib/cmdline_kunit.c:45:29: warning: passing argument 2 of ‘cmdline_do_one_test’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] cmdline_do_one_test(test, str, rc, offset); ^~~ lib/cmdline_kunit.c:21:13: note: expected ‘char *’ but argument is of type ‘const char *’ static void cmdline_do_one_test(struct kunit *test, char *in, int rc, int offset) ^~~~~~~~~~~~~~~~~~~ lib/cmdline_kunit.c: In function ‘cmdline_test_lead_int’: lib/cmdline_kunit.c:56:12: warning: initialization makes integer from pointer without a cast [-Wint-conversion] int rc = cmdline_test_values[i]; ^~~~~~~~~~~~~~~~~~~