Test API¶
This file documents all of the standard testing API.
- enumkunit_status¶
Type of result for a test or test suite
Constants
KUNIT_SUCCESSDenotes the test suite has not failed nor been skipped
KUNIT_FAILUREDenotes the test has failed.
KUNIT_SKIPPEDDenotes the test has been skipped.
- structkunit_case¶
represents an individual test case.
Definition:
struct kunit_case { void (*run_case)(struct kunit *test); const char *name; const void* (*generate_params)(struct kunit *test, const void *prev, char *desc); struct kunit_attributes attr; int (*param_init)(struct kunit *test); void (*param_exit)(struct kunit *test);};Members
run_casethe function representing the actual test case.
namethe name of the test case.
generate_paramsthe generator function for parameterized tests.
attrthe attributes associated with the test
param_initThe init function to run before a parameterized test.
param_exitThe exit function to run after a parameterized test.
Description
A test case is a function with the signature,void(*)(structkunit*)that makes expectations and assertions (seeKUNIT_EXPECT_TRUE() andKUNIT_ASSERT_TRUE()) about code under test. Each test case is associatedwith astructkunit_suite and will be run after the suite’s initfunction and followed by the suite’s exit function.
A test case should be static and should only be created with theKUNIT_CASE() macro; additionally, every array of test cases should beterminated with an empty test case.
Example
voidadd_test_basic(structkunit*test){KUNIT_EXPECT_EQ(test,1,add(1,0));KUNIT_EXPECT_EQ(test,2,add(1,1));KUNIT_EXPECT_EQ(test,0,add(-1,1));KUNIT_EXPECT_EQ(test,INT_MAX,add(0,INT_MAX));KUNIT_EXPECT_EQ(test,-1,add(INT_MAX,INT_MIN));}staticstructkunit_caseexample_test_cases[]={KUNIT_CASE(add_test_basic),{}};
- KUNIT_CASE¶
KUNIT_CASE(test_name)
A helper for creating a
structkunit_case
Parameters
test_namea reference to a test case function.
Description
Takes a symbol for a function representing a test case and creates astructkunit_case object from it. See the documentation forstructkunit_case for an example on how to use it.
- KUNIT_CASE_ATTR¶
KUNIT_CASE_ATTR(test_name,attributes)
A helper for creating a
structkunit_casewith attributes
Parameters
test_namea reference to a test case function.
attributesa reference to a
structkunit_attributesobject containingtest attributes
- KUNIT_CASE_SLOW¶
KUNIT_CASE_SLOW(test_name)
A helper for creating a
structkunit_casewith the slow attribute
Parameters
test_namea reference to a test case function.
- KUNIT_CASE_PARAM¶
KUNIT_CASE_PARAM(test_name,gen_params)
A helper for creation a parameterized
structkunit_case
Parameters
test_namea reference to a test case function.
gen_paramsa reference to a parameter generator function.
Description
The generator function:
const void* gen_params(const void *prev, char *desc)
is used to lazily generate a series of arbitrarily typed values that fit intoa void*. The argumentprev is the previously returned value, which should beused to derive the next value;prev is set to NULL on the initial generatorcall. When no more values are available, the generator must return NULL.Optionally write a string intodesc (size of KUNIT_PARAM_DESC_SIZE)describing the parameter.
- KUNIT_CASE_PARAM_ATTR¶
KUNIT_CASE_PARAM_ATTR(test_name,gen_params,attributes)
A helper for creating a parameterized
structkunit_casewith attributes
Parameters
test_namea reference to a test case function.
gen_paramsa reference to a parameter generator function.
attributesa reference to a
structkunit_attributesobject containingtest attributes
- KUNIT_CASE_PARAM_WITH_INIT¶
KUNIT_CASE_PARAM_WITH_INIT(test_name,gen_params,init,exit)
Define a parameterized KUnit test case with custom
param_init()andparam_exit()functions.
Parameters
test_nameThe function implementing the test case.
gen_paramsThe function to generate parameters for the test case.
initA reference to the
param_init()function to run before a parameterized test.exitA reference to the
param_exit()function to run after a parameterized test.
Description
Provides the option to registerparam_init() andparam_exit() functions.param_init/exit will be passed the parameterized test context and run oncebefore and once after the parameterized test. The init function can be usedto add resources to share between parameter runs, pass parameter arrays,and any other setup logic. The exit function can be used to clean up resourcesthat were not managed by the parameterized test, and any other teardown logic.
Note
If you are registering a parameter array inparam_init() withkunit_register_param_array() then you need to passkunit_array_gen_params()to this as the generator function.
- structkunit_suite¶
describes a related collection of
structkunit_case
Definition:
struct kunit_suite { const char name[256]; int (*suite_init)(struct kunit_suite *suite); void (*suite_exit)(struct kunit_suite *suite); int (*init)(struct kunit *test); void (*exit)(struct kunit *test); struct kunit_case *test_cases; struct kunit_attributes attr;};Members
namethe name of the test. Purely informational.
suite_initcalled once per test suite before the test cases.
suite_exitcalled once per test suite after all test cases.
initcalled before every test case.
exitcalled after every test case.
test_casesa null terminated array of test cases.
attrthe attributes associated with the test suite
Description
A kunit_suite is a collection of relatedstructkunit_case s, such thatinit is called before every test case andexit is called after everytest case, similar to the notion of atest fixture or atest classin other unit testing frameworks like JUnit or Googletest.
Note thatexit andsuite_exit will run even ifinit orsuite_initfail: make sure they can handle any inconsistent state which may result.
Everystructkunit_case must be associated with a kunit_suite for KUnitto run it.
- structkunit¶
represents a running instance of a test.
Definition:
struct kunit { void *priv; struct kunit *parent; struct kunit_params params_array;};Members
privfor user to store arbitrary data. Commonly used to pass datacreated in the init function (see
structkunit_suite).parentreference to the parent context of type
structkunitthat canbe used for storing shared resources.params_arrayfor storing the parameter array.
Description
Used to store information about the current context under which the testis running. Most of this data is private and should only be accessedindirectly via public functions; the exceptions arepriv,parent andparams_array which can be used by the test writer to store arbitrary data,access the parent context, and to store the parameter array, respectively.
- kunit_test_suites¶
kunit_test_suites(__suites...)
used to register one or more
structkunit_suitewith KUnit.
Parameters
__suites...a statically allocated list of
structkunit_suite.
Description
Registerssuites with the test framework.This is done by placing the array ofstructkunit_suite * in the.kunit_test_suites ELF section.
When builtin, KUnit tests are all run via the executor at boot, and whenbuilt as a module, they run on module load.
- kunit_test_init_section_suites¶
kunit_test_init_section_suites(__suites...)
used to register one or more
structkunit_suitecontaining init functions or init data.
Parameters
__suites...a statically allocated list of
structkunit_suite.
Description
This functions similar tokunit_test_suites() except that it compiles thelist of suites during init phase.
This macro also suffixes the array and suite declarations it makes with_probe; so that modpost suppresses warnings about referencing init datafor symbols named in this manner.
Note
these init tests are not able to be run after boot so there is no“run” debugfs file generated for these tests.
Also, do not mark the suite or test case structs with __initdata becausethey will be used after the init phase with debugfs.
- void*kunit_kmalloc_array(structkunit*test,size_tn,size_tsize,gfp_tgfp)¶
Like
kmalloc_array()except the allocation istest managed.
Parameters
structkunit*testThe test context object.
size_tnnumber of elements.
size_tsizeThe size in bytes of the desired memory.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Just likekmalloc_array(...), except the allocation is managed by the test caseand is automatically cleaned up after the test case concludes. Seekunit_add_action()for more information.
Note that some internal context data is also allocated with GFP_KERNEL,regardless of the gfp passed in.
- void*kunit_kmalloc(structkunit*test,size_tsize,gfp_tgfp)¶
Like
kmalloc()except the allocation istest managed.
Parameters
structkunit*testThe test context object.
size_tsizeThe size in bytes of the desired memory.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Seekmalloc() andkunit_kmalloc_array() for more information.
Note that some internal context data is also allocated with GFP_KERNEL,regardless of the gfp passed in.
Parameters
structkunit*testThe test case to which the resource belongs.
constvoid*ptrThe memory allocation to free.
- void*kunit_kzalloc(structkunit*test,size_tsize,gfp_tgfp)¶
Just like
kunit_kmalloc(), but zeroes the allocation.
Parameters
structkunit*testThe test context object.
size_tsizeThe size in bytes of the desired memory.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Seekzalloc() andkunit_kmalloc_array() for more information.
- void*kunit_kcalloc(structkunit*test,size_tn,size_tsize,gfp_tgfp)¶
Just like
kunit_kmalloc_array(), but zeroes the allocation.
Parameters
structkunit*testThe test context object.
size_tnnumber of elements.
size_tsizeThe size in bytes of the desired memory.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Seekcalloc() andkunit_kmalloc_array() for more information.
Parameters
structkunit*testThe test context object.
constvoid*xpointer to the memory
Description
Callskunit_kfree() only ifx is not in .rodata section.Seekunit_kstrdup_const() for more information.
- char*kunit_kstrdup(structkunit*test,constchar*str,gfp_tgfp)¶
Duplicates a string into a test managed allocation.
Parameters
structkunit*testThe test context object.
constchar*strThe NULL-terminated string to duplicate.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Seekstrdup() andkunit_kmalloc_array() for more information.
- constchar*kunit_kstrdup_const(structkunit*test,constchar*str,gfp_tgfp)¶
Conditionally duplicates a string into a test managed allocation.
Parameters
structkunit*testThe test context object.
constchar*strThe NULL-terminated string to duplicate.
gfp_tgfpflags passed to underlying
kmalloc().
Description
Callskunit_kstrdup() only ifstr is not in the rodata section. Must be freed withkunit_kfree_const() -- notkunit_kfree().Seekstrdup_const() andkunit_kmalloc_array() for more information.
- intkunit_attach_mm(void)¶
Create and attach a new mm if it doesn’t already exist.
Parameters
voidno arguments
Description
Allocates astructmm_struct and attaches it tocurrent. In most cases, callkunit_vm_mmap() without callingkunit_attach_mm() directly. Only necessary whencode under test accesses the mm before executing the mmap (e.g., to performadditional initialization beforehand).
Return
0 on success, -errno on failure.
- unsignedlongkunit_vm_mmap(structkunit*test,structfile*file,unsignedlongaddr,unsignedlonglen,unsignedlongprot,unsignedlongflag,unsignedlongoffset)¶
Allocate KUnit-tracked
vm_mmap()area
Parameters
structkunit*testThe test context object.
structfile*filestructfilepointer to map from, if anyunsignedlongaddrdesired address, if any
unsignedlonglenhow many bytes to allocate
unsignedlongprotmmap PROT_* bits
unsignedlongflagmmap flags
unsignedlongoffsetoffset intofile to start mapping from.
Description
Seevm_mmap() for more information.
- kunit_mark_skipped¶
kunit_mark_skipped(test,fmt,...)
Markstest as skipped
Parameters
testThe test context object.
fmtA
printk()style format string....variable arguments
Description
Marks the test as skipped.fmt is given output as the test statuscomment, typically the reason the test was skipped.
Test execution continues afterkunit_mark_skipped() is called.
- kunit_skip¶
kunit_skip(test,fmt,...)
Markstest as skipped
Parameters
testThe test context object.
fmtA
printk()style format string....variable arguments
Description
Skips the test.fmt is given output as the test statuscomment, typically the reason the test was skipped.
Test execution is halted afterkunit_skip() is called.
- kunit_info¶
kunit_info(test,fmt,...)
Prints an INFO level message associated withtest.
Parameters
testThe test context object.
fmtA
printk()style format string....variable arguments
Description
Prints an info level message associated with the test suite being run.Takes a variable number of format parameters just likeprintk().
- kunit_warn¶
kunit_warn(test,fmt,...)
Prints a WARN level message associated withtest.
Parameters
testThe test context object.
fmtA
printk()style format string....variable arguments
Description
Prints a warning level message.
- kunit_err¶
kunit_err(test,fmt,...)
Prints an ERROR level message associated withtest.
Parameters
testThe test context object.
fmtA
printk()style format string....variable arguments
Description
Prints an error level message.
- KUNIT_SUCCEED¶
KUNIT_SUCCEED(test)
A no-op expectation. Only exists for code clarity.
Parameters
testThe test context object.
Description
The opposite ofKUNIT_FAIL(), it is an expectation that cannot fail. In otherwords, it does nothing and only exists for code clarity. SeeKUNIT_EXPECT_TRUE() for more information.
- KUNIT_FAIL¶
KUNIT_FAIL(test,fmt,...)
Always causes a test to fail when evaluated.
Parameters
testThe test context object.
fmtan informational message to be printed when the assertion is made.
...string format arguments.
Description
The opposite ofKUNIT_SUCCEED(), it is an expectation that always fails. Inother words, it always results in a failed expectation, and consequentlyalways causes the test case to fail when evaluated. SeeKUNIT_EXPECT_TRUE()for more information.
- KUNIT_EXPECT_TRUE¶
KUNIT_EXPECT_TRUE(test,condition)
Causes a test failure when the expression is not true.
Parameters
testThe test context object.
conditionan arbitrary boolean expression. The test fails when this doesnot evaluate to true.
Description
This and expectations of the formKUNIT_EXPECT_* will cause the test caseto fail when the specified condition is not met; however, it will not preventthe test case from continuing to run; this is otherwise known as anexpectation failure.
- KUNIT_EXPECT_FALSE¶
KUNIT_EXPECT_FALSE(test,condition)
Makes a test failure when the expression is not false.
Parameters
testThe test context object.
conditionan arbitrary boolean expression. The test fails when this doesnot evaluate to false.
Description
Sets an expectation thatcondition evaluates to false. SeeKUNIT_EXPECT_TRUE() for more information.
- KUNIT_EXPECT_EQ¶
KUNIT_EXPECT_EQ(test,left,right)
Sets an expectation thatleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the values thatleft andright evaluate to areequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) == (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_PTR_EQ¶
KUNIT_EXPECT_PTR_EQ(test,left,right)
Expects that pointersleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a pointer.
rightan arbitrary expression that evaluates to a pointer.
Description
Sets an expectation that the values thatleft andright evaluate to areequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) == (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_NE¶
KUNIT_EXPECT_NE(test,left,right)
An expectation thatleft andright are not equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the values thatleft andright evaluate to are notequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) != (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_PTR_NE¶
KUNIT_EXPECT_PTR_NE(test,left,right)
Expects that pointersleft andright are not equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a pointer.
rightan arbitrary expression that evaluates to a pointer.
Description
Sets an expectation that the values thatleft andright evaluate to are notequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) != (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_LT¶
KUNIT_EXPECT_LT(test,left,right)
An expectation thatleft is less thanright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the value thatleft evaluates to is less than thevalue thatright evaluates to. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) < (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_LE¶
KUNIT_EXPECT_LE(test,left,right)
Expects thatleft is less than or equal toright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the value thatleft evaluates to is less than orequal to the value thatright evaluates to. Semantically this is equivalentto KUNIT_EXPECT_TRUE(test, (left) <= (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_GT¶
KUNIT_EXPECT_GT(test,left,right)
An expectation thatleft is greater thanright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the value thatleft evaluates to is greater thanthe value thatright evaluates to. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) > (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_GE¶
KUNIT_EXPECT_GE(test,left,right)
Expects thatleft is greater than or equal toright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an expectation that the value thatleft evaluates to is greater thanthe value thatright evaluates to. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, (left) >= (right)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_EXPECT_STREQ¶
KUNIT_EXPECT_STREQ(test,left,right)
Expects that stringsleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a null terminated string.
rightan arbitrary expression that evaluates to a null terminated string.
Description
Sets an expectation that the values thatleft andright evaluate to areequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, !strcmp((left), (right))). SeeKUNIT_EXPECT_TRUE()for more information.
- KUNIT_EXPECT_STRNEQ¶
KUNIT_EXPECT_STRNEQ(test,left,right)
Expects that stringsleft andright are not equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a null terminated string.
rightan arbitrary expression that evaluates to a null terminated string.
Description
Sets an expectation that the values thatleft andright evaluate to arenot equal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, strcmp((left), (right))). SeeKUNIT_EXPECT_TRUE()for more information.
- KUNIT_EXPECT_MEMEQ¶
KUNIT_EXPECT_MEMEQ(test,left,right,size)
Expects that the firstsize bytes ofleft andright are equal.
Parameters
testThe test context object.
leftAn arbitrary expression that evaluates to the specified size.
rightAn arbitrary expression that evaluates to the specified size.
sizeNumber of bytes compared.
Description
Sets an expectation that the values thatleft andright evaluate to areequal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, !memcmp((left), (right), (size))). SeeKUNIT_EXPECT_TRUE() for more information.
Although this expectation works for any memory block, it is not recommendedfor comparing more structured data, such as structs. This expectation isrecommended for comparing, for example, data arrays.
- KUNIT_EXPECT_MEMNEQ¶
KUNIT_EXPECT_MEMNEQ(test,left,right,size)
Expects that the firstsize bytes ofleft andright are not equal.
Parameters
testThe test context object.
leftAn arbitrary expression that evaluates to the specified size.
rightAn arbitrary expression that evaluates to the specified size.
sizeNumber of bytes compared.
Description
Sets an expectation that the values thatleft andright evaluate to arenot equal. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, memcmp((left), (right), (size))). SeeKUNIT_EXPECT_TRUE() for more information.
Although this expectation works for any memory block, it is not recommendedfor comparing more structured data, such as structs. This expectation isrecommended for comparing, for example, data arrays.
- KUNIT_EXPECT_NULL¶
KUNIT_EXPECT_NULL(test,ptr)
Expects thatptr is null.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an expectation that the value thatptr evaluates to is null. This issemantically equivalent to KUNIT_EXPECT_PTR_EQ(test, ptr, NULL).SeeKUNIT_EXPECT_TRUE() for more information.
- KUNIT_EXPECT_NOT_NULL¶
KUNIT_EXPECT_NOT_NULL(test,ptr)
Expects thatptr is not null.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an expectation that the value thatptr evaluates to is not null. Thisis semantically equivalent to KUNIT_EXPECT_PTR_NE(test, ptr, NULL).SeeKUNIT_EXPECT_TRUE() for more information.
- KUNIT_EXPECT_NOT_ERR_OR_NULL¶
KUNIT_EXPECT_NOT_ERR_OR_NULL(test,ptr)
Expects thatptr is not null and not err.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an expectation that the value thatptr evaluates to is not null and notan errno stored in a pointer. This is semantically equivalent toKUNIT_EXPECT_TRUE(test, !IS_ERR_OR_NULL(ptr)). SeeKUNIT_EXPECT_TRUE() formore information.
- KUNIT_FAIL_AND_ABORT¶
KUNIT_FAIL_AND_ABORT(test,fmt,...)
Always causes a test to fail and abort when evaluated.
Parameters
testThe test context object.
fmtan informational message to be printed when the assertion is made.
...string format arguments.
Description
The opposite ofKUNIT_SUCCEED(), it is an assertion that always fails. Inother words, it always results in a failed assertion, and consequentlyalways causes the test case to fail and abort when evaluated.SeeKUNIT_ASSERT_TRUE() for more information.
- KUNIT_ASSERT_TRUE¶
KUNIT_ASSERT_TRUE(test,condition)
Sets an assertion thatcondition is true.
Parameters
testThe test context object.
conditionan arbitrary boolean expression. The test fails and aborts whenthis does not evaluate to true.
Description
This and assertions of the formKUNIT_ASSERT_* will cause the test case tofailand immediately abort when the specified condition is not met. Unlikean expectation failure, it will prevent the test case from continuing to run;this is otherwise known as anassertion failure.
- KUNIT_ASSERT_FALSE¶
KUNIT_ASSERT_FALSE(test,condition)
Sets an assertion thatcondition is false.
Parameters
testThe test context object.
conditionan arbitrary boolean expression.
Description
Sets an assertion that the value thatcondition evaluates to is false. Thisis the same asKUNIT_EXPECT_FALSE(), except it causes an assertion failure(seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_EQ¶
KUNIT_ASSERT_EQ(test,left,right)
Sets an assertion thatleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the values thatleft andright evaluate to areequal. This is the same asKUNIT_EXPECT_EQ(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_PTR_EQ¶
KUNIT_ASSERT_PTR_EQ(test,left,right)
Asserts that pointersleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a pointer.
rightan arbitrary expression that evaluates to a pointer.
Description
Sets an assertion that the values thatleft andright evaluate to areequal. This is the same asKUNIT_EXPECT_EQ(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_NE¶
KUNIT_ASSERT_NE(test,left,right)
An assertion thatleft andright are not equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the values thatleft andright evaluate to are notequal. This is the same asKUNIT_EXPECT_NE(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_PTR_NE¶
KUNIT_ASSERT_PTR_NE(test,left,right)
Asserts that pointersleft andright are not equal.
KUNIT_ASSERT_PTR_EQ()- Asserts that pointersleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a pointer.
rightan arbitrary expression that evaluates to a pointer.
Description
Sets an assertion that the values thatleft andright evaluate to are notequal. This is the same asKUNIT_EXPECT_NE(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_LT¶
KUNIT_ASSERT_LT(test,left,right)
An assertion thatleft is less thanright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the value thatleft evaluates to is less than thevalue thatright evaluates to. This is the same asKUNIT_EXPECT_LT(), exceptit causes an assertion failure (seeKUNIT_ASSERT_TRUE()) when the assertionis not met.
- KUNIT_ASSERT_LE¶
KUNIT_ASSERT_LE(test,left,right)
An assertion thatleft is less than or equal toright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the value thatleft evaluates to is less than orequal to the value thatright evaluates to. This is the same asKUNIT_EXPECT_LE(), except it causes an assertion failure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_GT¶
KUNIT_ASSERT_GT(test,left,right)
An assertion thatleft is greater thanright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the value thatleft evaluates to is greater than thevalue thatright evaluates to. This is the same asKUNIT_EXPECT_GT(), exceptit causes an assertion failure (seeKUNIT_ASSERT_TRUE()) when the assertionis not met.
- KUNIT_ASSERT_GE¶
KUNIT_ASSERT_GE(test,left,right)
Assertion thatleft is greater than or equal toright.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a primitive C type.
rightan arbitrary expression that evaluates to a primitive C type.
Description
Sets an assertion that the value thatleft evaluates to is greater than thevalue thatright evaluates to. This is the same asKUNIT_EXPECT_GE(), exceptit causes an assertion failure (seeKUNIT_ASSERT_TRUE()) when the assertionis not met.
- KUNIT_ASSERT_STREQ¶
KUNIT_ASSERT_STREQ(test,left,right)
An assertion that stringsleft andright are equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a null terminated string.
rightan arbitrary expression that evaluates to a null terminated string.
Description
Sets an assertion that the values thatleft andright evaluate to areequal. This is the same asKUNIT_EXPECT_STREQ(), except it causes anassertion failure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_STRNEQ¶
KUNIT_ASSERT_STRNEQ(test,left,right)
An assertion that stringsleft andright are not equal.
Parameters
testThe test context object.
leftan arbitrary expression that evaluates to a null terminated string.
rightan arbitrary expression that evaluates to a null terminated string.
Description
Sets an assertion that the values thatleft andright evaluate to arenot equal. This is semantically equivalent toKUNIT_ASSERT_TRUE(test, strcmp((left), (right))). SeeKUNIT_ASSERT_TRUE()for more information.
- KUNIT_ASSERT_MEMEQ¶
KUNIT_ASSERT_MEMEQ(test,left,right,size)
Asserts that the firstsize bytes ofleft andright are equal.
Parameters
testThe test context object.
leftAn arbitrary expression that evaluates to the specified size.
rightAn arbitrary expression that evaluates to the specified size.
sizeNumber of bytes compared.
Description
Sets an assertion that the values thatleft andright evaluate to areequal. This is semantically equivalent toKUNIT_ASSERT_TRUE(test, !memcmp((left), (right), (size))). SeeKUNIT_ASSERT_TRUE() for more information.
Although this assertion works for any memory block, it is not recommendedfor comparing more structured data, such as structs. This assertion isrecommended for comparing, for example, data arrays.
- KUNIT_ASSERT_MEMNEQ¶
KUNIT_ASSERT_MEMNEQ(test,left,right,size)
Asserts that the firstsize bytes ofleft andright are not equal.
Parameters
testThe test context object.
leftAn arbitrary expression that evaluates to the specified size.
rightAn arbitrary expression that evaluates to the specified size.
sizeNumber of bytes compared.
Description
Sets an assertion that the values thatleft andright evaluate to arenot equal. This is semantically equivalent toKUNIT_ASSERT_TRUE(test, memcmp((left), (right), (size))). SeeKUNIT_ASSERT_TRUE() for more information.
Although this assertion works for any memory block, it is not recommendedfor comparing more structured data, such as structs. This assertion isrecommended for comparing, for example, data arrays.
- KUNIT_ASSERT_NULL¶
KUNIT_ASSERT_NULL(test,ptr)
Asserts that pointersptr is null.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an assertion that the values thatptr evaluates to is null. This isthe same asKUNIT_EXPECT_NULL(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_NOT_NULL¶
KUNIT_ASSERT_NOT_NULL(test,ptr)
Asserts that pointersptr is not null.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an assertion that the values thatptr evaluates to is not null. Thisis the same asKUNIT_EXPECT_NOT_NULL(), except it causes an assertionfailure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ASSERT_NOT_ERR_OR_NULL¶
KUNIT_ASSERT_NOT_ERR_OR_NULL(test,ptr)
Assertion thatptr is not null and not err.
Parameters
testThe test context object.
ptran arbitrary pointer.
Description
Sets an assertion that the value thatptr evaluates to is not null and notan errno stored in a pointer. This is the same asKUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (seeKUNIT_ASSERT_TRUE()) when the assertion is not met.
- KUNIT_ARRAY_PARAM¶
KUNIT_ARRAY_PARAM(name,array,get_desc)
Define test parameter generator from an array.
Parameters
nameprefix for the test parameter generator function.
arrayarray of test parameters.
get_descfunction to convert param to description; NULL to use default
Description
Define functionname_gen_params which usesarray to generate parameters.
- KUNIT_ARRAY_PARAM_DESC¶
KUNIT_ARRAY_PARAM_DESC(name,array,desc_member)
Define test parameter generator from an array.
Parameters
nameprefix for the test parameter generator function.
arrayarray of test parameters.
desc_memberstructure member from array element to use as description
Description
Define functionname_gen_params which usesarray to generate parameters.
- kunit_register_params_array¶
kunit_register_params_array(test,array,param_count,get_desc)
Register parameter array for a KUnit test.
Parameters
testThe KUnit test structure to which parameters will be added.
arrayAn array of test parameters.
param_countNumber of parameters.
get_descFunction that generates a string description for a given parameterelement.
Description
This macro initializes thetest’s parameter array data, storing informationincluding the parameter array, its count, the element size, and the parameterdescription function withintest->params_array.
Note
If using this macro inparam_init(),kunit_array_gen_params()will then need to be manually provided as the parameter generator function toKUNIT_CASE_PARAM_WITH_INIT().kunit_array_gen_params() is a KUnitfunction that uses the registered array to generate parameters