Commit b820b90
kunit: Enable direct registration of parameter arrays to a KUnit test
KUnit parameterized tests currently support two primary methods f
or getting parameters:
1. Defining custom logic within a generate_params() function.
2. Using the KUNIT_ARRAY_PARAM() and KUNIT_ARRAY_PARAM_DESC()
macros with a pre-defined static array and passing
the created *_gen_params() to KUNIT_CASE_PARAM().
These methods present limitations when dealing with dynamically
generated parameter arrays, or in scenarios where populating parameters
sequentially via generate_params() is inefficient or overly complex.
This patch addresses these limitations by adding a new `params_array`
field to `struct kunit`, of the type `kunit_params`. The
`struct kunit_params` is designed to store the parameter array itself,
along with essential metadata including the parameter count, parameter
size, and a get_description() function for providing custom descriptions
for individual parameters.
The `params_array` field can be populated by calling the new
kunit_register_params_array() macro from within a param_init() function.
This will register the array as part of the parameterized test context.
The user will then need to pass kunit_array_gen_params() to the
KUNIT_CASE_PARAM_WITH_INIT() macro as the generator function, if not
providing their own. kunit_array_gen_params() is a KUnit helper that will
use the registered array to generate parameters.
The arrays passed to KUNIT_ARRAY_PARAM(,DESC) will also be registered to
the parameterized test context for consistency as well as for higher
availability of the parameter count that will be used for outputting a KTAP
test plan for a parameterized test.
This modification provides greater flexibility to the KUnit framework,
allowing testers to easily register and utilize both dynamic and static
parameter arrays.
Link: https://lore.kernel.org/r/20250826091341.1427123-5-davidgow@google.com
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Signed-off-by: Marie Zhussupova <marievic@google.com>
[Only output the test plan if using kunit_array_gen_params --David]
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>1 parent b9a214b commit b820b90
2 files changed
Lines changed: 91 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
240 | 244 | | |
241 | 245 | | |
242 | 246 | | |
| |||
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
292 | 310 | | |
293 | 311 | | |
294 | 312 | | |
295 | 313 | | |
296 | 314 | | |
297 | 315 | | |
298 | 316 | | |
| 317 | + | |
299 | 318 | | |
300 | 319 | | |
301 | 320 | | |
302 | | - | |
303 | | - | |
304 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
305 | 324 | | |
306 | 325 | | |
307 | 326 | | |
308 | 327 | | |
| 328 | + | |
309 | 329 | | |
310 | 330 | | |
311 | 331 | | |
| |||
376 | 396 | | |
377 | 397 | | |
378 | 398 | | |
| 399 | + | |
| 400 | + | |
379 | 401 | | |
380 | 402 | | |
381 | 403 | | |
| |||
1708 | 1730 | | |
1709 | 1731 | | |
1710 | 1732 | | |
| 1733 | + | |
| 1734 | + | |
1711 | 1735 | | |
1712 | 1736 | | |
1713 | 1737 | | |
| |||
1730 | 1754 | | |
1731 | 1755 | | |
1732 | 1756 | | |
| 1757 | + | |
| 1758 | + | |
1733 | 1759 | | |
1734 | 1760 | | |
1735 | 1761 | | |
1736 | 1762 | | |
1737 | 1763 | | |
1738 | 1764 | | |
1739 | 1765 | | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
1740 | 1793 | | |
1741 | 1794 | | |
1742 | 1795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
340 | 348 | | |
341 | 349 | | |
342 | 350 | | |
| |||
347 | 355 | | |
348 | 356 | | |
349 | 357 | | |
| 358 | + | |
350 | 359 | | |
351 | 360 | | |
352 | 361 | | |
| |||
641 | 650 | | |
642 | 651 | | |
643 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
644 | 670 | | |
645 | 671 | | |
646 | 672 | | |
| |||
706 | 732 | | |
707 | 733 | | |
708 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
709 | 741 | | |
710 | 742 | | |
711 | 743 | | |
| |||
0 commit comments