18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Assertion and expectation serialization API. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2019, Google LLC. 68c2ecf20Sopenharmony_ci * Author: Brendan Higgins <brendanhiggins@google.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _KUNIT_ASSERT_H 108c2ecf20Sopenharmony_ci#define _KUNIT_ASSERT_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/err.h> 138c2ecf20Sopenharmony_ci#include <linux/kernel.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct kunit; 168c2ecf20Sopenharmony_cistruct string_stream; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/** 198c2ecf20Sopenharmony_ci * enum kunit_assert_type - Type of expectation/assertion. 208c2ecf20Sopenharmony_ci * @KUNIT_ASSERTION: Used to denote that a kunit_assert represents an assertion. 218c2ecf20Sopenharmony_ci * @KUNIT_EXPECTATION: Denotes that a kunit_assert represents an expectation. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Used in conjunction with a &struct kunit_assert to denote whether it 248c2ecf20Sopenharmony_ci * represents an expectation or an assertion. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_cienum kunit_assert_type { 278c2ecf20Sopenharmony_ci KUNIT_ASSERTION, 288c2ecf20Sopenharmony_ci KUNIT_EXPECTATION, 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/** 328c2ecf20Sopenharmony_ci * struct kunit_assert - Data for printing a failed assertion or expectation. 338c2ecf20Sopenharmony_ci * @test: the test case this expectation/assertion is associated with. 348c2ecf20Sopenharmony_ci * @type: the type (either an expectation or an assertion) of this kunit_assert. 358c2ecf20Sopenharmony_ci * @line: the source code line number that the expectation/assertion is at. 368c2ecf20Sopenharmony_ci * @file: the file path of the source file that the expectation/assertion is in. 378c2ecf20Sopenharmony_ci * @message: an optional message to provide additional context. 388c2ecf20Sopenharmony_ci * @format: a function which formats the data in this kunit_assert to a string. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * Represents a failed expectation/assertion. Contains all the data necessary to 418c2ecf20Sopenharmony_ci * format a string to a user reporting the failure. 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_cistruct kunit_assert { 448c2ecf20Sopenharmony_ci struct kunit *test; 458c2ecf20Sopenharmony_ci enum kunit_assert_type type; 468c2ecf20Sopenharmony_ci int line; 478c2ecf20Sopenharmony_ci const char *file; 488c2ecf20Sopenharmony_ci struct va_format message; 498c2ecf20Sopenharmony_ci void (*format)(const struct kunit_assert *assert, 508c2ecf20Sopenharmony_ci struct string_stream *stream); 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/** 548c2ecf20Sopenharmony_ci * KUNIT_INIT_VA_FMT_NULL - Default initializer for struct va_format. 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * Used inside a struct initialization block to initialize struct va_format to 578c2ecf20Sopenharmony_ci * default values where fmt and va are null. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci#define KUNIT_INIT_VA_FMT_NULL { .fmt = NULL, .va = NULL } 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/** 628c2ecf20Sopenharmony_ci * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert. 638c2ecf20Sopenharmony_ci * @kunit: The test case that this expectation/assertion is associated with. 648c2ecf20Sopenharmony_ci * @assert_type: The type (assertion or expectation) of this kunit_assert. 658c2ecf20Sopenharmony_ci * @fmt: The formatting function which builds a string out of this kunit_assert. 668c2ecf20Sopenharmony_ci * 678c2ecf20Sopenharmony_ci * The base initializer for a &struct kunit_assert. 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ci#define KUNIT_INIT_ASSERT_STRUCT(kunit, assert_type, fmt) { \ 708c2ecf20Sopenharmony_ci .test = kunit, \ 718c2ecf20Sopenharmony_ci .type = assert_type, \ 728c2ecf20Sopenharmony_ci .file = __FILE__, \ 738c2ecf20Sopenharmony_ci .line = __LINE__, \ 748c2ecf20Sopenharmony_ci .message = KUNIT_INIT_VA_FMT_NULL, \ 758c2ecf20Sopenharmony_ci .format = fmt \ 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_civoid kunit_base_assert_format(const struct kunit_assert *assert, 798c2ecf20Sopenharmony_ci struct string_stream *stream); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_civoid kunit_assert_print_msg(const struct kunit_assert *assert, 828c2ecf20Sopenharmony_ci struct string_stream *stream); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/** 858c2ecf20Sopenharmony_ci * struct kunit_fail_assert - Represents a plain fail expectation/assertion. 868c2ecf20Sopenharmony_ci * @assert: The parent of this type. 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cistruct kunit_fail_assert { 918c2ecf20Sopenharmony_ci struct kunit_assert assert; 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_civoid kunit_fail_assert_format(const struct kunit_assert *assert, 958c2ecf20Sopenharmony_ci struct string_stream *stream); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/** 988c2ecf20Sopenharmony_ci * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert. 998c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 1008c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * Initializes a &struct kunit_fail_assert. Intended to be used in 1038c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ci#define KUNIT_INIT_FAIL_ASSERT_STRUCT(test, type) { \ 1068c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 1078c2ecf20Sopenharmony_ci type, \ 1088c2ecf20Sopenharmony_ci kunit_fail_assert_format) \ 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/** 1128c2ecf20Sopenharmony_ci * struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE} 1138c2ecf20Sopenharmony_ci * @assert: The parent of this type. 1148c2ecf20Sopenharmony_ci * @condition: A string representation of a conditional expression. 1158c2ecf20Sopenharmony_ci * @expected_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. 1168c2ecf20Sopenharmony_ci * 1178c2ecf20Sopenharmony_ci * Represents a simple expectation or assertion that simply asserts something is 1188c2ecf20Sopenharmony_ci * true or false. In other words, represents the expectations: 1198c2ecf20Sopenharmony_ci * KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE} 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_cistruct kunit_unary_assert { 1228c2ecf20Sopenharmony_ci struct kunit_assert assert; 1238c2ecf20Sopenharmony_ci const char *condition; 1248c2ecf20Sopenharmony_ci bool expected_true; 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_civoid kunit_unary_assert_format(const struct kunit_assert *assert, 1288c2ecf20Sopenharmony_ci struct string_stream *stream); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/** 1318c2ecf20Sopenharmony_ci * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. 1328c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 1338c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 1348c2ecf20Sopenharmony_ci * @cond: A string representation of the expression asserted true or false. 1358c2ecf20Sopenharmony_ci * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. 1368c2ecf20Sopenharmony_ci * 1378c2ecf20Sopenharmony_ci * Initializes a &struct kunit_unary_assert. Intended to be used in 1388c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 1398c2ecf20Sopenharmony_ci */ 1408c2ecf20Sopenharmony_ci#define KUNIT_INIT_UNARY_ASSERT_STRUCT(test, type, cond, expect_true) { \ 1418c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 1428c2ecf20Sopenharmony_ci type, \ 1438c2ecf20Sopenharmony_ci kunit_unary_assert_format), \ 1448c2ecf20Sopenharmony_ci .condition = cond, \ 1458c2ecf20Sopenharmony_ci .expected_true = expect_true \ 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/** 1498c2ecf20Sopenharmony_ci * struct kunit_ptr_not_err_assert - An expectation/assertion that a pointer is 1508c2ecf20Sopenharmony_ci * not NULL and not a -errno. 1518c2ecf20Sopenharmony_ci * @assert: The parent of this type. 1528c2ecf20Sopenharmony_ci * @text: A string representation of the expression passed to the expectation. 1538c2ecf20Sopenharmony_ci * @value: The actual evaluated pointer value of the expression. 1548c2ecf20Sopenharmony_ci * 1558c2ecf20Sopenharmony_ci * Represents an expectation/assertion that a pointer is not null and is does 1568c2ecf20Sopenharmony_ci * not contain a -errno. (See IS_ERR_OR_NULL().) 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistruct kunit_ptr_not_err_assert { 1598c2ecf20Sopenharmony_ci struct kunit_assert assert; 1608c2ecf20Sopenharmony_ci const char *text; 1618c2ecf20Sopenharmony_ci const void *value; 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_civoid kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, 1658c2ecf20Sopenharmony_ci struct string_stream *stream); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/** 1688c2ecf20Sopenharmony_ci * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a 1698c2ecf20Sopenharmony_ci * &struct kunit_ptr_not_err_assert. 1708c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 1718c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 1728c2ecf20Sopenharmony_ci * @txt: A string representation of the expression passed to the expectation. 1738c2ecf20Sopenharmony_ci * @val: The actual evaluated pointer value of the expression. 1748c2ecf20Sopenharmony_ci * 1758c2ecf20Sopenharmony_ci * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in 1768c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_ci#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, type, txt, val) { \ 1798c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 1808c2ecf20Sopenharmony_ci type, \ 1818c2ecf20Sopenharmony_ci kunit_ptr_not_err_assert_format), \ 1828c2ecf20Sopenharmony_ci .text = txt, \ 1838c2ecf20Sopenharmony_ci .value = val \ 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/** 1878c2ecf20Sopenharmony_ci * struct kunit_binary_assert - An expectation/assertion that compares two 1888c2ecf20Sopenharmony_ci * non-pointer values (for example, KUNIT_EXPECT_EQ(test, 1 + 1, 2)). 1898c2ecf20Sopenharmony_ci * @assert: The parent of this type. 1908c2ecf20Sopenharmony_ci * @operation: A string representation of the comparison operator (e.g. "=="). 1918c2ecf20Sopenharmony_ci * @left_text: A string representation of the expression in the left slot. 1928c2ecf20Sopenharmony_ci * @left_value: The actual evaluated value of the expression in the left slot. 1938c2ecf20Sopenharmony_ci * @right_text: A string representation of the expression in the right slot. 1948c2ecf20Sopenharmony_ci * @right_value: The actual evaluated value of the expression in the right slot. 1958c2ecf20Sopenharmony_ci * 1968c2ecf20Sopenharmony_ci * Represents an expectation/assertion that compares two non-pointer values. For 1978c2ecf20Sopenharmony_ci * example, to expect that 1 + 1 == 2, you can use the expectation 1988c2ecf20Sopenharmony_ci * KUNIT_EXPECT_EQ(test, 1 + 1, 2); 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_cistruct kunit_binary_assert { 2018c2ecf20Sopenharmony_ci struct kunit_assert assert; 2028c2ecf20Sopenharmony_ci const char *operation; 2038c2ecf20Sopenharmony_ci const char *left_text; 2048c2ecf20Sopenharmony_ci long long left_value; 2058c2ecf20Sopenharmony_ci const char *right_text; 2068c2ecf20Sopenharmony_ci long long right_value; 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_civoid kunit_binary_assert_format(const struct kunit_assert *assert, 2108c2ecf20Sopenharmony_ci struct string_stream *stream); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci/** 2138c2ecf20Sopenharmony_ci * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a 2148c2ecf20Sopenharmony_ci * &struct kunit_binary_assert. 2158c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 2168c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 2178c2ecf20Sopenharmony_ci * @op_str: A string representation of the comparison operator (e.g. "=="). 2188c2ecf20Sopenharmony_ci * @left_str: A string representation of the expression in the left slot. 2198c2ecf20Sopenharmony_ci * @left_val: The actual evaluated value of the expression in the left slot. 2208c2ecf20Sopenharmony_ci * @right_str: A string representation of the expression in the right slot. 2218c2ecf20Sopenharmony_ci * @right_val: The actual evaluated value of the expression in the right slot. 2228c2ecf20Sopenharmony_ci * 2238c2ecf20Sopenharmony_ci * Initializes a &struct kunit_binary_assert. Intended to be used in 2248c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 2258c2ecf20Sopenharmony_ci */ 2268c2ecf20Sopenharmony_ci#define KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \ 2278c2ecf20Sopenharmony_ci type, \ 2288c2ecf20Sopenharmony_ci op_str, \ 2298c2ecf20Sopenharmony_ci left_str, \ 2308c2ecf20Sopenharmony_ci left_val, \ 2318c2ecf20Sopenharmony_ci right_str, \ 2328c2ecf20Sopenharmony_ci right_val) { \ 2338c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 2348c2ecf20Sopenharmony_ci type, \ 2358c2ecf20Sopenharmony_ci kunit_binary_assert_format), \ 2368c2ecf20Sopenharmony_ci .operation = op_str, \ 2378c2ecf20Sopenharmony_ci .left_text = left_str, \ 2388c2ecf20Sopenharmony_ci .left_value = left_val, \ 2398c2ecf20Sopenharmony_ci .right_text = right_str, \ 2408c2ecf20Sopenharmony_ci .right_value = right_val \ 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci/** 2448c2ecf20Sopenharmony_ci * struct kunit_binary_ptr_assert - An expectation/assertion that compares two 2458c2ecf20Sopenharmony_ci * pointer values (for example, KUNIT_EXPECT_PTR_EQ(test, foo, bar)). 2468c2ecf20Sopenharmony_ci * @assert: The parent of this type. 2478c2ecf20Sopenharmony_ci * @operation: A string representation of the comparison operator (e.g. "=="). 2488c2ecf20Sopenharmony_ci * @left_text: A string representation of the expression in the left slot. 2498c2ecf20Sopenharmony_ci * @left_value: The actual evaluated value of the expression in the left slot. 2508c2ecf20Sopenharmony_ci * @right_text: A string representation of the expression in the right slot. 2518c2ecf20Sopenharmony_ci * @right_value: The actual evaluated value of the expression in the right slot. 2528c2ecf20Sopenharmony_ci * 2538c2ecf20Sopenharmony_ci * Represents an expectation/assertion that compares two pointer values. For 2548c2ecf20Sopenharmony_ci * example, to expect that foo and bar point to the same thing, you can use the 2558c2ecf20Sopenharmony_ci * expectation KUNIT_EXPECT_PTR_EQ(test, foo, bar); 2568c2ecf20Sopenharmony_ci */ 2578c2ecf20Sopenharmony_cistruct kunit_binary_ptr_assert { 2588c2ecf20Sopenharmony_ci struct kunit_assert assert; 2598c2ecf20Sopenharmony_ci const char *operation; 2608c2ecf20Sopenharmony_ci const char *left_text; 2618c2ecf20Sopenharmony_ci const void *left_value; 2628c2ecf20Sopenharmony_ci const char *right_text; 2638c2ecf20Sopenharmony_ci const void *right_value; 2648c2ecf20Sopenharmony_ci}; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_civoid kunit_binary_ptr_assert_format(const struct kunit_assert *assert, 2678c2ecf20Sopenharmony_ci struct string_stream *stream); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci/** 2708c2ecf20Sopenharmony_ci * KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT() - Initializes a 2718c2ecf20Sopenharmony_ci * &struct kunit_binary_ptr_assert. 2728c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 2738c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 2748c2ecf20Sopenharmony_ci * @op_str: A string representation of the comparison operator (e.g. "=="). 2758c2ecf20Sopenharmony_ci * @left_str: A string representation of the expression in the left slot. 2768c2ecf20Sopenharmony_ci * @left_val: The actual evaluated value of the expression in the left slot. 2778c2ecf20Sopenharmony_ci * @right_str: A string representation of the expression in the right slot. 2788c2ecf20Sopenharmony_ci * @right_val: The actual evaluated value of the expression in the right slot. 2798c2ecf20Sopenharmony_ci * 2808c2ecf20Sopenharmony_ci * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in 2818c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 2828c2ecf20Sopenharmony_ci */ 2838c2ecf20Sopenharmony_ci#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(test, \ 2848c2ecf20Sopenharmony_ci type, \ 2858c2ecf20Sopenharmony_ci op_str, \ 2868c2ecf20Sopenharmony_ci left_str, \ 2878c2ecf20Sopenharmony_ci left_val, \ 2888c2ecf20Sopenharmony_ci right_str, \ 2898c2ecf20Sopenharmony_ci right_val) { \ 2908c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 2918c2ecf20Sopenharmony_ci type, \ 2928c2ecf20Sopenharmony_ci kunit_binary_ptr_assert_format), \ 2938c2ecf20Sopenharmony_ci .operation = op_str, \ 2948c2ecf20Sopenharmony_ci .left_text = left_str, \ 2958c2ecf20Sopenharmony_ci .left_value = left_val, \ 2968c2ecf20Sopenharmony_ci .right_text = right_str, \ 2978c2ecf20Sopenharmony_ci .right_value = right_val \ 2988c2ecf20Sopenharmony_ci} 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/** 3018c2ecf20Sopenharmony_ci * struct kunit_binary_str_assert - An expectation/assertion that compares two 3028c2ecf20Sopenharmony_ci * string values (for example, KUNIT_EXPECT_STREQ(test, foo, "bar")). 3038c2ecf20Sopenharmony_ci * @assert: The parent of this type. 3048c2ecf20Sopenharmony_ci * @operation: A string representation of the comparison operator (e.g. "=="). 3058c2ecf20Sopenharmony_ci * @left_text: A string representation of the expression in the left slot. 3068c2ecf20Sopenharmony_ci * @left_value: The actual evaluated value of the expression in the left slot. 3078c2ecf20Sopenharmony_ci * @right_text: A string representation of the expression in the right slot. 3088c2ecf20Sopenharmony_ci * @right_value: The actual evaluated value of the expression in the right slot. 3098c2ecf20Sopenharmony_ci * 3108c2ecf20Sopenharmony_ci * Represents an expectation/assertion that compares two string values. For 3118c2ecf20Sopenharmony_ci * example, to expect that the string in foo is equal to "bar", you can use the 3128c2ecf20Sopenharmony_ci * expectation KUNIT_EXPECT_STREQ(test, foo, "bar"); 3138c2ecf20Sopenharmony_ci */ 3148c2ecf20Sopenharmony_cistruct kunit_binary_str_assert { 3158c2ecf20Sopenharmony_ci struct kunit_assert assert; 3168c2ecf20Sopenharmony_ci const char *operation; 3178c2ecf20Sopenharmony_ci const char *left_text; 3188c2ecf20Sopenharmony_ci const char *left_value; 3198c2ecf20Sopenharmony_ci const char *right_text; 3208c2ecf20Sopenharmony_ci const char *right_value; 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_civoid kunit_binary_str_assert_format(const struct kunit_assert *assert, 3248c2ecf20Sopenharmony_ci struct string_stream *stream); 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci/** 3278c2ecf20Sopenharmony_ci * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a 3288c2ecf20Sopenharmony_ci * &struct kunit_binary_str_assert. 3298c2ecf20Sopenharmony_ci * @test: The test case that this expectation/assertion is associated with. 3308c2ecf20Sopenharmony_ci * @type: The type (assertion or expectation) of this kunit_assert. 3318c2ecf20Sopenharmony_ci * @op_str: A string representation of the comparison operator (e.g. "=="). 3328c2ecf20Sopenharmony_ci * @left_str: A string representation of the expression in the left slot. 3338c2ecf20Sopenharmony_ci * @left_val: The actual evaluated value of the expression in the left slot. 3348c2ecf20Sopenharmony_ci * @right_str: A string representation of the expression in the right slot. 3358c2ecf20Sopenharmony_ci * @right_val: The actual evaluated value of the expression in the right slot. 3368c2ecf20Sopenharmony_ci * 3378c2ecf20Sopenharmony_ci * Initializes a &struct kunit_binary_str_assert. Intended to be used in 3388c2ecf20Sopenharmony_ci * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. 3398c2ecf20Sopenharmony_ci */ 3408c2ecf20Sopenharmony_ci#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \ 3418c2ecf20Sopenharmony_ci type, \ 3428c2ecf20Sopenharmony_ci op_str, \ 3438c2ecf20Sopenharmony_ci left_str, \ 3448c2ecf20Sopenharmony_ci left_val, \ 3458c2ecf20Sopenharmony_ci right_str, \ 3468c2ecf20Sopenharmony_ci right_val) { \ 3478c2ecf20Sopenharmony_ci .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ 3488c2ecf20Sopenharmony_ci type, \ 3498c2ecf20Sopenharmony_ci kunit_binary_str_assert_format), \ 3508c2ecf20Sopenharmony_ci .operation = op_str, \ 3518c2ecf20Sopenharmony_ci .left_text = left_str, \ 3528c2ecf20Sopenharmony_ci .left_value = left_val, \ 3538c2ecf20Sopenharmony_ci .right_text = right_str, \ 3548c2ecf20Sopenharmony_ci .right_value = right_val \ 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci#endif /* _KUNIT_ASSERT_H */ 358