1. 08 Aug, 2023 3 commits
    • Janusz Krzysztofik's avatar
      kunit: Allow kunit test modules to use test filtering · b67abaad
      Janusz Krzysztofik authored
      External tools, e.g., Intel GPU tools (IGT), support execution of
      individual selftests provided by kernel modules.  That could be also
      applicable to kunit test modules if they provided test filtering.  But
      test filtering is now possible only when kunit code is built into the
      kernel.  Moreover, a filter can be specified only at boot time, then
      reboot is required each time a different filter is needed.
      
      Build the test filtering code also when kunit is configured as a module,
      expose test filtering functions to other kunit source files, and use them
      in kunit module notifier callback functions.  Userspace can then reload
      the kunit module with a value of the filter_glob parameter tuned to a
      specific kunit test module every time it wants to limit the scope of tests
      executed on that module load.  Make the kunit.filter* parameters visible
      in sysfs for user convenience.
      
      v5: Refresh on tpp of attributes filtering fix
      v4: Refresh on top of newly applied attributes patches and changes
          introdced by new versions of other patches submitted in series with
          this one.
      v3: Fix CONFIG_GLOB, required by filtering functions, not selected when
          building as a module (lkp@intel.com).
      v2: Fix new name of a structure moved to kunit namespace not updated
          across all uses (lkp@intel.com).
      Signed-off-by: default avatarJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      b67abaad
    • Janusz Krzysztofik's avatar
      kunit: Make 'list' action available to kunit test modules · 18258c60
      Janusz Krzysztofik authored
      Results from kunit tests reported via dmesg may be interleaved with other
      kernel messages.  When parsing dmesg for modular kunit results in real
      time, external tools, e.g., Intel GPU tools (IGT), may want to insert
      their own test name markers into dmesg at the start of each test, before
      any kernel message related to that test appears there, so existing upper
      level test result parsers have no doubt which test to blame for a specific
      kernel message.  Unfortunately, kunit reports names of tests only at their
      completion (with the exeption of a not standarized "# Subtest: <name>"
      header above a test plan of each test suite or parametrized test).
      
      External tools could be able to insert their own "start of the test"
      markers with test names included if they new those names in advance.
      Test names could be learned from a list if provided by a kunit test
      module.
      
      There exists a feature of listing kunit tests without actually executing
      them, but it is now limited to configurations with the kunit module built
      in and covers only built-in tests, already available at boot time.
      Moreover, switching from list to normal mode requires reboot.  If that
      feature was also available when kunit is built as a module, userspace
      could load the module with action=list parameter, load some kunit test
      modules they are interested in and learn about the list of tests provided
      by those modules, then unload them, reload the kunit module in normal mode
      and execute the tests with their lists already known.
      
      Extend kunit module notifier initialization callback with a processing
      path for only listing the tests provided by a module if the kunit action
      parameter is set to "list" or "list_attr".  For user convenience, make the
      kunit.action parameter visible in sysfs.
      
      v2: Don't use a different format, use kunit_exec_list_tests() (Rae),
        - refresh on top of new attributes patches, handle newly introduced
          kunit.action=list_attr case (Rae).
      Signed-off-by: default avatarJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
      Cc: Rae Moar <rmoar@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      18258c60
    • Janusz Krzysztofik's avatar
      kunit: Report the count of test suites in a module · c95e7c05
      Janusz Krzysztofik authored
      According to KTAP specification[1], results should always start from a
      header that provides a TAP protocol version, followed by a test plan with
      a count of items to be executed.  That pattern should be followed at each
      nesting level.  In the current implementation of the top-most, i.e., test
      suite level, those rules apply only for test suites built into the kernel,
      executed and reported on boot.  Results submitted to dmesg from kunit test
      modules loaded later are missing those top-level headers.
      
      As a consequence, if a kunit test module provides more than one test suite
      then, without the top level test plan, external tools that are parsing
      dmesg for kunit test output are not able to tell how many test suites
      should be expected and whether to continue parsing after complete output
      from the first test suite is collected.
      
      Submit the top-level headers also from the kunit test module notifier
      initialization callback.
      
      v3: Fix new name of a structure moved to kunit namespace not updated in
          executor_test functions (lkp@intel.com).
      v2: Use kunit_exec_run_tests() (Mauro, Rae), but prevent it from
          emitting the headers when called on load of non-test modules.
      
      [1] https://docs.kernel.org/dev-tools/ktap.html#Signed-off-by: default avatarJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Rae Moar <rmoar@google.com>
      Reviewed-by: default avatarRae Moar <rmoar@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      c95e7c05
  2. 04 Aug, 2023 2 commits
    • Rae Moar's avatar
      kunit: fix uninitialized variables bug in attributes filtering · 1c9fd080
      Rae Moar authored
      Fix smatch warnings regarding uninitialized variables in the filtering
      patch of the new KUnit Attributes feature.
      
      Fixes: 529534e8 ("kunit: Add ability to filter attributes")
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Closes: https://lore.kernel.org/r/202307270610.s0w4NKEn-lkp@intel.com/Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      1c9fd080
    • Ruan Jinjie's avatar
      kunit: fix possible memory leak in kunit_filter_suites() · abbf7381
      Ruan Jinjie authored
      Inject fault while probing drm_kunit_helpers.ko, if one of
      kunit_next_attr_filter(), kunit_filter_glob_tests() and
      kunit_filter_attr_tests() fails, parsed_filters,
      parsed_glob.suite_glob/test_glob alloced in
      kunit_parse_glob_filter() is leaked.
      And the filtered_suite->test_cases alloced in kunit_filter_glob_tests()
      or kunit_filter_attr_tests() may also be leaked.
      
      unreferenced object 0xff110001067e4800 (size 1024):
        comm "kunit_try_catch", pid 96, jiffies 4294671796 (age 763.547s)
        hex dump (first 32 bytes):
          73 75 69 74 65 32 00 00 00 00 00 00 00 00 00 00  suite2..........
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000116e8eba>] __kmalloc_node_track_caller+0x4e/0x140
          [<00000000e2f9cce9>] kmemdup+0x2c/0x60
          [<000000002a36710b>] kunit_filter_suites+0x3e4/0xa50
          [<0000000045779fb9>] filter_suites_test+0x1b7/0x440
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000105d79b00 (size 192):
        comm "kunit_try_catch", pid 96, jiffies 4294671796 (age 763.547s)
        hex dump (first 32 bytes):
          f0 e1 5a 88 ff ff ff ff 60 59 bb 8a ff ff ff ff  ..Z.....`Y......
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<000000006afe50bd>] kunit_filter_suites+0x424/0xa50
          [<0000000045779fb9>] filter_suites_test+0x1b7/0x440
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff110001067e6000 (size 1024):
        comm "kunit_try_catch", pid 98, jiffies 4294671798 (age 763.545s)
        hex dump (first 32 bytes):
          73 75 69 74 65 32 00 00 00 00 00 00 00 00 00 00  suite2..........
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000116e8eba>] __kmalloc_node_track_caller+0x4e/0x140
          [<00000000e2f9cce9>] kmemdup+0x2c/0x60
          [<000000002a36710b>] kunit_filter_suites+0x3e4/0xa50
          [<00000000f452f130>] filter_suites_test_glob_test+0x1b7/0x660
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000103f3a800 (size 96):
        comm "kunit_try_catch", pid 98, jiffies 4294671798 (age 763.545s)
        hex dump (first 32 bytes):
          f0 e1 5a 88 ff ff ff ff 40 39 bb 8a ff ff ff ff  ..Z.....@9......
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<000000006afe50bd>] kunit_filter_suites+0x424/0xa50
          [<00000000f452f130>] filter_suites_test_glob_test+0x1b7/0x660
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000101a72ac0 (size 16):
        comm "kunit_try_catch", pid 104, jiffies 4294671814 (age 763.529s)
        hex dump (first 16 bytes):
          00 00 00 00 00 00 00 00 e0 2a a7 01 01 00 11 ff  .........*......
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<00000000c7b724e7>] kunit_filter_suites+0x108/0xa50
          [<00000000bad5427d>] filter_attr_test+0x1e9/0x6a0
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000103caf880 (size 32):
        comm "kunit_try_catch", pid 104, jiffies 4294671814 (age 763.547s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<00000000c47b0f75>] kunit_filter_suites+0x189/0xa50
          [<00000000bad5427d>] filter_attr_test+0x1e9/0x6a0
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000101a72ae0 (size 16):
        comm "kunit_try_catch", pid 106, jiffies 4294671823 (age 763.538s)
        hex dump (first 16 bytes):
          00 00 00 00 00 00 00 00 00 2b a7 01 01 00 11 ff  .........+......
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<00000000c7b724e7>] kunit_filter_suites+0x108/0xa50
          [<0000000096255c51>] filter_attr_empty_test+0x1b0/0x310
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000103caf9c0 (size 32):
        comm "kunit_try_catch", pid 106, jiffies 4294671823 (age 763.538s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<00000000c47b0f75>] kunit_filter_suites+0x189/0xa50
          [<0000000096255c51>] filter_attr_empty_test+0x1b0/0x310
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      unreferenced object 0xff11000101a72b00 (size 16):
        comm "kunit_try_catch", pid 108, jiffies 4294671832 (age 763.529s)
        hex dump (first 16 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<000000000d6e4891>] __kmalloc+0x4d/0x140
          [<00000000c47b0f75>] kunit_filter_suites+0x189/0xa50
          [<00000000881258cc>] filter_attr_skip_test+0x148/0x770
          [<00000000cd1104a7>] kunit_try_run_case+0x119/0x270
          [<00000000c654c917>] kunit_generic_run_threadfn_adapter+0x4e/0xa0
          [<00000000d195ac13>] kthread+0x2c7/0x3c0
          [<00000000b79c1ee9>] ret_from_fork+0x2c/0x70
          [<000000001167f7e6>] ret_from_fork_asm+0x1b/0x30
      
      Fixes: 5d31f71e ("kunit: add kunit.filter_glob cmdline option to filter suites")
      Fixes: 529534e8 ("kunit: Add ability to filter attributes")
      Signed-off-by: default avatarRuan Jinjie <ruanjinjie@huawei.com>
      Reviewed-by: default avatarRae Moar <rmoar@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      abbf7381
  3. 31 Jul, 2023 1 commit
    • Ruan Jinjie's avatar
      kunit: fix wild-memory-access bug in kunit_filter_suites() · 5a175d36
      Ruan Jinjie authored
      As for kunit_filter_suites(), When the filters arg = NULL, such as
      the call of kunit_filter_suites(&suite_set, "suite2", NULL, NULL, &err)
      in filter_suites_test() tese case in kunit, both filter_count and
      parsed_filters will not be initialized.
      
      So it's possible to enter kunit_filter_attr_tests(), and the use of
      uninitialized parsed_filters will cause below wild-memory-access.
      
       RIP: 0010:kunit_filter_suites+0x780/0xa40
       Code: fe ff ff e8 42 87 4d ff 41 83 c6 01 49 83 c5 10 49 89 dc 44 39 74 24 50 0f 8e 81 fe ff ff e8 27 87 4d ff 4c 89 e8 48 c1 e8 03 <66> 42 83 3c 38 00 0f 85 af 01 00 00 49 8b 75 00 49 8b 55 08 4c 89
       RSP: 0000:ff1100010743fc38 EFLAGS: 00010203
       RAX: 03fc4400041d0ff1 RBX: ff1100010389a900 RCX: ffffffff9f940ad9
       RDX: ff11000107429740 RSI: 0000000000000000 RDI: ff110001037ec920
       RBP: ff1100010743fd50 R08: 0000000000000000 R09: ffe21c0020e87f1e
       R10: 0000000000000003 R11: 0000000000032001 R12: ff110001037ec800
       R13: 1fe2200020e87f8c R14: 0000000000000000 R15: dffffc0000000000
       FS:  0000000000000000(0000) GS:ff1100011b000000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: ff11000115201000 CR3: 0000000113066001 CR4: 0000000000771ef0
       DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
       PKRU: 55555554
       Call Trace:
        <TASK>
        ? die_addr+0x3c/0xa0
        ? exc_general_protection+0x148/0x220
        ? asm_exc_general_protection+0x26/0x30
        ? kunit_filter_suites+0x779/0xa40
        ? kunit_filter_suites+0x780/0xa40
        ? kunit_filter_suites+0x779/0xa40
        ? __pfx_kunit_filter_suites+0x10/0x10
        ? __pfx_kfree+0x10/0x10
        ? kunit_add_action_or_reset+0x3d/0x50
        filter_suites_test+0x1b7/0x440
        ? __pfx_filter_suites_test+0x10/0x10
        ? __pfx___schedule+0x10/0x10
        ? try_to_wake_up+0xa8e/0x1210
        ? _raw_spin_lock_irqsave+0x86/0xe0
        ? __pfx__raw_spin_lock_irqsave+0x10/0x10
        ? set_cpus_allowed_ptr+0x7c/0xb0
        kunit_try_run_case+0x119/0x270
        ? __kthread_parkme+0xdc/0x160
        ? __pfx_kunit_try_run_case+0x10/0x10
        kunit_generic_run_threadfn_adapter+0x4e/0xa0
        ? __pfx_kunit_generic_run_threadfn_adapter+0x10/0x10
        kthread+0x2c7/0x3c0
        ? __pfx_kthread+0x10/0x10
        ret_from_fork+0x2c/0x70
        ? __pfx_kthread+0x10/0x10
        ret_from_fork_asm+0x1b/0x30
        </TASK>
       Modules linked in:
       Dumping ftrace buffer:
          (ftrace buffer empty)
       ---[ end trace 0000000000000000 ]---
       RIP: 0010:kunit_filter_suites+0x780/0xa40
       Code: fe ff ff e8 42 87 4d ff 41 83 c6 01 49 83 c5 10 49 89 dc 44 39 74 24 50 0f 8e 81 fe ff ff e8 27 87 4d ff 4c 89 e8 48 c1 e8 03 <66> 42 83 3c 38 00 0f 85 af 01 00 00 49 8b 75 00 49 8b 55 08 4c 89
       RSP: 0000:ff1100010743fc38 EFLAGS: 00010203
       RAX: 03fc4400041d0ff1 RBX: ff1100010389a900 RCX: ffffffff9f940ad9
       RDX: ff11000107429740 RSI: 0000000000000000 RDI: ff110001037ec920
       RBP: ff1100010743fd50 R08: 0000000000000000 R09: ffe21c0020e87f1e
       R10: 0000000000000003 R11: 0000000000032001 R12: ff110001037ec800
       R13: 1fe2200020e87f8c R14: 0000000000000000 R15: dffffc0000000000
       FS:  0000000000000000(0000) GS:ff1100011b000000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: ff11000115201000 CR3: 0000000113066001 CR4: 0000000000771ef0
       DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
       DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
       PKRU: 55555554
       Kernel panic - not syncing: Fatal exception
       Dumping ftrace buffer:
          (ftrace buffer empty)
       Kernel Offset: 0x1da00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
       Rebooting in 1 seconds..
      
      Fixes: 529534e8 ("kunit: Add ability to filter attributes")
      Signed-off-by: default avatarRuan Jinjie <ruanjinjie@huawei.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      5a175d36
  4. 26 Jul, 2023 9 commits
    • Rae Moar's avatar
      kunit: Add documentation of KUnit test attributes · e5885866
      Rae Moar authored
      Add documentation on the use of test attributes under the section "Tips for
      Running KUnit Tests" in the KUnit docs.
      
      Documentation includes three sections on how to mark tests with attributes,
      how attributes are reported, and how the user can filter tests using test
      attributes.
      
      Add descriptions of new flags to list of command-line arguments.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      e5885866
    • Rae Moar's avatar
      kunit: add tests for filtering attributes · 76066f93
      Rae Moar authored
      Add four tests to executor_test.c to test behavior of filtering attributes.
      
      - parse_filter_attr_test - to test the parsing of inputted filters
      
      - filter_attr_test - to test the filtering procedure on attributes
      
      - filter_attr_empty_test - to test the behavior when all tests are filtered
        out
      
      - filter_attr_skip_test - to test the configurable filter_action=skip
        option
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      76066f93
    • Rae Moar's avatar
      kunit: time: Mark test as slow using test attributes · a547c4ce
      Rae Moar authored
      Mark the time KUnit test, time64_to_tm_test_date_range, as slow using test
      attributes.
      
      This test ran relatively much slower than most other KUnit tests.
      
      By marking this test as slow, the test can now be filtered using the KUnit
      test attribute filtering feature. Example: --filter "speed>slow". This will
      run only the tests that have speeds faster than slow. The slow attribute
      will also be outputted in KTAP.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a547c4ce
    • Rae Moar's avatar
      kunit: memcpy: Mark tests as slow using test attributes · d055c6a2
      Rae Moar authored
      Mark slow memcpy KUnit tests using test attributes.
      
      Tests marked as slow are as follows: memcpy_large_test, memmove_test,
      memmove_large_test, and memmove_overlap_test. These tests were the slowest
      of the memcpy tests and relatively slower to most other KUnit tests. Most
      of these tests are already skipped when CONFIG_MEMCPY_SLOW_KUNIT_TEST is
      not enabled.
      
      These tests can now be filtered using the KUnit test attribute filtering
      feature. Example: --filter "speed>slow". This will run only the tests that
      have speeds faster than slow. The slow attribute will also be outputted in
      KTAP.
      
      Note: This patch is intended to replace the use of
      CONFIG_MEMCPY_SLOW_KUNIT_TEST and to potentially deprecate this feature.
      This patch does not remove the config option but does add a note to the
      config definition commenting on this future shift.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      d055c6a2
    • Rae Moar's avatar
      kunit: tool: Add command line interface to filter and report attributes · 723c8258
      Rae Moar authored
      Add ability to kunit.py to filter attributes and report a list of tests
      including attributes without running tests.
      
      Add flag "--filter" to input filters on test attributes. Tests will be
      filtered out if they do not match all inputted filters.
      
      Example: --filter speed=slow (This filter would run only the tests that are
      marked as slow)
      
      Filters have operations: <, >, <=, >=, !=, and =. But note that the
      characters < and > are often interpreted by the shell, so they may need to
      be quoted or escaped.
      
      Example: --filter "speed>slow" or --filter speed\>slow (This filter would
      run only the tests that have the speed faster than slow.
      
      Additionally, multiple filters can be used.
      
      Example: --filter "speed=slow, module!=example" (This filter would run
      only the tests that have the speed slow and are not in the "example"
      module)
      
      Note if the user wants to skip filtered tests instead of not
      running/showing them use the "--filter_action=skip" flag instead.
      
      Expose the output of kunit.action=list option with flag "--list_tests" to
      output a list of tests. Additionally, add flag "--list_tests_attr" to
      output a list of tests and their attributes. These flags are useful to see
      tests and test attributes without needing to run tests.
      
      Example of the output of "--list_tests_attr":
        example
        example.test_1
        example.test_2
        # example.test_2.speed: slow
      
      This output includes a suite, example, with two test cases, test_1 and
      test_2. And in this instance test_2 has been marked as slow.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      723c8258
    • Rae Moar's avatar
      kunit: Add ability to filter attributes · 529534e8
      Rae Moar authored
      Add filtering of test attributes. Users can filter tests using the
      module_param called "filter".
      
      Filters are imputed in the format: <attribute_name><operation><value>
      
      Example: kunit.filter="speed>slow"
      
      Operations include: >, <, >=, <=, !=, and =. These operations will act the
      same for attributes of the same type but may not between types.
      
      Note multiple filters can be inputted by separating them with a comma.
      Example: kunit.filter="speed=slow, module!=example"
      
      Since both suites and test cases can have attributes, there may be
      conflicts. The process of filtering follows these rules:
      - Filtering always operates at a per-test level.
      - If a test has an attribute set, then the test's value is filtered on.
      - Otherwise, the value falls back to the suite's value.
      - If neither are set, the attribute has a global "default" value, which
        is used.
      
      Filtered tests will not be run or show in output. The tests can instead be
      skipped using the configurable option "kunit.filter_action=skip".
      
      Note the default settings for running tests remains unfiltered.
      
      Finally, add "filter" methods for the speed and module attributes to parse
      and compare attribute values.
      
      Note this filtering functionality will be added to kunit.py in the next
      patch.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      529534e8
    • Rae Moar's avatar
      kunit: Add module attribute · a00a7270
      Rae Moar authored
      Add module attribute to the test attribute API. This attribute stores the
      module name associated with the test using KBUILD_MODNAME.
      
      The name of a test suite and the module name often do not match. A
      reference to the module name associated with the suite could be extremely
      helpful in running tests as modules without needing to check the codebase.
      
      This attribute will be printed for each suite.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a00a7270
    • Rae Moar's avatar
      kunit: Add speed attribute · 02c2d0c2
      Rae Moar authored
      Add speed attribute to the test attribute API. This attribute will allow
      users to mark tests with a category of speed.
      
      Currently the categories of speed proposed are: normal, slow, and very_slow
      (outlined in enum kunit_speed). These are outlined in the enum kunit_speed.
      
      The assumed default speed for tests is "normal". This indicates that the
      test takes a relatively trivial amount of time (less than 1 second),
      regardless of the machine it is running on. Any test slower than this could
      be marked as "slow" or "very_slow".
      
      Add the macro KUNIT_CASE_SLOW to set a test as slow, as this is likely a
      common use of the attributes API.
      
      Add an example of marking a slow test to kunit-example-test.c.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      02c2d0c2
    • Rae Moar's avatar
      kunit: Add test attributes API structure · 39e92cb1
      Rae Moar authored
      Add the basic structure of the test attribute API to KUnit, which can be
      used to save and access test associated data.
      
      Add attributes.c and attributes.h to hold associated structs and functions
      for the API.
      
      Create a struct that holds a variety of associated helper functions for
      each test attribute. These helper functions will be used to get the
      attribute value, convert the value to a string, and filter based on the
      value. This struct is flexible by design to allow for attributes of
      numerous types and contexts.
      
      Add a method to print test attributes in the format of "# [<test_name if
      not suite>.]<attribute_name>: <attribute_value>".
      
      Example for a suite: "# speed: slow"
      
      Example for a test case: "# test_case.speed: very_slow"
      
      Use this method to report attributes in the KTAP output (KTAP spec:
      https://docs.kernel.org/dev-tools/ktap.html) and _list_tests output when
      kernel's new kunit.action=list_attr option is used. Note this is derivative
      of the kunit.action=list option.
      
      In test.h, add fields and associated helper functions to test cases and
      suites to hold user-inputted test attributes.
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarRae Moar <rmoar@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      39e92cb1
  5. 19 Jul, 2023 5 commits
  6. 18 Jul, 2023 3 commits
  7. 09 Jul, 2023 10 commits
  8. 08 Jul, 2023 7 commits