UEFIStarter
a simple UEFI framework
Macros | Functions | Variables
tests.c File Reference

This is the basis for all test suites. More...

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <UEFIStarter/core/memory.h>
#include <UEFIStarter/core/logger.h>
#include <UEFIStarter/core/cmdline.h>
#include <UEFIStarter/core/string.h>
#include <UEFIStarter/tests/tests.h>
#include <UEFIStarter/tests/output.h>

Macros

#define ARG_SKIP_TESTS   tests_args[0].value.wcstr
 helper macro to access the -skip argument's values
 
#define ARG_VERBOSITY   tests_args[1].value.uint64
 helper macro to access the -verbosity argument's value
 
#define ARG_MULTILINE   tests_args[2].value.uint64
 helper macro to access the -multiline argument's value
 
#define ARG_NO_COUNTS   tests_args[3].value.uint64
 helper macro to access the -no-counts argument's value
 
#define ARG_ASSERTIONS   tests_args[4].value.uint64
 helper macro to access the -assertions argument's value
 
#define ARG_NO_STATISTICS   tests_args[5].value.uint64
 helper macro to access the -no-statistics argument's value
 

Functions

static BOOLEAN validate_verbosity (cmdline_value_t v)
 Validator for the -verbosity <level> argument. More...
 
void log_errorprint (LOGLEVEL level, CHAR16 *msg)
 Log printer function writing to STDERR. More...
 
void reset_test_results (test_results_t *results)
 Initializes a test_results_t structure. More...
 
static test_outcome _combine_outcomes (test_outcome v1, test_outcome v2)
 Internal: combines two test outcomes. More...
 
void add_test_results (test_results_t *target, test_results_t *source)
 Adds test result data to a larger collection of results. More...
 
void handle_result (test_results_t *result)
 Updates internal test_results_t data after a test. More...
 
void handle_individual_result ()
 Processes an individual test's results.
 
void handle_group_result ()
 Processes a test group's results.
 
void run_test (void(*func)(), CHAR16 *description)
 Runs an individual test. More...
 
void run_group (BOOLEAN(*func)())
 Runs a test group. More...
 
static void _parse_skipped_tests (CHAR16 *str)
 Internal: parses a list of skipped tests into internal storage. More...
 
BOOLEAN is_skipped_test (CHAR16 *name)
 Tests whether a given test should be skipped. More...
 
void assemble_and_set_verbosity ()
 Transforms the -verbosity command-line argument into its internal representation.
 
int main (int argc, char **argv_ascii)
 Main function for test suite, gets invoked by UEFI shell. More...
 

Variables

static LOGLEVEL _initial_log_level
 internal storage for the initial log level to set before each test
 
static CHAR16 ** _skipped_tests_list
 internal storage for the list of skipped tests
 
static UINTN _skipped_tests_count
 internal storage for the number of skipped tests
 
test_verbosity_t test_verbosity
 the current test verbosity
 
test_results_t individual_test_results
 results for the current test
 
test_results_t group_test_results
 results for the current test group
 
test_results_t global_test_results
 results for all tests in this suite
 
cmdline_argument_t tests_args []
 list of command-line arguments More...
 
cmdline_argument_group_t tests_arggroup ={ L"Test options" ,sizeof( tests_args )/sizeof(cmdline_argument_t), tests_args }
 command-line argument group
 

Detailed Description

This is the basis for all test suites.

This handles the test execution, the test suite is just responsible for producing results.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter
Todo:

add pause-on-error/incomplete feature

could add a way to capture error messages and output them later

Function Documentation

◆ validate_verbosity()

static BOOLEAN validate_verbosity ( cmdline_value_t  v)
static

Validator for the -verbosity <level> argument.

Parameters
vthe input to validate
Returns
whether the given value is a valid verbosity

◆ log_errorprint()

void log_errorprint ( LOGLEVEL  level,
CHAR16 *  msg 
)

Log printer function writing to STDERR.

Parameters
levelthe log entry's log level
msgthe log entry's message

◆ reset_test_results()

void reset_test_results ( test_results_t results)

Initializes a test_results_t structure.

Parameters
resultsthe structure to reset

◆ _combine_outcomes()

static test_outcome _combine_outcomes ( test_outcome  v1,
test_outcome  v2 
)
static

Internal: combines two test outcomes.

Parameters
v1the first value to compare
v2the second value to compare
Returns
the combined outcome

◆ add_test_results()

void add_test_results ( test_results_t target,
test_results_t source 
)

Adds test result data to a larger collection of results.

This is e.g. used to sum up individual test results into test group results.

Parameters
targetthe larger collection of results to add to
sourcethe new data to add

◆ handle_result()

void handle_result ( test_results_t result)

Updates internal test_results_t data after a test.

Parameters
resultthe data to update

◆ run_test()

void run_test ( void(*)()  func,
CHAR16 *  description 
)

Runs an individual test.

This function takes care of required setup/teardown around tests.

Parameters
functhe test function to execute
descriptionthe test's description

◆ run_group()

void run_group ( BOOLEAN(*)()  func)

Runs a test group.

Parameters
functhe test group to run

◆ _parse_skipped_tests()

static void _parse_skipped_tests ( CHAR16 *  str)
static

Internal: parses a list of skipped tests into internal storage.

Parameters
strthe list of tests to skip

◆ is_skipped_test()

BOOLEAN is_skipped_test ( CHAR16 *  name)

Tests whether a given test should be skipped.

Parameters
namethe test's name
Returns
whether the test should be skipped

◆ main()

int main ( int  argc,
char **  argv_ascii 
)

Main function for test suite, gets invoked by UEFI shell.

Parameters
argcthe number of command-line arguments passed
argv_asciithe command-line arguments passed, as ASCII
Returns
an EFI status code for the shell

Variable Documentation

◆ tests_args

cmdline_argument_t tests_args[]
Initial value:
={
{{wcstr:L""},ARG_STRING,NULL, L"-skip", L"Comma-separated test groups to skip"},
{{uint64:4}, ARG_INT, validate_verbosity,L"-verbosity", L"Set verbosity (the higher the more detailed) [1..4]"},
{{uint64:0}, ARG_BOOL, NULL, L"-multiline", L"Use multiple lines per test (verbosity 4 only)"},
{{uint64:0}, ARG_BOOL, NULL, L"-no-counts", L"Disable assertion counts (shown at verbosities 2 and 4 only)"},
{{uint64:0}, ARG_BOOL, NULL, L"-assertions", L"Show successful assertions (verbosity 4 only)"},
{{uint64:0}, ARG_BOOL, NULL, L"-no-statistics",L"Disable summary statistics"},
}
boolean
Definition: cmdline.h:22
integer
Definition: cmdline.h:23
UTF-16 string.
Definition: cmdline.h:25
static BOOLEAN validate_verbosity(cmdline_value_t v)
Validator for the -verbosity <level> argument.
Definition: tests.c:54

list of command-line arguments