Test Framework
Assertions and reporting functions
-
voidut_fail(structunit_test_state*uts, constchar*fname, intline, constchar*func, constchar*cond)
Record failure of a unit test
Parameters
struct unit_test_state *utsTest state
const char *fnameFilename where the error occurred
int lineLine number where the error occurred
const char *funcFunction name where the error occurred
const char *condThe condition that failed
-
voidut_failf(structunit_test_state*uts, constchar*fname, intline, constchar*func, constchar*cond, constchar*fmt, ...)
Record failure of a unit test
Parameters
struct unit_test_state *utsTest state
const char *fnameFilename where the error occurred
int lineLine number where the error occurred
const char *funcFunction name where the error occurred
const char *condThe condition that failed
const char *fmtprintf() format string for the error, followed by args
...variable arguments
-
intut_check_console_line(structunit_test_state*uts, constchar*fmt, ...)
Check the next console line against expectations
Parameters
struct unit_test_state *utsTest state
const char *fmtprintf() format string for the error, followed by args
...variable arguments
Description
This creates a string and then checks it against the next line of console output obtained with console_record_readline().
After the function returns, uts->expect_str holds the expected string and uts->actual_str holds the actual string read from the console.
Return
0 if OK, other value on error
-
intut_check_console_linen(structunit_test_state*uts, constchar*fmt, ...)
Check part of the next console line
Parameters
struct unit_test_state *utsTest state
const char *fmtprintf() format string for the error, followed by args
...variable arguments
Description
This creates a string and then checks it against the next line of console output obtained with console_record_readline(). Only the length of the string is checked
After the function returns, uts->expect_str holds the expected string and uts->actual_str holds the actual string read from the console.
Return
0 if OK, other value on error
-
intut_check_skipline(structunit_test_state*uts)
Check that the next console line exists and skip it
Parameters
struct unit_test_state *utsTest state
Return
0 if OK, other value on error
-
intut_check_skip_to_line(structunit_test_state*uts, constchar*fmt, ...)
skip output until a line is found
Parameters
struct unit_test_state *utsTest state
const char *fmtprintf() format string to look for, followed by args
...variable arguments
Description
This creates a string and then checks it against the following lines of console output obtained with console_record_readline() until it is found.
After the function returns, uts->expect_str holds the expected string and uts->actual_str holds the actual string read from the console.
Return
0 if OK, -ENOENT if not found, other value on error
-
intut_check_skip_to_linen(structunit_test_state*uts, constchar*fmt, ...)
skip output until a partial line is found
Parameters
struct unit_test_state *utsTest state
const char *fmtprintf() format string to look for, followed by args
...variable arguments
Description
This creates a string and then checks it against the following lines of console output obtained with console_record_readline() until it is found. Only the characters up to the length of the string are checked, so the line may extend further
After the function returns, uts->expect_str holds the expected string and uts->actual_str holds the actual string read from the console.
Return
0 if OK, -ENOENT if not found, other value on error
-
intut_check_console_end(structunit_test_state*uts)
Check there is no more console output
Parameters
struct unit_test_state *utsTest state
Description
After the function returns, uts->actual_str holds the actual string read from the console
Return
0 if OK (console has no output), other value on error
-
intut_check_console_dump(structunit_test_state*uts, inttotal_bytes)
Check that next lines have a print_buffer() dump
Parameters
struct unit_test_state *utsTest state
int total_bytesSize of the expected dump in bytes
Description
This only supports a byte dump.
Return
- 0 if OK (looks like a dump and the length matches),
other value on error
-
ut_reportf
ut_reportf (fmt, args...)
Report a failure, with printf() string
Parameters
fmtformat string
args...arguments to be printed
-
ut_assert
ut_assert (cond)
Assert that a condition is true (not 0)
Parameters
condcondition
-
ut_assertf
ut_assertf (cond, fmt, args...)
Assert that a condition is true with printf string
Parameters
condcondition
fmtformat string
args...arguments to be printed
-
ut_asserteq
ut_asserteq (expr1, expr2)
Assert that two int32 expressions are equal
Parameters
expr1expected value
expr2actual value
-
ut_asserteq_64
ut_asserteq_64 (expr1, expr2)
Assert that two int64 expressions are equal
Parameters
expr1expected value
expr2actual value
-
ut_asserteq_str
ut_asserteq_str (expr1, expr2)
Assert that two string expressions are equal
Parameters
expr1expected value
expr2actual value
-
ut_asserteq_strn
ut_asserteq_strn (expr1, expr2)
Assert that two string expressions are equal up to the length of the first expression
Parameters
expr1expected value
expr2actual value
-
ut_asserteq_mem
ut_asserteq_mem (expr1, expr2, len)
Assert that two memory areas are equal
Parameters
expr1expected value
expr2actual value
lenlength of the memory areas
-
ut_asserteq_ptr
ut_asserteq_ptr (expr1, expr2)
Assert that two string pointers are equal
Parameters
expr1expected value
expr2actual value
-
ut_asserteq_addr
ut_asserteq_addr (expr1, expr2)
Assert that two addresses (converted from pointers) are equal
Parameters
expr1expected value
expr2actual value
-
ut_assertnull
ut_assertnull (expr)
Assert that a pointer is NULL
Parameters
exprpointer
-
ut_assertnonnull
ut_assertnonnull (expr)
Assert that a pointer is not NULL
Parameters
exprpointer
-
ut_assertok_ptr
ut_assertok_ptr (expr)
Assert that a pointer is not an error pointer
Parameters
exprpointer
-
ut_assertok
ut_assertok (cond)
Assert that an operation succeeds (returns 0)
Parameters
condexpression
-
ut_assert_nextline
ut_assert_nextline (fmt, args...)
Assert that the next console output line matches
Parameters
fmtformat string
args...print arguments
-
ut_assert_nextlinen
ut_assert_nextlinen (fmt, args...)
Assert that the next console output line matches up to the length of the expected string.
Parameters
fmtformat string
args...print arguments
-
ut_assert_skipline
ut_assert_skipline ()
Assert that there is a ‘next’ console output line, and skip it
Parameters
-
ut_assert_skip_to_line
ut_assert_skip_to_line (fmt, args...)
Assert that a following console output line matches
Parameters
fmtformat string
args...print arguments
-
ut_assert_skip_to_linen
ut_assert_skip_to_linen (fmt, args...)
Assert that a following console output line matches up to the length of the expected string
Parameters
fmtformat string
args...print arguments
-
ut_assert_console_end
ut_assert_console_end ()
Assert that there is no more console output
Parameters
-
ut_assert_nextlines_are_dump
ut_assert_nextlines_are_dump (total_bytes)
Assert that the next lines are print_buffer() dump at an address
Parameters
total_bytesSize of the expected dump in bytes
-
ut_assert_nextline_empty
ut_assert_nextline_empty ()
Assert that the next console output line is empty
Parameters
-
ulongut_check_free(void)
Return the number of bytes free in the malloc() pool
Parameters
voidno arguments
Return
bytes free
-
longut_check_delta(ulonglast)
Return the number of bytes allocated/freed
Parameters
ulong lastLast value from ut_check_free
Return
- free memory delta from last; positive means more memory has been
allocated, negative means less has been allocated (i.e. some is freed)
-
voidut_silence_console(structunit_test_state*uts)
Silence the console if requested by the user
Parameters
struct unit_test_state *utsTest state (in case in future we want to keep state here)
Description
This stops test output from appear on the console. It is the default on sandbox, unless the -v flag is given. For other boards, this does nothing.
-
voidut_unsilence_console(structunit_test_state*uts)
Unsilence the console after a test
Parameters
struct unit_test_state *utsTest state
Description
This restarts console output again and turns off console recording. This happens on all boards, including sandbox.
-
voidut_set_skip_delays(structunit_test_state*uts, boolskip_delays)
Sets whether delays should be skipped
Parameters
struct unit_test_state *utsTest state (in case in future we want to keep state here)
bool skip_delaystrue to skip delays, false to process them normally
Description
Normally functions like mdelay() cause U-Boot to wait for a while. This allows all such delays to be skipped on sandbox, to speed up tests
-
structunit_test_state*ut_get_state(void)
Get the active test state
Parameters
voidno arguments
Return
the currently active test state, or NULL if none
-
voidut_set_state(structunit_test_state*uts)
Set the active test state
Parameters
struct unit_test_state *utsTest state to use as currently active test state, or NULL if none
-
voidut_init_state(structunit_test_state*uts)
Set up a new test state
Parameters
struct unit_test_state *utsTest state to init
Description
This must be called before using the test state with ut_run_tests()
-
voidut_uninit_state(structunit_test_state*uts)
Free memory used by test state
Parameters
struct unit_test_state *utsTest state to uninit
Description
This must be called before after the test state with ut_run_tests(). To later reuse the test state to run more tests, call test_state_init() first
-
intut_run_list(structunit_test_state*uts, constchar*category, constchar*prefix, structunit_test*tests, intcount, constchar*select_name, intruns_per_test, boolforce_run, constchar*test_insert)
Run a set of tests
Parameters
struct unit_test_state *utsUnit-test state, which must be ready for use, i.e. ut_init_state() has been called. The caller is responsible for calling ut_uninit_state() after this function returns
const char *categoryCategory of these tests. This is a string printed at the start to announce the the number of tests
const char *prefixString prefix for the tests. Any tests that have this prefix will be printed without the prefix, so that it is easier to see the unique part of the test name. If NULL, no prefix processing is done
struct unit_test *testsList of tests to run
int countNumber of tests to run
const char *select_nameName of a single test to run (from the list provided). If NULL then all tests are run
int runs_per_testNumber of times to run each test (typically 1)
bool force_runRun tests that are marked as manual-only (UTF_MANUAL)
const char *test_insertString describing a test to run after n other tests run, in the format n:name where n is the number of tests to run before this one and name is the name of the test to run. This is used to find which test causes another test to fail. If the one test fails, testing stops immediately. Pass NULL to disable this
Description
This runs the test, handling any preparation and clean-up needed. It prints the name of each test before running it.
Return
0 if all tests passed, -1 if any failed
-
voidut_report(structut_stats*stats, intrun_count)
Report stats on a test run
Parameters
struct ut_stats *statsStats to show
int run_countNumber of suites that were run