|
libose
|
provides utility functions and global variables for testing More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdint.h>#include <stdarg.h>#include <signal.h>#include <setjmp.h>#include <time.h>#include "ose.h"#include "ose_util.h"#include "ose_context.h"#include "ose_print.h"#include "ose_pprint.h"Go to the source code of this file.
Macros | |
| #define | MAX_BNDLSIZE 1024 |
| The size of a simple bundle. | |
| #define | COMPARE_BUNDLES(refbndl, testbndl) memcmp(refbndl, testbndl, 4 + ntohl(*((int32_t *)refbndl))) |
| Perform a byte-for-byte comparison of two bundles. | |
| #define | TEST_FUNCTION(pfx, fn) |
| Test a function. | |
| #define | SKIP_TEST_FUNCTION(fn) |
| Skip a test function. | |
| #define | SKIP_TEST(test, expected_result) |
| Skip an individual test. | |
Functions | |
| static char * | align (char *p) |
| static void | pbndl (ose_bundle bundle, const char *const str) |
| Format and print the contents of a bundle to stderr. | |
| static void | pbytes (ose_bundle bundle, int32_t start, int32_t end) |
| Print each byte of a bundle on a separate line to stderr. | |
| static void | print_passed (const char *const fname) |
| Print a message indicating that the current test passed. | |
| static void | print_failed (const char *const fname) |
| Print a message indicating that the current test failed. | |
| static void | print_results (const char *const fname) |
| Print the results of the current test. | |
| static void | print_startTest (const char *const fname) |
| Initialize global variables and print a preamble for a test. | |
| static void | init (void) |
| Initialize the testing system. | |
| static int | finalize (void) |
| Finalize the testing system. | |
Variables | |
| const int32_t | ASSERTION_FAILED = 0x66666666 |
| The return code for a failed assertion. | |
| const int32_t | ASSERTION_PASSED = 0x33333333 |
| The return code for a passed assertion. | |
| jmp_buf | env |
| int | grand_total_failctr |
| int | grand_total_testctr |
| int | test_functions_skipped |
| int | failctr |
| int | testctr |
| int | tests_skipped |
| int | verbose = 0 |
| Enable / disable verbosity. | |
provides utility functions and global variables for testing
| #define SKIP_TEST | ( | test, | |
| expected_result | |||
| ) |
Skip an individual test.
This function allows a single test to be disabled. It will keep track of any skipped tests to note their existence at the end of the run.
| test | the test being skipped |
| expected_result | the expected result of the test being skipped |
| #define SKIP_TEST_FUNCTION | ( | fn | ) |
Skip a test function.
This function allows a test function to be disabled by placing the SKIP_ prefix in front of TEST_FUNCTION, and will keep track of any skipped test functions to note their existence at the end of the run.
| fn | the function under test (being skipped) |
| #define TEST_FUNCTION | ( | pfx, | |
| fn | |||
| ) |
Test a function.
This is the basic macro that test functions of any sort (unit, etc.) should use to perform their tests. It handles any global variables, results printing, etc.
| pfx | the prefix for the type of test (ut_, etc.) |
| fn | the function under test |
|
static |
Finalize the testing system.
This should be called after finishing all test functions in a particular file (i.e. in main).
main so that the process exit status reflects the result — otherwise a failing suite is indistinguishable from a passing one to make, CI, or any other automation.
|
static |
Initialize the testing system.
This should be called before running any test functions in a particular file (i.e. in main).
|
static |
Format and print the contents of a bundle to stderr.
This function is mainly useful for debugging in gdb or llvm when the debugger is paused and you want to see the contents of a bundle. stderr is used so that the output can be redirected to another tty.
| bundle | the bundle to print |
| str | an identifier for the bundle—useful when printing many different bundles in the same session |
|
static |
Print each byte of a bundle on a separate line to stderr.
This function is mainly useful for debugging in gdb or llvm when the debugger is paused and you want to see the contents of a bundle. stderr is used so that the output can be redirected to another tty.
| bundle | the bundle to print |
| start | the index of the first byte to print (-4 to start with the size field of the bundle) |
| end | the index of the last byte to print |
| const int32_t ASSERTION_FAILED = 0x66666666 |
The return code for a failed assertion.
Test functions may intentionally call functions with conditions that will cause an assertion to fail, in which case this will be returned and compared to the test's expected_result.
| const int32_t ASSERTION_PASSED = 0x33333333 |
The return code for a passed assertion.
| int verbose = 0 |
Enable / disable verbosity.
Use this flag to enable extra printing to the console during testing. It may be switched on and off as desired, for example when verbosity is needed only for a specific test function.