18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Base unit test (KUnit) 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_TEST_H
108c2ecf20Sopenharmony_ci#define _KUNIT_TEST_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <kunit/assert.h>
138c2ecf20Sopenharmony_ci#include <kunit/try-catch.h>
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/module.h>
168c2ecf20Sopenharmony_ci#include <linux/slab.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <linux/kref.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct kunit_resource;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_citypedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
238c2ecf20Sopenharmony_citypedef void (*kunit_resource_free_t)(struct kunit_resource *);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/**
268c2ecf20Sopenharmony_ci * struct kunit_resource - represents a *test managed resource*
278c2ecf20Sopenharmony_ci * @data: for the user to store arbitrary data.
288c2ecf20Sopenharmony_ci * @name: optional name
298c2ecf20Sopenharmony_ci * @free: a user supplied function to free the resource. Populated by
308c2ecf20Sopenharmony_ci * kunit_resource_alloc().
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci * Represents a *test managed resource*, a resource which will automatically be
338c2ecf20Sopenharmony_ci * cleaned up at the end of a test case.
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci * Resources are reference counted so if a resource is retrieved via
368c2ecf20Sopenharmony_ci * kunit_alloc_and_get_resource() or kunit_find_resource(), we need
378c2ecf20Sopenharmony_ci * to call kunit_put_resource() to reduce the resource reference count
388c2ecf20Sopenharmony_ci * when finished with it.  Note that kunit_alloc_resource() does not require a
398c2ecf20Sopenharmony_ci * kunit_resource_put() because it does not retrieve the resource itself.
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci * Example:
428c2ecf20Sopenharmony_ci *
438c2ecf20Sopenharmony_ci * .. code-block:: c
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci *	struct kunit_kmalloc_params {
468c2ecf20Sopenharmony_ci *		size_t size;
478c2ecf20Sopenharmony_ci *		gfp_t gfp;
488c2ecf20Sopenharmony_ci *	};
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci *	static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
518c2ecf20Sopenharmony_ci *	{
528c2ecf20Sopenharmony_ci *		struct kunit_kmalloc_params *params = context;
538c2ecf20Sopenharmony_ci *		res->data = kmalloc(params->size, params->gfp);
548c2ecf20Sopenharmony_ci *
558c2ecf20Sopenharmony_ci *		if (!res->data)
568c2ecf20Sopenharmony_ci *			return -ENOMEM;
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci *		return 0;
598c2ecf20Sopenharmony_ci *	}
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci *	static void kunit_kmalloc_free(struct kunit_resource *res)
628c2ecf20Sopenharmony_ci *	{
638c2ecf20Sopenharmony_ci *		kfree(res->data);
648c2ecf20Sopenharmony_ci *	}
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci *	void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
678c2ecf20Sopenharmony_ci *	{
688c2ecf20Sopenharmony_ci *		struct kunit_kmalloc_params params;
698c2ecf20Sopenharmony_ci *
708c2ecf20Sopenharmony_ci *		params.size = size;
718c2ecf20Sopenharmony_ci *		params.gfp = gfp;
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci *		return kunit_alloc_resource(test, kunit_kmalloc_init,
748c2ecf20Sopenharmony_ci *			kunit_kmalloc_free, &params);
758c2ecf20Sopenharmony_ci *	}
768c2ecf20Sopenharmony_ci *
778c2ecf20Sopenharmony_ci * Resources can also be named, with lookup/removal done on a name
788c2ecf20Sopenharmony_ci * basis also.  kunit_add_named_resource(), kunit_find_named_resource()
798c2ecf20Sopenharmony_ci * and kunit_destroy_named_resource().  Resource names must be
808c2ecf20Sopenharmony_ci * unique within the test instance.
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_cistruct kunit_resource {
838c2ecf20Sopenharmony_ci	void *data;
848c2ecf20Sopenharmony_ci	const char *name;
858c2ecf20Sopenharmony_ci	kunit_resource_free_t free;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/* private: internal use only. */
888c2ecf20Sopenharmony_ci	struct kref refcount;
898c2ecf20Sopenharmony_ci	struct list_head node;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct kunit;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Size of log associated with test. */
958c2ecf20Sopenharmony_ci#define KUNIT_LOG_SIZE	512
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
998c2ecf20Sopenharmony_ci * sub-subtest.  See the "Subtests" section in
1008c2ecf20Sopenharmony_ci * https://node-tap.org/tap-protocol/
1018c2ecf20Sopenharmony_ci */
1028c2ecf20Sopenharmony_ci#define KUNIT_SUBTEST_INDENT		"    "
1038c2ecf20Sopenharmony_ci#define KUNIT_SUBSUBTEST_INDENT		"        "
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/**
1068c2ecf20Sopenharmony_ci * struct kunit_case - represents an individual test case.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * @run_case: the function representing the actual test case.
1098c2ecf20Sopenharmony_ci * @name:     the name of the test case.
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * A test case is a function with the signature,
1128c2ecf20Sopenharmony_ci * ``void (*)(struct kunit *)``
1138c2ecf20Sopenharmony_ci * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
1148c2ecf20Sopenharmony_ci * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
1158c2ecf20Sopenharmony_ci * with a &struct kunit_suite and will be run after the suite's init
1168c2ecf20Sopenharmony_ci * function and followed by the suite's exit function.
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * A test case should be static and should only be created with the
1198c2ecf20Sopenharmony_ci * KUNIT_CASE() macro; additionally, every array of test cases should be
1208c2ecf20Sopenharmony_ci * terminated with an empty test case.
1218c2ecf20Sopenharmony_ci *
1228c2ecf20Sopenharmony_ci * Example:
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci * .. code-block:: c
1258c2ecf20Sopenharmony_ci *
1268c2ecf20Sopenharmony_ci *	void add_test_basic(struct kunit *test)
1278c2ecf20Sopenharmony_ci *	{
1288c2ecf20Sopenharmony_ci *		KUNIT_EXPECT_EQ(test, 1, add(1, 0));
1298c2ecf20Sopenharmony_ci *		KUNIT_EXPECT_EQ(test, 2, add(1, 1));
1308c2ecf20Sopenharmony_ci *		KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
1318c2ecf20Sopenharmony_ci *		KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
1328c2ecf20Sopenharmony_ci *		KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
1338c2ecf20Sopenharmony_ci *	}
1348c2ecf20Sopenharmony_ci *
1358c2ecf20Sopenharmony_ci *	static struct kunit_case example_test_cases[] = {
1368c2ecf20Sopenharmony_ci *		KUNIT_CASE(add_test_basic),
1378c2ecf20Sopenharmony_ci *		{}
1388c2ecf20Sopenharmony_ci *	};
1398c2ecf20Sopenharmony_ci *
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_cistruct kunit_case {
1428c2ecf20Sopenharmony_ci	void (*run_case)(struct kunit *test);
1438c2ecf20Sopenharmony_ci	const char *name;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	/* private: internal use only. */
1468c2ecf20Sopenharmony_ci	bool success;
1478c2ecf20Sopenharmony_ci	char *log;
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic inline char *kunit_status_to_string(bool status)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	return status ? "ok" : "not ok";
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci/**
1568c2ecf20Sopenharmony_ci * KUNIT_CASE - A helper for creating a &struct kunit_case
1578c2ecf20Sopenharmony_ci *
1588c2ecf20Sopenharmony_ci * @test_name: a reference to a test case function.
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci * Takes a symbol for a function representing a test case and creates a
1618c2ecf20Sopenharmony_ci * &struct kunit_case object from it. See the documentation for
1628c2ecf20Sopenharmony_ci * &struct kunit_case for an example on how to use it.
1638c2ecf20Sopenharmony_ci */
1648c2ecf20Sopenharmony_ci#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/**
1678c2ecf20Sopenharmony_ci * struct kunit_suite - describes a related collection of &struct kunit_case
1688c2ecf20Sopenharmony_ci *
1698c2ecf20Sopenharmony_ci * @name:	the name of the test. Purely informational.
1708c2ecf20Sopenharmony_ci * @init:	called before every test case.
1718c2ecf20Sopenharmony_ci * @exit:	called after every test case.
1728c2ecf20Sopenharmony_ci * @test_cases:	a null terminated array of test cases.
1738c2ecf20Sopenharmony_ci *
1748c2ecf20Sopenharmony_ci * A kunit_suite is a collection of related &struct kunit_case s, such that
1758c2ecf20Sopenharmony_ci * @init is called before every test case and @exit is called after every
1768c2ecf20Sopenharmony_ci * test case, similar to the notion of a *test fixture* or a *test class*
1778c2ecf20Sopenharmony_ci * in other unit testing frameworks like JUnit or Googletest.
1788c2ecf20Sopenharmony_ci *
1798c2ecf20Sopenharmony_ci * Every &struct kunit_case must be associated with a kunit_suite for KUnit
1808c2ecf20Sopenharmony_ci * to run it.
1818c2ecf20Sopenharmony_ci */
1828c2ecf20Sopenharmony_cistruct kunit_suite {
1838c2ecf20Sopenharmony_ci	const char name[256];
1848c2ecf20Sopenharmony_ci	int (*init)(struct kunit *test);
1858c2ecf20Sopenharmony_ci	void (*exit)(struct kunit *test);
1868c2ecf20Sopenharmony_ci	struct kunit_case *test_cases;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	/* private: internal use only */
1898c2ecf20Sopenharmony_ci	struct dentry *debugfs;
1908c2ecf20Sopenharmony_ci	char *log;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/**
1948c2ecf20Sopenharmony_ci * struct kunit - represents a running instance of a test.
1958c2ecf20Sopenharmony_ci *
1968c2ecf20Sopenharmony_ci * @priv: for user to store arbitrary data. Commonly used to pass data
1978c2ecf20Sopenharmony_ci *	  created in the init function (see &struct kunit_suite).
1988c2ecf20Sopenharmony_ci *
1998c2ecf20Sopenharmony_ci * Used to store information about the current context under which the test
2008c2ecf20Sopenharmony_ci * is running. Most of this data is private and should only be accessed
2018c2ecf20Sopenharmony_ci * indirectly via public functions; the one exception is @priv which can be
2028c2ecf20Sopenharmony_ci * used by the test writer to store arbitrary data.
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_cistruct kunit {
2058c2ecf20Sopenharmony_ci	void *priv;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	/* private: internal use only. */
2088c2ecf20Sopenharmony_ci	const char *name; /* Read only after initialization! */
2098c2ecf20Sopenharmony_ci	char *log; /* Points at case log after initialization */
2108c2ecf20Sopenharmony_ci	struct kunit_try_catch try_catch;
2118c2ecf20Sopenharmony_ci	/*
2128c2ecf20Sopenharmony_ci	 * success starts as true, and may only be set to false during a
2138c2ecf20Sopenharmony_ci	 * test case; thus, it is safe to update this across multiple
2148c2ecf20Sopenharmony_ci	 * threads using WRITE_ONCE; however, as a consequence, it may only
2158c2ecf20Sopenharmony_ci	 * be read after the test case finishes once all threads associated
2168c2ecf20Sopenharmony_ci	 * with the test case have terminated.
2178c2ecf20Sopenharmony_ci	 */
2188c2ecf20Sopenharmony_ci	bool success; /* Read only after test_case finishes! */
2198c2ecf20Sopenharmony_ci	spinlock_t lock; /* Guards all mutable test state. */
2208c2ecf20Sopenharmony_ci	/*
2218c2ecf20Sopenharmony_ci	 * Because resources is a list that may be updated multiple times (with
2228c2ecf20Sopenharmony_ci	 * new resources) from any thread associated with a test case, we must
2238c2ecf20Sopenharmony_ci	 * protect it with some type of lock.
2248c2ecf20Sopenharmony_ci	 */
2258c2ecf20Sopenharmony_ci	struct list_head resources; /* Protected by lock. */
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic inline void kunit_set_failure(struct kunit *test)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	WRITE_ONCE(test->success, false);
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_civoid kunit_init_test(struct kunit *test, const char *name, char *log);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ciint kunit_run_tests(struct kunit_suite *suite);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cisize_t kunit_suite_num_test_cases(struct kunit_suite *suite);
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ciunsigned int kunit_test_case_num(struct kunit_suite *suite,
2408c2ecf20Sopenharmony_ci				 struct kunit_case *test_case);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ciint __kunit_test_suites_init(struct kunit_suite * const * const suites);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_civoid __kunit_test_suites_exit(struct kunit_suite **suites);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#if IS_BUILTIN(CONFIG_KUNIT)
2478c2ecf20Sopenharmony_ciint kunit_run_all_tests(void);
2488c2ecf20Sopenharmony_ci#else
2498c2ecf20Sopenharmony_cistatic inline int kunit_run_all_tests(void)
2508c2ecf20Sopenharmony_ci{
2518c2ecf20Sopenharmony_ci	return 0;
2528c2ecf20Sopenharmony_ci}
2538c2ecf20Sopenharmony_ci#endif /* IS_BUILTIN(CONFIG_KUNIT) */
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#ifdef MODULE
2568c2ecf20Sopenharmony_ci/**
2578c2ecf20Sopenharmony_ci * kunit_test_suites_for_module() - used to register one or more
2588c2ecf20Sopenharmony_ci *			 &struct kunit_suite with KUnit.
2598c2ecf20Sopenharmony_ci *
2608c2ecf20Sopenharmony_ci * @__suites: a statically allocated list of &struct kunit_suite.
2618c2ecf20Sopenharmony_ci *
2628c2ecf20Sopenharmony_ci * Registers @__suites with the test framework. See &struct kunit_suite for
2638c2ecf20Sopenharmony_ci * more information.
2648c2ecf20Sopenharmony_ci *
2658c2ecf20Sopenharmony_ci * If a test suite is built-in, module_init() gets translated into
2668c2ecf20Sopenharmony_ci * an initcall which we don't want as the idea is that for builtins
2678c2ecf20Sopenharmony_ci * the executor will manage execution.  So ensure we do not define
2688c2ecf20Sopenharmony_ci * module_{init|exit} functions for the builtin case when registering
2698c2ecf20Sopenharmony_ci * suites via kunit_test_suites() below.
2708c2ecf20Sopenharmony_ci */
2718c2ecf20Sopenharmony_ci#define kunit_test_suites_for_module(__suites)				\
2728c2ecf20Sopenharmony_ci	static int __init kunit_test_suites_init(void)			\
2738c2ecf20Sopenharmony_ci	{								\
2748c2ecf20Sopenharmony_ci		return __kunit_test_suites_init(__suites);		\
2758c2ecf20Sopenharmony_ci	}								\
2768c2ecf20Sopenharmony_ci	module_init(kunit_test_suites_init);				\
2778c2ecf20Sopenharmony_ci									\
2788c2ecf20Sopenharmony_ci	static void __exit kunit_test_suites_exit(void)			\
2798c2ecf20Sopenharmony_ci	{								\
2808c2ecf20Sopenharmony_ci		return __kunit_test_suites_exit(__suites);		\
2818c2ecf20Sopenharmony_ci	}								\
2828c2ecf20Sopenharmony_ci	module_exit(kunit_test_suites_exit)
2838c2ecf20Sopenharmony_ci#else
2848c2ecf20Sopenharmony_ci#define kunit_test_suites_for_module(__suites)
2858c2ecf20Sopenharmony_ci#endif /* MODULE */
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci#define __kunit_test_suites(unique_array, unique_suites, ...)		       \
2888c2ecf20Sopenharmony_ci	static struct kunit_suite *unique_array[] = { __VA_ARGS__, NULL };     \
2898c2ecf20Sopenharmony_ci	kunit_test_suites_for_module(unique_array);			       \
2908c2ecf20Sopenharmony_ci	static struct kunit_suite **unique_suites			       \
2918c2ecf20Sopenharmony_ci	__used __section(".kunit_test_suites") = unique_array
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/**
2948c2ecf20Sopenharmony_ci * kunit_test_suites() - used to register one or more &struct kunit_suite
2958c2ecf20Sopenharmony_ci *			 with KUnit.
2968c2ecf20Sopenharmony_ci *
2978c2ecf20Sopenharmony_ci * @__suites: a statically allocated list of &struct kunit_suite.
2988c2ecf20Sopenharmony_ci *
2998c2ecf20Sopenharmony_ci * Registers @suites with the test framework. See &struct kunit_suite for
3008c2ecf20Sopenharmony_ci * more information.
3018c2ecf20Sopenharmony_ci *
3028c2ecf20Sopenharmony_ci * When builtin,  KUnit tests are all run via executor; this is done
3038c2ecf20Sopenharmony_ci * by placing the array of struct kunit_suite * in the .kunit_test_suites
3048c2ecf20Sopenharmony_ci * ELF section.
3058c2ecf20Sopenharmony_ci *
3068c2ecf20Sopenharmony_ci * An alternative is to build the tests as a module.  Because modules do not
3078c2ecf20Sopenharmony_ci * support multiple initcall()s, we need to initialize an array of suites for a
3088c2ecf20Sopenharmony_ci * module.
3098c2ecf20Sopenharmony_ci *
3108c2ecf20Sopenharmony_ci */
3118c2ecf20Sopenharmony_ci#define kunit_test_suites(__suites...)						\
3128c2ecf20Sopenharmony_ci	__kunit_test_suites(__UNIQUE_ID(array),				\
3138c2ecf20Sopenharmony_ci			    __UNIQUE_ID(suites),			\
3148c2ecf20Sopenharmony_ci			    ##__suites)
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci#define kunit_test_suite(suite)	kunit_test_suites(&suite)
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci#define kunit_suite_for_each_test_case(suite, test_case)		\
3198c2ecf20Sopenharmony_ci	for (test_case = suite->test_cases; test_case->run_case; test_case++)
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cibool kunit_suite_has_succeeded(struct kunit_suite *suite);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/*
3248c2ecf20Sopenharmony_ci * Like kunit_alloc_resource() below, but returns the struct kunit_resource
3258c2ecf20Sopenharmony_ci * object that contains the allocation. This is mostly for testing purposes.
3268c2ecf20Sopenharmony_ci */
3278c2ecf20Sopenharmony_cistruct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
3288c2ecf20Sopenharmony_ci						    kunit_resource_init_t init,
3298c2ecf20Sopenharmony_ci						    kunit_resource_free_t free,
3308c2ecf20Sopenharmony_ci						    gfp_t internal_gfp,
3318c2ecf20Sopenharmony_ci						    void *context);
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/**
3348c2ecf20Sopenharmony_ci * kunit_get_resource() - Hold resource for use.  Should not need to be used
3358c2ecf20Sopenharmony_ci *			  by most users as we automatically get resources
3368c2ecf20Sopenharmony_ci *			  retrieved by kunit_find_resource*().
3378c2ecf20Sopenharmony_ci * @res: resource
3388c2ecf20Sopenharmony_ci */
3398c2ecf20Sopenharmony_cistatic inline void kunit_get_resource(struct kunit_resource *res)
3408c2ecf20Sopenharmony_ci{
3418c2ecf20Sopenharmony_ci	kref_get(&res->refcount);
3428c2ecf20Sopenharmony_ci}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/*
3458c2ecf20Sopenharmony_ci * Called when refcount reaches zero via kunit_put_resources();
3468c2ecf20Sopenharmony_ci * should not be called directly.
3478c2ecf20Sopenharmony_ci */
3488c2ecf20Sopenharmony_cistatic inline void kunit_release_resource(struct kref *kref)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	struct kunit_resource *res = container_of(kref, struct kunit_resource,
3518c2ecf20Sopenharmony_ci						  refcount);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	/* If free function is defined, resource was dynamically allocated. */
3548c2ecf20Sopenharmony_ci	if (res->free) {
3558c2ecf20Sopenharmony_ci		res->free(res);
3568c2ecf20Sopenharmony_ci		kfree(res);
3578c2ecf20Sopenharmony_ci	}
3588c2ecf20Sopenharmony_ci}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/**
3618c2ecf20Sopenharmony_ci * kunit_put_resource() - When caller is done with retrieved resource,
3628c2ecf20Sopenharmony_ci *			  kunit_put_resource() should be called to drop
3638c2ecf20Sopenharmony_ci *			  reference count.  The resource list maintains
3648c2ecf20Sopenharmony_ci *			  a reference count on resources, so if no users
3658c2ecf20Sopenharmony_ci *			  are utilizing a resource and it is removed from
3668c2ecf20Sopenharmony_ci *			  the resource list, it will be freed via the
3678c2ecf20Sopenharmony_ci *			  associated free function (if any).  Only
3688c2ecf20Sopenharmony_ci *			  needs to be used if we alloc_and_get() or
3698c2ecf20Sopenharmony_ci *			  find() resource.
3708c2ecf20Sopenharmony_ci * @res: resource
3718c2ecf20Sopenharmony_ci */
3728c2ecf20Sopenharmony_cistatic inline void kunit_put_resource(struct kunit_resource *res)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	kref_put(&res->refcount, kunit_release_resource);
3758c2ecf20Sopenharmony_ci}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci/**
3788c2ecf20Sopenharmony_ci * kunit_add_resource() - Add a *test managed resource*.
3798c2ecf20Sopenharmony_ci * @test: The test context object.
3808c2ecf20Sopenharmony_ci * @init: a user-supplied function to initialize the result (if needed).  If
3818c2ecf20Sopenharmony_ci *        none is supplied, the resource data value is simply set to @data.
3828c2ecf20Sopenharmony_ci *	  If an init function is supplied, @data is passed to it instead.
3838c2ecf20Sopenharmony_ci * @free: a user-supplied function to free the resource (if needed).
3848c2ecf20Sopenharmony_ci * @res: The resource.
3858c2ecf20Sopenharmony_ci * @data: value to pass to init function or set in resource data field.
3868c2ecf20Sopenharmony_ci */
3878c2ecf20Sopenharmony_ciint kunit_add_resource(struct kunit *test,
3888c2ecf20Sopenharmony_ci		       kunit_resource_init_t init,
3898c2ecf20Sopenharmony_ci		       kunit_resource_free_t free,
3908c2ecf20Sopenharmony_ci		       struct kunit_resource *res,
3918c2ecf20Sopenharmony_ci		       void *data);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci/**
3948c2ecf20Sopenharmony_ci * kunit_add_named_resource() - Add a named *test managed resource*.
3958c2ecf20Sopenharmony_ci * @test: The test context object.
3968c2ecf20Sopenharmony_ci * @init: a user-supplied function to initialize the resource data, if needed.
3978c2ecf20Sopenharmony_ci * @free: a user-supplied function to free the resource data, if needed.
3988c2ecf20Sopenharmony_ci * @res: The resource.
3998c2ecf20Sopenharmony_ci * @name: name to be set for resource.
4008c2ecf20Sopenharmony_ci * @data: value to pass to init function or set in resource data field.
4018c2ecf20Sopenharmony_ci */
4028c2ecf20Sopenharmony_ciint kunit_add_named_resource(struct kunit *test,
4038c2ecf20Sopenharmony_ci			     kunit_resource_init_t init,
4048c2ecf20Sopenharmony_ci			     kunit_resource_free_t free,
4058c2ecf20Sopenharmony_ci			     struct kunit_resource *res,
4068c2ecf20Sopenharmony_ci			     const char *name,
4078c2ecf20Sopenharmony_ci			     void *data);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci/**
4108c2ecf20Sopenharmony_ci * kunit_alloc_resource() - Allocates a *test managed resource*.
4118c2ecf20Sopenharmony_ci * @test: The test context object.
4128c2ecf20Sopenharmony_ci * @init: a user supplied function to initialize the resource.
4138c2ecf20Sopenharmony_ci * @free: a user supplied function to free the resource.
4148c2ecf20Sopenharmony_ci * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
4158c2ecf20Sopenharmony_ci * @context: for the user to pass in arbitrary data to the init function.
4168c2ecf20Sopenharmony_ci *
4178c2ecf20Sopenharmony_ci * Allocates a *test managed resource*, a resource which will automatically be
4188c2ecf20Sopenharmony_ci * cleaned up at the end of a test case. See &struct kunit_resource for an
4198c2ecf20Sopenharmony_ci * example.
4208c2ecf20Sopenharmony_ci *
4218c2ecf20Sopenharmony_ci * Note: KUnit needs to allocate memory for a kunit_resource object. You must
4228c2ecf20Sopenharmony_ci * specify an @internal_gfp that is compatible with the use context of your
4238c2ecf20Sopenharmony_ci * resource.
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_cistatic inline void *kunit_alloc_resource(struct kunit *test,
4268c2ecf20Sopenharmony_ci					 kunit_resource_init_t init,
4278c2ecf20Sopenharmony_ci					 kunit_resource_free_t free,
4288c2ecf20Sopenharmony_ci					 gfp_t internal_gfp,
4298c2ecf20Sopenharmony_ci					 void *context)
4308c2ecf20Sopenharmony_ci{
4318c2ecf20Sopenharmony_ci	struct kunit_resource *res;
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	res = kzalloc(sizeof(*res), internal_gfp);
4348c2ecf20Sopenharmony_ci	if (!res)
4358c2ecf20Sopenharmony_ci		return NULL;
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	if (!kunit_add_resource(test, init, free, res, context))
4388c2ecf20Sopenharmony_ci		return res->data;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	return NULL;
4418c2ecf20Sopenharmony_ci}
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_citypedef bool (*kunit_resource_match_t)(struct kunit *test,
4448c2ecf20Sopenharmony_ci				       struct kunit_resource *res,
4458c2ecf20Sopenharmony_ci				       void *match_data);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/**
4488c2ecf20Sopenharmony_ci * kunit_resource_instance_match() - Match a resource with the same instance.
4498c2ecf20Sopenharmony_ci * @test: Test case to which the resource belongs.
4508c2ecf20Sopenharmony_ci * @res: The resource.
4518c2ecf20Sopenharmony_ci * @match_data: The resource pointer to match against.
4528c2ecf20Sopenharmony_ci *
4538c2ecf20Sopenharmony_ci * An instance of kunit_resource_match_t that matches a resource whose
4548c2ecf20Sopenharmony_ci * allocation matches @match_data.
4558c2ecf20Sopenharmony_ci */
4568c2ecf20Sopenharmony_cistatic inline bool kunit_resource_instance_match(struct kunit *test,
4578c2ecf20Sopenharmony_ci						 struct kunit_resource *res,
4588c2ecf20Sopenharmony_ci						 void *match_data)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	return res->data == match_data;
4618c2ecf20Sopenharmony_ci}
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci/**
4648c2ecf20Sopenharmony_ci * kunit_resource_name_match() - Match a resource with the same name.
4658c2ecf20Sopenharmony_ci * @test: Test case to which the resource belongs.
4668c2ecf20Sopenharmony_ci * @res: The resource.
4678c2ecf20Sopenharmony_ci * @match_name: The name to match against.
4688c2ecf20Sopenharmony_ci */
4698c2ecf20Sopenharmony_cistatic inline bool kunit_resource_name_match(struct kunit *test,
4708c2ecf20Sopenharmony_ci					     struct kunit_resource *res,
4718c2ecf20Sopenharmony_ci					     void *match_name)
4728c2ecf20Sopenharmony_ci{
4738c2ecf20Sopenharmony_ci	return res->name && strcmp(res->name, match_name) == 0;
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci/**
4778c2ecf20Sopenharmony_ci * kunit_find_resource() - Find a resource using match function/data.
4788c2ecf20Sopenharmony_ci * @test: Test case to which the resource belongs.
4798c2ecf20Sopenharmony_ci * @match: match function to be applied to resources/match data.
4808c2ecf20Sopenharmony_ci * @match_data: data to be used in matching.
4818c2ecf20Sopenharmony_ci */
4828c2ecf20Sopenharmony_cistatic inline struct kunit_resource *
4838c2ecf20Sopenharmony_cikunit_find_resource(struct kunit *test,
4848c2ecf20Sopenharmony_ci		    kunit_resource_match_t match,
4858c2ecf20Sopenharmony_ci		    void *match_data)
4868c2ecf20Sopenharmony_ci{
4878c2ecf20Sopenharmony_ci	struct kunit_resource *res, *found = NULL;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	spin_lock(&test->lock);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	list_for_each_entry_reverse(res, &test->resources, node) {
4928c2ecf20Sopenharmony_ci		if (match(test, res, (void *)match_data)) {
4938c2ecf20Sopenharmony_ci			found = res;
4948c2ecf20Sopenharmony_ci			kunit_get_resource(found);
4958c2ecf20Sopenharmony_ci			break;
4968c2ecf20Sopenharmony_ci		}
4978c2ecf20Sopenharmony_ci	}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	spin_unlock(&test->lock);
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	return found;
5028c2ecf20Sopenharmony_ci}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci/**
5058c2ecf20Sopenharmony_ci * kunit_find_named_resource() - Find a resource using match name.
5068c2ecf20Sopenharmony_ci * @test: Test case to which the resource belongs.
5078c2ecf20Sopenharmony_ci * @name: match name.
5088c2ecf20Sopenharmony_ci */
5098c2ecf20Sopenharmony_cistatic inline struct kunit_resource *
5108c2ecf20Sopenharmony_cikunit_find_named_resource(struct kunit *test,
5118c2ecf20Sopenharmony_ci			  const char *name)
5128c2ecf20Sopenharmony_ci{
5138c2ecf20Sopenharmony_ci	return kunit_find_resource(test, kunit_resource_name_match,
5148c2ecf20Sopenharmony_ci				   (void *)name);
5158c2ecf20Sopenharmony_ci}
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci/**
5188c2ecf20Sopenharmony_ci * kunit_destroy_resource() - Find a kunit_resource and destroy it.
5198c2ecf20Sopenharmony_ci * @test: Test case to which the resource belongs.
5208c2ecf20Sopenharmony_ci * @match: Match function. Returns whether a given resource matches @match_data.
5218c2ecf20Sopenharmony_ci * @match_data: Data passed into @match.
5228c2ecf20Sopenharmony_ci *
5238c2ecf20Sopenharmony_ci * RETURNS:
5248c2ecf20Sopenharmony_ci * 0 if kunit_resource is found and freed, -ENOENT if not found.
5258c2ecf20Sopenharmony_ci */
5268c2ecf20Sopenharmony_ciint kunit_destroy_resource(struct kunit *test,
5278c2ecf20Sopenharmony_ci			   kunit_resource_match_t match,
5288c2ecf20Sopenharmony_ci			   void *match_data);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic inline int kunit_destroy_named_resource(struct kunit *test,
5318c2ecf20Sopenharmony_ci					       const char *name)
5328c2ecf20Sopenharmony_ci{
5338c2ecf20Sopenharmony_ci	return kunit_destroy_resource(test, kunit_resource_name_match,
5348c2ecf20Sopenharmony_ci				      (void *)name);
5358c2ecf20Sopenharmony_ci}
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci/**
5388c2ecf20Sopenharmony_ci * kunit_remove_resource() - remove resource from resource list associated with
5398c2ecf20Sopenharmony_ci *			     test.
5408c2ecf20Sopenharmony_ci * @test: The test context object.
5418c2ecf20Sopenharmony_ci * @res: The resource to be removed.
5428c2ecf20Sopenharmony_ci *
5438c2ecf20Sopenharmony_ci * Note that the resource will not be immediately freed since it is likely
5448c2ecf20Sopenharmony_ci * the caller has a reference to it via alloc_and_get() or find();
5458c2ecf20Sopenharmony_ci * in this case a final call to kunit_put_resource() is required.
5468c2ecf20Sopenharmony_ci */
5478c2ecf20Sopenharmony_civoid kunit_remove_resource(struct kunit *test, struct kunit_resource *res);
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci/**
5508c2ecf20Sopenharmony_ci * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
5518c2ecf20Sopenharmony_ci * @test: The test context object.
5528c2ecf20Sopenharmony_ci * @size: The size in bytes of the desired memory.
5538c2ecf20Sopenharmony_ci * @gfp: flags passed to underlying kmalloc().
5548c2ecf20Sopenharmony_ci *
5558c2ecf20Sopenharmony_ci * Just like `kmalloc(...)`, except the allocation is managed by the test case
5568c2ecf20Sopenharmony_ci * and is automatically cleaned up after the test case concludes. See &struct
5578c2ecf20Sopenharmony_ci * kunit_resource for more information.
5588c2ecf20Sopenharmony_ci */
5598c2ecf20Sopenharmony_civoid *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci/**
5628c2ecf20Sopenharmony_ci * kunit_kfree() - Like kfree except for allocations managed by KUnit.
5638c2ecf20Sopenharmony_ci * @test: The test case to which the resource belongs.
5648c2ecf20Sopenharmony_ci * @ptr: The memory allocation to free.
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_civoid kunit_kfree(struct kunit *test, const void *ptr);
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci/**
5698c2ecf20Sopenharmony_ci * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
5708c2ecf20Sopenharmony_ci * @test: The test context object.
5718c2ecf20Sopenharmony_ci * @size: The size in bytes of the desired memory.
5728c2ecf20Sopenharmony_ci * @gfp: flags passed to underlying kmalloc().
5738c2ecf20Sopenharmony_ci *
5748c2ecf20Sopenharmony_ci * See kzalloc() and kunit_kmalloc() for more information.
5758c2ecf20Sopenharmony_ci */
5768c2ecf20Sopenharmony_cistatic inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
5778c2ecf20Sopenharmony_ci{
5788c2ecf20Sopenharmony_ci	return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
5798c2ecf20Sopenharmony_ci}
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_civoid kunit_cleanup(struct kunit *test);
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_civoid kunit_log_append(char *log, const char *fmt, ...);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci/*
5868c2ecf20Sopenharmony_ci * printk and log to per-test or per-suite log buffer.  Logging only done
5878c2ecf20Sopenharmony_ci * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
5888c2ecf20Sopenharmony_ci */
5898c2ecf20Sopenharmony_ci#define kunit_log(lvl, test_or_suite, fmt, ...)				\
5908c2ecf20Sopenharmony_ci	do {								\
5918c2ecf20Sopenharmony_ci		printk(lvl fmt, ##__VA_ARGS__);				\
5928c2ecf20Sopenharmony_ci		kunit_log_append((test_or_suite)->log,	fmt "\n",	\
5938c2ecf20Sopenharmony_ci				 ##__VA_ARGS__);			\
5948c2ecf20Sopenharmony_ci	} while (0)
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci#define kunit_printk(lvl, test, fmt, ...)				\
5978c2ecf20Sopenharmony_ci	kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt,		\
5988c2ecf20Sopenharmony_ci		  (test)->name,	##__VA_ARGS__)
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci/**
6018c2ecf20Sopenharmony_ci * kunit_info() - Prints an INFO level message associated with @test.
6028c2ecf20Sopenharmony_ci *
6038c2ecf20Sopenharmony_ci * @test: The test context object.
6048c2ecf20Sopenharmony_ci * @fmt:  A printk() style format string.
6058c2ecf20Sopenharmony_ci *
6068c2ecf20Sopenharmony_ci * Prints an info level message associated with the test suite being run.
6078c2ecf20Sopenharmony_ci * Takes a variable number of format parameters just like printk().
6088c2ecf20Sopenharmony_ci */
6098c2ecf20Sopenharmony_ci#define kunit_info(test, fmt, ...) \
6108c2ecf20Sopenharmony_ci	kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci/**
6138c2ecf20Sopenharmony_ci * kunit_warn() - Prints a WARN level message associated with @test.
6148c2ecf20Sopenharmony_ci *
6158c2ecf20Sopenharmony_ci * @test: The test context object.
6168c2ecf20Sopenharmony_ci * @fmt:  A printk() style format string.
6178c2ecf20Sopenharmony_ci *
6188c2ecf20Sopenharmony_ci * Prints a warning level message.
6198c2ecf20Sopenharmony_ci */
6208c2ecf20Sopenharmony_ci#define kunit_warn(test, fmt, ...) \
6218c2ecf20Sopenharmony_ci	kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci/**
6248c2ecf20Sopenharmony_ci * kunit_err() - Prints an ERROR level message associated with @test.
6258c2ecf20Sopenharmony_ci *
6268c2ecf20Sopenharmony_ci * @test: The test context object.
6278c2ecf20Sopenharmony_ci * @fmt:  A printk() style format string.
6288c2ecf20Sopenharmony_ci *
6298c2ecf20Sopenharmony_ci * Prints an error level message.
6308c2ecf20Sopenharmony_ci */
6318c2ecf20Sopenharmony_ci#define kunit_err(test, fmt, ...) \
6328c2ecf20Sopenharmony_ci	kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci/**
6358c2ecf20Sopenharmony_ci * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
6368c2ecf20Sopenharmony_ci * @test: The test context object.
6378c2ecf20Sopenharmony_ci *
6388c2ecf20Sopenharmony_ci * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
6398c2ecf20Sopenharmony_ci * words, it does nothing and only exists for code clarity. See
6408c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE() for more information.
6418c2ecf20Sopenharmony_ci */
6428c2ecf20Sopenharmony_ci#define KUNIT_SUCCEED(test) do {} while (0)
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_civoid kunit_do_assertion(struct kunit *test,
6458c2ecf20Sopenharmony_ci			struct kunit_assert *assert,
6468c2ecf20Sopenharmony_ci			bool pass,
6478c2ecf20Sopenharmony_ci			const char *fmt, ...);
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci#define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do {  \
6508c2ecf20Sopenharmony_ci	struct assert_class __assertion = INITIALIZER;			       \
6518c2ecf20Sopenharmony_ci	kunit_do_assertion(test,					       \
6528c2ecf20Sopenharmony_ci			   &__assertion.assert,				       \
6538c2ecf20Sopenharmony_ci			   pass,					       \
6548c2ecf20Sopenharmony_ci			   fmt,						       \
6558c2ecf20Sopenharmony_ci			   ##__VA_ARGS__);				       \
6568c2ecf20Sopenharmony_ci} while (0)
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci#define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...)		       \
6608c2ecf20Sopenharmony_ci	KUNIT_ASSERTION(test,						       \
6618c2ecf20Sopenharmony_ci			false,						       \
6628c2ecf20Sopenharmony_ci			kunit_fail_assert,				       \
6638c2ecf20Sopenharmony_ci			KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type),      \
6648c2ecf20Sopenharmony_ci			fmt,						       \
6658c2ecf20Sopenharmony_ci			##__VA_ARGS__)
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci/**
6688c2ecf20Sopenharmony_ci * KUNIT_FAIL() - Always causes a test to fail when evaluated.
6698c2ecf20Sopenharmony_ci * @test: The test context object.
6708c2ecf20Sopenharmony_ci * @fmt: an informational message to be printed when the assertion is made.
6718c2ecf20Sopenharmony_ci * @...: string format arguments.
6728c2ecf20Sopenharmony_ci *
6738c2ecf20Sopenharmony_ci * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
6748c2ecf20Sopenharmony_ci * other words, it always results in a failed expectation, and consequently
6758c2ecf20Sopenharmony_ci * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
6768c2ecf20Sopenharmony_ci * for more information.
6778c2ecf20Sopenharmony_ci */
6788c2ecf20Sopenharmony_ci#define KUNIT_FAIL(test, fmt, ...)					       \
6798c2ecf20Sopenharmony_ci	KUNIT_FAIL_ASSERTION(test,					       \
6808c2ecf20Sopenharmony_ci			     KUNIT_EXPECTATION,				       \
6818c2ecf20Sopenharmony_ci			     fmt,					       \
6828c2ecf20Sopenharmony_ci			     ##__VA_ARGS__)
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci#define KUNIT_UNARY_ASSERTION(test,					       \
6858c2ecf20Sopenharmony_ci			      assert_type,				       \
6868c2ecf20Sopenharmony_ci			      condition,				       \
6878c2ecf20Sopenharmony_ci			      expected_true,				       \
6888c2ecf20Sopenharmony_ci			      fmt,					       \
6898c2ecf20Sopenharmony_ci			      ...)					       \
6908c2ecf20Sopenharmony_ci	KUNIT_ASSERTION(test,						       \
6918c2ecf20Sopenharmony_ci			!!(condition) == !!expected_true,		       \
6928c2ecf20Sopenharmony_ci			kunit_unary_assert,				       \
6938c2ecf20Sopenharmony_ci			KUNIT_INIT_UNARY_ASSERT_STRUCT(test,		       \
6948c2ecf20Sopenharmony_ci						       assert_type,	       \
6958c2ecf20Sopenharmony_ci						       #condition,	       \
6968c2ecf20Sopenharmony_ci						       expected_true),	       \
6978c2ecf20Sopenharmony_ci			fmt,						       \
6988c2ecf20Sopenharmony_ci			##__VA_ARGS__)
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci#define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...)       \
7018c2ecf20Sopenharmony_ci	KUNIT_UNARY_ASSERTION(test,					       \
7028c2ecf20Sopenharmony_ci			      assert_type,				       \
7038c2ecf20Sopenharmony_ci			      condition,				       \
7048c2ecf20Sopenharmony_ci			      true,					       \
7058c2ecf20Sopenharmony_ci			      fmt,					       \
7068c2ecf20Sopenharmony_ci			      ##__VA_ARGS__)
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci#define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
7098c2ecf20Sopenharmony_ci	KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci#define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...)      \
7128c2ecf20Sopenharmony_ci	KUNIT_UNARY_ASSERTION(test,					       \
7138c2ecf20Sopenharmony_ci			      assert_type,				       \
7148c2ecf20Sopenharmony_ci			      condition,				       \
7158c2ecf20Sopenharmony_ci			      false,					       \
7168c2ecf20Sopenharmony_ci			      fmt,					       \
7178c2ecf20Sopenharmony_ci			      ##__VA_ARGS__)
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci#define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
7208c2ecf20Sopenharmony_ci	KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci/*
7238c2ecf20Sopenharmony_ci * A factory macro for defining the assertions and expectations for the basic
7248c2ecf20Sopenharmony_ci * comparisons defined for the built in types.
7258c2ecf20Sopenharmony_ci *
7268c2ecf20Sopenharmony_ci * Unfortunately, there is no common type that all types can be promoted to for
7278c2ecf20Sopenharmony_ci * which all the binary operators behave the same way as for the actual types
7288c2ecf20Sopenharmony_ci * (for example, there is no type that long long and unsigned long long can
7298c2ecf20Sopenharmony_ci * both be cast to where the comparison result is preserved for all values). So
7308c2ecf20Sopenharmony_ci * the best we can do is do the comparison in the original types and then coerce
7318c2ecf20Sopenharmony_ci * everything to long long for printing; this way, the comparison behaves
7328c2ecf20Sopenharmony_ci * correctly and the printed out value usually makes sense without
7338c2ecf20Sopenharmony_ci * interpretation, but can always be interpreted to figure out the actual
7348c2ecf20Sopenharmony_ci * value.
7358c2ecf20Sopenharmony_ci */
7368c2ecf20Sopenharmony_ci#define KUNIT_BASE_BINARY_ASSERTION(test,				       \
7378c2ecf20Sopenharmony_ci				    assert_class,			       \
7388c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7398c2ecf20Sopenharmony_ci				    assert_type,			       \
7408c2ecf20Sopenharmony_ci				    left,				       \
7418c2ecf20Sopenharmony_ci				    op,					       \
7428c2ecf20Sopenharmony_ci				    right,				       \
7438c2ecf20Sopenharmony_ci				    fmt,				       \
7448c2ecf20Sopenharmony_ci				    ...)				       \
7458c2ecf20Sopenharmony_cido {									       \
7468c2ecf20Sopenharmony_ci	typeof(left) __left = (left);					       \
7478c2ecf20Sopenharmony_ci	typeof(right) __right = (right);				       \
7488c2ecf20Sopenharmony_ci	((void)__typecheck(__left, __right));				       \
7498c2ecf20Sopenharmony_ci									       \
7508c2ecf20Sopenharmony_ci	KUNIT_ASSERTION(test,						       \
7518c2ecf20Sopenharmony_ci			__left op __right,				       \
7528c2ecf20Sopenharmony_ci			assert_class,					       \
7538c2ecf20Sopenharmony_ci			ASSERT_CLASS_INIT(test,				       \
7548c2ecf20Sopenharmony_ci					  assert_type,			       \
7558c2ecf20Sopenharmony_ci					  #op,				       \
7568c2ecf20Sopenharmony_ci					  #left,			       \
7578c2ecf20Sopenharmony_ci					  __left,			       \
7588c2ecf20Sopenharmony_ci					  #right,			       \
7598c2ecf20Sopenharmony_ci					  __right),			       \
7608c2ecf20Sopenharmony_ci			fmt,						       \
7618c2ecf20Sopenharmony_ci			##__VA_ARGS__);					       \
7628c2ecf20Sopenharmony_ci} while (0)
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci#define KUNIT_BASE_EQ_MSG_ASSERTION(test,				       \
7658c2ecf20Sopenharmony_ci				    assert_class,			       \
7668c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7678c2ecf20Sopenharmony_ci				    assert_type,			       \
7688c2ecf20Sopenharmony_ci				    left,				       \
7698c2ecf20Sopenharmony_ci				    right,				       \
7708c2ecf20Sopenharmony_ci				    fmt,				       \
7718c2ecf20Sopenharmony_ci				    ...)				       \
7728c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
7738c2ecf20Sopenharmony_ci				    assert_class,			       \
7748c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7758c2ecf20Sopenharmony_ci				    assert_type,			       \
7768c2ecf20Sopenharmony_ci				    left, ==, right,			       \
7778c2ecf20Sopenharmony_ci				    fmt,				       \
7788c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci#define KUNIT_BASE_NE_MSG_ASSERTION(test,				       \
7818c2ecf20Sopenharmony_ci				    assert_class,			       \
7828c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7838c2ecf20Sopenharmony_ci				    assert_type,			       \
7848c2ecf20Sopenharmony_ci				    left,				       \
7858c2ecf20Sopenharmony_ci				    right,				       \
7868c2ecf20Sopenharmony_ci				    fmt,				       \
7878c2ecf20Sopenharmony_ci				    ...)				       \
7888c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
7898c2ecf20Sopenharmony_ci				    assert_class,			       \
7908c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7918c2ecf20Sopenharmony_ci				    assert_type,			       \
7928c2ecf20Sopenharmony_ci				    left, !=, right,			       \
7938c2ecf20Sopenharmony_ci				    fmt,				       \
7948c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci#define KUNIT_BASE_LT_MSG_ASSERTION(test,				       \
7978c2ecf20Sopenharmony_ci				    assert_class,			       \
7988c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
7998c2ecf20Sopenharmony_ci				    assert_type,			       \
8008c2ecf20Sopenharmony_ci				    left,				       \
8018c2ecf20Sopenharmony_ci				    right,				       \
8028c2ecf20Sopenharmony_ci				    fmt,				       \
8038c2ecf20Sopenharmony_ci				    ...)				       \
8048c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
8058c2ecf20Sopenharmony_ci				    assert_class,			       \
8068c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8078c2ecf20Sopenharmony_ci				    assert_type,			       \
8088c2ecf20Sopenharmony_ci				    left, <, right,			       \
8098c2ecf20Sopenharmony_ci				    fmt,				       \
8108c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci#define KUNIT_BASE_LE_MSG_ASSERTION(test,				       \
8138c2ecf20Sopenharmony_ci				    assert_class,			       \
8148c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8158c2ecf20Sopenharmony_ci				    assert_type,			       \
8168c2ecf20Sopenharmony_ci				    left,				       \
8178c2ecf20Sopenharmony_ci				    right,				       \
8188c2ecf20Sopenharmony_ci				    fmt,				       \
8198c2ecf20Sopenharmony_ci				    ...)				       \
8208c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
8218c2ecf20Sopenharmony_ci				    assert_class,			       \
8228c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8238c2ecf20Sopenharmony_ci				    assert_type,			       \
8248c2ecf20Sopenharmony_ci				    left, <=, right,			       \
8258c2ecf20Sopenharmony_ci				    fmt,				       \
8268c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci#define KUNIT_BASE_GT_MSG_ASSERTION(test,				       \
8298c2ecf20Sopenharmony_ci				    assert_class,			       \
8308c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8318c2ecf20Sopenharmony_ci				    assert_type,			       \
8328c2ecf20Sopenharmony_ci				    left,				       \
8338c2ecf20Sopenharmony_ci				    right,				       \
8348c2ecf20Sopenharmony_ci				    fmt,				       \
8358c2ecf20Sopenharmony_ci				    ...)				       \
8368c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
8378c2ecf20Sopenharmony_ci				    assert_class,			       \
8388c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8398c2ecf20Sopenharmony_ci				    assert_type,			       \
8408c2ecf20Sopenharmony_ci				    left, >, right,			       \
8418c2ecf20Sopenharmony_ci				    fmt,				       \
8428c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci#define KUNIT_BASE_GE_MSG_ASSERTION(test,				       \
8458c2ecf20Sopenharmony_ci				    assert_class,			       \
8468c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8478c2ecf20Sopenharmony_ci				    assert_type,			       \
8488c2ecf20Sopenharmony_ci				    left,				       \
8498c2ecf20Sopenharmony_ci				    right,				       \
8508c2ecf20Sopenharmony_ci				    fmt,				       \
8518c2ecf20Sopenharmony_ci				    ...)				       \
8528c2ecf20Sopenharmony_ci	KUNIT_BASE_BINARY_ASSERTION(test,				       \
8538c2ecf20Sopenharmony_ci				    assert_class,			       \
8548c2ecf20Sopenharmony_ci				    ASSERT_CLASS_INIT,			       \
8558c2ecf20Sopenharmony_ci				    assert_type,			       \
8568c2ecf20Sopenharmony_ci				    left, >=, right,			       \
8578c2ecf20Sopenharmony_ci				    fmt,				       \
8588c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
8618c2ecf20Sopenharmony_ci	KUNIT_BASE_EQ_MSG_ASSERTION(test,				       \
8628c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
8638c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
8648c2ecf20Sopenharmony_ci				    assert_type,			       \
8658c2ecf20Sopenharmony_ci				    left,				       \
8668c2ecf20Sopenharmony_ci				    right,				       \
8678c2ecf20Sopenharmony_ci				    fmt,				       \
8688c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci#define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right)	       \
8718c2ecf20Sopenharmony_ci	KUNIT_BINARY_EQ_MSG_ASSERTION(test,				       \
8728c2ecf20Sopenharmony_ci				      assert_type,			       \
8738c2ecf20Sopenharmony_ci				      left,				       \
8748c2ecf20Sopenharmony_ci				      right,				       \
8758c2ecf20Sopenharmony_ci				      NULL)
8768c2ecf20Sopenharmony_ci
8778c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,				       \
8788c2ecf20Sopenharmony_ci					  assert_type,			       \
8798c2ecf20Sopenharmony_ci					  left,				       \
8808c2ecf20Sopenharmony_ci					  right,			       \
8818c2ecf20Sopenharmony_ci					  fmt,				       \
8828c2ecf20Sopenharmony_ci					  ...)				       \
8838c2ecf20Sopenharmony_ci	KUNIT_BASE_EQ_MSG_ASSERTION(test,				       \
8848c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
8858c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
8868c2ecf20Sopenharmony_ci				    assert_type,			       \
8878c2ecf20Sopenharmony_ci				    left,				       \
8888c2ecf20Sopenharmony_ci				    right,				       \
8898c2ecf20Sopenharmony_ci				    fmt,				       \
8908c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right)	       \
8938c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,				       \
8948c2ecf20Sopenharmony_ci					  assert_type,			       \
8958c2ecf20Sopenharmony_ci					  left,				       \
8968c2ecf20Sopenharmony_ci					  right,			       \
8978c2ecf20Sopenharmony_ci					  NULL)
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
9008c2ecf20Sopenharmony_ci	KUNIT_BASE_NE_MSG_ASSERTION(test,				       \
9018c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
9028c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
9038c2ecf20Sopenharmony_ci				    assert_type,			       \
9048c2ecf20Sopenharmony_ci				    left,				       \
9058c2ecf20Sopenharmony_ci				    right,				       \
9068c2ecf20Sopenharmony_ci				    fmt,				       \
9078c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci#define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right)	       \
9108c2ecf20Sopenharmony_ci	KUNIT_BINARY_NE_MSG_ASSERTION(test,				       \
9118c2ecf20Sopenharmony_ci				      assert_type,			       \
9128c2ecf20Sopenharmony_ci				      left,				       \
9138c2ecf20Sopenharmony_ci				      right,				       \
9148c2ecf20Sopenharmony_ci				      NULL)
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,				       \
9178c2ecf20Sopenharmony_ci					  assert_type,			       \
9188c2ecf20Sopenharmony_ci					  left,				       \
9198c2ecf20Sopenharmony_ci					  right,			       \
9208c2ecf20Sopenharmony_ci					  fmt,				       \
9218c2ecf20Sopenharmony_ci					  ...)				       \
9228c2ecf20Sopenharmony_ci	KUNIT_BASE_NE_MSG_ASSERTION(test,				       \
9238c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
9248c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
9258c2ecf20Sopenharmony_ci				    assert_type,			       \
9268c2ecf20Sopenharmony_ci				    left,				       \
9278c2ecf20Sopenharmony_ci				    right,				       \
9288c2ecf20Sopenharmony_ci				    fmt,				       \
9298c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right)	       \
9328c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,				       \
9338c2ecf20Sopenharmony_ci					  assert_type,			       \
9348c2ecf20Sopenharmony_ci					  left,				       \
9358c2ecf20Sopenharmony_ci					  right,			       \
9368c2ecf20Sopenharmony_ci					  NULL)
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_ci#define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
9398c2ecf20Sopenharmony_ci	KUNIT_BASE_LT_MSG_ASSERTION(test,				       \
9408c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
9418c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
9428c2ecf20Sopenharmony_ci				    assert_type,			       \
9438c2ecf20Sopenharmony_ci				    left,				       \
9448c2ecf20Sopenharmony_ci				    right,				       \
9458c2ecf20Sopenharmony_ci				    fmt,				       \
9468c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci#define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right)	       \
9498c2ecf20Sopenharmony_ci	KUNIT_BINARY_LT_MSG_ASSERTION(test,				       \
9508c2ecf20Sopenharmony_ci				      assert_type,			       \
9518c2ecf20Sopenharmony_ci				      left,				       \
9528c2ecf20Sopenharmony_ci				      right,				       \
9538c2ecf20Sopenharmony_ci				      NULL)
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test,				       \
9568c2ecf20Sopenharmony_ci					  assert_type,			       \
9578c2ecf20Sopenharmony_ci					  left,				       \
9588c2ecf20Sopenharmony_ci					  right,			       \
9598c2ecf20Sopenharmony_ci					  fmt,				       \
9608c2ecf20Sopenharmony_ci					  ...)				       \
9618c2ecf20Sopenharmony_ci	KUNIT_BASE_LT_MSG_ASSERTION(test,				       \
9628c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
9638c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
9648c2ecf20Sopenharmony_ci				    assert_type,			       \
9658c2ecf20Sopenharmony_ci				    left,				       \
9668c2ecf20Sopenharmony_ci				    right,				       \
9678c2ecf20Sopenharmony_ci				    fmt,				       \
9688c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right)	       \
9718c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test,				       \
9728c2ecf20Sopenharmony_ci					  assert_type,			       \
9738c2ecf20Sopenharmony_ci					  left,				       \
9748c2ecf20Sopenharmony_ci					  right,			       \
9758c2ecf20Sopenharmony_ci					  NULL)
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_ci#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
9788c2ecf20Sopenharmony_ci	KUNIT_BASE_LE_MSG_ASSERTION(test,				       \
9798c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
9808c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
9818c2ecf20Sopenharmony_ci				    assert_type,			       \
9828c2ecf20Sopenharmony_ci				    left,				       \
9838c2ecf20Sopenharmony_ci				    right,				       \
9848c2ecf20Sopenharmony_ci				    fmt,				       \
9858c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci#define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right)	       \
9888c2ecf20Sopenharmony_ci	KUNIT_BINARY_LE_MSG_ASSERTION(test,				       \
9898c2ecf20Sopenharmony_ci				      assert_type,			       \
9908c2ecf20Sopenharmony_ci				      left,				       \
9918c2ecf20Sopenharmony_ci				      right,				       \
9928c2ecf20Sopenharmony_ci				      NULL)
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test,				       \
9958c2ecf20Sopenharmony_ci					  assert_type,			       \
9968c2ecf20Sopenharmony_ci					  left,				       \
9978c2ecf20Sopenharmony_ci					  right,			       \
9988c2ecf20Sopenharmony_ci					  fmt,				       \
9998c2ecf20Sopenharmony_ci					  ...)				       \
10008c2ecf20Sopenharmony_ci	KUNIT_BASE_LE_MSG_ASSERTION(test,				       \
10018c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
10028c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
10038c2ecf20Sopenharmony_ci				    assert_type,			       \
10048c2ecf20Sopenharmony_ci				    left,				       \
10058c2ecf20Sopenharmony_ci				    right,				       \
10068c2ecf20Sopenharmony_ci				    fmt,				       \
10078c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right)	       \
10108c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test,				       \
10118c2ecf20Sopenharmony_ci					  assert_type,			       \
10128c2ecf20Sopenharmony_ci					  left,				       \
10138c2ecf20Sopenharmony_ci					  right,			       \
10148c2ecf20Sopenharmony_ci					  NULL)
10158c2ecf20Sopenharmony_ci
10168c2ecf20Sopenharmony_ci#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
10178c2ecf20Sopenharmony_ci	KUNIT_BASE_GT_MSG_ASSERTION(test,				       \
10188c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
10198c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
10208c2ecf20Sopenharmony_ci				    assert_type,			       \
10218c2ecf20Sopenharmony_ci				    left,				       \
10228c2ecf20Sopenharmony_ci				    right,				       \
10238c2ecf20Sopenharmony_ci				    fmt,				       \
10248c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci#define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right)	       \
10278c2ecf20Sopenharmony_ci	KUNIT_BINARY_GT_MSG_ASSERTION(test,				       \
10288c2ecf20Sopenharmony_ci				      assert_type,			       \
10298c2ecf20Sopenharmony_ci				      left,				       \
10308c2ecf20Sopenharmony_ci				      right,				       \
10318c2ecf20Sopenharmony_ci				      NULL)
10328c2ecf20Sopenharmony_ci
10338c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test,				       \
10348c2ecf20Sopenharmony_ci					  assert_type,			       \
10358c2ecf20Sopenharmony_ci					  left,				       \
10368c2ecf20Sopenharmony_ci					  right,			       \
10378c2ecf20Sopenharmony_ci					  fmt,				       \
10388c2ecf20Sopenharmony_ci					  ...)				       \
10398c2ecf20Sopenharmony_ci	KUNIT_BASE_GT_MSG_ASSERTION(test,				       \
10408c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
10418c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
10428c2ecf20Sopenharmony_ci				    assert_type,			       \
10438c2ecf20Sopenharmony_ci				    left,				       \
10448c2ecf20Sopenharmony_ci				    right,				       \
10458c2ecf20Sopenharmony_ci				    fmt,				       \
10468c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right)	       \
10498c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test,				       \
10508c2ecf20Sopenharmony_ci					  assert_type,			       \
10518c2ecf20Sopenharmony_ci					  left,				       \
10528c2ecf20Sopenharmony_ci					  right,			       \
10538c2ecf20Sopenharmony_ci					  NULL)
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ci#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
10568c2ecf20Sopenharmony_ci	KUNIT_BASE_GE_MSG_ASSERTION(test,				       \
10578c2ecf20Sopenharmony_ci				    kunit_binary_assert,		       \
10588c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_ASSERT_STRUCT,	       \
10598c2ecf20Sopenharmony_ci				    assert_type,			       \
10608c2ecf20Sopenharmony_ci				    left,				       \
10618c2ecf20Sopenharmony_ci				    right,				       \
10628c2ecf20Sopenharmony_ci				    fmt,				       \
10638c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci#define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right)	       \
10668c2ecf20Sopenharmony_ci	KUNIT_BINARY_GE_MSG_ASSERTION(test,				       \
10678c2ecf20Sopenharmony_ci				      assert_type,			       \
10688c2ecf20Sopenharmony_ci				      left,				       \
10698c2ecf20Sopenharmony_ci				      right,				       \
10708c2ecf20Sopenharmony_ci				      NULL)
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test,				       \
10738c2ecf20Sopenharmony_ci					  assert_type,			       \
10748c2ecf20Sopenharmony_ci					  left,				       \
10758c2ecf20Sopenharmony_ci					  right,			       \
10768c2ecf20Sopenharmony_ci					  fmt,				       \
10778c2ecf20Sopenharmony_ci					  ...)				       \
10788c2ecf20Sopenharmony_ci	KUNIT_BASE_GE_MSG_ASSERTION(test,				       \
10798c2ecf20Sopenharmony_ci				    kunit_binary_ptr_assert,		       \
10808c2ecf20Sopenharmony_ci				    KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
10818c2ecf20Sopenharmony_ci				    assert_type,			       \
10828c2ecf20Sopenharmony_ci				    left,				       \
10838c2ecf20Sopenharmony_ci				    right,				       \
10848c2ecf20Sopenharmony_ci				    fmt,				       \
10858c2ecf20Sopenharmony_ci				    ##__VA_ARGS__)
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci#define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right)	       \
10888c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test,				       \
10898c2ecf20Sopenharmony_ci					  assert_type,			       \
10908c2ecf20Sopenharmony_ci					  left,				       \
10918c2ecf20Sopenharmony_ci					  right,			       \
10928c2ecf20Sopenharmony_ci					  NULL)
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci#define KUNIT_BINARY_STR_ASSERTION(test,				       \
10958c2ecf20Sopenharmony_ci				   assert_type,				       \
10968c2ecf20Sopenharmony_ci				   left,				       \
10978c2ecf20Sopenharmony_ci				   op,					       \
10988c2ecf20Sopenharmony_ci				   right,				       \
10998c2ecf20Sopenharmony_ci				   fmt,					       \
11008c2ecf20Sopenharmony_ci				   ...)					       \
11018c2ecf20Sopenharmony_cido {									       \
11028c2ecf20Sopenharmony_ci	typeof(left) __left = (left);					       \
11038c2ecf20Sopenharmony_ci	typeof(right) __right = (right);				       \
11048c2ecf20Sopenharmony_ci									       \
11058c2ecf20Sopenharmony_ci	KUNIT_ASSERTION(test,						       \
11068c2ecf20Sopenharmony_ci			strcmp(__left, __right) op 0,			       \
11078c2ecf20Sopenharmony_ci			kunit_binary_str_assert,			       \
11088c2ecf20Sopenharmony_ci			KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test,	       \
11098c2ecf20Sopenharmony_ci							assert_type,	       \
11108c2ecf20Sopenharmony_ci							#op,		       \
11118c2ecf20Sopenharmony_ci							#left,		       \
11128c2ecf20Sopenharmony_ci							__left,		       \
11138c2ecf20Sopenharmony_ci							#right,		       \
11148c2ecf20Sopenharmony_ci							__right),	       \
11158c2ecf20Sopenharmony_ci			fmt,						       \
11168c2ecf20Sopenharmony_ci			##__VA_ARGS__);					       \
11178c2ecf20Sopenharmony_ci} while (0)
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci#define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,				       \
11208c2ecf20Sopenharmony_ci					  assert_type,			       \
11218c2ecf20Sopenharmony_ci					  left,				       \
11228c2ecf20Sopenharmony_ci					  right,			       \
11238c2ecf20Sopenharmony_ci					  fmt,				       \
11248c2ecf20Sopenharmony_ci					  ...)				       \
11258c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_ASSERTION(test,				       \
11268c2ecf20Sopenharmony_ci				   assert_type,				       \
11278c2ecf20Sopenharmony_ci				   left, ==, right,			       \
11288c2ecf20Sopenharmony_ci				   fmt,					       \
11298c2ecf20Sopenharmony_ci				   ##__VA_ARGS__)
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ci#define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right)	       \
11328c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,				       \
11338c2ecf20Sopenharmony_ci					  assert_type,			       \
11348c2ecf20Sopenharmony_ci					  left,				       \
11358c2ecf20Sopenharmony_ci					  right,			       \
11368c2ecf20Sopenharmony_ci					  NULL)
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci#define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,				       \
11398c2ecf20Sopenharmony_ci					  assert_type,			       \
11408c2ecf20Sopenharmony_ci					  left,				       \
11418c2ecf20Sopenharmony_ci					  right,			       \
11428c2ecf20Sopenharmony_ci					  fmt,				       \
11438c2ecf20Sopenharmony_ci					  ...)				       \
11448c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_ASSERTION(test,				       \
11458c2ecf20Sopenharmony_ci				   assert_type,				       \
11468c2ecf20Sopenharmony_ci				   left, !=, right,			       \
11478c2ecf20Sopenharmony_ci				   fmt,					       \
11488c2ecf20Sopenharmony_ci				   ##__VA_ARGS__)
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci#define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right)	       \
11518c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,				       \
11528c2ecf20Sopenharmony_ci					  assert_type,			       \
11538c2ecf20Sopenharmony_ci					  left,				       \
11548c2ecf20Sopenharmony_ci					  right,			       \
11558c2ecf20Sopenharmony_ci					  NULL)
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci#define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,			       \
11588c2ecf20Sopenharmony_ci						assert_type,		       \
11598c2ecf20Sopenharmony_ci						ptr,			       \
11608c2ecf20Sopenharmony_ci						fmt,			       \
11618c2ecf20Sopenharmony_ci						...)			       \
11628c2ecf20Sopenharmony_cido {									       \
11638c2ecf20Sopenharmony_ci	typeof(ptr) __ptr = (ptr);					       \
11648c2ecf20Sopenharmony_ci									       \
11658c2ecf20Sopenharmony_ci	KUNIT_ASSERTION(test,						       \
11668c2ecf20Sopenharmony_ci			!IS_ERR_OR_NULL(__ptr),				       \
11678c2ecf20Sopenharmony_ci			kunit_ptr_not_err_assert,			       \
11688c2ecf20Sopenharmony_ci			KUNIT_INIT_PTR_NOT_ERR_STRUCT(test,		       \
11698c2ecf20Sopenharmony_ci						      assert_type,	       \
11708c2ecf20Sopenharmony_ci						      #ptr,		       \
11718c2ecf20Sopenharmony_ci						      __ptr),		       \
11728c2ecf20Sopenharmony_ci			fmt,						       \
11738c2ecf20Sopenharmony_ci			##__VA_ARGS__);					       \
11748c2ecf20Sopenharmony_ci} while (0)
11758c2ecf20Sopenharmony_ci
11768c2ecf20Sopenharmony_ci#define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr)	       \
11778c2ecf20Sopenharmony_ci	KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,			       \
11788c2ecf20Sopenharmony_ci						assert_type,		       \
11798c2ecf20Sopenharmony_ci						ptr,			       \
11808c2ecf20Sopenharmony_ci						NULL)
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci/**
11838c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
11848c2ecf20Sopenharmony_ci * @test: The test context object.
11858c2ecf20Sopenharmony_ci * @condition: an arbitrary boolean expression. The test fails when this does
11868c2ecf20Sopenharmony_ci * not evaluate to true.
11878c2ecf20Sopenharmony_ci *
11888c2ecf20Sopenharmony_ci * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
11898c2ecf20Sopenharmony_ci * to fail when the specified condition is not met; however, it will not prevent
11908c2ecf20Sopenharmony_ci * the test case from continuing to run; this is otherwise known as an
11918c2ecf20Sopenharmony_ci * *expectation failure*.
11928c2ecf20Sopenharmony_ci */
11938c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_TRUE(test, condition) \
11948c2ecf20Sopenharmony_ci	KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...)		       \
11978c2ecf20Sopenharmony_ci	KUNIT_TRUE_MSG_ASSERTION(test,					       \
11988c2ecf20Sopenharmony_ci				 KUNIT_EXPECTATION,			       \
11998c2ecf20Sopenharmony_ci				 condition,				       \
12008c2ecf20Sopenharmony_ci				 fmt,					       \
12018c2ecf20Sopenharmony_ci				 ##__VA_ARGS__)
12028c2ecf20Sopenharmony_ci
12038c2ecf20Sopenharmony_ci/**
12048c2ecf20Sopenharmony_ci * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
12058c2ecf20Sopenharmony_ci * @test: The test context object.
12068c2ecf20Sopenharmony_ci * @condition: an arbitrary boolean expression. The test fails when this does
12078c2ecf20Sopenharmony_ci * not evaluate to false.
12088c2ecf20Sopenharmony_ci *
12098c2ecf20Sopenharmony_ci * Sets an expectation that @condition evaluates to false. See
12108c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE() for more information.
12118c2ecf20Sopenharmony_ci */
12128c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_FALSE(test, condition) \
12138c2ecf20Sopenharmony_ci	KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...)		       \
12168c2ecf20Sopenharmony_ci	KUNIT_FALSE_MSG_ASSERTION(test,					       \
12178c2ecf20Sopenharmony_ci				  KUNIT_EXPECTATION,			       \
12188c2ecf20Sopenharmony_ci				  condition,				       \
12198c2ecf20Sopenharmony_ci				  fmt,					       \
12208c2ecf20Sopenharmony_ci				  ##__VA_ARGS__)
12218c2ecf20Sopenharmony_ci
12228c2ecf20Sopenharmony_ci/**
12238c2ecf20Sopenharmony_ci * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
12248c2ecf20Sopenharmony_ci * @test: The test context object.
12258c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
12268c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
12278c2ecf20Sopenharmony_ci *
12288c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are
12298c2ecf20Sopenharmony_ci * equal. This is semantically equivalent to
12308c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
12318c2ecf20Sopenharmony_ci * more information.
12328c2ecf20Sopenharmony_ci */
12338c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_EQ(test, left, right) \
12348c2ecf20Sopenharmony_ci	KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
12358c2ecf20Sopenharmony_ci
12368c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...)		       \
12378c2ecf20Sopenharmony_ci	KUNIT_BINARY_EQ_MSG_ASSERTION(test,				       \
12388c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
12398c2ecf20Sopenharmony_ci				      left,				       \
12408c2ecf20Sopenharmony_ci				      right,				       \
12418c2ecf20Sopenharmony_ci				      fmt,				       \
12428c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci/**
12458c2ecf20Sopenharmony_ci * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
12468c2ecf20Sopenharmony_ci * @test: The test context object.
12478c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a pointer.
12488c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a pointer.
12498c2ecf20Sopenharmony_ci *
12508c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are
12518c2ecf20Sopenharmony_ci * equal. This is semantically equivalent to
12528c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
12538c2ecf20Sopenharmony_ci * more information.
12548c2ecf20Sopenharmony_ci */
12558c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_PTR_EQ(test, left, right)				       \
12568c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_EQ_ASSERTION(test,				       \
12578c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
12588c2ecf20Sopenharmony_ci				      left,				       \
12598c2ecf20Sopenharmony_ci				      right)
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...)		       \
12628c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,				       \
12638c2ecf20Sopenharmony_ci					  KUNIT_EXPECTATION,		       \
12648c2ecf20Sopenharmony_ci					  left,				       \
12658c2ecf20Sopenharmony_ci					  right,			       \
12668c2ecf20Sopenharmony_ci					  fmt,				       \
12678c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci/**
12708c2ecf20Sopenharmony_ci * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
12718c2ecf20Sopenharmony_ci * @test: The test context object.
12728c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
12738c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
12748c2ecf20Sopenharmony_ci *
12758c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are not
12768c2ecf20Sopenharmony_ci * equal. This is semantically equivalent to
12778c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
12788c2ecf20Sopenharmony_ci * more information.
12798c2ecf20Sopenharmony_ci */
12808c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_NE(test, left, right) \
12818c2ecf20Sopenharmony_ci	KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...)		       \
12848c2ecf20Sopenharmony_ci	KUNIT_BINARY_NE_MSG_ASSERTION(test,				       \
12858c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
12868c2ecf20Sopenharmony_ci				      left,				       \
12878c2ecf20Sopenharmony_ci				      right,				       \
12888c2ecf20Sopenharmony_ci				      fmt,				       \
12898c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
12908c2ecf20Sopenharmony_ci
12918c2ecf20Sopenharmony_ci/**
12928c2ecf20Sopenharmony_ci * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
12938c2ecf20Sopenharmony_ci * @test: The test context object.
12948c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a pointer.
12958c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a pointer.
12968c2ecf20Sopenharmony_ci *
12978c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are not
12988c2ecf20Sopenharmony_ci * equal. This is semantically equivalent to
12998c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
13008c2ecf20Sopenharmony_ci * more information.
13018c2ecf20Sopenharmony_ci */
13028c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_PTR_NE(test, left, right)				       \
13038c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_NE_ASSERTION(test,				       \
13048c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
13058c2ecf20Sopenharmony_ci				      left,				       \
13068c2ecf20Sopenharmony_ci				      right)
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...)		       \
13098c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,				       \
13108c2ecf20Sopenharmony_ci					  KUNIT_EXPECTATION,		       \
13118c2ecf20Sopenharmony_ci					  left,				       \
13128c2ecf20Sopenharmony_ci					  right,			       \
13138c2ecf20Sopenharmony_ci					  fmt,				       \
13148c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
13158c2ecf20Sopenharmony_ci
13168c2ecf20Sopenharmony_ci/**
13178c2ecf20Sopenharmony_ci * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
13188c2ecf20Sopenharmony_ci * @test: The test context object.
13198c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
13208c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
13218c2ecf20Sopenharmony_ci *
13228c2ecf20Sopenharmony_ci * Sets an expectation that the value that @left evaluates to is less than the
13238c2ecf20Sopenharmony_ci * value that @right evaluates to. This is semantically equivalent to
13248c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
13258c2ecf20Sopenharmony_ci * more information.
13268c2ecf20Sopenharmony_ci */
13278c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_LT(test, left, right) \
13288c2ecf20Sopenharmony_ci	KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
13298c2ecf20Sopenharmony_ci
13308c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...)		       \
13318c2ecf20Sopenharmony_ci	KUNIT_BINARY_LT_MSG_ASSERTION(test,				       \
13328c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
13338c2ecf20Sopenharmony_ci				      left,				       \
13348c2ecf20Sopenharmony_ci				      right,				       \
13358c2ecf20Sopenharmony_ci				      fmt,				       \
13368c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_ci/**
13398c2ecf20Sopenharmony_ci * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
13408c2ecf20Sopenharmony_ci * @test: The test context object.
13418c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
13428c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
13438c2ecf20Sopenharmony_ci *
13448c2ecf20Sopenharmony_ci * Sets an expectation that the value that @left evaluates to is less than or
13458c2ecf20Sopenharmony_ci * equal to the value that @right evaluates to. Semantically this is equivalent
13468c2ecf20Sopenharmony_ci * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
13478c2ecf20Sopenharmony_ci * more information.
13488c2ecf20Sopenharmony_ci */
13498c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_LE(test, left, right) \
13508c2ecf20Sopenharmony_ci	KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
13518c2ecf20Sopenharmony_ci
13528c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...)		       \
13538c2ecf20Sopenharmony_ci	KUNIT_BINARY_LE_MSG_ASSERTION(test,				       \
13548c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
13558c2ecf20Sopenharmony_ci				      left,				       \
13568c2ecf20Sopenharmony_ci				      right,				       \
13578c2ecf20Sopenharmony_ci				      fmt,				       \
13588c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci/**
13618c2ecf20Sopenharmony_ci * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
13628c2ecf20Sopenharmony_ci * @test: The test context object.
13638c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
13648c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
13658c2ecf20Sopenharmony_ci *
13668c2ecf20Sopenharmony_ci * Sets an expectation that the value that @left evaluates to is greater than
13678c2ecf20Sopenharmony_ci * the value that @right evaluates to. This is semantically equivalent to
13688c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
13698c2ecf20Sopenharmony_ci * more information.
13708c2ecf20Sopenharmony_ci */
13718c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_GT(test, left, right) \
13728c2ecf20Sopenharmony_ci	KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...)		       \
13758c2ecf20Sopenharmony_ci	KUNIT_BINARY_GT_MSG_ASSERTION(test,				       \
13768c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
13778c2ecf20Sopenharmony_ci				      left,				       \
13788c2ecf20Sopenharmony_ci				      right,				       \
13798c2ecf20Sopenharmony_ci				      fmt,				       \
13808c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci/**
13838c2ecf20Sopenharmony_ci * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
13848c2ecf20Sopenharmony_ci * @test: The test context object.
13858c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
13868c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
13878c2ecf20Sopenharmony_ci *
13888c2ecf20Sopenharmony_ci * Sets an expectation that the value that @left evaluates to is greater than
13898c2ecf20Sopenharmony_ci * the value that @right evaluates to. This is semantically equivalent to
13908c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
13918c2ecf20Sopenharmony_ci * more information.
13928c2ecf20Sopenharmony_ci */
13938c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_GE(test, left, right) \
13948c2ecf20Sopenharmony_ci	KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
13958c2ecf20Sopenharmony_ci
13968c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...)		       \
13978c2ecf20Sopenharmony_ci	KUNIT_BINARY_GE_MSG_ASSERTION(test,				       \
13988c2ecf20Sopenharmony_ci				      KUNIT_EXPECTATION,		       \
13998c2ecf20Sopenharmony_ci				      left,				       \
14008c2ecf20Sopenharmony_ci				      right,				       \
14018c2ecf20Sopenharmony_ci				      fmt,				       \
14028c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci/**
14058c2ecf20Sopenharmony_ci * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
14068c2ecf20Sopenharmony_ci * @test: The test context object.
14078c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a null terminated string.
14088c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a null terminated string.
14098c2ecf20Sopenharmony_ci *
14108c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are
14118c2ecf20Sopenharmony_ci * equal. This is semantically equivalent to
14128c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
14138c2ecf20Sopenharmony_ci * for more information.
14148c2ecf20Sopenharmony_ci */
14158c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_STREQ(test, left, right) \
14168c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
14178c2ecf20Sopenharmony_ci
14188c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...)		       \
14198c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,				       \
14208c2ecf20Sopenharmony_ci					  KUNIT_EXPECTATION,		       \
14218c2ecf20Sopenharmony_ci					  left,				       \
14228c2ecf20Sopenharmony_ci					  right,			       \
14238c2ecf20Sopenharmony_ci					  fmt,				       \
14248c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
14258c2ecf20Sopenharmony_ci
14268c2ecf20Sopenharmony_ci/**
14278c2ecf20Sopenharmony_ci * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
14288c2ecf20Sopenharmony_ci * @test: The test context object.
14298c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a null terminated string.
14308c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a null terminated string.
14318c2ecf20Sopenharmony_ci *
14328c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are
14338c2ecf20Sopenharmony_ci * not equal. This is semantically equivalent to
14348c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
14358c2ecf20Sopenharmony_ci * for more information.
14368c2ecf20Sopenharmony_ci */
14378c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_STRNEQ(test, left, right) \
14388c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
14398c2ecf20Sopenharmony_ci
14408c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...)		       \
14418c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,				       \
14428c2ecf20Sopenharmony_ci					  KUNIT_EXPECTATION,		       \
14438c2ecf20Sopenharmony_ci					  left,				       \
14448c2ecf20Sopenharmony_ci					  right,			       \
14458c2ecf20Sopenharmony_ci					  fmt,				       \
14468c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
14478c2ecf20Sopenharmony_ci
14488c2ecf20Sopenharmony_ci/**
14498c2ecf20Sopenharmony_ci * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
14508c2ecf20Sopenharmony_ci * @test: The test context object.
14518c2ecf20Sopenharmony_ci * @ptr: an arbitrary pointer.
14528c2ecf20Sopenharmony_ci *
14538c2ecf20Sopenharmony_ci * Sets an expectation that the value that @ptr evaluates to is not null and not
14548c2ecf20Sopenharmony_ci * an errno stored in a pointer. This is semantically equivalent to
14558c2ecf20Sopenharmony_ci * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
14568c2ecf20Sopenharmony_ci * more information.
14578c2ecf20Sopenharmony_ci */
14588c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
14598c2ecf20Sopenharmony_ci	KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
14608c2ecf20Sopenharmony_ci
14618c2ecf20Sopenharmony_ci#define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...)		       \
14628c2ecf20Sopenharmony_ci	KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,			       \
14638c2ecf20Sopenharmony_ci						KUNIT_EXPECTATION,	       \
14648c2ecf20Sopenharmony_ci						ptr,			       \
14658c2ecf20Sopenharmony_ci						fmt,			       \
14668c2ecf20Sopenharmony_ci						##__VA_ARGS__)
14678c2ecf20Sopenharmony_ci
14688c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
14698c2ecf20Sopenharmony_ci	KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
14708c2ecf20Sopenharmony_ci
14718c2ecf20Sopenharmony_ci/**
14728c2ecf20Sopenharmony_ci * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
14738c2ecf20Sopenharmony_ci * @test: The test context object.
14748c2ecf20Sopenharmony_ci * @condition: an arbitrary boolean expression. The test fails and aborts when
14758c2ecf20Sopenharmony_ci * this does not evaluate to true.
14768c2ecf20Sopenharmony_ci *
14778c2ecf20Sopenharmony_ci * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
14788c2ecf20Sopenharmony_ci * fail *and immediately abort* when the specified condition is not met. Unlike
14798c2ecf20Sopenharmony_ci * an expectation failure, it will prevent the test case from continuing to run;
14808c2ecf20Sopenharmony_ci * this is otherwise known as an *assertion failure*.
14818c2ecf20Sopenharmony_ci */
14828c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_TRUE(test, condition) \
14838c2ecf20Sopenharmony_ci	KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
14848c2ecf20Sopenharmony_ci
14858c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...)		       \
14868c2ecf20Sopenharmony_ci	KUNIT_TRUE_MSG_ASSERTION(test,					       \
14878c2ecf20Sopenharmony_ci				 KUNIT_ASSERTION,			       \
14888c2ecf20Sopenharmony_ci				 condition,				       \
14898c2ecf20Sopenharmony_ci				 fmt,					       \
14908c2ecf20Sopenharmony_ci				 ##__VA_ARGS__)
14918c2ecf20Sopenharmony_ci
14928c2ecf20Sopenharmony_ci/**
14938c2ecf20Sopenharmony_ci * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
14948c2ecf20Sopenharmony_ci * @test: The test context object.
14958c2ecf20Sopenharmony_ci * @condition: an arbitrary boolean expression.
14968c2ecf20Sopenharmony_ci *
14978c2ecf20Sopenharmony_ci * Sets an assertion that the value that @condition evaluates to is false. This
14988c2ecf20Sopenharmony_ci * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
14998c2ecf20Sopenharmony_ci * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
15008c2ecf20Sopenharmony_ci */
15018c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_FALSE(test, condition) \
15028c2ecf20Sopenharmony_ci	KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
15038c2ecf20Sopenharmony_ci
15048c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...)		       \
15058c2ecf20Sopenharmony_ci	KUNIT_FALSE_MSG_ASSERTION(test,					       \
15068c2ecf20Sopenharmony_ci				  KUNIT_ASSERTION,			       \
15078c2ecf20Sopenharmony_ci				  condition,				       \
15088c2ecf20Sopenharmony_ci				  fmt,					       \
15098c2ecf20Sopenharmony_ci				  ##__VA_ARGS__)
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci/**
15128c2ecf20Sopenharmony_ci * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
15138c2ecf20Sopenharmony_ci * @test: The test context object.
15148c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
15158c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
15168c2ecf20Sopenharmony_ci *
15178c2ecf20Sopenharmony_ci * Sets an assertion that the values that @left and @right evaluate to are
15188c2ecf20Sopenharmony_ci * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
15198c2ecf20Sopenharmony_ci * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
15208c2ecf20Sopenharmony_ci */
15218c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_EQ(test, left, right) \
15228c2ecf20Sopenharmony_ci	KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
15238c2ecf20Sopenharmony_ci
15248c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...)		       \
15258c2ecf20Sopenharmony_ci	KUNIT_BINARY_EQ_MSG_ASSERTION(test,				       \
15268c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
15278c2ecf20Sopenharmony_ci				      left,				       \
15288c2ecf20Sopenharmony_ci				      right,				       \
15298c2ecf20Sopenharmony_ci				      fmt,				       \
15308c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
15318c2ecf20Sopenharmony_ci
15328c2ecf20Sopenharmony_ci/**
15338c2ecf20Sopenharmony_ci * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
15348c2ecf20Sopenharmony_ci * @test: The test context object.
15358c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a pointer.
15368c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a pointer.
15378c2ecf20Sopenharmony_ci *
15388c2ecf20Sopenharmony_ci * Sets an assertion that the values that @left and @right evaluate to are
15398c2ecf20Sopenharmony_ci * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
15408c2ecf20Sopenharmony_ci * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
15418c2ecf20Sopenharmony_ci */
15428c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_PTR_EQ(test, left, right) \
15438c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
15448c2ecf20Sopenharmony_ci
15458c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...)		       \
15468c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,				       \
15478c2ecf20Sopenharmony_ci					  KUNIT_ASSERTION,		       \
15488c2ecf20Sopenharmony_ci					  left,				       \
15498c2ecf20Sopenharmony_ci					  right,			       \
15508c2ecf20Sopenharmony_ci					  fmt,				       \
15518c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
15528c2ecf20Sopenharmony_ci
15538c2ecf20Sopenharmony_ci/**
15548c2ecf20Sopenharmony_ci * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
15558c2ecf20Sopenharmony_ci * @test: The test context object.
15568c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
15578c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
15588c2ecf20Sopenharmony_ci *
15598c2ecf20Sopenharmony_ci * Sets an assertion that the values that @left and @right evaluate to are not
15608c2ecf20Sopenharmony_ci * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
15618c2ecf20Sopenharmony_ci * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
15628c2ecf20Sopenharmony_ci */
15638c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_NE(test, left, right) \
15648c2ecf20Sopenharmony_ci	KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
15658c2ecf20Sopenharmony_ci
15668c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...)		       \
15678c2ecf20Sopenharmony_ci	KUNIT_BINARY_NE_MSG_ASSERTION(test,				       \
15688c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
15698c2ecf20Sopenharmony_ci				      left,				       \
15708c2ecf20Sopenharmony_ci				      right,				       \
15718c2ecf20Sopenharmony_ci				      fmt,				       \
15728c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
15738c2ecf20Sopenharmony_ci
15748c2ecf20Sopenharmony_ci/**
15758c2ecf20Sopenharmony_ci * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
15768c2ecf20Sopenharmony_ci * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
15778c2ecf20Sopenharmony_ci * @test: The test context object.
15788c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a pointer.
15798c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a pointer.
15808c2ecf20Sopenharmony_ci *
15818c2ecf20Sopenharmony_ci * Sets an assertion that the values that @left and @right evaluate to are not
15828c2ecf20Sopenharmony_ci * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
15838c2ecf20Sopenharmony_ci * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
15848c2ecf20Sopenharmony_ci */
15858c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_PTR_NE(test, left, right) \
15868c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
15878c2ecf20Sopenharmony_ci
15888c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...)		       \
15898c2ecf20Sopenharmony_ci	KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,				       \
15908c2ecf20Sopenharmony_ci					  KUNIT_ASSERTION,		       \
15918c2ecf20Sopenharmony_ci					  left,				       \
15928c2ecf20Sopenharmony_ci					  right,			       \
15938c2ecf20Sopenharmony_ci					  fmt,				       \
15948c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
15958c2ecf20Sopenharmony_ci/**
15968c2ecf20Sopenharmony_ci * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
15978c2ecf20Sopenharmony_ci * @test: The test context object.
15988c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
15998c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
16008c2ecf20Sopenharmony_ci *
16018c2ecf20Sopenharmony_ci * Sets an assertion that the value that @left evaluates to is less than the
16028c2ecf20Sopenharmony_ci * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
16038c2ecf20Sopenharmony_ci * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
16048c2ecf20Sopenharmony_ci * is not met.
16058c2ecf20Sopenharmony_ci */
16068c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_LT(test, left, right) \
16078c2ecf20Sopenharmony_ci	KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
16088c2ecf20Sopenharmony_ci
16098c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...)		       \
16108c2ecf20Sopenharmony_ci	KUNIT_BINARY_LT_MSG_ASSERTION(test,				       \
16118c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
16128c2ecf20Sopenharmony_ci				      left,				       \
16138c2ecf20Sopenharmony_ci				      right,				       \
16148c2ecf20Sopenharmony_ci				      fmt,				       \
16158c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
16168c2ecf20Sopenharmony_ci/**
16178c2ecf20Sopenharmony_ci * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
16188c2ecf20Sopenharmony_ci * @test: The test context object.
16198c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
16208c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
16218c2ecf20Sopenharmony_ci *
16228c2ecf20Sopenharmony_ci * Sets an assertion that the value that @left evaluates to is less than or
16238c2ecf20Sopenharmony_ci * equal to the value that @right evaluates to. This is the same as
16248c2ecf20Sopenharmony_ci * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
16258c2ecf20Sopenharmony_ci * KUNIT_ASSERT_TRUE()) when the assertion is not met.
16268c2ecf20Sopenharmony_ci */
16278c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_LE(test, left, right) \
16288c2ecf20Sopenharmony_ci	KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
16298c2ecf20Sopenharmony_ci
16308c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...)		       \
16318c2ecf20Sopenharmony_ci	KUNIT_BINARY_LE_MSG_ASSERTION(test,				       \
16328c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
16338c2ecf20Sopenharmony_ci				      left,				       \
16348c2ecf20Sopenharmony_ci				      right,				       \
16358c2ecf20Sopenharmony_ci				      fmt,				       \
16368c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_ci/**
16398c2ecf20Sopenharmony_ci * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
16408c2ecf20Sopenharmony_ci * @test: The test context object.
16418c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
16428c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
16438c2ecf20Sopenharmony_ci *
16448c2ecf20Sopenharmony_ci * Sets an assertion that the value that @left evaluates to is greater than the
16458c2ecf20Sopenharmony_ci * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
16468c2ecf20Sopenharmony_ci * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
16478c2ecf20Sopenharmony_ci * is not met.
16488c2ecf20Sopenharmony_ci */
16498c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_GT(test, left, right) \
16508c2ecf20Sopenharmony_ci	KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...)		       \
16538c2ecf20Sopenharmony_ci	KUNIT_BINARY_GT_MSG_ASSERTION(test,				       \
16548c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
16558c2ecf20Sopenharmony_ci				      left,				       \
16568c2ecf20Sopenharmony_ci				      right,				       \
16578c2ecf20Sopenharmony_ci				      fmt,				       \
16588c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
16598c2ecf20Sopenharmony_ci
16608c2ecf20Sopenharmony_ci/**
16618c2ecf20Sopenharmony_ci * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
16628c2ecf20Sopenharmony_ci * @test: The test context object.
16638c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a primitive C type.
16648c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a primitive C type.
16658c2ecf20Sopenharmony_ci *
16668c2ecf20Sopenharmony_ci * Sets an assertion that the value that @left evaluates to is greater than the
16678c2ecf20Sopenharmony_ci * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
16688c2ecf20Sopenharmony_ci * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
16698c2ecf20Sopenharmony_ci * is not met.
16708c2ecf20Sopenharmony_ci */
16718c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_GE(test, left, right) \
16728c2ecf20Sopenharmony_ci	KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...)		       \
16758c2ecf20Sopenharmony_ci	KUNIT_BINARY_GE_MSG_ASSERTION(test,				       \
16768c2ecf20Sopenharmony_ci				      KUNIT_ASSERTION,			       \
16778c2ecf20Sopenharmony_ci				      left,				       \
16788c2ecf20Sopenharmony_ci				      right,				       \
16798c2ecf20Sopenharmony_ci				      fmt,				       \
16808c2ecf20Sopenharmony_ci				      ##__VA_ARGS__)
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_ci/**
16838c2ecf20Sopenharmony_ci * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
16848c2ecf20Sopenharmony_ci * @test: The test context object.
16858c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a null terminated string.
16868c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a null terminated string.
16878c2ecf20Sopenharmony_ci *
16888c2ecf20Sopenharmony_ci * Sets an assertion that the values that @left and @right evaluate to are
16898c2ecf20Sopenharmony_ci * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
16908c2ecf20Sopenharmony_ci * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
16918c2ecf20Sopenharmony_ci */
16928c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_STREQ(test, left, right) \
16938c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
16948c2ecf20Sopenharmony_ci
16958c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...)		       \
16968c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,				       \
16978c2ecf20Sopenharmony_ci					  KUNIT_ASSERTION,		       \
16988c2ecf20Sopenharmony_ci					  left,				       \
16998c2ecf20Sopenharmony_ci					  right,			       \
17008c2ecf20Sopenharmony_ci					  fmt,				       \
17018c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
17028c2ecf20Sopenharmony_ci
17038c2ecf20Sopenharmony_ci/**
17048c2ecf20Sopenharmony_ci * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
17058c2ecf20Sopenharmony_ci * @test: The test context object.
17068c2ecf20Sopenharmony_ci * @left: an arbitrary expression that evaluates to a null terminated string.
17078c2ecf20Sopenharmony_ci * @right: an arbitrary expression that evaluates to a null terminated string.
17088c2ecf20Sopenharmony_ci *
17098c2ecf20Sopenharmony_ci * Sets an expectation that the values that @left and @right evaluate to are
17108c2ecf20Sopenharmony_ci * not equal. This is semantically equivalent to
17118c2ecf20Sopenharmony_ci * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
17128c2ecf20Sopenharmony_ci * for more information.
17138c2ecf20Sopenharmony_ci */
17148c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_STRNEQ(test, left, right) \
17158c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...)		       \
17188c2ecf20Sopenharmony_ci	KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,				       \
17198c2ecf20Sopenharmony_ci					  KUNIT_ASSERTION,		       \
17208c2ecf20Sopenharmony_ci					  left,				       \
17218c2ecf20Sopenharmony_ci					  right,			       \
17228c2ecf20Sopenharmony_ci					  fmt,				       \
17238c2ecf20Sopenharmony_ci					  ##__VA_ARGS__)
17248c2ecf20Sopenharmony_ci
17258c2ecf20Sopenharmony_ci/**
17268c2ecf20Sopenharmony_ci * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
17278c2ecf20Sopenharmony_ci * @test: The test context object.
17288c2ecf20Sopenharmony_ci * @ptr: an arbitrary pointer.
17298c2ecf20Sopenharmony_ci *
17308c2ecf20Sopenharmony_ci * Sets an assertion that the value that @ptr evaluates to is not null and not
17318c2ecf20Sopenharmony_ci * an errno stored in a pointer. This is the same as
17328c2ecf20Sopenharmony_ci * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
17338c2ecf20Sopenharmony_ci * KUNIT_ASSERT_TRUE()) when the assertion is not met.
17348c2ecf20Sopenharmony_ci */
17358c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
17368c2ecf20Sopenharmony_ci	KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ci#define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...)		       \
17398c2ecf20Sopenharmony_ci	KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,			       \
17408c2ecf20Sopenharmony_ci						KUNIT_ASSERTION,	       \
17418c2ecf20Sopenharmony_ci						ptr,			       \
17428c2ecf20Sopenharmony_ci						fmt,			       \
17438c2ecf20Sopenharmony_ci						##__VA_ARGS__)
17448c2ecf20Sopenharmony_ci
17458c2ecf20Sopenharmony_ci#endif /* _KUNIT_TEST_H */
1746