OpenVPN
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cmocka.c File Reference
#include <stdint.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cmocka.h>
#include <cmocka_private.h>
Include dependency graph for cmocka.c:

Go to the source code of this file.

Data Structures

union  ValuePointer
 
struct  ListNode
 
struct  MallocBlockInfo
 
struct  TestState
 
struct  SymbolValue
 
struct  SymbolMapValue
 
struct  FuncOrderingValue
 
struct  CheckIntegerRange
 
struct  CheckIntegerSet
 
struct  CheckMemoryData
 
struct  ExceptionCodeInfo
 
struct  CMUnitTestState
 

Macros

#define MALLOC_GUARD_SIZE   16
 
#define MALLOC_GUARD_PATTERN   0xEF
 
#define MALLOC_ALLOC_PATTERN   0xBA
 
#define MALLOC_FREE_PATTERN   0xCD
 
#define MALLOC_ALIGNMENT   sizeof(size_t)
 
#define SOURCE_LOCATION_FORMAT   "%s:%u"
 
#define CMOCKA_THREAD
 
#define CMOCKA_CLOCK_GETTIME(clock_id, ts)
 
#define cm_jmp_buf   jmp_buf
 POSIX has sigsetjmp/siglongjmp, while Windows only has setjmp/longjmp. More...
 
#define cm_setjmp(env)   setjmp(env)
 
#define cm_longjmp(env, val)   longjmp(env, val)
 
#define declare_initialize_value_pointer_pointer(name, ptr)
 
#define declare_initialize_value_pointer_value(name, val)
 
#define cast_largest_integral_type_to_pointer(pointer_type, largest_integral_type)   ((pointer_type)((ValuePointer*)&(largest_integral_type))->x.pointer)
 
#define EXCEPTION_CODE_INFO(exception_code)   {exception_code, #exception_code}
 
#define malloc   test_malloc
 
#define free   test_free
 
#define realloc   test_realloc
 
#define malloc   test_malloc
 
#define free   test_free
 
#define realloc   test_realloc
 

Typedefs

typedef union ValuePointer ValuePointer
 
typedef struct ListNode ListNode
 
typedef struct MallocBlockInfo MallocBlockInfo
 
typedef struct TestState TestState
 
typedef int(* EqualityFunction) (const void *left, const void *right)
 
typedef struct SymbolValue SymbolValue
 
typedef struct SymbolMapValue SymbolMapValue
 
typedef struct FuncOrderingValue FuncOrderingValue
 
typedef void(* CleanupListValue) (const void *value, void *cleanup_value_data)
 
typedef struct CheckIntegerRange CheckIntegerRange
 
typedef struct CheckIntegerSet CheckIntegerSet
 
typedef struct CheckMemoryData CheckMemoryData
 
typedef struct ExceptionCodeInfo ExceptionCodeInfo
 

Enumerations

enum  CMUnitTestStatus {
  CM_TEST_NOT_STARTED, CM_TEST_PASSED, CM_TEST_FAILED, CM_TEST_ERROR,
  CM_TEST_SKIPPED
}
 
enum  cm_printf_type {
  PRINTF_TEST_START, PRINTF_TEST_SUCCESS, PRINTF_TEST_FAILURE, PRINTF_TEST_ERROR,
  PRINTF_TEST_SKIPPED
}
 

Functions

static ListNodelist_initialize (ListNode *const node)
 
static ListNodelist_add (ListNode *const head, ListNode *new_node)
 
static ListNodelist_add_value (ListNode *const head, const void *value, const int count)
 
static ListNodelist_remove (ListNode *const node, const CleanupListValue cleanup_value, void *const cleanup_value_data)
 
static void list_remove_free (ListNode *const node, const CleanupListValue cleanup_value, void *const cleanup_value_data)
 
static int list_empty (const ListNode *const head)
 
static int list_find (ListNode *const head, const void *value, const EqualityFunction equal_func, ListNode **output)
 
static int list_first (ListNode *const head, ListNode **output)
 
static ListNodelist_free (ListNode *const head, const CleanupListValue cleanup_value, void *const cleanup_value_data)
 
static void add_symbol_value (ListNode *const symbol_map_head, const char *const symbol_names[], const size_t number_of_symbol_names, const void *value, const int count)
 
static int get_symbol_value (ListNode *const symbol_map_head, const char *const symbol_names[], const size_t number_of_symbol_names, void **output)
 
static void free_value (const void *value, void *cleanup_value_data)
 
static void free_symbol_map_value (const void *value, void *cleanup_value_data)
 
static void remove_always_return_values (ListNode *const map_head, const size_t number_of_symbol_names)
 
static int check_for_leftover_values_list (const ListNode *head, const char *const error_message)
 
static int check_for_leftover_values (const ListNode *const map_head, const char *const error_message, const size_t number_of_symbol_names)
 
static void remove_always_return_values_from_list (ListNode *const map_head)
 Taverse a list of nodes and remove first symbol value in list that has a refcount < -1 (i.e. More...
 
static void initialize_testing (const char *test_name)
 
static void teardown_testing (const char *test_name)
 
static enum cm_message_output cm_get_output (void)
 
void cm_print_error (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
 
static void exit_test (const int quit_application)
 
void _skip (const char *const file, const int line)
 
static void initialize_source_location (SourceLocation *const location)
 
static int source_location_is_set (const SourceLocation *const location)
 
static void set_source_location (SourceLocation *const location, const char *const file, const int line)
 
static void fail_if_leftover_values (const char *test_name)
 
static int symbol_names_match (const void *map_value, const void *symbol)
 
LargestIntegralType _mock (const char *const function, const char *const file, const int line)
 
void _function_called (const char *const function, const char *const file, const int line)
 
void _will_return (const char *const function_name, const char *const file, const int line, const LargestIntegralType value, const int count)
 
void _expect_check (const char *const function, const char *const parameter, const char *const file, const int line, const CheckParameterValue check_function, const LargestIntegralType check_data, CheckParameterEvent *const event, const int count)
 
void _expect_function_call (const char *const function_name, const char *const file, const int line, const int count)
 
static int values_equal_display_error (const LargestIntegralType left, const LargestIntegralType right)
 
static int values_not_equal_display_error (const LargestIntegralType left, const LargestIntegralType right)
 
static int value_in_set_display_error (const LargestIntegralType value, const CheckIntegerSet *const check_integer_set, const int invert)
 
static int integer_in_range_display_error (const LargestIntegralType value, const LargestIntegralType range_min, const LargestIntegralType range_max)
 
static int integer_not_in_range_display_error (const LargestIntegralType value, const LargestIntegralType range_min, const LargestIntegralType range_max)
 
static int string_equal_display_error (const char *const left, const char *const right)
 
static int string_not_equal_display_error (const char *const left, const char *const right)
 
static int memory_equal_display_error (const char *const a, const char *const b, const size_t size)
 
static int memory_not_equal_display_error (const char *const a, const char *const b, const size_t size)
 
static int check_in_set (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
static int check_not_in_set (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
static void expect_set (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const CheckParameterValue check_function, const int count)
 
void _expect_in_set (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
 
void _expect_not_in_set (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
 
static int check_in_range (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
static int check_not_in_range (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
static void expect_range (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const CheckParameterValue check_function, const int count)
 
void _expect_in_range (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
 
void _expect_not_in_range (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
 
static int check_value (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_value (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
 
static int check_not_value (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_not_value (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
 
static int check_string (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_string (const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
 
static int check_not_string (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_not_string (const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
 
static int check_memory (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
static void expect_memory_setup (const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const CheckParameterValue check_function, const int count)
 
void _expect_memory (const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
 
static int check_not_memory (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_not_memory (const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
 
static int check_any (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
void _expect_any (const char *const function, const char *const parameter, const char *const file, const int line, const int count)
 
void _check_expected (const char *const function_name, const char *const parameter_name, const char *file, const int line, const LargestIntegralType value)
 
void mock_assert (const int result, const char *const expression, const char *const file, const int line)
 Function to replace assert(3) in tested code. More...
 
void _assert_true (const LargestIntegralType result, const char *const expression, const char *const file, const int line)
 
void _assert_return_code (const LargestIntegralType result, size_t rlen, const LargestIntegralType error, const char *const expression, const char *const file, const int line)
 
void _assert_int_equal (const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
 
void _assert_int_not_equal (const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
 
void _assert_string_equal (const char *const a, const char *const b, const char *const file, const int line)
 
void _assert_string_not_equal (const char *const a, const char *const b, const char *file, const int line)
 
void _assert_memory_equal (const void *const a, const void *const b, const size_t size, const char *const file, const int line)
 
void _assert_memory_not_equal (const void *const a, const void *const b, const size_t size, const char *const file, const int line)
 
void _assert_in_range (const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)
 
void _assert_not_in_range (const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)
 
void _assert_in_set (const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char *const file, const int line)
 
void _assert_not_in_set (const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char *const file, const int line)
 
static ListNodeget_allocated_blocks_list ()
 
static void * libc_malloc (size_t size)
 
static void libc_free (void *ptr)
 
static void * libc_realloc (void *ptr, size_t size)
 
static void vcm_print_error (const char *const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1
 
static void vcm_free_error (char *err_msg)
 
void * _test_malloc (const size_t size, const char *file, const int line)
 
void * _test_calloc (const size_t number_of_elements, const size_t size, const char *file, const int line)
 
void _test_free (void *const ptr, const char *file, const int line)
 
void * _test_realloc (void *ptr, const size_t size, const char *file, const int line)
 
static const ListNodecheck_point_allocated_blocks ()
 
static int display_allocated_blocks (const ListNode *const check_point)
 
static void free_allocated_blocks (const ListNode *const check_point)
 
static void fail_if_blocks_allocated (const ListNode *const check_point, const char *const test_name)
 
void _fail (const char *const file, const int line)
 
static LONG WINAPI exception_filter (EXCEPTION_POINTERS *exception_pointers)
 
void vprint_message (const char *const format, va_list args)
 
void vprint_error (const char *const format, va_list args)
 
void print_message (const char *const format,...)
 
void print_error (const char *const format,...)
 
static void cmprintf_group_finish_xml (const char *group_name, size_t total_executed, size_t total_failed, size_t total_errors, size_t total_skipped, double total_runtime, struct CMUnitTestState *cm_tests)
 
static void cmprintf_group_start_standard (const size_t num_tests)
 
static void cmprintf_group_finish_standard (size_t total_executed, size_t total_passed, size_t total_failed, size_t total_errors, size_t total_skipped, struct CMUnitTestState *cm_tests)
 
static void cmprintf_standard (enum cm_printf_type type, const char *test_name, const char *error_message)
 
static void cmprintf_group_start_tap (const size_t num_tests)
 
static void cmprintf_group_finish_tap (const char *group_name, size_t total_executed, size_t total_passed, size_t total_skipped)
 
static void cmprintf_tap (enum cm_printf_type type, uint32_t test_number, const char *test_name, const char *error_message)
 
static void cmprintf_subunit (enum cm_printf_type type, const char *test_name, const char *error_message)
 
static void cmprintf_group_start (const size_t num_tests)
 
static void cmprintf_group_finish (const char *group_name, size_t total_executed, size_t total_passed, size_t total_failed, size_t total_errors, size_t total_skipped, double total_runtime, struct CMUnitTestState *cm_tests)
 
static void cmprintf (enum cm_printf_type type, size_t test_number, const char *test_name, const char *error_message)
 
void cmocka_set_message_output (enum cm_message_output output)
 Function to set the output format for a test. More...
 
static int cmocka_run_one_test_or_fixture (const char *function_name, CMUnitTestFunction test_func, CMFixtureFunction setup_func, CMFixtureFunction teardown_func, void **const volatile state, const void *const heap_check_point)
 
static int cmocka_run_group_fixture (const char *function_name, CMFixtureFunction setup_func, CMFixtureFunction teardown_func, void **state, const void *const heap_check_point)
 
static int cmocka_run_one_tests (struct CMUnitTestState *test_state)
 
int _cmocka_run_group_tests (const char *group_name, const struct CMUnitTest *const tests, const size_t num_tests, CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
 
int _run_test (const char *const function_name, const UnitTestFunction Function, void **const volatile state, const UnitTestFunctionType function_type, const void *const heap_check_point)
 
int _run_tests (const UnitTest *const tests, const size_t number_of_tests)
 
int _run_group_tests (const UnitTest *const tests, const size_t number_of_tests)
 

Variables

static int cm_error_message_enabled = 1
 
static CMOCKA_THREAD char * cm_error_message
 
void static CMOCKA_THREAD cm_jmp_buf global_run_test_env
 
static CMOCKA_THREAD int global_running_test = 0
 
jmp_buf global_expect_assert_env
 
int global_expecting_assert = 0
 
const char * global_last_failed_assert = NULL
 
static int global_skip_test
 
static CMOCKA_THREAD ListNode global_function_result_map_head
 
static CMOCKA_THREAD SourceLocation global_last_mock_value_location
 
static CMOCKA_THREAD ListNode global_function_parameter_map_head
 
static CMOCKA_THREAD SourceLocation global_last_parameter_location
 
static CMOCKA_THREAD ListNode global_call_ordering_head
 
static CMOCKA_THREAD SourceLocation global_last_call_ordering_location
 
static CMOCKA_THREAD ListNode global_allocated_blocks
 
static enum cm_message_output global_msg_output = CM_OUTPUT_STDOUT
 
static LPTOP_LEVEL_EXCEPTION_FILTER previous_exception_filter
 
static const ExceptionCodeInfo exception_codes []
 

Macro Definition Documentation

◆ cast_largest_integral_type_to_pointer

#define cast_largest_integral_type_to_pointer (   pointer_type,
  largest_integral_type 
)    ((pointer_type)((ValuePointer*)&(largest_integral_type))->x.pointer)

◆ cm_jmp_buf

#define cm_jmp_buf   jmp_buf

POSIX has sigsetjmp/siglongjmp, while Windows only has setjmp/longjmp.

Definition at line 99 of file cmocka.c.

◆ cm_longjmp

#define cm_longjmp (   env,
  val 
)    longjmp(env, val)

Definition at line 101 of file cmocka.c.

Referenced by exit_test().

◆ cm_setjmp

#define cm_setjmp (   env)    setjmp(env)

Definition at line 100 of file cmocka.c.

Referenced by _run_test(), and cmocka_run_one_test_or_fixture().

◆ CMOCKA_CLOCK_GETTIME

#define CMOCKA_CLOCK_GETTIME (   clock_id,
  ts 
)

Definition at line 88 of file cmocka.c.

Referenced by cmocka_run_one_tests().

◆ CMOCKA_THREAD

#define CMOCKA_THREAD

Definition at line 82 of file cmocka.c.

◆ declare_initialize_value_pointer_pointer

#define declare_initialize_value_pointer_pointer (   name,
  ptr 
)
Value:
ValuePointer name ; \
name.value = 0; \
name.x.pointer = (void*)(ptr)
LargestIntegralType value
Definition: cmocka.c:129

Definition at line 109 of file cmocka.c.

Referenced by _expect_not_string(), _expect_string(), expect_memory_setup(), expect_range(), and expect_set().

◆ declare_initialize_value_pointer_value

#define declare_initialize_value_pointer_value (   name,
  val 
)
Value:
ValuePointer name ; \
name.value = val
LargestIntegralType value
Definition: cmocka.c:129

Definition at line 118 of file cmocka.c.

◆ EXCEPTION_CODE_INFO

#define EXCEPTION_CODE_INFO (   exception_code)    {exception_code, #exception_code}

Definition at line 334 of file cmocka.c.

◆ free [1/2]

#define free   test_free

Definition at line 1850 of file cmocka.c.

Referenced by _check_expected(), _mock(), _run_group_tests(), _run_tests(), _test_free(), AsyncPipeOp(), auth_set_client_reason(), auth_token_test_session_mismatch(), auth_token_test_timeout(), buffer_list_aggregate_separator(), buffer_list_file(), buffer_list_free(), buffer_list_pop(), buffer_list_reset(), buffer_overflow(), buffer_underflow(), CAPI_DATA_free(), ccs_delete_config_file(), ccs_delete_deferred_ret_file(), cert_hash_free(), check_file_access(), cipher_kt_block_size(), close_syslog(), close_tun(), command_line_free(), DllMain(), do_close_tls(), do_open_tun(), do_setenv_x509(), env_set_destroy(), establish_http_proxy_passthru(), EvaluateTUNTAPAdapters(), EVP_MD_CTX_free(), ExecCommand(), find_adapters(), fork_to_self(), fragment_free(), free_allocated_blocks(), free_buf(), free_buf_gc(), free_context(), free_context_buffers(), free_symbol_map_value(), free_value(), FreeStartupData(), FreeWaitHandles(), frequency_limit_free(), generate_auth_token(), get_addr_generic(), get_console_input_win32(), get_net_adapter_guid(), get_proxy_authenticate(), get_reg_string(), get_sig_from_man(), get_user_pass_cr(), GetBuiltinAdminGroupName(), GetStartupData(), GetTokenGroups(), group_teardown(), HandleAddressMessage(), HandleBlockDNSMessage(), HandleDNSConfigMessage(), HandleEnableDHCPMessage(), HandleRouteMessage(), hash_free(), hash_remove_fast(), hash_remove_marked(), HMAC_CTX_free(), http_proxy_close(), ifconfig_pool_entry_free(), ifconfig_pool_free(), ifconfig_pool_persist_close(), init_ssl(), InterfaceLuid(), ipset2ascii_all(), IsAuthorizedUser(), key_method_2_read(), key_state_free(), key_state_rm_auth_control_files(), key_state_rm_auth_pending_file(), libc_free(), link_socket_close(), list_remove_free(), log_entry_free_contents(), log_history_close(), log_history_free_contents(), main(), make_base64_string2(), malloc_setup_test(), man_send_cc_message(), man_settings_close(), management_close(), mbuf_free(), mbuf_free_buf(), mroute_helper_free(), msi_format_field(), msi_format_record(), msi_get_record_string(), msi_get_string(), msica_arg_seq_free(), multi_instance_dec_refcount(), multi_learn_addr(), multi_reap_free(), multi_route_del(), multi_tcp_free(), multi_uninit(), mutate_ncp_cipher_list(), my_conv(), netsh_dns_cmd(), open_null(), openvpn_execve(), openvpn_plugin_client_destructor_v1(), openvpn_plugin_close_v1(), openvpn_plugin_func_v1(), openvpn_plugin_open_v3(), openvpn_plugin_string_list_item_free(), options_string(), packet_id_free(), pattern_not_found__returns_original(), perform_operation(), plugin_common_close(), plugin_list_close(), prestate_teardown(), prng_uninit(), ProcessDeferredAction(), read_string_alloc(), reliable_free(), remove_env_item(), RemoveListItem(), replace_longer_text__multiple_times__match_all_matches_are_replaced(), replace_single_char__multiple_times__match_all_matches_are_replaced(), replace_single_char__one_time__match_is_replaced(), RSA_meth_free(), rsa_priv_enc(), RunOpenvpn(), schedule_free(), schedule_remove_entry(), set_common_name(), set_win_sys_path(), SetDNSDomain(), setenv_str_incr(), setup_sequence(), show_available_curves(), socks_proxy_close(), split_scrv1_password(), ssl_purge_auth_challenge(), StartOpenVPNGUI(), status_close(), store_proxy_authenticate(), tap_free_adapter_list(), tap_list_adapters(), tap_set_adapter_name(), teardown(), teardown_only(), test_buffer_list_teardown(), test_order_hotdog(), test_packet_id_write_teardown(), test_tls_crypt_teardown(), test_tls_crypt_v2_teardown(), tls_item_in_cipher_list(), tls_multi_free(), tls_session_free(), Undo(), uninit_win32(), waiter_process(), we_free(), we_init(), wipe_auth_token(), wmain(), wmic_nicconfig_cmd(), x509_setenv(), x_gc_free(), x_gc_freespecial(), and x_msg_va().

◆ free [2/2]

#define free   test_free

Definition at line 1850 of file cmocka.c.

◆ malloc [1/2]

#define malloc   test_malloc

◆ malloc [2/2]

#define malloc   test_malloc

Definition at line 1795 of file cmocka.c.

◆ MALLOC_ALIGNMENT

#define MALLOC_ALIGNMENT   sizeof(size_t)

Definition at line 72 of file cmocka.c.

Referenced by _test_malloc().

◆ MALLOC_ALLOC_PATTERN

#define MALLOC_ALLOC_PATTERN   0xBA

Definition at line 69 of file cmocka.c.

Referenced by _test_malloc().

◆ MALLOC_FREE_PATTERN

#define MALLOC_FREE_PATTERN   0xCD

Definition at line 70 of file cmocka.c.

Referenced by _test_free().

◆ MALLOC_GUARD_PATTERN

#define MALLOC_GUARD_PATTERN   0xEF

Definition at line 67 of file cmocka.c.

Referenced by _test_free(), and _test_malloc().

◆ MALLOC_GUARD_SIZE

#define MALLOC_GUARD_SIZE   16

Definition at line 65 of file cmocka.c.

Referenced by _test_free(), _test_malloc(), _test_realloc(), and free_allocated_blocks().

◆ realloc [1/2]

#define realloc   test_realloc

Definition at line 1891 of file cmocka.c.

Referenced by libc_realloc(), and UpdateWaitHandles().

◆ realloc [2/2]

#define realloc   test_realloc

Definition at line 1891 of file cmocka.c.

◆ SOURCE_LOCATION_FORMAT

#define SOURCE_LOCATION_FORMAT   "%s:%u"

Typedef Documentation

◆ CheckIntegerRange

◆ CheckIntegerSet

◆ CheckMemoryData

◆ CleanupListValue

typedef void(* CleanupListValue) (const void *value, void *cleanup_value_data)

Definition at line 188 of file cmocka.c.

◆ EqualityFunction

typedef int(* EqualityFunction) (const void *left, const void *right)

Definition at line 163 of file cmocka.c.

◆ ExceptionCodeInfo

◆ FuncOrderingValue

◆ ListNode

typedef struct ListNode ListNode

◆ MallocBlockInfo

◆ SymbolMapValue

◆ SymbolValue

typedef struct SymbolValue SymbolValue

◆ TestState

typedef struct TestState TestState

◆ ValuePointer

typedef union ValuePointer ValuePointer

Enumeration Type Documentation

◆ cm_printf_type

Enumerator
PRINTF_TEST_START 
PRINTF_TEST_SUCCESS 
PRINTF_TEST_FAILURE 
PRINTF_TEST_ERROR 
PRINTF_TEST_SKIPPED 

Definition at line 2093 of file cmocka.c.

◆ CMUnitTestStatus

Enumerator
CM_TEST_NOT_STARTED 
CM_TEST_PASSED 
CM_TEST_FAILED 
CM_TEST_ERROR 
CM_TEST_SKIPPED 

Definition at line 360 of file cmocka.c.

Function Documentation

◆ add_symbol_value()

static void add_symbol_value ( ListNode *const  symbol_map_head,
const char *const  symbol_names[],
const size_t  number_of_symbol_names,
const void *  value,
const int  count 
)
static

◆ check_any()

static int check_any ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1458 of file cmocka.c.

Referenced by _expect_any().

◆ check_for_leftover_values()

static int check_for_leftover_values ( const ListNode *const  map_head,
const char *const  error_message,
const size_t  number_of_symbol_names 
)
static

◆ check_for_leftover_values_list()

static int check_for_leftover_values_list ( const ListNode head,
const char *const  error_message 
)
static

◆ check_in_range()

static int check_in_range ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

◆ check_in_set()

static int check_in_set ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1185 of file cmocka.c.

References cast_largest_integral_type_to_pointer, and value_in_set_display_error().

Referenced by _expect_in_set().

◆ check_memory()

static int check_memory ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

◆ check_not_in_range()

static int check_not_in_range ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

◆ check_not_in_set()

static int check_not_in_set ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1194 of file cmocka.c.

References cast_largest_integral_type_to_pointer, and value_in_set_display_error().

Referenced by _expect_not_in_set().

◆ check_not_memory()

static int check_not_memory ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

◆ check_not_string()

static int check_not_string ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

◆ check_not_value()

static int check_not_value ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1331 of file cmocka.c.

References values_not_equal_display_error().

Referenced by _expect_not_value().

◆ check_point_allocated_blocks()

static const ListNode* check_point_allocated_blocks ( )
static

◆ check_string()

static int check_string ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1348 of file cmocka.c.

References cast_largest_integral_type_to_pointer, and string_equal_display_error().

Referenced by _expect_string().

◆ check_value()

static int check_value ( const LargestIntegralType  value,
const LargestIntegralType  check_value_data 
)
static

Definition at line 1313 of file cmocka.c.

References values_equal_display_error().

Referenced by _expect_value().

◆ cm_get_output()

static enum cm_message_output cm_get_output ( void  )
static

◆ cm_print_error()

void cm_print_error ( const char *const  format,
  ... 
)

◆ cmocka_run_group_fixture()

static int cmocka_run_group_fixture ( const char *  function_name,
CMFixtureFunction  setup_func,
CMFixtureFunction  teardown_func,
void **  state,
const void *const  heap_check_point 
)
static

Definition at line 2578 of file cmocka.c.

References cmocka_run_one_test_or_fixture().

Referenced by _cmocka_run_group_tests().

◆ cmocka_run_one_test_or_fixture()

static int cmocka_run_one_test_or_fixture ( const char *  function_name,
CMUnitTestFunction  test_func,
CMFixtureFunction  setup_func,
CMFixtureFunction  teardown_func,
void **const volatile  state,
const void *const  heap_check_point 
)
static

◆ cmocka_run_one_tests()

static int cmocka_run_one_tests ( struct CMUnitTestState test_state)
static

◆ cmprintf()

static void cmprintf ( enum cm_printf_type  type,
size_t  test_number,
const char *  test_name,
const char *  error_message 
)
static

◆ cmprintf_group_finish()

static void cmprintf_group_finish ( const char *  group_name,
size_t  total_executed,
size_t  total_passed,
size_t  total_failed,
size_t  total_errors,
size_t  total_skipped,
double  total_runtime,
struct CMUnitTestState cm_tests 
)
static

◆ cmprintf_group_finish_standard()

static void cmprintf_group_finish_standard ( size_t  total_executed,
size_t  total_passed,
size_t  total_failed,
size_t  total_errors,
size_t  total_skipped,
struct CMUnitTestState cm_tests 
)
static

◆ cmprintf_group_finish_tap()

static void cmprintf_group_finish_tap ( const char *  group_name,
size_t  total_executed,
size_t  total_passed,
size_t  total_skipped 
)
static

Definition at line 2259 of file cmocka.c.

References print_message(), and status.

Referenced by cmprintf_group_finish().

◆ cmprintf_group_finish_xml()

static void cmprintf_group_finish_xml ( const char *  group_name,
size_t  total_executed,
size_t  total_failed,
size_t  total_errors,
size_t  total_skipped,
double  total_runtime,
struct CMUnitTestState cm_tests 
)
static

◆ cmprintf_group_start()

static void cmprintf_group_start ( const size_t  num_tests)
static

◆ cmprintf_group_start_standard()

static void cmprintf_group_start_standard ( const size_t  num_tests)
static

Definition at line 2180 of file cmocka.c.

References print_message().

Referenced by cmprintf_group_start().

◆ cmprintf_group_start_tap()

static void cmprintf_group_start_tap ( const size_t  num_tests)
static

Definition at line 2254 of file cmocka.c.

References print_message().

Referenced by cmprintf_group_start().

◆ cmprintf_standard()

static void cmprintf_standard ( enum cm_printf_type  type,
const char *  test_name,
const char *  error_message 
)
static

◆ cmprintf_subunit()

static void cmprintf_subunit ( enum cm_printf_type  type,
const char *  test_name,
const char *  error_message 
)
static

◆ cmprintf_tap()

static void cmprintf_tap ( enum cm_printf_type  type,
uint32_t  test_number,
const char *  test_name,
const char *  error_message 
)
static

◆ display_allocated_blocks()

static int display_allocated_blocks ( const ListNode *const  check_point)
static

◆ exception_filter()

static LONG WINAPI exception_filter ( EXCEPTION_POINTERS *  exception_pointers)
static

◆ exit_test()

static void exit_test ( const int  quit_application)
static

◆ expect_memory_setup()

static void expect_memory_setup ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const void *const  memory,
const size_t  size,
const CheckParameterValue  check_function,
const int  count 
)
static

◆ expect_range()

static void expect_range ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const LargestIntegralType  minimum,
const LargestIntegralType  maximum,
const CheckParameterValue  check_function,
const int  count 
)
static

◆ expect_set()

static void expect_set ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const LargestIntegralType  values[],
const size_t  number_of_values,
const CheckParameterValue  check_function,
const int  count 
)
static

◆ fail_if_blocks_allocated()

static void fail_if_blocks_allocated ( const ListNode *const  check_point,
const char *const  test_name 
)
static

◆ fail_if_leftover_values()

static void fail_if_leftover_values ( const char *  test_name)
static

◆ free_allocated_blocks()

static void free_allocated_blocks ( const ListNode *const  check_point)
static

◆ free_symbol_map_value()

static void free_symbol_map_value ( const void *  value,
void *  cleanup_value_data 
)
static

◆ free_value()

static void free_value ( const void *  value,
void *  cleanup_value_data 
)
static

◆ get_allocated_blocks_list()

static ListNode* get_allocated_blocks_list ( )
static

◆ get_symbol_value()

static int get_symbol_value ( ListNode *const  symbol_map_head,
const char *const  symbol_names[],
const size_t  number_of_symbol_names,
void **  output 
)
static

◆ initialize_source_location()

static void initialize_source_location ( SourceLocation *const  location)
static

Definition at line 400 of file cmocka.c.

References assert_non_null, SourceLocation::file, and SourceLocation::line.

Referenced by initialize_testing(), and teardown_testing().

◆ initialize_testing()

void initialize_testing ( const char *  test_name)
static

Definition at line 425 of file cmocka.c.

References initialize_source_location(), and list_initialize().

Referenced by _run_test(), and cmocka_run_one_test_or_fixture().

◆ integer_in_range_display_error()

static int integer_in_range_display_error ( const LargestIntegralType  value,
const LargestIntegralType  range_min,
const LargestIntegralType  range_max 
)
static

Definition at line 1074 of file cmocka.c.

References cm_print_error(), and PRIu64.

Referenced by _assert_in_range(), and check_in_range().

◆ integer_not_in_range_display_error()

static int integer_not_in_range_display_error ( const LargestIntegralType  value,
const LargestIntegralType  range_min,
const LargestIntegralType  range_max 
)
static

Definition at line 1091 of file cmocka.c.

References cm_print_error(), and PRIu64.

Referenced by _assert_not_in_range(), and check_not_in_range().

◆ libc_free()

static void libc_free ( void *  ptr)
static

Definition at line 1697 of file cmocka.c.

References free.

Referenced by _cmocka_run_group_tests(), cmprintf_tap(), and vcm_free_error().

◆ libc_malloc()

static void* libc_malloc ( size_t  size)
static

Definition at line 1690 of file cmocka.c.

References malloc.

Referenced by _cmocka_run_group_tests(), and vcm_print_error().

◆ libc_realloc()

static void* libc_realloc ( void *  ptr,
size_t  size 
)
static

Definition at line 1704 of file cmocka.c.

References CMOCKA_PRINTF_ATTRIBUTE, realloc, and vcm_print_error().

Referenced by vcm_print_error().

◆ list_add()

static ListNode * list_add ( ListNode *const  head,
ListNode new_node 
)
static

Definition at line 503 of file cmocka.c.

References assert_non_null, ListNode::next, and ListNode::prev.

Referenced by _test_malloc(), and list_add_value().

◆ list_add_value()

static ListNode * list_add_value ( ListNode *const  head,
const void *  value,
const int  count 
)
static

◆ list_empty()

static int list_empty ( const ListNode *const  head)
static

◆ list_find()

static int list_find ( ListNode *const  head,
const void *  value,
const EqualityFunction  equal_func,
ListNode **  output 
)
static

Definition at line 565 of file cmocka.c.

References assert_non_null, ListNode::next, and ListNode::value.

Referenced by add_symbol_value(), and get_symbol_value().

◆ list_first()

static int list_first ( ListNode *const  head,
ListNode **  output 
)
static

Definition at line 579 of file cmocka.c.

References assert_non_null, list_empty(), and ListNode::next.

Referenced by _function_called(), and get_symbol_value().

◆ list_free()

static ListNode * list_free ( ListNode *const  head,
const CleanupListValue  cleanup_value,
void *const  cleanup_value_data 
)
static

Definition at line 543 of file cmocka.c.

References assert_non_null, list_empty(), list_remove_free(), and ListNode::next.

Referenced by free_symbol_map_value(), and teardown_testing().

◆ list_initialize()

static ListNode * list_initialize ( ListNode *const  node)
static

◆ list_remove()

static ListNode * list_remove ( ListNode *const  node,
const CleanupListValue  cleanup_value,
void *const  cleanup_value_data 
)
static

Definition at line 515 of file cmocka.c.

References assert_non_null, ListNode::next, ListNode::prev, and ListNode::value.

Referenced by _test_free(), and list_remove_free().

◆ list_remove_free()

static void list_remove_free ( ListNode *const  node,
const CleanupListValue  cleanup_value,
void *const  cleanup_value_data 
)
static

◆ memory_equal_display_error()

static int memory_equal_display_error ( const char *const  a,
const char *const  b,
const size_t  size 
)
static

Definition at line 1137 of file cmocka.c.

References cm_print_error(), and PRIdS.

Referenced by _assert_memory_equal(), and check_memory().

◆ memory_not_equal_display_error()

static int memory_not_equal_display_error ( const char *const  a,
const char *const  b,
const size_t  size 
)
static

Definition at line 1164 of file cmocka.c.

References cm_print_error(), and PRIdS.

Referenced by _assert_memory_not_equal(), and check_not_memory().

◆ print_error()

void print_error ( const char *const  format,
  ... 
)

◆ print_message()

void print_message ( const char *const  format,
  ... 
)

◆ remove_always_return_values()

static void remove_always_return_values ( ListNode *const  map_head,
const size_t  number_of_symbol_names 
)
static

◆ remove_always_return_values_from_list()

static void remove_always_return_values_from_list ( ListNode *const  map_head)
static

Taverse a list of nodes and remove first symbol value in list that has a refcount < -1 (i.e.

should always be returned and has been returned at least once).

Definition at line 718 of file cmocka.c.

References assert_non_null, free_value(), list_remove_free(), ListNode::next, and ListNode::refcount.

Referenced by fail_if_leftover_values().

◆ set_source_location()

static void set_source_location ( SourceLocation *const  location,
const char *const  file,
const int  line 
)
static

◆ source_location_is_set()

static int source_location_is_set ( const SourceLocation *const  location)
static

Definition at line 408 of file cmocka.c.

References assert_non_null, SourceLocation::file, and SourceLocation::line.

Referenced by _check_expected(), and _mock().

◆ string_equal_display_error()

static int string_equal_display_error ( const char *const  left,
const char *const  right 
)
static

Definition at line 1108 of file cmocka.c.

References cm_print_error().

Referenced by _assert_string_equal(), and check_string().

◆ string_not_equal_display_error()

static int string_not_equal_display_error ( const char *const  left,
const char *const  right 
)
static

Definition at line 1123 of file cmocka.c.

References cm_print_error().

Referenced by _assert_string_not_equal(), and check_not_string().

◆ symbol_names_match()

static int symbol_names_match ( const void *  map_value,
const void *  symbol 
)
static

Definition at line 616 of file cmocka.c.

Referenced by add_symbol_value(), and get_symbol_value().

◆ teardown_testing()

static void teardown_testing ( const char *  test_name)
static

◆ value_in_set_display_error()

static int value_in_set_display_error ( const LargestIntegralType  value,
const CheckIntegerSet *const  check_integer_set,
const int  invert 
)
static

◆ values_equal_display_error()

static int values_equal_display_error ( const LargestIntegralType  left,
const LargestIntegralType  right 
)
static

Definition at line 1007 of file cmocka.c.

References cm_print_error(), and LargestIntegralTypePrintfFormat.

Referenced by _assert_int_equal(), and check_value().

◆ values_not_equal_display_error()

static int values_not_equal_display_error ( const LargestIntegralType  left,
const LargestIntegralType  right 
)
static

Definition at line 1020 of file cmocka.c.

References cm_print_error(), and LargestIntegralTypePrintfFormat.

Referenced by _assert_int_not_equal(), and check_not_value().

◆ vcm_free_error()

static void vcm_free_error ( char *  err_msg)
static

Definition at line 1760 of file cmocka.c.

References libc_free().

Referenced by _cmocka_run_group_tests().

◆ vcm_print_error()

static void static void vcm_print_error ( const char *const  format,
va_list  args 
)
static

Definition at line 1717 of file cmocka.c.

References cm_error_message, libc_malloc(), libc_realloc(), and vsnprintf.

Referenced by cm_print_error(), and libc_realloc().

◆ vprint_error()

void vprint_error ( const char *const  format,
va_list  args 
)

Definition at line 2045 of file cmocka.c.

References vsnprintf.

Referenced by cm_print_error(), and print_error().

◆ vprint_message()

void vprint_message ( const char *const  format,
va_list  args 
)

Definition at line 2034 of file cmocka.c.

References vsnprintf.

Referenced by print_message().

Variable Documentation

◆ cm_error_message

CMOCKA_THREAD char* cm_error_message
static

◆ cm_error_message_enabled

int cm_error_message_enabled = 1
static

Definition at line 263 of file cmocka.c.

Referenced by _run_test(), and cm_print_error().

◆ exception_codes

const ExceptionCodeInfo exception_codes[]
static
Initial value:
= {
EXCEPTION_CODE_INFO(EXCEPTION_ACCESS_VIOLATION),
EXCEPTION_CODE_INFO(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
EXCEPTION_CODE_INFO(EXCEPTION_DATATYPE_MISALIGNMENT),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_DENORMAL_OPERAND),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_DIVIDE_BY_ZERO),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_INEXACT_RESULT),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_INVALID_OPERATION),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_OVERFLOW),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_STACK_CHECK),
EXCEPTION_CODE_INFO(EXCEPTION_FLT_UNDERFLOW),
EXCEPTION_CODE_INFO(EXCEPTION_GUARD_PAGE),
EXCEPTION_CODE_INFO(EXCEPTION_ILLEGAL_INSTRUCTION),
EXCEPTION_CODE_INFO(EXCEPTION_INT_DIVIDE_BY_ZERO),
EXCEPTION_CODE_INFO(EXCEPTION_INT_OVERFLOW),
EXCEPTION_CODE_INFO(EXCEPTION_INVALID_DISPOSITION),
EXCEPTION_CODE_INFO(EXCEPTION_INVALID_HANDLE),
EXCEPTION_CODE_INFO(EXCEPTION_IN_PAGE_ERROR),
EXCEPTION_CODE_INFO(EXCEPTION_NONCONTINUABLE_EXCEPTION),
EXCEPTION_CODE_INFO(EXCEPTION_PRIV_INSTRUCTION),
EXCEPTION_CODE_INFO(EXCEPTION_STACK_OVERFLOW),
}
#define EXCEPTION_CODE_INFO(exception_code)
Definition: cmocka.c:334

Definition at line 336 of file cmocka.c.

◆ global_allocated_blocks

CMOCKA_THREAD ListNode global_allocated_blocks
static

Definition at line 300 of file cmocka.c.

Referenced by get_allocated_blocks_list().

◆ global_call_ordering_head

CMOCKA_THREAD ListNode global_call_ordering_head
static

Definition at line 295 of file cmocka.c.

◆ global_function_parameter_map_head

CMOCKA_THREAD ListNode global_function_parameter_map_head
static

Definition at line 290 of file cmocka.c.

◆ global_function_result_map_head

CMOCKA_THREAD ListNode global_function_result_map_head
static

Definition at line 284 of file cmocka.c.

◆ global_last_call_ordering_location

CMOCKA_THREAD SourceLocation global_last_call_ordering_location
static

Definition at line 297 of file cmocka.c.

◆ global_last_mock_value_location

CMOCKA_THREAD SourceLocation global_last_mock_value_location
static

Definition at line 286 of file cmocka.c.

◆ global_last_parameter_location

CMOCKA_THREAD SourceLocation global_last_parameter_location
static

Definition at line 292 of file cmocka.c.

◆ global_msg_output

enum cm_message_output global_msg_output = CM_OUTPUT_STDOUT
static

Definition at line 302 of file cmocka.c.

Referenced by cm_get_output(), and cmocka_set_message_output().

◆ global_run_test_env

void static CMOCKA_THREAD cm_jmp_buf global_run_test_env
static

Definition at line 266 of file cmocka.c.

◆ global_running_test

CMOCKA_THREAD int global_running_test = 0
static

Definition at line 273 of file cmocka.c.

◆ global_skip_test

int global_skip_test
static

Definition at line 280 of file cmocka.c.

◆ previous_exception_filter

LPTOP_LEVEL_EXCEPTION_FILTER previous_exception_filter
static

Definition at line 326 of file cmocka.c.