|
checkasm 1.0.1
Assembly testing and benchmarking framework
|
Test writing API for checkasm.
This header provides the API used within test functions to declare, call, report, and benchmark different implementations of functions.
Go to the source code of this file.
Data Structures | |
| struct | CheckasmPerf |
Macros | |
| #define | checkasm_check_func(func, ...) |
| Check if a function should be tested and set up function references. | |
| #define | checkasm_fail() |
| Mark the current test as failed. | |
| #define | checkasm_declare(ret, ...) |
| Declare a function signature for testing. | |
| #define | checkasm_declare_emms(cpu_flags, ret, ...) |
| Declare signature for non-ABI compliant MMX functions (x86 only). | |
| #define | checkasm_call(func, ...) |
| Call a function with signal handling. | |
| #define | checkasm_call_checked(func, ...) |
| Call an assembly function with full validation. | |
| #define | checkasm_func_ref ((func_type *) checkasm_key_ref) |
| Function pointer to the reference implementation. | |
| #define | checkasm_func_new ((func_type *) checkasm_key_new) |
| Function pointer to the implementation being tested. | |
| #define | checkasm_call_ref(...) |
| Call the reference implementation. | |
| #define | checkasm_call_new(...) |
| Call the implementation being tested with validation. | |
| #define | checkasm_bench(func, ...) |
| Benchmark a function. | |
| #define | checkasm_bench_new(...) |
| Benchmark the optimized implementation. | |
| #define | checkasm_alternate(a, b) |
| Alternate between two values during benchmarking. | |
| #define | fail checkasm_fail |
| #define | report checkasm_report |
| #define | check_func checkasm_check_func |
| #define | func_ref checkasm_func_ref |
| #define | func_new checkasm_func_new |
| #define | call_ref checkasm_call_ref |
| #define | call_new checkasm_call_new |
| #define | bench_new checkasm_bench_new |
| #define | alternate checkasm_alternate |
| #define | declare_func checkasm_declare |
| #define | declare_func_emms checkasm_declare_emms |
| #define | checkasm_clear_cpu_state() |
| Clear CPU state after running a function. | |
| #define | CHECKASM_PERF_CALL4(...) |
| #define | CHECKASM_PERF_CALL16(...) |
| #define | CHECKASM_PERF_BENCH_SIMPLE(count, time, ...) |
| #define | CHECKASM_PERF_BENCH_ASM(total_count, time, ...) |
| #define | CHECKASM_PERF_BENCH(count, time, ...) |
Functions | |
| CHECKASM_API int | checkasm_fail_func (const char *msg,...) CHECKASM_PRINTF(1 |
| Mark the current function as failed with a custom message. | |
| CHECKASM_API void | checkasm_report (const char *name,...) CHECKASM_PRINTF(1 |
| Report test outcome for a named group of functions. | |
| CHECKASM_API int | checkasm_should_fail (CheckasmCpu cpu_flags) |
| Mark a block of tests as expected to fail. | |
| CHECKASM_API CheckasmKey | checkasm_check_key (CheckasmKey version, const char *name,...) CHECKASM_PRINTF(2 |
| Internal implementation of checkasm_check_func(). | |
| CHECKASM_API CheckasmKey CHECKASM_API void | checkasm_set_signal_handler_state (int enabled) |
| Enable or disable signal handling. | |
| CHECKASM_API void | checkasm_push_stack_guard (uintptr_t guard[2]) |
| Push stack guard values for corruption detection. | |
| CHECKASM_API void | checkasm_pop_stack_guard (void) |
| CHECKASM_API const CheckasmPerf * | checkasm_get_perf (void) |
| CHECKASM_API int | checkasm_bench_func (void) |
| Check if current function should be benchmarked. | |
| CHECKASM_API int | checkasm_bench_runs (void) |
| Get number of iterations for current benchmark run. | |
| CHECKASM_API void | checkasm_bench_update (int iterations, uint64_t cycles) |
| Update benchmark statistics with timing results. | |
| CHECKASM_API void | checkasm_bench_finish (void) |
| Finalize and store benchmark results. | |
| static void | checkasm_unused (void) |
| Suppress unused variable warnings. | |
Variables | |
| static CheckasmKey | checkasm_key_ref |
| Key identifying the reference implementation. | |
| static CheckasmKey | checkasm_key_new |
| Key identifying the implementation being tested. | |
| #define checkasm_alternate | ( | a, | |
| b ) |
Alternate between two values during benchmarking.
Returns one of two values, alternating between them across benchmark iterations. Intended for use within bench_new() calls for functions that modify their input buffers. This ensures throughput (not latency) is measured by preventing data dependencies between iterations.
| a | First value |
| b | Second value |
| #define checkasm_bench | ( | func, | |
| ... ) |
Benchmark a function.
Repeatedly calls a function to measure its performance. If benchmarking is enabled, runs the function many times and collects timing statistics. If benchmarking is disabled, simply calls the function once with validation.
| func | Function pointer to benchmark |
| ... | Arguments to pass to the function |
| #define checkasm_bench_new | ( | ... | ) |
Benchmark the optimized implementation.
Convenience macro that benchmarks the optimized implementation set up by checkasm_check_func(). Equivalent to checkasm_bench(checkasm_func_new, ...).
| ... | Arguments to pass to the function |
| #define checkasm_call | ( | func, | |
| ... ) |
Call a function with signal handling.
Calls an arbitrary function while handling signals (crashes, segfaults, etc.). Use this for calling the reference implementation or other nominally-safe code. For testing assembly/optimized implementations, use checkasm_call_checked() instead, which provides additional validation for common assembly mistakes.
| func | Function pointer to call |
| ... | Arguments to pass to the function |
| #define checkasm_call_checked | ( | func, | |
| ... ) |
Call an assembly function with full validation.
Calls an assembly/optimized function (matching the signature declared by checkasm_declare()) while handling signals and checking for common assembly errors like stack corruption, clobbered registers, register size mismatches and ABI violations. Use this for calling the implementation being tested.
| func | Function pointer to call (must match declared signature) |
| ... | Arguments to pass to the function |
| #define checkasm_call_new | ( | ... | ) |
Call the implementation being tested with validation.
Calls the optimized implementation being tested with the specified arguments, including full validation for register clobbering, stack corruption, etc. Must be preceded by a successful checkasm_check_func() call.
| ... | Arguments to pass to the function |
| #define checkasm_call_ref | ( | ... | ) |
Call the reference implementation.
Calls the reference (C) implementation with the specified arguments. Must be preceded by a successful checkasm_check_func() call.
| ... | Arguments to pass to the function |
| #define checkasm_check_func | ( | func, | |
| ... ) |
Check if a function should be tested and set up function references.
Determines if the given function implementation should be tested, and if so, sets up the function pointers for subsequent calls to checkasm_call_ref() and checkasm_call_new().
| [in] | func | Function pointer (or arbitrary CheckasmKey) to test, or 0 to skip |
| [in] | name | Printf-style format string for the function name |
| [in] | ... | Format arguments for the function name |
| #define checkasm_declare | ( | ret, | |
| ... ) |
Declare a function signature for testing.
Declares the function prototype that will be tested. This must be called before using checkasm_call_checked(), checkasm_call_ref(), or checkasm_call_new(). The first argument is the return type, and remaining arguments are the function parameters (naming parameters is optional).
| ret | Return type of the function |
| ... | Function parameter types |
| #define checkasm_declare_emms | ( | cpu_flags, | |
| ret, | |||
| ... ) |
Declare signature for non-ABI compliant MMX functions (x86 only).
Variant of checkasm_declare() for MMX functions that omit calling emms before returning to the caller. This is used for optimized MMX kernels that expect the caller to run emms manually.
| cpu_flags | Mask of CPU flags under which to enable the extra emms call |
| ret | Return type of the function |
| ... | Function parameter types |
| #define checkasm_fail | ( | ) |
Mark the current test as failed.
Records a test failure with the current file and line number. This is the most common way to indicate test failure. The test will continue executing, but any future calls to checkasm_check_func() for this function will return 0.
| #define checkasm_func_new ((func_type *) checkasm_key_new) |
Function pointer to the implementation being tested.
This is just a typed version of checkasm_key_new, cast to the type declared by checkasm_declare().
| #define checkasm_func_ref ((func_type *) checkasm_key_ref) |
Function pointer to the reference implementation.
This is just a typed version of checkasm_key_ref, cast to the type declared by checkasm_declare().
| CHECKASM_API int checkasm_fail_func | ( | const char * | msg, |
| ... ) |
Mark the current function as failed with a custom message.
Records a test failure with a printf-style formatted message.
| [in] | msg | Printf-style format string describing the failure |
| [in] | ... | Format arguments |
| CHECKASM_API void checkasm_report | ( | const char * | name, |
| ... ) |
Report test outcome for a named group of functions.
Prints the result (pass/fail) for a named group of functions. Typically called at the end of a test, as well as after any larger block of similar functions.
| [in] | name | Printf-style format string for the test case name |
| [in] | ... | Format arguments |
| CHECKASM_API int checkasm_should_fail | ( | CheckasmCpu | cpu_flags | ) |
Mark a block of tests as expected to fail.
Marks the following test functions as expected to fail when any of the specified CPU flags are set. Returns whether these functions should be executed.
| [in] | cpu_flags | CPU flags for which failure is expected (or -1 for all) |
|
static |
Key identifying the implementation being tested.
Set by checkasm_check_func() to point to the key passed to it.
|
static |
Key identifying the reference implementation.
Set by checkasm_check_func() to point to the reference key for the function currently being tested.