linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Daniel Latypov <dlatypov@google.com>
Cc: Brendan Higgins <brendanhiggins@google.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	KUnit Development <kunit-dev@googlegroups.com>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 6/6] kunit: drop unused assert_type from kunit_assert and clean up macros
Date: Tue, 11 Jan 2022 14:57:13 +0800	[thread overview]
Message-ID: <CABVgOSkOqMkPNUWpn+eavb0ykv+psbRAEEv0sQfd7xpG0zmogQ@mail.gmail.com> (raw)
In-Reply-To: <20220108012304.1049587-7-dlatypov@google.com>

On Sat, Jan 8, 2022 at 9:23 AM Daniel Latypov <dlatypov@google.com> wrote:
>
> This field has been split out from kunit_assert to make the struct less
> heavy along with the filename and line number.
>
> This change drops the assert_type field and cleans up all the macros
> that were plumbing assert_type into kunit_assert.
>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>
> ---

Looks good to me. Anything that simplifies these macros is a good
thing, in my opinion.

One minor formatting nitpick below.

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

-- David


>  include/kunit/assert.h | 46 +++++++++++++-----------------------------
>  include/kunit/test.h   | 14 +++++--------
>  2 files changed, 19 insertions(+), 41 deletions(-)
>
> diff --git a/include/kunit/assert.h b/include/kunit/assert.h
> index 4f91dbdb886a..21299232c120 100644
> --- a/include/kunit/assert.h
> +++ b/include/kunit/assert.h
> @@ -42,7 +42,6 @@ struct kunit_loc {
>
>  /**
>   * struct kunit_assert - Data for printing a failed assertion or expectation.
> - * @type: the type (either an expectation or an assertion) of this kunit_assert.
>   * @message: an optional message to provide additional context.
>   * @format: a function which formats the data in this kunit_assert to a string.
>   *
> @@ -50,7 +49,6 @@ struct kunit_loc {
>   * format a string to a user reporting the failure.
>   */
>  struct kunit_assert {
> -       enum kunit_assert_type type; // TODO(dlatypov@google.com): delete this
>         struct va_format message;
>         void (*format)(const struct kunit_assert *assert,
>                        struct string_stream *stream);
> @@ -66,13 +64,11 @@ struct kunit_assert {
>
>  /**
>   * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert.
> - * @assert_type: The type (assertion or expectation) of this kunit_assert.
>   * @fmt: The formatting function which builds a string out of this kunit_assert.
>   *
>   * The base initializer for a &struct kunit_assert.
>   */
> -#define KUNIT_INIT_ASSERT_STRUCT(assert_type, fmt) {                          \
> -       .type = assert_type,                                                   \
> +#define KUNIT_INIT_ASSERT_STRUCT(fmt) {                                               \
>         .message = KUNIT_INIT_VA_FMT_NULL,                                     \
>         .format = fmt                                                          \
>  }
> @@ -98,15 +94,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,
>                               struct string_stream *stream);
>
>  /**
> - * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert.
> - * @type: The type (assertion or expectation) of this kunit_assert.
> + * KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert.
>   *
>   * Initializes a &struct kunit_fail_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_FAIL_ASSERT_STRUCT(type) {                         \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_fail_assert_format)           \
> +#define KUNIT_INIT_FAIL_ASSERT_STRUCT {                                        \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_fail_assert_format)    \
>  }
>
>  /**
> @@ -130,16 +124,14 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
>
>  /**
>   * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert.
> - * @type: The type (assertion or expectation) of this kunit_assert.
>   * @cond: A string representation of the expression asserted true or false.
>   * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
>   *
>   * Initializes a &struct kunit_unary_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_UNARY_ASSERT_STRUCT(type, cond, expect_true) {             \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_unary_assert_format),         \
> +#define KUNIT_INIT_UNARY_ASSERT_STRUCT(cond, expect_true) {                   \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_unary_assert_format),         \
>         .condition = cond,                                                     \
>         .expected_true = expect_true                                           \
>  }
> @@ -166,16 +158,14 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
>  /**
>   * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a
>   *     &struct kunit_ptr_not_err_assert.
> - * @type: The type (assertion or expectation) of this kunit_assert.
>   * @txt: A string representation of the expression passed to the expectation.
>   * @val: The actual evaluated pointer value of the expression.
>   *
>   * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(type, txt, val) {                               \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_ptr_not_err_assert_format),   \
> +#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(txt, val) {                             \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_ptr_not_err_assert_format),   \
>         .text = txt,                                                           \
>         .value = val                                                           \
>  }
> @@ -209,7 +199,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
>  /**
>   * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a
>   *     &struct kunit_binary_assert.
> - * @type: The type (assertion or expectation) of this kunit_assert.
>   * @op_str: A string representation of the comparison operator (e.g. "==").
>   * @left_str: A string representation of the expression in the left slot.
>   * @left_val: The actual evaluated value of the expression in the left slot.
> @@ -219,14 +208,12 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
>   * Initializes a &struct kunit_binary_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_BINARY_ASSERT_STRUCT(type,                                 \
> -                                       op_str,                                \
> +#define KUNIT_INIT_BINARY_ASSERT_STRUCT(op_str,                                       \
>                                         left_str,                              \
>                                         left_val,                              \
>                                         right_str,                             \
>                                         right_val) {                           \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_binary_assert_format),        \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_assert_format),        \
>         .operation = op_str,                                                   \
>         .left_text = left_str,                                                 \
>         .left_value = left_val,                                                \
> @@ -273,14 +260,12 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
>   * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(type,                             \
> -                                           op_str,                            \
> +#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(op_str,                           \
>                                             left_str,                          \
>                                             left_val,                          \
>                                             right_str,                         \
>                                             right_val) {                       \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_binary_ptr_assert_format),    \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_ptr_assert_format),    \
>         .operation = op_str,                                                   \
>         .left_text = left_str,                                                 \
>         .left_value = left_val,                                                \
> @@ -317,7 +302,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
>  /**
>   * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a
>   *     &struct kunit_binary_str_assert.
> - * @type: The type (assertion or expectation) of this kunit_assert.
>   * @op_str: A string representation of the comparison operator (e.g. "==").
>   * @left_str: A string representation of the expression in the left slot.
>   * @left_val: The actual evaluated value of the expression in the left slot.
> @@ -327,14 +311,12 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
>   * Initializes a &struct kunit_binary_str_assert. Intended to be used in
>   * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
>   */
> -#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(type,                             \
> -                                           op_str,                            \
> +#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(op_str,                           \
>                                             left_str,                          \
>                                             left_val,                          \
>                                             right_str,                         \
>                                             right_val) {                       \
> -       .assert = KUNIT_INIT_ASSERT_STRUCT(type,                               \
> -                                          kunit_binary_str_assert_format),    \
> +       .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_str_assert_format),    \
>         .operation = op_str,                                                   \
>         .left_text = left_str,                                                 \
>         .left_value = left_val,                                                \
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 6e201b45ada6..6f9074ec1995 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -795,7 +795,7 @@ void kunit_failed_assertion(struct kunit *test,
>                         assert_type,                                           \
>                         false,                                                 \
>                         kunit_fail_assert,                                     \
> -                       KUNIT_INIT_FAIL_ASSERT_STRUCT(assert_type),      \
> +                       KUNIT_INIT_FAIL_ASSERT_STRUCT,                        \

The '\' at the end of this line is misaligned. (The others seem fine,
but it's possible I missed one.)




>                         fmt,                                                   \
>                         ##__VA_ARGS__)
>
> @@ -826,8 +826,7 @@ void kunit_failed_assertion(struct kunit *test,
>                         assert_type,                                           \
>                         !!(condition) == !!expected_true,                      \
>                         kunit_unary_assert,                                    \
> -                       KUNIT_INIT_UNARY_ASSERT_STRUCT(assert_type,            \
> -                                                      #condition,             \
> +                       KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition,             \
>                                                        expected_true),         \
>                         fmt,                                                   \
>                         ##__VA_ARGS__)
> @@ -885,8 +884,7 @@ do {                                                                               \
>                         assert_type,                                           \
>                         __left op __right,                                     \
>                         assert_class,                                          \
> -                       ASSERT_CLASS_INIT(assert_type,                         \
> -                                         #op,                                 \
> +                       ASSERT_CLASS_INIT(#op,                                 \
>                                           #left,                               \
>                                           __left,                              \
>                                           #right,                              \
> @@ -1240,8 +1238,7 @@ do {                                                                             \
>                         assert_type,                                           \
>                         strcmp(__left, __right) op 0,                          \
>                         kunit_binary_str_assert,                               \
> -                       KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(assert_type,       \
> -                                                       #op,                   \
> +                       KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(#op,               \
>                                                         #left,                 \
>                                                         __left,                \
>                                                         #right,                \
> @@ -1300,8 +1297,7 @@ do {                                                                             \
>                         assert_type,                                           \
>                         !IS_ERR_OR_NULL(__ptr),                                \
>                         kunit_ptr_not_err_assert,                              \
> -                       KUNIT_INIT_PTR_NOT_ERR_STRUCT(assert_type,             \
> -                                                     #ptr,                    \
> +                       KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr,                    \
>                                                       __ptr),                  \
>                         fmt,                                                   \
>                         ##__VA_ARGS__);                                        \
> --
> 2.34.1.575.g55b058a8bb-goog
>

  reply	other threads:[~2022-01-11  6:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-08  1:22 [PATCH 0/6] kunit: refactor assertions to use less stack Daniel Latypov
2022-01-08  1:22 ` [PATCH 1/6] kunit: add example test case showing off all the expect macros Daniel Latypov
2022-01-10 22:13   ` Brendan Higgins
2022-01-10 22:25     ` Daniel Latypov
2022-01-11  6:50   ` David Gow
2022-01-11 17:27     ` Daniel Latypov
2022-01-08  1:23 ` [PATCH 2/6] kunit: move check if assertion passed into the macros Daniel Latypov
2022-01-10 22:21   ` Brendan Higgins
2022-01-10 22:32     ` Daniel Latypov
2022-01-11  6:51       ` David Gow
2022-01-11 18:42         ` Daniel Latypov
2022-01-08  1:23 ` [PATCH 3/6] kunit: drop unused kunit* field in kunit_assert Daniel Latypov
2022-01-10 22:24   ` Brendan Higgins
2022-01-11  6:51   ` David Gow
2022-01-11 18:34     ` Daniel Latypov
2022-01-08  1:23 ` [PATCH 4/6] kunit: factor out kunit_base_assert_format() call into kunit_fail() Daniel Latypov
2022-01-10 22:31   ` Brendan Higgins
2022-01-10 22:35     ` Daniel Latypov
2022-01-11  6:51   ` David Gow
2022-01-08  1:23 ` [PATCH 5/6] kunit: split out part of kunit_assert into a static const Daniel Latypov
2022-01-11  6:57   ` David Gow
2022-01-11 17:07     ` Daniel Latypov
2022-01-08  1:23 ` [PATCH 6/6] kunit: drop unused assert_type from kunit_assert and clean up macros Daniel Latypov
2022-01-11  6:57   ` David Gow [this message]
2022-01-11 19:21     ` Daniel Latypov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABVgOSkOqMkPNUWpn+eavb0ykv+psbRAEEv0sQfd7xpG0zmogQ@mail.gmail.com \
    --to=davidgow@google.com \
    --cc=brendanhiggins@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).