4.7 Utilities Reference
The following function can be used to provide a custom error handler
to be executed by the library if any postcondition, implicit or
explicit, could not be provided:
- C Error Function: void micro_benchmark_set_error_handler (void (*handler) (void)) ¶
-
Preconditions:
- The function pointed by handler does not return, neither through
a return statement or the end of its scope, nor non-locally such as a
longjmp call.
Effects:
- Store handler, forgetting any previous value provided.
Postconditions:
- handler will be called if a postcondition could not be provided.
These are some utilities to make quick and easy a test with
MicroBenchmark.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_TEST (fun) ¶
-
Preconditions:
- File scope macro.
- fun type is (or decays to)
micro_benchmark_test_fun
.
Effects:
- Register the directed test fun.
- Use
#fun
as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_FULL_TEST (setup, fun, teardown) ¶
-
Preconditions:
- File scope macro.
- setup type is (or decays to)
micro_benchmark_set_up_fun
.
- fun type is (or decays to)
micro_benchmark_test_fun
.
- teardown type is (or decays to)
micro_benchmark_set_up_fun
.
Effects:
- Register the directed test fun, calling setup before each
run of fun, and calling teardown after each run.
- Use
#fun
as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_NAMED_TEST (name, setup, test, teardown) ¶
-
Preconditions:
- File scope macro.
- The type of name is (or decays to)
const char *
, and
points to a valid, zero-ended array of characters.
- setup type is (or decays to)
micro_benchmark_set_up_fun
.
- fun type is (or decays to)
micro_benchmark_test_fun
.
- teardown type is (or decays to)
micro_benchmark_set_up_fun
.
Effects:
- Register the directed test fun, calling setup before each
run of fun, and calling teardown after each run.
- Use name as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_SIMPLE_TEST (fun) ¶
-
Preconditions:
- File scope macro.
- fun type is (or decays to)
micro_benchmark_auto_test_fun
.
Effects:
- Register the automatic test fun.
- Use
#fun
as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_AUTO_TEST (setup, fun, teardown) ¶
-
Preconditions:
- File scope macro.
- setup type is (or decays to)
micro_benchmark_set_up_fun
.
- fun type is (or decays to)
micro_benchmark_auto_test_fun
.
- teardown type is (or decays to)
micro_benchmark_set_up_fun
.
Effects:
- Register the automatic test fun, calling setup before each
run of fun, and calling teardown after each run.
- Use
#fun
as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Utility Macro: MICRO_BENCHMARK_REGISTER_NAMED_AUTO_TEST (name, setup, test, teardown) ¶
-
Preconditions:
- File scope macro.
- The type of name is (or decays to)
const char *
, and
points to a valid, zero-ended array of characters.
- setup type is (or decays to)
micro_benchmark_set_up_fun
.
- fun type is (or decays to)
micro_benchmark_auto_test_fun
.
- teardown type is (or decays to)
micro_benchmark_set_up_fun
.
Effects:
- Register the automatic test fun, calling setup before each
run of fun, and calling teardown after each run.
- Use name as the test registration name.
Postconditions:
- The test will be executed by
micro_benchmark_main
unless its
execution is disabled by its parameters or the provided test
constraints.
- C Function Type: micro_benchmark_static_constraint ¶
-
Its prototype is void (*) (micro_benchmark_test_case)
.
- C Utility Macro: MICRO_BENCHMARK_CONSTRAINT_TEST (name, fun) ¶
-
Preconditions:
- File scope macro.
- The type of name is (or decays to)
const char *
, and
points to a valid, zero-ended array of characters.
- fun type is (or decays to)
micro_benchmark_static_constraint
.
Effects:
- Register the constraint fun.
Postconditions:
- fun will be called with the test named name as its
parameter by
micro_benchmark_main
, if a test with that name has
been registered.
- C Utility Macro: MICRO_BENCHMARK_MAIN () ¶
-
Preconditions:
- File scope macro.
-
int main (int, char**)
is not defined elsewhere on the binary.
Effects:
- Define
int main (int, char **)
.
Postconditions:
- The resulting binary will call
micro_benchmark_main
with the
provided command line arguments its value to the main
function.
- C Utility Function: void micro_benchmark_main (int argc, char **argv) ¶
-
Preconditions:
- argc is a non positive integer.
- argv points to an array of
char *
.
- argc is less or equal to the number of elements pointed by
argv.
- Each value pointed by argv either is
NULL
or points to a
valid, readable, zero-ended array of characters.
Effects:
- Parse the command line:
- If argv contains the parameters
--help
, --version
or an unrecognized parameter, call exit
with the corresponding
value.
- Execute the registered tests.
- Print the results.
Postconditions:
- The standard output, or the output file provided through the command
line parameters, was flushed.
- The value returned is
EXIT_SUCCESS
.
The following functions are used to implement the registration macros:
- C Utility Function: void micro_benchmark_register_static_test (const char *name, micro_benchmark_test test) ¶
-
Preconditions:
- name must point to a valid, zero-ended array of characters.
- test must point to a valid test definition.
Effects:
- Register test as name.
Postconditions:
-
micro_benchmark_main
will execute test unless it is
disabled through its parameters or the constraints associated to
name.
- C Utility Function: void micro_benchmark_register_static_constraint (const char *name, micro_benchmark_static_constraint constraint) ¶
-
Preconditions:
- name must point to a valid, zero-ended array of characters.
- constraint must point to a valid function.
Effects:
- Register constraints for name.
Postconditions:
-
micro_benchmark_main
will call constraint if a test was
registered as name as its parameter, with the test case as its
parameter.
NOTE: The following functions are executed automatically by
the linker on all known configurations. Do not call them
manually.
- C Utility Function: void micro_benchmark_init () ¶
-
Preconditions:
- Either:
-
micro_benchmark_init
has not been called before.
- Each call to
micro_benchmark_init
has been followed by a
corresponding call to micro_benchmark_cleanup
.
Effects:
- Configure message translations when the library was built with Native
Language Support (see Configuration).
- Configure Logging output.
Postconditions:
- Messages are printed on the user localization, when this is available.
- C Utility Function: void micro_benchmark_cleanup () ¶
-
Preconditions:
- Either:
-
micro_benchmark_init
has been called once.
- Every call to
micro_benchmark_init
except the last one has been
followed by a corresponding call to micro_benchmark_cleanup
.
Effects:
- Cleanup internal data.
Postconditions:
- The registered tests are not executed by a call to
micro_benchmark_main
anymore.