• Daniel Latypov's avatar
    kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros · 697365c0
    Daniel Latypov authored
    
    
    These macros exist because passing an initializer list to other macros
    is hard.
    
    The goal of these macros is to generate a line like
      struct $ASSERT_TYPE __assertion = $APPROPRIATE_INITIALIZER;
    e.g.
      struct kunit_unary_assertion __assertion = {
    	  .condition = "foo()",
    	  .expected_true = true
      };
    
    But the challenge is you can't pass `{.condition=..., .expect_true=...}`
    as a macro argument, since the comma means you're actually passing two
    arguments, `{.condition=...` and `.expect_true=....}`.
    So we'd made custom macros for each different initializer-list shape.
    
    But we can work around this with the following generic macro
      #define KUNIT_INIT_ASSERT(initializers...) { initializers }
    
    Note: this has the downside that we have to rename some macros arguments
    to not conflict with the struct field names (e.g. `expected_true`).
    It's a bit gross, but probably worth reducing the # of macros.
    Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
    Reviewed-by: default avatarDavid Gow <davidgow@google.com>
    Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
    697365c0
test.h 49.9 KB