lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABVgOSkwk2a96b6-5jpwsqSVsc8jm72KKodsG3YpZaV9N78Rsw@mail.gmail.com>
Date:   Fri, 21 Jan 2022 15:21:59 +0800
From:   David Gow <davidgow@...gle.com>
To:     Daniel Latypov <dlatypov@...gle.com>
Cc:     Brendan Higgins <brendanhiggins@...gle.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        KUnit Development <kunit-dev@...glegroups.com>,
        "open list:KERNEL SELFTEST FRAMEWORK" 
        <linux-kselftest@...r.kernel.org>,
        Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH 5/5] kunit: decrease macro layering for EQ/NE asserts

On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov <dlatypov@...gle.com> wrote:
>
> Introduce KUNIT_BINARY_PTR_ASSERTION to match KUNIT_BINARY_INT_ASSERTION
> and make KUNIT_EXPECT_EQ and KUNIT_EXPECT_PTREQ use these instead of
> shared intermediate macros that only remove the need to type "==" or
> "!=".
>
> The current macro chain looks like:
> KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
> KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
> <ditto for NE and ASSERT>
>
> After this change:
> KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
> KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
>
> Signed-off-by: Daniel Latypov <dlatypov@...gle.com>
> ---

This is great: the macros are much simpler and nicer now. In fact,
this whole series is one of the nicest I've seen for a while: I can't
think of any serious downsides to any of it.

Reviewed-by: David Gow <davidgow@...gle.com>

Thanks,
-- David


>  include/kunit/test.h | 173 ++++++++++++-------------------------------
>  1 file changed, 49 insertions(+), 124 deletions(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 48cf520b69ce..bf82c313223b 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -888,48 +888,6 @@ do {                                                                              \
>                         ##__VA_ARGS__);                                        \
>  } while (0)
>
> -#define KUNIT_BASE_EQ_MSG_ASSERTION(test,                                     \
> -                                   assert_class,                              \
> -                                   ASSERT_CLASS_INIT,                         \
> -                                   assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> -                                   fmt,                                       \
> -                                   ...)                                       \
> -       KUNIT_BASE_BINARY_ASSERTION(test,                                      \
> -                                   assert_class,                              \
> -                                   ASSERT_CLASS_INIT,                         \
> -                                   assert_type,                               \
> -                                   left, ==, right,                           \
> -                                   fmt,                                       \
> -                                   ##__VA_ARGS__)
> -
> -#define KUNIT_BASE_NE_MSG_ASSERTION(test,                                     \
> -                                   assert_class,                              \
> -                                   ASSERT_CLASS_INIT,                         \
> -                                   assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> -                                   fmt,                                       \
> -                                   ...)                                       \
> -       KUNIT_BASE_BINARY_ASSERTION(test,                                      \
> -                                   assert_class,                              \
> -                                   ASSERT_CLASS_INIT,                         \
> -                                   assert_type,                               \
> -                                   left, !=, right,                           \
> -                                   fmt,                                       \
> -                                   ##__VA_ARGS__)
> -
> -#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
> -       KUNIT_BASE_EQ_MSG_ASSERTION(test,                                      \
> -                                   kunit_binary_assert,                       \
> -                                   KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
> -                                   assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> -                                   fmt,                                       \
> -                                   ##__VA_ARGS__)
> -
>  #define KUNIT_BINARY_INT_ASSERTION(test,                                      \
>                                    assert_type,                                \
>                                    left,                                       \
> @@ -945,43 +903,18 @@ do {                                                                             \
>                                     fmt,                                       \
>                                     ##__VA_ARGS__)
>
> -#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                       \
> -                                         assert_type,                         \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ...)                                 \
> -       KUNIT_BASE_EQ_MSG_ASSERTION(test,                                      \
> -                                   kunit_binary_ptr_assert,                   \
> -                                   KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
> -                                   assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> -                                   fmt,                                       \
> -                                   ##__VA_ARGS__)
> -
> -#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
> -       KUNIT_BASE_NE_MSG_ASSERTION(test,                                      \
> -                                   kunit_binary_assert,                       \
> -                                   KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
> -                                   assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> -                                   fmt,                                       \
> -                                   ##__VA_ARGS__)
> -
> -#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                       \
> -                                         assert_type,                         \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ...)                                 \
> -       KUNIT_BASE_NE_MSG_ASSERTION(test,                                      \
> +#define KUNIT_BINARY_PTR_ASSERTION(test,                                      \
> +                                  assert_type,                                \
> +                                  left,                                       \
> +                                  op,                                         \
> +                                  right,                                      \
> +                                  fmt,                                        \
> +                                   ...)                                       \
> +       KUNIT_BASE_BINARY_ASSERTION(test,                                      \
>                                     kunit_binary_ptr_assert,                   \
>                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
>                                     assert_type,                               \
> -                                   left,                                      \
> -                                   right,                                     \
> +                                   left, op, right,                           \
>                                     fmt,                                       \
>                                     ##__VA_ARGS__)
>
> @@ -1082,12 +1015,11 @@ do {                                                                           \
>         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
>
>  #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...)                      \
> -       KUNIT_BINARY_EQ_MSG_ASSERTION(test,                                    \
> -                                     KUNIT_EXPECTATION,                       \
> -                                     left,                                    \
> -                                     right,                                   \
> -                                     fmt,                                     \
> -                                     ##__VA_ARGS__)
> +       KUNIT_BINARY_INT_ASSERTION(test,                                       \
> +                                  KUNIT_EXPECTATION,                          \
> +                                  left, ==, right,                            \
> +                                  fmt,                                        \
> +                                   ##__VA_ARGS__)
>
>  /**
>   * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
> @@ -1104,12 +1036,11 @@ do {                                                                           \
>         KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
>
>  #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...)                  \
> -       KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                \
> -                                         KUNIT_EXPECTATION,                   \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ##__VA_ARGS__)
> +       KUNIT_BINARY_PTR_ASSERTION(test,                                       \
> +                                  KUNIT_EXPECTATION,                          \
> +                                  left, ==, right,                            \
> +                                  fmt,                                        \
> +                                  ##__VA_ARGS__)
>
>  /**
>   * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
> @@ -1126,12 +1057,11 @@ do {                                                                           \
>         KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
>
>  #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...)                      \
> -       KUNIT_BINARY_NE_MSG_ASSERTION(test,                                    \
> -                                     KUNIT_EXPECTATION,                       \
> -                                     left,                                    \
> -                                     right,                                   \
> -                                     fmt,                                     \
> -                                     ##__VA_ARGS__)
> +       KUNIT_BINARY_INT_ASSERTION(test,                                       \
> +                                  KUNIT_EXPECTATION,                          \
> +                                  left, !=, right,                            \
> +                                  fmt,                                        \
> +                                   ##__VA_ARGS__)
>
>  /**
>   * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
> @@ -1148,12 +1078,11 @@ do {                                                                           \
>         KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
>
>  #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...)                  \
> -       KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                \
> -                                         KUNIT_EXPECTATION,                   \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ##__VA_ARGS__)
> +       KUNIT_BINARY_PTR_ASSERTION(test,                                       \
> +                                  KUNIT_EXPECTATION,                          \
> +                                  left, !=, right,                            \
> +                                  fmt,                                        \
> +                                  ##__VA_ARGS__)
>
>  /**
>   * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
> @@ -1358,12 +1287,11 @@ do {                                                                           \
>         KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
>
>  #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...)                      \
> -       KUNIT_BINARY_EQ_MSG_ASSERTION(test,                                    \
> -                                     KUNIT_ASSERTION,                         \
> -                                     left,                                    \
> -                                     right,                                   \
> -                                     fmt,                                     \
> -                                     ##__VA_ARGS__)
> +       KUNIT_BINARY_INT_ASSERTION(test,                                       \
> +                                  KUNIT_ASSERTION,                            \
> +                                  left, ==, right,                            \
> +                                  fmt,                                        \
> +                                   ##__VA_ARGS__)
>
>  /**
>   * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
> @@ -1379,12 +1307,11 @@ do {                                                                           \
>         KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
>
>  #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...)                  \
> -       KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                \
> -                                         KUNIT_ASSERTION,                     \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ##__VA_ARGS__)
> +       KUNIT_BINARY_PTR_ASSERTION(test,                                       \
> +                                  KUNIT_ASSERTION,                            \
> +                                  left, ==, right,                            \
> +                                  fmt,                                        \
> +                                  ##__VA_ARGS__)
>
>  /**
>   * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
> @@ -1400,12 +1327,11 @@ do {                                                                           \
>         KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
>
>  #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...)                      \
> -       KUNIT_BINARY_NE_MSG_ASSERTION(test,                                    \
> -                                     KUNIT_ASSERTION,                         \
> -                                     left,                                    \
> -                                     right,                                   \
> -                                     fmt,                                     \
> -                                     ##__VA_ARGS__)
> +       KUNIT_BINARY_INT_ASSERTION(test,                                       \
> +                                  KUNIT_ASSERTION,                            \
> +                                  left, !=, right,                            \
> +                                  fmt,                                        \
> +                                   ##__VA_ARGS__)
>
>  /**
>   * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
> @@ -1422,12 +1348,11 @@ do {                                                                           \
>         KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
>
>  #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...)                  \
> -       KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                \
> -                                         KUNIT_ASSERTION,                     \
> -                                         left,                                \
> -                                         right,                               \
> -                                         fmt,                                 \
> -                                         ##__VA_ARGS__)
> +       KUNIT_BINARY_PTR_ASSERTION(test,                                       \
> +                                  KUNIT_ASSERTION,                            \
> +                                  left, !=, right,                            \
> +                                  fmt,                                        \
> +                                  ##__VA_ARGS__)
>  /**
>   * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
>   * @test: The test context object.
> --
> 2.34.1.703.g22d0c6ccf7-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ