1. 12 May, 2022 6 commits
    • Daniel Latypov's avatar
      kunit: tool: print clearer error message when there's no TAP output · 9660209d
      Daniel Latypov authored
      Before:
      $ ./tools/testing/kunit/kunit.py parse /dev/null
      ...
      [ERROR] Test : invalid KTAP input!
      
      After:
      $ ./tools/testing/kunit/kunit.py parse /dev/null
      ...
      [ERROR] Test <missing>: could not find any KTAP output!
      
      This error message gets printed out when extract_tap_output() yielded no
      lines. So while it could be because of malformed KTAP output from KUnit,
      it could also be due to not having any KTAP output at all.
      
      Try and make the error message here more clear.
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      9660209d
    • Daniel Latypov's avatar
      kunit: tool: stop using a shell to run kernel under QEMU · 3f0a50f3
      Daniel Latypov authored
      Note: this potentially breaks custom qemu_configs if people are using
      them! But the fix for them is simple, don't specify multiple arguments
      in one string and don't add on a redundant ''.
      
      It feels a bit iffy to be using a shell in the first place.
      
      There's the usual shenanigans where people could pass in arbitrary shell
      commands via --kernel_arg (since we're just adding '' around the
      kernel_cmdline) or via a custom qemu_config.
      This isn't too much of a concern given the nature of this script (and
      the qemu_config file is in python, you can do w/e you want already).
      
      But it does have some other drawbacks.
      
      One example of a kunit-specific pain point:
      If the relevant qemu binary is missing, we get output like this:
      > /bin/sh: line 1: qemu-system-aarch64: command not found
      This in turn results in our KTAP parser complaining about
      missing/invalid KTAP, but we don't directly show the error!
      It's even more annoying to debug when you consider --raw_output only
      shows KUnit output by default, i.e. you need --raw_output=all to see it.
      
      Whereas directly invoking the binary, Python will raise a
      FileNotFoundError for us, which is a noisier but more clear.
      
      Making this change requires
      * splitting parameters like ['-m 256'] into ['-m', '256'] in
        kunit/qemu_configs/*.py
      * change [''] to [] in kunit/qemu_configs/*.py since otherwise
        QEMU fails w/ 'Device needs media, but drive is empty'
      * dropping explicit quoting of the kernel cmdline
      * using shlex.quote() when we print what command we're running
        so the user can copy-paste and run it
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      3f0a50f3
    • Daniel Latypov's avatar
      kunit: tool: update test counts summary line format · c2497643
      Daniel Latypov authored
      Before:
      > Testing complete. Passed: 137, Failed: 0, Crashed: 0, Skipped: 36, Errors: 0
      
      After:
      > Testing complete. Ran 173 tests: passed: 137, skipped: 36
      
      Even with our current set of statuses, the output is a bit verbose.
      It could get worse in the future if we add more (e.g. timeout, kasan).
      Let's only print the relevant ones.
      
      I had previously been sympathetic to the argument that always
      printing out all the statuses would make it easier to parse results.
      But now we have commit acd8e840 ("kunit: Print test statistics on
      failure"), there are test counts printed out in the raw output.
      We don't currently print out an overall total across all suites, but it
      would be easy to add, if we see a need for that.
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Co-developed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      c2497643
    • Daniel Latypov's avatar
      kunit: bail out of test filtering logic quicker if OOM · a02353f4
      Daniel Latypov authored
      When filtering what tests to run (suites and/or cases) via
      kunit.filter_glob (e.g. kunit.py run <glob>), we allocate copies of
      suites.
      
      These allocations can fail, and we largely don't handle that.
      Note: realistically, this probably doesn't matter much.
      We're not allocating much memory and this happens early in boot, so if
      we can't do that, then there's likely far bigger problems.
      
      This patch makes us immediately bail out from the top-level function
      (kunit_filter_suites) with -ENOMEM if any of the underlying kmalloc()
      calls return NULL.
      
      Implementation note: we used to return NULL pointers from some functions
      to indicate either that all suites/tests were filtered out or there was
      an error allocating the new array.
      
      We'll log a short error in this case and not run any tests or print a
      TAP header. From a kunit.py user's perspective, they'll get a message
      about missing/invalid TAP output and have to dig into the test.log to
      see it. Since hitting this error seems so unlikely, it's probably fine
      to not invent a way to plumb this error message more visibly.
      
      See also: https://lore.kernel.org/linux-kselftest/20220329103919.2376818-1-lv.ruyi@zte.com.cn/Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reported-by: default avatarZeal Robot <zealci@zte.com.cn>
      Reported-by: default avatarLv Ruyi <lv.ruyi@zte.com.cn>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a02353f4
    • Daniel Latypov's avatar
      lib/Kconfig.debug: change KUnit tests to default to KUNIT_ALL_TESTS · dcbb2ee2
      Daniel Latypov authored
      This is in line with Documentation/dev-tools/kunit/style.rst.
      Some of these tests predate that so they don't follow this convention.
      
      With this and commit b0841b51 ("kunit: arch/um/configs: Enable
      KUNIT_ALL_TESTS by default"), kunit.py will now run these tests by
      default. This hopefully makes it easier to run and maintain the tests.
      If any of these were to start failing, people would notice much quicker.
      
      Note: this commit doesn't update LINEAR_RANGES_TEST since that would
      select its dependency (LINEAR_RANGES). We don't want KUNIT_ALL_TESTS
      to enable anything other than test kconfigs.
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarNico Pache <npache@redhat.com>
      Acked-by: default avatarNico Pache <npache@redhat.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      dcbb2ee2
    • David Gow's avatar
      kunit: Rework kunit_resource allocation policy · ad69172e
      David Gow authored
      KUnit's test-managed resources can be created in two ways:
      - Using the kunit_add_resource() family of functions, which accept a
        struct kunit_resource pointer, typically allocated statically or on
        the stack during the test.
      - Using the kunit_alloc_resource() family of functions, which allocate a
        struct kunit_resource using kzalloc() behind the scenes.
      
      Both of these families of functions accept a 'free' function to be
      called when the resource is finally disposed of.
      
      At present, KUnit will kfree() the resource if this 'free' function is
      specified, and will not if it is NULL. However, this can lead
      kunit_alloc_resource() to leak memory (if no 'free' function is passed
      in), or kunit_add_resource() to incorrectly kfree() memory which was
      allocated by some other means (on the stack, as part of a larger
      allocation, etc), if a 'free' function is provided.
      
      Instead, always kfree() if the resource was allocated with
      kunit_alloc_resource(), and never kfree() if it was passed into
      kunit_add_resource() by the user. (If the user of kunit_add_resource()
      wishes the resource be kfree()ed, they can call kfree() on the resource
      from within the 'free' function.
      
      This is implemented by adding a 'should_free' member to
      struct kunit_resource and setting it appropriately. To facilitate this,
      the various resource add/alloc functions have been refactored somewhat,
      making them all call a __kunit_add_resource() helper after setting the
      'should_free' member appropriately. In the process, all other functions
      have been made static inline functions.
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Tested-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      ad69172e
  2. 02 May, 2022 4 commits
  3. 27 Apr, 2022 1 commit
  4. 05 Apr, 2022 2 commits
    • David Gow's avatar
      kunit: Make kunit_remove_resource() idempotent · 59729170
      David Gow authored
      The kunit_remove_resource() function is used to unlink a resource from
      the list of resources in the test, making it no longer show up in
      kunit_find_resource().
      
      However, this could lead to a race condition if two threads called
      kunit_remove_resource() on the same resource at the same time: the
      resource would be removed from the list twice (causing a crash at the
      second list_del()), and the refcount for the resource would be
      decremented twice (instead of once, for the reference held by the
      resource list).
      
      Fix both problems, the first by using list_del_init(), and the second by
      checking if the resource has already been removed using list_empty(),
      and only decrementing its refcount if it has not.
      
      Also add a KUnit test for the kunit_remove_resource() function which
      tests this behaviour.
      Reported-by: default avatarDaniel Latypov <dlatypov@google.com>
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      59729170
    • David Gow's avatar
      list: test: Test the hlist structure · 1ff522b6
      David Gow authored
      Add KUnit tests to the hlist linked-list structure which is used by
      hashtables. This should give coverage of every function and macro in
      list.h, as well as (combined with the KUnit tests for the hash
      functions) get very close to having tests for the hashtable structure.
      
      The tests here mirror the existing list tests, and are found in a new
      suite titled 'hlist'.
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      1ff522b6
  5. 04 Apr, 2022 18 commits
  6. 03 Apr, 2022 8 commits
  7. 02 Apr, 2022 1 commit
    • Linus Torvalds's avatar
      Merge tag 'perf-tools-for-v5.18-2022-04-02' of... · be2d3ece
      Linus Torvalds authored
      Merge tag 'perf-tools-for-v5.18-2022-04-02' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
      
      Pull more perf tools updates from Arnaldo Carvalho de Melo:
      
       - Avoid SEGV if core.cpus isn't set in 'perf stat'.
      
       - Stop depending on .git files for building PERF-VERSION-FILE, used in
         'perf --version', fixing some perf tools build scenarios.
      
       - Convert tracepoint.py example to python3.
      
       - Update UAPI header copies from the kernel sources: socket,
         mman-common, msr-index, KVM, i915 and cpufeatures.
      
       - Update copy of libbpf's hashmap.c.
      
       - Directly return instead of using local ret variable in
         evlist__create_syswide_maps(), found by coccinelle.
      
      * tag 'perf-tools-for-v5.18-2022-04-02' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux:
        perf python: Convert tracepoint.py example to python3
        perf evlist: Directly return instead of using local ret variable
        perf cpumap: More cpu map reuse by merge.
        perf cpumap: Add is_subset function
        perf evlist: Rename cpus to user_requested_cpus
        perf tools: Stop depending on .git files for building PERF-VERSION-FILE
        tools headers cpufeatures: Sync with the kernel sources
        tools headers UAPI: Sync drm/i915_drm.h with the kernel sources
        tools headers UAPI: Sync linux/kvm.h with the kernel sources
        tools kvm headers arm64: Update KVM headers from the kernel sources
        tools arch x86: Sync the msr-index.h copy with the kernel sources
        tools headers UAPI: Sync asm-generic/mman-common.h with the kernel
        perf beauty: Update copy of linux/socket.h with the kernel sources
        perf tools: Update copy of libbpf's hashmap.c
        perf stat: Avoid SEGV if core.cpus isn't set
      be2d3ece