Skip to content
Snippets Groups Projects
  1. Nov 09, 2021
  2. Oct 06, 2021
  3. Jun 29, 2021
  4. Jun 25, 2021
  5. Jun 23, 2021
  6. Apr 06, 2021
  7. Apr 02, 2021
    • Uriel Guajardo's avatar
      kunit: support failure from dynamic analysis tools · 359a3760
      Uriel Guajardo authored
      
      Add a kunit_fail_current_test() function to fail the currently running
      test, if any, with an error message.
      
      This is largely intended for dynamic analysis tools like UBSAN and for
      fakes.
      E.g. say I had a fake ops struct for testing and I wanted my `free`
      function to complain if it was called with an invalid argument, or
      caught a double-free. Most return void and have no normal means of
      signalling failure (e.g. super_operations, iommu_ops, etc.).
      
      Key points:
      * Always update current->kunit_test so anyone can use it.
        * commit 83c4e7a0 ("KUnit: KASAN Integration") only updated it for
        CONFIG_KASAN=y
      
      * Create a new header <kunit/test-bug.h> so non-test code doesn't have
      to include all of <kunit/test.h> (e.g. lib/ubsan.c)
      
      * Forward the file and line number to make it easier to track down
      failures
      
      * Declare the helper function for nice __printf() warnings about mismatched
      format strings even when KUnit is not enabled.
      
      Example output from kunit_fail_current_test("message"):
      [15:19:34] [FAILED] example_simple_test
      [15:19:34]     # example_simple_test: initializing
      [15:19:34]     # example_simple_test: lib/kunit/kunit-example-test.c:24: message
      [15:19:34]     not ok 1 - example_simple_test
      
      Fixed minor check patch with checkpatch --fix option:
      Shuah Khan <skhan@linuxfoundation.org>
      
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Signed-off-by: default avatarUriel Guajardo <urielguajardo@google.com>
      Reviewed-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      359a3760
  8. Dec 02, 2020
  9. Nov 10, 2020
  10. Oct 26, 2020
  11. Oct 25, 2020
  12. Oct 15, 2020
    • Mauro Carvalho Chehab's avatar
      kunit: test.h: fix a bad kernel-doc markup · 623050ae
      Mauro Carvalho Chehab authored
      
      As warned by:
      
      	./include/kunit/test.h:504: WARNING: Block quote ends without a blank line; unexpected unindent.
      
      The right way to describe a function is:
      
      	name - description
      
      Instead, kunit_remove_resource was using:
      
      	name: description
      
      Causing it to be improperly parsed.
      
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      623050ae
    • Mauro Carvalho Chehab's avatar
      kunit: test.h: solve kernel-doc warnings · 38d9b909
      Mauro Carvalho Chehab authored
      
      There are some warnings there:
      	./include/kunit/test.h:90: warning: Function parameter or member 'name' not described in 'kunit_resource'
      	./include/kunit/test.h:353: warning: Function parameter or member 'res' not described in 'kunit_add_resource'
      	./include/kunit/test.h:367: warning: Function parameter or member 'res' not described in 'kunit_add_named_resource'
      	./include/kunit/test.h:367: warning: Function parameter or member 'name' not described in 'kunit_add_named_resource'
      	./include/kunit/test.h:367: warning: Function parameter or member 'data' not described in 'kunit_add_named_resource'
      	./include/kunit/test.h:367: warning: Excess function parameter 'name_data' description in 'kunit_add_named_resource'
      
      Address them, ensuring that all non-private arguments will
      be properly described. With that regards, at struct kunit_resource,
      the free argument is described as user-provided. So, this
      doesn't seem to belong to the "private" part of the struct.
      
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      38d9b909
  13. Oct 14, 2020
  14. Oct 09, 2020
  15. Jun 26, 2020
    • Alan Maguire's avatar
      kunit: add support for named resources · 725aca95
      Alan Maguire authored
      
      The kunit resources API allows for custom initialization and
      cleanup code (init/fini); here a new resource add function sets
      the "struct kunit_resource" "name" field, and calls the standard
      add function.  Having a simple way to name resources is
      useful in cases such as multithreaded tests where a set of
      resources are shared among threads; a pointer to the
      "struct kunit *" test state then is all that is needed to
      retrieve and use named resources.  Support is provided to add,
      find and destroy named resources; the latter two are simply
      wrappers that use a "match-by-name" callback.
      
      If an attempt to add a resource with a name that already exists
      is made kunit_add_named_resource() will return -EEXIST.
      
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      725aca95
    • Alan Maguire's avatar
      kunit: generalize kunit_resource API beyond allocated resources · d4cdd146
      Alan Maguire authored
      In its original form, the kunit resources API - consisting the
      struct kunit_resource and associated functions - was focused on
      adding allocated resources during test operation that would be
      automatically cleaned up on test completion.
      
      The recent RFC patch proposing converting KASAN tests to KUnit [1]
      showed another potential model - where outside of test context,
      but with a pointer to the test state, we wish to access/update
      test-related data, but expressly want to avoid allocations.
      
      It turns out we can generalize the kunit_resource to support
      static resources where the struct kunit_resource * is passed
      in and initialized for us. As part of this work, we also
      change the "allocation" field to the more general "data" name,
      as instead of associating an allocation, we can associate a
      pointer to static data.  Static data is distinguished by a NULL
      free functions.  A test is added to cover using kunit_add_resource()
      with a static resource and data.
      
      Finally we also make use of the kernel's krefcount interfaces
      to manage reference counting of KUnit resources.  The motivation
      for this is simple; if we have kernel threads accessing and
      using resources (say via kunit_find_resource()) we need to
      ensure we do not remove said resources (or indeed free them
      if they were dynamically allocated) until the reference count
      reaches zero.  A new function - kunit_put_resource() - is
      added to handle this, and it should be called after a
      thread using kunit_find_resource() is finished with the
      retrieved resource.
      
      We ensure that the functions needed to look up, use and
      drop reference count are "static inline"-defined so that
      they can be used by builtin code as well as modules in
      the case that KUnit is built as a module.
      
      A cosmetic change here also; I've tried moving to
      kunit_[action]_resource() as the format of function names
      for consistency and readability.
      
      [1] https://lkml.org/lkml/2020/2/26/1286
      
      
      
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      d4cdd146
  16. May 22, 2020
  17. Mar 26, 2020
  18. Jan 09, 2020
  19. Sep 30, 2019
Loading