<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/include/kunit, branch v5.18.2</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v5.18.2</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v5.18.2'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2022-01-31T18:55:48+00:00</updated>
<entry>
<title>kunit: cleanup assertion macro internal variables</title>
<updated>2022-01-31T18:55:48+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-27T21:52:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c2741453478badf571ef020d160053e8d5e1ba94'/>
<id>urn:sha1:c2741453478badf571ef020d160053e8d5e1ba94</id>
<content type='text'>
All the operands should be tagged `const`.
We're only assigning them to variables so that we can compare them (e.g.
check if left == right, etc.) and avoid evaluating expressions multiple
times.

There's no need for them to be mutable.

Also rename the helper variable `loc` to `__loc` like we do with
`__assertion` and `__strs` to avoid potential name collisions with user
code.

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: factor out str constants from binary assertion structs</title>
<updated>2022-01-31T18:55:39+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-25T21:00:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2b6861e2372bac68861c54372f68f6016a7484fc'/>
<id>urn:sha1:2b6861e2372bac68861c54372f68f6016a7484fc</id>
<content type='text'>
If the compiler doesn't optimize them away, each kunit assertion (use of
KUNIT_EXPECT_EQ, etc.) can use 88 bytes of stack space in the worst and
most common case. This has led to compiler warnings and a suggestion
from Linus to move data from the structs into static const's where
possible [1].

This builds upon [2] which did so for the base struct kunit_assert type.
That only reduced sizeof(struct kunit_binary_assert) from 88 to 64.

Given these are by far the most commonly used asserts, this patch
factors out the textual representations of the operands and comparator
into another static const, saving 16 more bytes.

In detail, KUNIT_EXPECT_EQ(test, 2 + 2, 5) yields the following struct
  (struct kunit_binary_assert) {
    .assert = &lt;struct kunit_assert&gt;,
    .operation = "==",
    .left_text = "2 + 2",
    .left_value = 4,
    .right_text = "5",
    .right_value = 5,
  }
After this change
  static const struct kunit_binary_assert_text __text = {
    .operation = "==",
    .left_text = "2 + 2",
    .right_text = "5",
  };
  (struct kunit_binary_assert) {
    .assert = &lt;struct kunit_assert&gt;,
    .text = &amp;__text,
    .left_value = 4,
    .right_value = 5,
  }

This also DRYs the code a bit more since these str fields were repeated
for the string and pointer versions of kunit_binary_assert.

Note: we could name the kunit_binary_assert_text fields left/right
instead of left_text/right_text. But that would require changing the
macros a bit since they have args called "left" and "right" which would
be substituted in `.left = #left` as `.2 + 2 = \"2 + 2\"`.

[1] https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/VULQg1z6BAAJ
[2] https://lore.kernel.org/linux-kselftest/20220113165931.451305-6-dlatypov@google.com/

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: consolidate KUNIT_INIT_BINARY_ASSERT_STRUCT macros</title>
<updated>2022-01-31T18:55:33+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-25T21:00:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=064ff292aca500d6b911dca6abe1ece22620d475'/>
<id>urn:sha1:064ff292aca500d6b911dca6abe1ece22620d475</id>
<content type='text'>
We currently have 2 other versions of KUNIT_INIT_BINARY_ASSERT_STRUCT.
The only differences are that
* the format funcition they pass is different
* the types of left_val/right_val should be different (integral,
pointer, string).

The latter doesn't actually matter since these macros are just plumbing
them along to KUNIT_ASSERTION where they will get type checked.

So combine them all into a single KUNIT_INIT_BINARY_ASSERT_STRUCT that
now also takes the format function as a parameter.

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: remove va_format from kunit_assert</title>
<updated>2022-01-31T18:55:27+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-25T21:00:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6419abb80e82c603bbec6d7f5af6c2f79fa5c4ae'/>
<id>urn:sha1:6419abb80e82c603bbec6d7f5af6c2f79fa5c4ae</id>
<content type='text'>
The concern is that having a lot of redundant fields in kunit_assert can
blow up stack usage if the compiler doesn't optimize them away [1].

The comment on this field implies that it was meant to be initialized
when the expect/assert was declared, but this only happens when we run
kunit_do_failed_assertion().

We don't need to access it outside of that function, so move it out of
the struct and make it a local variable there.

This change also takes the chance to reduce the number of macros by
inlining the now simplified KUNIT_INIT_ASSERT_STRUCT() macro.

[1] https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/VULQg1z6BAAJ

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: decrease macro layering for EQ/NE asserts</title>
<updated>2022-01-25T20:04:50+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-18T22:35:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6125a5c70acddd9fc1fb7329047a254c74d0173c'/>
<id>urn:sha1:6125a5c70acddd9fc1fb7329047a254c74d0173c</id>
<content type='text'>
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 =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION =&gt; KUNIT_BASE_EQ_MSG_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
KUNIT_EXPECT_PTR_EQ_MSG =&gt; KUNIT_BINARY_PTR_EQ_MSG_ASSERTION =&gt; KUNIT_BASE_EQ_MSG_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
&lt;ditto for NE and ASSERT&gt;

After this change:
KUNIT_EXPECT_EQ_MSG =&gt; KUNIT_BINARY_INT_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
KUNIT_EXPECT_PTR_EQ_MSG =&gt; KUNIT_BINARY_PTR_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: decrease macro layering for integer asserts</title>
<updated>2022-01-25T20:04:44+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-18T22:35:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=40f39777ce4f8e65ca16c10f1b895bbe8306a42f'/>
<id>urn:sha1:40f39777ce4f8e65ca16c10f1b895bbe8306a42f</id>
<content type='text'>
Introduce a KUNIT_BINARY_INT_ASSERTION for the likes of KUNIT_EXPECT_LT.
This is analagous to KUNIT_BINARY_STR_ASSERTION.

Note: this patch leaves the EQ/NE macros untouched since those share
some intermediate macros for the pointer-based macros.

The current macro chain looks like:
KUNIT_EXPECT_LT_MSG =&gt; KUNIT_BASE_LT_MSG_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
KUNIT_EXPECT_GT_MSG =&gt; KUNIT_BASE_GT_MSG_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
&lt;ditto for LE, GE, and ASSERT variants&gt;

After this change:
KUNIT_EXPECT_LT_MSG =&gt; KUNIT_BINARY_INT_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION
KUNIT_EXPECT_GT_MSG =&gt; KUNIT_BINARY_INT_ASSERTION =&gt; KUNIT_BASE_BINARY_ASSERTION

I.e. we've traded all the unique intermediary macros for a single shared
KUNIT_BINARY_INT_ASSERTION. The only difference is that users of
KUNIT_BINARY_INT_ASSERTION also need to pass the operation (==, &lt;, etc.).

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: reduce layering in string assertion macros</title>
<updated>2022-01-25T20:04:38+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-18T22:35:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=955df7d85e58b8090f1fd2d10b4b2713e99b552c'/>
<id>urn:sha1:955df7d85e58b8090f1fd2d10b4b2713e99b552c</id>
<content type='text'>
The current macro chain looks like:
KUNIT_EXPECT_STREQ =&gt; KUNIT_EXPECT_STREQ_MSG =&gt; KUNIT_BINARY_STR_EQ_MSG_ASSERTION =&gt; KUNIT_BINARY_STR_ASSERTION.
KUNIT_ASSERT_STREQ =&gt; KUNIT_ASSERT_STREQ_MSG =&gt; KUNIT_BINARY_STR_EQ_MSG_ASSERTION =&gt; KUNIT_BINARY_STR_ASSERTION.
&lt;ditto for STR_NE&gt;

After this change:
KUNIT_EXPECT_STREQ =&gt; KUNIT_EXPECT_STREQ_MSG =&gt; KUNIT_BINARY_STR_ASSERTION.
KUNIT_ASSERT_STREQ =&gt; KUNIT_ASSERT_STREQ_MSG =&gt; KUNIT_BINARY_STR_ASSERTION.
&lt;ditto for STR_NE&gt;

All the intermediate macro did was pass in "==" or "!=", so it seems
better to just drop them at the cost of a bit more copy-paste.

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: drop unused intermediate macros for ptr inequality checks</title>
<updated>2022-01-25T20:04:31+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-18T22:35:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c5855907d388321c1089023489e49ba9a5e9afc7'/>
<id>urn:sha1:c5855907d388321c1089023489e49ba9a5e9afc7</id>
<content type='text'>
We have the intermediate macros for KUNIT_EXPECT_PTR_GT() and friends,
but these macros don't exist.

I can see niche usecases for these macros existing, but since we've been
fine without them for so long, let's drop this dead code.

Users can instead cast the pointers and use the other GT/LT macros.

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: make KUNIT_EXPECT_EQ() use KUNIT_EXPECT_EQ_MSG(), etc.</title>
<updated>2022-01-25T20:04:18+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-18T22:35:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6709d0fe55933d3ac944f3cdd5b66d9786092f90'/>
<id>urn:sha1:6709d0fe55933d3ac944f3cdd5b66d9786092f90</id>
<content type='text'>
There's quite a few macros in play for KUnit assertions.

The current macro chain looks like:
  KUNIT_EXPECT_EQ =&gt; KUNIT_BINARY_EQ_ASSERTION =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION
  KUNIT_EXPECT_EQ_MSG =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION
  KUNIT_ASSERT_EQ =&gt; KUNIT_BINARY_EQ_ASSERTION =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION
  KUNIT_ASSERT_EQ_MSG =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION

After this change:
  KUNIT_EXPECT_EQ =&gt; KUNIT_EXPECT_EQ_MSG =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION
  KUNIT_ASSERT_EQ =&gt; KUNIT_ASSERT_EQ_MSG =&gt; KUNIT_BINARY_EQ_MSG_ASSERTION
and we can drop the intermediate KUNIT_BINARY_EQ_ASSERTION.

This change does this for all the other macros as well.

Signed-off-by: Daniel Latypov &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: drop unused assert_type from kunit_assert and clean up macros</title>
<updated>2022-01-25T19:50:05+00:00</updated>
<author>
<name>Daniel Latypov</name>
<email>dlatypov@google.com</email>
</author>
<published>2022-01-13T16:59:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=05a7da89c15ddb3fc7618a16f5941eca68fc441c'/>
<id>urn:sha1:05a7da89c15ddb3fc7618a16f5941eca68fc441c</id>
<content type='text'>
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 &lt;dlatypov@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Brendan Higgins &lt;brendanhiggins@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
</feed>
