ffs_kunit.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * KUnit tests for ffs()-family functions
  4. */
  5. #include <kunit/test.h>
  6. #include <linux/bitops.h>
  7. /*
  8. * Test data structures
  9. */
  10. struct ffs_test_case {
  11. unsigned long input;
  12. int expected_ffs; /* ffs() result (1-based) */
  13. int expected_fls; /* fls() result (1-based) */
  14. const char *description;
  15. };
  16. struct ffs64_test_case {
  17. u64 input;
  18. int expected_fls64; /* fls64() result (1-based) */
  19. unsigned int expected_ffs64_0based; /* __ffs64() result (0-based) */
  20. const char *description;
  21. };
  22. /*
  23. * Basic edge cases - core functionality validation
  24. */
  25. static const struct ffs_test_case basic_test_cases[] = {
  26. /* Zero case - special handling */
  27. {0x00000000, 0, 0, "zero value"},
  28. /* Single bit patterns - powers of 2 */
  29. {0x00000001, 1, 1, "bit 0 set"},
  30. {0x00000002, 2, 2, "bit 1 set"},
  31. {0x00000004, 3, 3, "bit 2 set"},
  32. {0x00000008, 4, 4, "bit 3 set"},
  33. {0x00000010, 5, 5, "bit 4 set"},
  34. {0x00000020, 6, 6, "bit 5 set"},
  35. {0x00000040, 7, 7, "bit 6 set"},
  36. {0x00000080, 8, 8, "bit 7 set"},
  37. {0x00000100, 9, 9, "bit 8 set"},
  38. {0x00008000, 16, 16, "bit 15 set"},
  39. {0x00010000, 17, 17, "bit 16 set"},
  40. {0x40000000, 31, 31, "bit 30 set"},
  41. {0x80000000, 32, 32, "bit 31 set (sign bit)"},
  42. /* Maximum values */
  43. {0xFFFFFFFF, 1, 32, "all bits set"},
  44. /* Multiple bit patterns */
  45. {0x00000003, 1, 2, "bits 0-1 set"},
  46. {0x00000007, 1, 3, "bits 0-2 set"},
  47. {0x0000000F, 1, 4, "bits 0-3 set"},
  48. {0x000000FF, 1, 8, "bits 0-7 set"},
  49. {0x0000FFFF, 1, 16, "bits 0-15 set"},
  50. {0x7FFFFFFF, 1, 31, "bits 0-30 set"},
  51. /* Sparse patterns */
  52. {0x00000101, 1, 9, "bits 0,8 set"},
  53. {0x00001001, 1, 13, "bits 0,12 set"},
  54. {0x80000001, 1, 32, "bits 0,31 set"},
  55. {0x40000002, 2, 31, "bits 1,30 set"},
  56. };
  57. /*
  58. * 64-bit test cases
  59. */
  60. static const struct ffs64_test_case ffs64_test_cases[] = {
  61. /* Zero case */
  62. {0x0000000000000000ULL, 0, 0, "zero value"},
  63. /* Single bit patterns */
  64. {0x0000000000000001ULL, 1, 0, "bit 0 set"},
  65. {0x0000000000000002ULL, 2, 1, "bit 1 set"},
  66. {0x0000000000000004ULL, 3, 2, "bit 2 set"},
  67. {0x0000000000000008ULL, 4, 3, "bit 3 set"},
  68. {0x0000000000008000ULL, 16, 15, "bit 15 set"},
  69. {0x0000000000010000ULL, 17, 16, "bit 16 set"},
  70. {0x0000000080000000ULL, 32, 31, "bit 31 set"},
  71. {0x0000000100000000ULL, 33, 32, "bit 32 set"},
  72. {0x0000000200000000ULL, 34, 33, "bit 33 set"},
  73. {0x4000000000000000ULL, 63, 62, "bit 62 set"},
  74. {0x8000000000000000ULL, 64, 63, "bit 63 set (sign bit)"},
  75. /* Maximum values */
  76. {0xFFFFFFFFFFFFFFFFULL, 64, 0, "all bits set"},
  77. /* Cross 32-bit boundary patterns */
  78. {0x00000000FFFFFFFFULL, 32, 0, "lower 32 bits set"},
  79. {0xFFFFFFFF00000000ULL, 64, 32, "upper 32 bits set"},
  80. {0x8000000000000001ULL, 64, 0, "bits 0,63 set"},
  81. {0x4000000000000002ULL, 63, 1, "bits 1,62 set"},
  82. /* Mixed patterns */
  83. {0x00000001FFFFFFFFULL, 33, 0, "bit 32 + lower 32 bits"},
  84. {0xFFFFFFFF80000000ULL, 64, 31, "upper 32 bits + bit 31"},
  85. };
  86. /*
  87. * Helper function to validate ffs results with detailed error messages
  88. */
  89. static void validate_ffs_result(struct kunit *test, unsigned long input,
  90. int actual, int expected, const char *func_name,
  91. const char *description)
  92. {
  93. KUNIT_EXPECT_EQ_MSG(test, actual, expected,
  94. "%s(0x%08lx) [%s]: expected %d, got %d",
  95. func_name, input, description, expected, actual);
  96. }
  97. /*
  98. * Helper function to validate 64-bit ffs results
  99. */
  100. static void validate_ffs64_result(struct kunit *test, u64 input,
  101. int actual, int expected, const char *func_name,
  102. const char *description)
  103. {
  104. KUNIT_EXPECT_EQ_MSG(test, actual, expected,
  105. "%s(0x%016llx) [%s]: expected %d, got %d",
  106. func_name, input, description, expected, actual);
  107. }
  108. /*
  109. * Helper function to validate mathematical relationships between functions
  110. */
  111. static void validate_ffs_relationships(struct kunit *test, unsigned long input)
  112. {
  113. int ffs_result;
  114. int fls_result;
  115. unsigned int ffs_0based;
  116. unsigned int fls_0based;
  117. if (input == 0) {
  118. /* Special case: zero input */
  119. KUNIT_EXPECT_EQ(test, ffs(input), 0);
  120. KUNIT_EXPECT_EQ(test, fls(input), 0);
  121. /* __ffs and __fls are undefined for 0, but often return specific values */
  122. return;
  123. }
  124. ffs_result = ffs(input);
  125. fls_result = fls(input);
  126. ffs_0based = __ffs(input);
  127. fls_0based = __fls(input);
  128. /* Relationship: ffs(x) == __ffs(x) + 1 for x != 0 */
  129. KUNIT_EXPECT_EQ_MSG(test, ffs_result, ffs_0based + 1,
  130. "ffs(0x%08lx) != __ffs(0x%08lx) + 1: %d != %u + 1",
  131. input, input, ffs_result, ffs_0based);
  132. /* Relationship: fls(x) == __fls(x) + 1 for x != 0 */
  133. KUNIT_EXPECT_EQ_MSG(test, fls_result, fls_0based + 1,
  134. "fls(0x%08lx) != __fls(0x%08lx) + 1: %d != %u + 1",
  135. input, input, fls_result, fls_0based);
  136. /* Range validation */
  137. KUNIT_EXPECT_GE(test, ffs_result, 1);
  138. KUNIT_EXPECT_LE(test, ffs_result, BITS_PER_LONG);
  139. KUNIT_EXPECT_GE(test, fls_result, 1);
  140. KUNIT_EXPECT_LE(test, fls_result, BITS_PER_LONG);
  141. }
  142. /*
  143. * Helper function to validate 64-bit relationships
  144. */
  145. static void validate_ffs64_relationships(struct kunit *test, u64 input)
  146. {
  147. int fls64_result;
  148. unsigned int ffs64_0based;
  149. if (input == 0) {
  150. KUNIT_EXPECT_EQ(test, fls64(input), 0);
  151. return;
  152. }
  153. fls64_result = fls64(input);
  154. ffs64_0based = __ffs64(input);
  155. /* Range validation */
  156. KUNIT_EXPECT_GE(test, fls64_result, 1);
  157. KUNIT_EXPECT_LE(test, fls64_result, 64);
  158. KUNIT_EXPECT_LT(test, ffs64_0based, 64);
  159. /*
  160. * Relationships with 32-bit functions should hold for small values
  161. * on all architectures.
  162. */
  163. if (input <= 0xFFFFFFFFULL) {
  164. unsigned long input_32 = (unsigned long)input;
  165. KUNIT_EXPECT_EQ_MSG(test, fls64(input), fls(input_32),
  166. "fls64(0x%llx) != fls(0x%lx): %d != %d",
  167. input, input_32, fls64(input), fls(input_32));
  168. if (input != 0) {
  169. KUNIT_EXPECT_EQ_MSG(test, __ffs64(input), __ffs(input_32),
  170. "__ffs64(0x%llx) != __ffs(0x%lx): %lu != %lu",
  171. input, input_32,
  172. (unsigned long)__ffs64(input),
  173. (unsigned long)__ffs(input_32));
  174. }
  175. }
  176. }
  177. /*
  178. * Test basic correctness of all ffs-family functions
  179. */
  180. static void ffs_basic_correctness_test(struct kunit *test)
  181. {
  182. int i;
  183. for (i = 0; i < ARRAY_SIZE(basic_test_cases); i++) {
  184. const struct ffs_test_case *tc = &basic_test_cases[i];
  185. /* Test ffs() */
  186. validate_ffs_result(test, tc->input, ffs(tc->input),
  187. tc->expected_ffs, "ffs", tc->description);
  188. /* Test fls() */
  189. validate_ffs_result(test, tc->input, fls(tc->input),
  190. tc->expected_fls, "fls", tc->description);
  191. /* Test __ffs() - skip zero case as it's undefined */
  192. if (tc->input != 0) {
  193. /* Calculate expected __ffs() result: __ffs(x) == ffs(x) - 1 */
  194. unsigned int expected_ffs_0based = tc->expected_ffs - 1;
  195. validate_ffs_result(test, tc->input, __ffs(tc->input),
  196. expected_ffs_0based, "__ffs", tc->description);
  197. }
  198. /* Test __fls() - skip zero case as it's undefined */
  199. if (tc->input != 0) {
  200. /* Calculate expected __fls() result: __fls(x) == fls(x) - 1 */
  201. unsigned int expected_fls_0based = tc->expected_fls - 1;
  202. validate_ffs_result(test, tc->input, __fls(tc->input),
  203. expected_fls_0based, "__fls", tc->description);
  204. }
  205. }
  206. }
  207. /*
  208. * Test 64-bit function correctness
  209. */
  210. static void ffs64_correctness_test(struct kunit *test)
  211. {
  212. int i;
  213. for (i = 0; i < ARRAY_SIZE(ffs64_test_cases); i++) {
  214. const struct ffs64_test_case *tc = &ffs64_test_cases[i];
  215. /* Test fls64() */
  216. validate_ffs64_result(test, tc->input, fls64(tc->input),
  217. tc->expected_fls64, "fls64", tc->description);
  218. /* Test __ffs64() - skip zero case as it's undefined */
  219. if (tc->input != 0) {
  220. validate_ffs64_result(test, tc->input, __ffs64(tc->input),
  221. tc->expected_ffs64_0based, "__ffs64",
  222. tc->description);
  223. }
  224. }
  225. }
  226. /*
  227. * Test mathematical relationships between functions
  228. */
  229. static void ffs_mathematical_relationships_test(struct kunit *test)
  230. {
  231. int i;
  232. /* Test basic cases */
  233. for (i = 0; i < ARRAY_SIZE(basic_test_cases); i++) {
  234. validate_ffs_relationships(test, basic_test_cases[i].input);
  235. }
  236. /* Test 64-bit cases */
  237. for (i = 0; i < ARRAY_SIZE(ffs64_test_cases); i++) {
  238. validate_ffs64_relationships(test, ffs64_test_cases[i].input);
  239. }
  240. }
  241. /*
  242. * Test edge cases and boundary conditions
  243. */
  244. static void ffs_edge_cases_test(struct kunit *test)
  245. {
  246. unsigned long test_patterns[] = {
  247. /* Powers of 2 */
  248. 1UL, 2UL, 4UL, 8UL, 16UL, 32UL, 64UL, 128UL,
  249. 256UL, 512UL, 1024UL, 2048UL, 4096UL, 8192UL,
  250. /* Powers of 2 minus 1 */
  251. 1UL, 3UL, 7UL, 15UL, 31UL, 63UL, 127UL, 255UL,
  252. 511UL, 1023UL, 2047UL, 4095UL, 8191UL,
  253. /* Boundary values */
  254. 0x7FFFFFFFUL, /* Maximum positive 32-bit */
  255. 0x80000000UL, /* Minimum negative 32-bit */
  256. 0xFFFFFFFFUL, /* Maximum 32-bit unsigned */
  257. };
  258. int i;
  259. for (i = 0; i < ARRAY_SIZE(test_patterns); i++) {
  260. validate_ffs_relationships(test, test_patterns[i]);
  261. }
  262. }
  263. /*
  264. * Test 64-bit edge cases
  265. */
  266. static void ffs64_edge_cases_test(struct kunit *test)
  267. {
  268. u64 test_patterns_64[] = {
  269. /* 64-bit powers of 2 */
  270. 0x0000000100000000ULL, /* 2^32 */
  271. 0x0000000200000000ULL, /* 2^33 */
  272. 0x0000000400000000ULL, /* 2^34 */
  273. 0x0000001000000000ULL, /* 2^36 */
  274. 0x0000010000000000ULL, /* 2^40 */
  275. 0x0001000000000000ULL, /* 2^48 */
  276. 0x0100000000000000ULL, /* 2^56 */
  277. 0x4000000000000000ULL, /* 2^62 */
  278. 0x8000000000000000ULL, /* 2^63 */
  279. /* Cross-boundary patterns */
  280. 0x00000000FFFFFFFFULL, /* Lower 32 bits */
  281. 0xFFFFFFFF00000000ULL, /* Upper 32 bits */
  282. 0x7FFFFFFFFFFFFFFFULL, /* Maximum positive 64-bit */
  283. 0xFFFFFFFFFFFFFFFFULL, /* Maximum 64-bit unsigned */
  284. };
  285. int i;
  286. for (i = 0; i < ARRAY_SIZE(test_patterns_64); i++) {
  287. validate_ffs64_relationships(test, test_patterns_64[i]);
  288. }
  289. }
  290. /*
  291. * ffz() test data - Find First Zero bit test cases
  292. */
  293. struct ffz_test_case {
  294. unsigned long input;
  295. unsigned long expected_ffz;
  296. const char *description;
  297. };
  298. static const struct ffz_test_case ffz_test_cases[] = {
  299. /* Zero bits in specific positions */
  300. {0xFFFFFFFE, 0, "bit 0 is zero"}, /* ...11111110 */
  301. {0xFFFFFFFD, 1, "bit 1 is zero"}, /* ...11111101 */
  302. {0xFFFFFFFB, 2, "bit 2 is zero"}, /* ...11111011 */
  303. {0xFFFFFFF7, 3, "bit 3 is zero"}, /* ...11110111 */
  304. {0xFFFFFFEF, 4, "bit 4 is zero"}, /* ...11101111 */
  305. {0xFFFFFFDF, 5, "bit 5 is zero"}, /* ...11011111 */
  306. {0xFFFFFFBF, 6, "bit 6 is zero"}, /* ...10111111 */
  307. {0xFFFFFF7F, 7, "bit 7 is zero"}, /* ...01111111 */
  308. {0xFFFFFEFF, 8, "bit 8 is zero"}, /* Gap in bit 8 */
  309. {0xFFFF7FFF, 15, "bit 15 is zero"}, /* Gap in bit 15 */
  310. {0xFFFEFFFF, 16, "bit 16 is zero"}, /* Gap in bit 16 */
  311. {0xBFFFFFFF, 30, "bit 30 is zero"}, /* Gap in bit 30 */
  312. {0x7FFFFFFF, 31, "bit 31 is zero"}, /* 01111111... */
  313. /* Multiple zero patterns */
  314. {0xFFFFFFFC, 0, "bits 0-1 are zero"}, /* ...11111100 */
  315. {0xFFFFFFF8, 0, "bits 0-2 are zero"}, /* ...11111000 */
  316. {0xFFFFFFF0, 0, "bits 0-3 are zero"}, /* ...11110000 */
  317. {0xFFFFFF00, 0, "bits 0-7 are zero"}, /* ...00000000 */
  318. {0xFFFF0000, 0, "bits 0-15 are zero"}, /* Lower 16 bits zero */
  319. /* All zeros (special case) */
  320. {0x00000000, 0, "all bits zero"},
  321. /* Complex patterns */
  322. {0xFFFDFFFF, 17, "bit 17 is zero"}, /* Gap in bit 17 */
  323. {0xFFF7FFFF, 19, "bit 19 is zero"}, /* Gap in bit 19 */
  324. {0xF7FFFFFF, 27, "bit 27 is zero"}, /* Gap in bit 27 */
  325. {0xDFFFFFFF, 29, "bit 29 is zero"}, /* Gap in bit 29 */
  326. };
  327. /*
  328. * Test basic correctness of ffz() function
  329. */
  330. static void ffz_basic_correctness_test(struct kunit *test)
  331. {
  332. int i;
  333. for (i = 0; i < ARRAY_SIZE(ffz_test_cases); i++) {
  334. const struct ffz_test_case *tc = &ffz_test_cases[i];
  335. unsigned long result = ffz(tc->input);
  336. KUNIT_EXPECT_EQ_MSG(test, result, tc->expected_ffz,
  337. "ffz(0x%08lx) [%s]: expected %lu, got %lu",
  338. tc->input, tc->description, tc->expected_ffz, result);
  339. }
  340. }
  341. /*
  342. * Test mathematical relationships between ffz() and other functions
  343. */
  344. static void validate_ffz_relationships(struct kunit *test, unsigned long input)
  345. {
  346. unsigned long ffz_result;
  347. if (input == 0) {
  348. /* ffz(0) should return 0 (first zero bit is at position 0) */
  349. KUNIT_EXPECT_EQ(test, ffz(input), 0);
  350. return;
  351. }
  352. if (input == ~0UL) {
  353. /* ffz(~0) is undefined (no zero bits) - just verify it doesn't crash */
  354. ffz_result = ffz(input);
  355. /* Implementation-defined behavior, just ensure it completes */
  356. return;
  357. }
  358. ffz_result = ffz(input);
  359. /* Range validation - result should be within valid bit range */
  360. KUNIT_EXPECT_LT(test, ffz_result, BITS_PER_LONG);
  361. /* Verify the bit at ffz_result position is actually zero */
  362. KUNIT_EXPECT_EQ_MSG(test, (input >> ffz_result) & 1, 0,
  363. "ffz(0x%08lx) = %lu, but bit %lu is not zero",
  364. input, ffz_result, ffz_result);
  365. /* Core relationship: if we set the ffz bit, ffz should find a different bit */
  366. if (ffz_result < BITS_PER_LONG - 1) {
  367. unsigned long modified = input | (1UL << ffz_result);
  368. if (modified != ~0UL) { /* Skip if all bits would be set */
  369. unsigned long new_ffz = ffz(modified);
  370. KUNIT_EXPECT_NE_MSG(test, new_ffz, ffz_result,
  371. "ffz(0x%08lx) = %lu, but setting that bit doesn't change ffz result",
  372. input, ffz_result);
  373. }
  374. }
  375. }
  376. static void ffz_mathematical_relationships_test(struct kunit *test)
  377. {
  378. unsigned long test_patterns[] = {
  379. /* Powers of 2 with one bit clear */
  380. 0xFFFFFFFE, 0xFFFFFFFD, 0xFFFFFFFB, 0xFFFFFFF7,
  381. 0xFFFFFFEF, 0xFFFFFFDF, 0xFFFFFFBF, 0xFFFFFF7F,
  382. /* Multiple patterns */
  383. 0xFFFFFF00, 0xFFFFF000, 0xFFFF0000, 0xFFF00000,
  384. 0x7FFFFFFF, 0x3FFFFFFF, 0x1FFFFFFF, 0x0FFFFFFF,
  385. /* Complex bit patterns */
  386. 0xAAAAAAAA, 0x55555555, 0xCCCCCCCC, 0x33333333,
  387. 0xF0F0F0F0, 0x0F0F0F0F, 0xFF00FF00, 0x00FF00FF,
  388. };
  389. int i;
  390. /* Test basic test cases */
  391. for (i = 0; i < ARRAY_SIZE(ffz_test_cases); i++) {
  392. validate_ffz_relationships(test, ffz_test_cases[i].input);
  393. }
  394. /* Test additional patterns */
  395. for (i = 0; i < ARRAY_SIZE(test_patterns); i++) {
  396. validate_ffz_relationships(test, test_patterns[i]);
  397. }
  398. }
  399. /*
  400. * Test edge cases and boundary conditions for ffz()
  401. */
  402. static void ffz_edge_cases_test(struct kunit *test)
  403. {
  404. unsigned long edge_patterns[] = {
  405. /* Boundary values */
  406. 0x00000000, /* All zeros */
  407. 0x80000000, /* Only MSB set */
  408. 0x00000001, /* Only LSB set */
  409. 0x7FFFFFFF, /* MSB clear */
  410. 0xFFFFFFFE, /* LSB clear */
  411. /* Powers of 2 complement patterns (one zero bit each) */
  412. ~(1UL << 0), ~(1UL << 1), ~(1UL << 2), ~(1UL << 3),
  413. ~(1UL << 4), ~(1UL << 8), ~(1UL << 16), ~(1UL << 31),
  414. /* Walking zero patterns */
  415. 0xFFFFFFFE, 0xFFFFFFFD, 0xFFFFFFFB, 0xFFFFFFF7,
  416. 0xFFFFFFEF, 0xFFFFFFDF, 0xFFFFFFBF, 0xFFFFFF7F,
  417. 0xFFFFFEFF, 0xFFFFFDFF, 0xFFFFFBFF, 0xFFFFF7FF,
  418. /* Multiple zeros */
  419. 0xFFFFFF00, 0xFFFFF000, 0xFFFF0000, 0xFFF00000,
  420. 0xFF000000, 0xF0000000, 0x00000000,
  421. };
  422. int i;
  423. for (i = 0; i < ARRAY_SIZE(edge_patterns); i++) {
  424. validate_ffz_relationships(test, edge_patterns[i]);
  425. }
  426. }
  427. /*
  428. * To have useful build error output, split the tests into separate
  429. * functions so it's clear which are missing __attribute_const__.
  430. */
  431. #define CREATE_WRAPPER(func) \
  432. static noinline bool build_test_##func(void) \
  433. { \
  434. int init_##func = 32; \
  435. int result_##func = func(6); \
  436. \
  437. /* Does the static initializer vanish after calling func? */ \
  438. BUILD_BUG_ON(init_##func < 32); \
  439. \
  440. /* "Consume" the results so optimizer doesn't drop them. */ \
  441. barrier_data(&init_##func); \
  442. barrier_data(&result_##func); \
  443. \
  444. return true; \
  445. }
  446. CREATE_WRAPPER(ffs)
  447. CREATE_WRAPPER(fls)
  448. CREATE_WRAPPER(__ffs)
  449. CREATE_WRAPPER(__fls)
  450. CREATE_WRAPPER(ffz)
  451. #undef CREATE_WRAPPER
  452. /*
  453. * Make sure that __attribute_const__ has be applied to all the
  454. * functions. This is a regression test for:
  455. * https://github.com/KSPP/linux/issues/364
  456. */
  457. static void ffs_attribute_const_test(struct kunit *test)
  458. {
  459. KUNIT_EXPECT_TRUE(test, build_test_ffs());
  460. KUNIT_EXPECT_TRUE(test, build_test_fls());
  461. KUNIT_EXPECT_TRUE(test, build_test___ffs());
  462. KUNIT_EXPECT_TRUE(test, build_test___fls());
  463. KUNIT_EXPECT_TRUE(test, build_test_ffz());
  464. }
  465. /*
  466. * KUnit test case definitions
  467. */
  468. static struct kunit_case ffs_test_cases[] = {
  469. KUNIT_CASE(ffs_basic_correctness_test),
  470. KUNIT_CASE(ffs64_correctness_test),
  471. KUNIT_CASE(ffs_mathematical_relationships_test),
  472. KUNIT_CASE(ffs_edge_cases_test),
  473. KUNIT_CASE(ffs64_edge_cases_test),
  474. KUNIT_CASE(ffz_basic_correctness_test),
  475. KUNIT_CASE(ffz_mathematical_relationships_test),
  476. KUNIT_CASE(ffz_edge_cases_test),
  477. KUNIT_CASE(ffs_attribute_const_test),
  478. {}
  479. };
  480. /*
  481. * KUnit test suite definition
  482. */
  483. static struct kunit_suite ffs_test_suite = {
  484. .name = "ffs",
  485. .test_cases = ffs_test_cases,
  486. };
  487. kunit_test_suites(&ffs_test_suite);
  488. MODULE_DESCRIPTION("KUnit tests for ffs()-family functions");
  489. MODULE_LICENSE("GPL");