xref: /OK3568_Linux_fs/kernel/include/kunit/assert.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Assertion and expectation serialization API.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2019, Google LLC.
6*4882a593Smuzhiyun  * Author: Brendan Higgins <brendanhiggins@google.com>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _KUNIT_ASSERT_H
10*4882a593Smuzhiyun #define _KUNIT_ASSERT_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct kunit;
16*4882a593Smuzhiyun struct string_stream;
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /**
19*4882a593Smuzhiyun  * enum kunit_assert_type - Type of expectation/assertion.
20*4882a593Smuzhiyun  * @KUNIT_ASSERTION: Used to denote that a kunit_assert represents an assertion.
21*4882a593Smuzhiyun  * @KUNIT_EXPECTATION: Denotes that a kunit_assert represents an expectation.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Used in conjunction with a &struct kunit_assert to denote whether it
24*4882a593Smuzhiyun  * represents an expectation or an assertion.
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun enum kunit_assert_type {
27*4882a593Smuzhiyun 	KUNIT_ASSERTION,
28*4882a593Smuzhiyun 	KUNIT_EXPECTATION,
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /**
32*4882a593Smuzhiyun  * struct kunit_assert - Data for printing a failed assertion or expectation.
33*4882a593Smuzhiyun  * @test: the test case this expectation/assertion is associated with.
34*4882a593Smuzhiyun  * @type: the type (either an expectation or an assertion) of this kunit_assert.
35*4882a593Smuzhiyun  * @line: the source code line number that the expectation/assertion is at.
36*4882a593Smuzhiyun  * @file: the file path of the source file that the expectation/assertion is in.
37*4882a593Smuzhiyun  * @message: an optional message to provide additional context.
38*4882a593Smuzhiyun  * @format: a function which formats the data in this kunit_assert to a string.
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * Represents a failed expectation/assertion. Contains all the data necessary to
41*4882a593Smuzhiyun  * format a string to a user reporting the failure.
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun struct kunit_assert {
44*4882a593Smuzhiyun 	struct kunit *test;
45*4882a593Smuzhiyun 	enum kunit_assert_type type;
46*4882a593Smuzhiyun 	int line;
47*4882a593Smuzhiyun 	const char *file;
48*4882a593Smuzhiyun 	struct va_format message;
49*4882a593Smuzhiyun 	void (*format)(const struct kunit_assert *assert,
50*4882a593Smuzhiyun 		       struct string_stream *stream);
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /**
54*4882a593Smuzhiyun  * KUNIT_INIT_VA_FMT_NULL - Default initializer for struct va_format.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * Used inside a struct initialization block to initialize struct va_format to
57*4882a593Smuzhiyun  * default values where fmt and va are null.
58*4882a593Smuzhiyun  */
59*4882a593Smuzhiyun #define KUNIT_INIT_VA_FMT_NULL { .fmt = NULL, .va = NULL }
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /**
62*4882a593Smuzhiyun  * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert.
63*4882a593Smuzhiyun  * @kunit: The test case that this expectation/assertion is associated with.
64*4882a593Smuzhiyun  * @assert_type: The type (assertion or expectation) of this kunit_assert.
65*4882a593Smuzhiyun  * @fmt: The formatting function which builds a string out of this kunit_assert.
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * The base initializer for a &struct kunit_assert.
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun #define KUNIT_INIT_ASSERT_STRUCT(kunit, assert_type, fmt) {		       \
70*4882a593Smuzhiyun 	.test = kunit,							       \
71*4882a593Smuzhiyun 	.type = assert_type,						       \
72*4882a593Smuzhiyun 	.file = __FILE__,						       \
73*4882a593Smuzhiyun 	.line = __LINE__,						       \
74*4882a593Smuzhiyun 	.message = KUNIT_INIT_VA_FMT_NULL,				       \
75*4882a593Smuzhiyun 	.format = fmt							       \
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun void kunit_base_assert_format(const struct kunit_assert *assert,
79*4882a593Smuzhiyun 			      struct string_stream *stream);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun void kunit_assert_print_msg(const struct kunit_assert *assert,
82*4882a593Smuzhiyun 			    struct string_stream *stream);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /**
85*4882a593Smuzhiyun  * struct kunit_fail_assert - Represents a plain fail expectation/assertion.
86*4882a593Smuzhiyun  * @assert: The parent of this type.
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun struct kunit_fail_assert {
91*4882a593Smuzhiyun 	struct kunit_assert assert;
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun void kunit_fail_assert_format(const struct kunit_assert *assert,
95*4882a593Smuzhiyun 			      struct string_stream *stream);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /**
98*4882a593Smuzhiyun  * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert.
99*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
100*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  * Initializes a &struct kunit_fail_assert. Intended to be used in
103*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun #define KUNIT_INIT_FAIL_ASSERT_STRUCT(test, type) {			       \
106*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
107*4882a593Smuzhiyun 					   type,			       \
108*4882a593Smuzhiyun 					   kunit_fail_assert_format)	       \
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /**
112*4882a593Smuzhiyun  * struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE}
113*4882a593Smuzhiyun  * @assert: The parent of this type.
114*4882a593Smuzhiyun  * @condition: A string representation of a conditional expression.
115*4882a593Smuzhiyun  * @expected_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  * Represents a simple expectation or assertion that simply asserts something is
118*4882a593Smuzhiyun  * true or false. In other words, represents the expectations:
119*4882a593Smuzhiyun  * KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE}
120*4882a593Smuzhiyun  */
121*4882a593Smuzhiyun struct kunit_unary_assert {
122*4882a593Smuzhiyun 	struct kunit_assert assert;
123*4882a593Smuzhiyun 	const char *condition;
124*4882a593Smuzhiyun 	bool expected_true;
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun void kunit_unary_assert_format(const struct kunit_assert *assert,
128*4882a593Smuzhiyun 			       struct string_stream *stream);
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /**
131*4882a593Smuzhiyun  * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert.
132*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
133*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
134*4882a593Smuzhiyun  * @cond: A string representation of the expression asserted true or false.
135*4882a593Smuzhiyun  * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
136*4882a593Smuzhiyun  *
137*4882a593Smuzhiyun  * Initializes a &struct kunit_unary_assert. Intended to be used in
138*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
139*4882a593Smuzhiyun  */
140*4882a593Smuzhiyun #define KUNIT_INIT_UNARY_ASSERT_STRUCT(test, type, cond, expect_true) {	       \
141*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
142*4882a593Smuzhiyun 					   type,			       \
143*4882a593Smuzhiyun 					   kunit_unary_assert_format),	       \
144*4882a593Smuzhiyun 	.condition = cond,						       \
145*4882a593Smuzhiyun 	.expected_true = expect_true					       \
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /**
149*4882a593Smuzhiyun  * struct kunit_ptr_not_err_assert - An expectation/assertion that a pointer is
150*4882a593Smuzhiyun  *	not NULL and not a -errno.
151*4882a593Smuzhiyun  * @assert: The parent of this type.
152*4882a593Smuzhiyun  * @text: A string representation of the expression passed to the expectation.
153*4882a593Smuzhiyun  * @value: The actual evaluated pointer value of the expression.
154*4882a593Smuzhiyun  *
155*4882a593Smuzhiyun  * Represents an expectation/assertion that a pointer is not null and is does
156*4882a593Smuzhiyun  * not contain a -errno. (See IS_ERR_OR_NULL().)
157*4882a593Smuzhiyun  */
158*4882a593Smuzhiyun struct kunit_ptr_not_err_assert {
159*4882a593Smuzhiyun 	struct kunit_assert assert;
160*4882a593Smuzhiyun 	const char *text;
161*4882a593Smuzhiyun 	const void *value;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
165*4882a593Smuzhiyun 				     struct string_stream *stream);
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun /**
168*4882a593Smuzhiyun  * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a
169*4882a593Smuzhiyun  *	&struct kunit_ptr_not_err_assert.
170*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
171*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
172*4882a593Smuzhiyun  * @txt: A string representation of the expression passed to the expectation.
173*4882a593Smuzhiyun  * @val: The actual evaluated pointer value of the expression.
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in
176*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
177*4882a593Smuzhiyun  */
178*4882a593Smuzhiyun #define KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, type, txt, val) {		       \
179*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
180*4882a593Smuzhiyun 					   type,			       \
181*4882a593Smuzhiyun 					   kunit_ptr_not_err_assert_format),   \
182*4882a593Smuzhiyun 	.text = txt,							       \
183*4882a593Smuzhiyun 	.value = val							       \
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun /**
187*4882a593Smuzhiyun  * struct kunit_binary_assert - An expectation/assertion that compares two
188*4882a593Smuzhiyun  *	non-pointer values (for example, KUNIT_EXPECT_EQ(test, 1 + 1, 2)).
189*4882a593Smuzhiyun  * @assert: The parent of this type.
190*4882a593Smuzhiyun  * @operation: A string representation of the comparison operator (e.g. "==").
191*4882a593Smuzhiyun  * @left_text: A string representation of the expression in the left slot.
192*4882a593Smuzhiyun  * @left_value: The actual evaluated value of the expression in the left slot.
193*4882a593Smuzhiyun  * @right_text: A string representation of the expression in the right slot.
194*4882a593Smuzhiyun  * @right_value: The actual evaluated value of the expression in the right slot.
195*4882a593Smuzhiyun  *
196*4882a593Smuzhiyun  * Represents an expectation/assertion that compares two non-pointer values. For
197*4882a593Smuzhiyun  * example, to expect that 1 + 1 == 2, you can use the expectation
198*4882a593Smuzhiyun  * KUNIT_EXPECT_EQ(test, 1 + 1, 2);
199*4882a593Smuzhiyun  */
200*4882a593Smuzhiyun struct kunit_binary_assert {
201*4882a593Smuzhiyun 	struct kunit_assert assert;
202*4882a593Smuzhiyun 	const char *operation;
203*4882a593Smuzhiyun 	const char *left_text;
204*4882a593Smuzhiyun 	long long left_value;
205*4882a593Smuzhiyun 	const char *right_text;
206*4882a593Smuzhiyun 	long long right_value;
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun void kunit_binary_assert_format(const struct kunit_assert *assert,
210*4882a593Smuzhiyun 				struct string_stream *stream);
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun /**
213*4882a593Smuzhiyun  * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a
214*4882a593Smuzhiyun  *	&struct kunit_binary_assert.
215*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
216*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
217*4882a593Smuzhiyun  * @op_str: A string representation of the comparison operator (e.g. "==").
218*4882a593Smuzhiyun  * @left_str: A string representation of the expression in the left slot.
219*4882a593Smuzhiyun  * @left_val: The actual evaluated value of the expression in the left slot.
220*4882a593Smuzhiyun  * @right_str: A string representation of the expression in the right slot.
221*4882a593Smuzhiyun  * @right_val: The actual evaluated value of the expression in the right slot.
222*4882a593Smuzhiyun  *
223*4882a593Smuzhiyun  * Initializes a &struct kunit_binary_assert. Intended to be used in
224*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
225*4882a593Smuzhiyun  */
226*4882a593Smuzhiyun #define KUNIT_INIT_BINARY_ASSERT_STRUCT(test,				       \
227*4882a593Smuzhiyun 					type,				       \
228*4882a593Smuzhiyun 					op_str,				       \
229*4882a593Smuzhiyun 					left_str,			       \
230*4882a593Smuzhiyun 					left_val,			       \
231*4882a593Smuzhiyun 					right_str,			       \
232*4882a593Smuzhiyun 					right_val) {			       \
233*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
234*4882a593Smuzhiyun 					   type,			       \
235*4882a593Smuzhiyun 					   kunit_binary_assert_format),	       \
236*4882a593Smuzhiyun 	.operation = op_str,						       \
237*4882a593Smuzhiyun 	.left_text = left_str,						       \
238*4882a593Smuzhiyun 	.left_value = left_val,						       \
239*4882a593Smuzhiyun 	.right_text = right_str,					       \
240*4882a593Smuzhiyun 	.right_value = right_val					       \
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun /**
244*4882a593Smuzhiyun  * struct kunit_binary_ptr_assert - An expectation/assertion that compares two
245*4882a593Smuzhiyun  *	pointer values (for example, KUNIT_EXPECT_PTR_EQ(test, foo, bar)).
246*4882a593Smuzhiyun  * @assert: The parent of this type.
247*4882a593Smuzhiyun  * @operation: A string representation of the comparison operator (e.g. "==").
248*4882a593Smuzhiyun  * @left_text: A string representation of the expression in the left slot.
249*4882a593Smuzhiyun  * @left_value: The actual evaluated value of the expression in the left slot.
250*4882a593Smuzhiyun  * @right_text: A string representation of the expression in the right slot.
251*4882a593Smuzhiyun  * @right_value: The actual evaluated value of the expression in the right slot.
252*4882a593Smuzhiyun  *
253*4882a593Smuzhiyun  * Represents an expectation/assertion that compares two pointer values. For
254*4882a593Smuzhiyun  * example, to expect that foo and bar point to the same thing, you can use the
255*4882a593Smuzhiyun  * expectation KUNIT_EXPECT_PTR_EQ(test, foo, bar);
256*4882a593Smuzhiyun  */
257*4882a593Smuzhiyun struct kunit_binary_ptr_assert {
258*4882a593Smuzhiyun 	struct kunit_assert assert;
259*4882a593Smuzhiyun 	const char *operation;
260*4882a593Smuzhiyun 	const char *left_text;
261*4882a593Smuzhiyun 	const void *left_value;
262*4882a593Smuzhiyun 	const char *right_text;
263*4882a593Smuzhiyun 	const void *right_value;
264*4882a593Smuzhiyun };
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
267*4882a593Smuzhiyun 				    struct string_stream *stream);
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun /**
270*4882a593Smuzhiyun  * KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT() - Initializes a
271*4882a593Smuzhiyun  *	&struct kunit_binary_ptr_assert.
272*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
273*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
274*4882a593Smuzhiyun  * @op_str: A string representation of the comparison operator (e.g. "==").
275*4882a593Smuzhiyun  * @left_str: A string representation of the expression in the left slot.
276*4882a593Smuzhiyun  * @left_val: The actual evaluated value of the expression in the left slot.
277*4882a593Smuzhiyun  * @right_str: A string representation of the expression in the right slot.
278*4882a593Smuzhiyun  * @right_val: The actual evaluated value of the expression in the right slot.
279*4882a593Smuzhiyun  *
280*4882a593Smuzhiyun  * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in
281*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
282*4882a593Smuzhiyun  */
283*4882a593Smuzhiyun #define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(test,			       \
284*4882a593Smuzhiyun 					    type,			       \
285*4882a593Smuzhiyun 					    op_str,			       \
286*4882a593Smuzhiyun 					    left_str,			       \
287*4882a593Smuzhiyun 					    left_val,			       \
288*4882a593Smuzhiyun 					    right_str,			       \
289*4882a593Smuzhiyun 					    right_val) {		       \
290*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
291*4882a593Smuzhiyun 					   type,			       \
292*4882a593Smuzhiyun 					   kunit_binary_ptr_assert_format),    \
293*4882a593Smuzhiyun 	.operation = op_str,						       \
294*4882a593Smuzhiyun 	.left_text = left_str,						       \
295*4882a593Smuzhiyun 	.left_value = left_val,						       \
296*4882a593Smuzhiyun 	.right_text = right_str,					       \
297*4882a593Smuzhiyun 	.right_value = right_val					       \
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun  * struct kunit_binary_str_assert - An expectation/assertion that compares two
302*4882a593Smuzhiyun  *	string values (for example, KUNIT_EXPECT_STREQ(test, foo, "bar")).
303*4882a593Smuzhiyun  * @assert: The parent of this type.
304*4882a593Smuzhiyun  * @operation: A string representation of the comparison operator (e.g. "==").
305*4882a593Smuzhiyun  * @left_text: A string representation of the expression in the left slot.
306*4882a593Smuzhiyun  * @left_value: The actual evaluated value of the expression in the left slot.
307*4882a593Smuzhiyun  * @right_text: A string representation of the expression in the right slot.
308*4882a593Smuzhiyun  * @right_value: The actual evaluated value of the expression in the right slot.
309*4882a593Smuzhiyun  *
310*4882a593Smuzhiyun  * Represents an expectation/assertion that compares two string values. For
311*4882a593Smuzhiyun  * example, to expect that the string in foo is equal to "bar", you can use the
312*4882a593Smuzhiyun  * expectation KUNIT_EXPECT_STREQ(test, foo, "bar");
313*4882a593Smuzhiyun  */
314*4882a593Smuzhiyun struct kunit_binary_str_assert {
315*4882a593Smuzhiyun 	struct kunit_assert assert;
316*4882a593Smuzhiyun 	const char *operation;
317*4882a593Smuzhiyun 	const char *left_text;
318*4882a593Smuzhiyun 	const char *left_value;
319*4882a593Smuzhiyun 	const char *right_text;
320*4882a593Smuzhiyun 	const char *right_value;
321*4882a593Smuzhiyun };
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun void kunit_binary_str_assert_format(const struct kunit_assert *assert,
324*4882a593Smuzhiyun 				    struct string_stream *stream);
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun /**
327*4882a593Smuzhiyun  * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a
328*4882a593Smuzhiyun  *	&struct kunit_binary_str_assert.
329*4882a593Smuzhiyun  * @test: The test case that this expectation/assertion is associated with.
330*4882a593Smuzhiyun  * @type: The type (assertion or expectation) of this kunit_assert.
331*4882a593Smuzhiyun  * @op_str: A string representation of the comparison operator (e.g. "==").
332*4882a593Smuzhiyun  * @left_str: A string representation of the expression in the left slot.
333*4882a593Smuzhiyun  * @left_val: The actual evaluated value of the expression in the left slot.
334*4882a593Smuzhiyun  * @right_str: A string representation of the expression in the right slot.
335*4882a593Smuzhiyun  * @right_val: The actual evaluated value of the expression in the right slot.
336*4882a593Smuzhiyun  *
337*4882a593Smuzhiyun  * Initializes a &struct kunit_binary_str_assert. Intended to be used in
338*4882a593Smuzhiyun  * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
339*4882a593Smuzhiyun  */
340*4882a593Smuzhiyun #define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test,			       \
341*4882a593Smuzhiyun 					    type,			       \
342*4882a593Smuzhiyun 					    op_str,			       \
343*4882a593Smuzhiyun 					    left_str,			       \
344*4882a593Smuzhiyun 					    left_val,			       \
345*4882a593Smuzhiyun 					    right_str,			       \
346*4882a593Smuzhiyun 					    right_val) {		       \
347*4882a593Smuzhiyun 	.assert = KUNIT_INIT_ASSERT_STRUCT(test,			       \
348*4882a593Smuzhiyun 					   type,			       \
349*4882a593Smuzhiyun 					   kunit_binary_str_assert_format),    \
350*4882a593Smuzhiyun 	.operation = op_str,						       \
351*4882a593Smuzhiyun 	.left_text = left_str,						       \
352*4882a593Smuzhiyun 	.left_value = left_val,						       \
353*4882a593Smuzhiyun 	.right_text = right_str,					       \
354*4882a593Smuzhiyun 	.right_value = right_val					       \
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun #endif /*  _KUNIT_ASSERT_H */
358