/*
* Copyright 2008 Google Inc.
* Copyright 2014-2015 Andreas Schneider <asn@cryptomilk.org>
* Copyright 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#include <stdint.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
* This allows to add a platform specific header file. Some embedded platforms
* sometimes miss certain types and definitions.
*
* Example:
*
* typedef unsigned long int uintptr_t
* #define _UINTPTR_T 1
* #define _UINTPTR_T_DEFINED 1
*/
#ifdef CMOCKA_PLATFORM_INCLUDE
# include "cmocka_platform.h"
#endif /* CMOCKA_PLATFORM_INCLUDE */
#include <cmocka.h>
#include <cmocka_private.h>
/* Size of guard bytes around dynamically allocated blocks. */
/* Pattern used to initialize guard blocks. */
/* Pattern used to initialize memory allocated with test_malloc(). */
/* Alignment of allocated blocks. NOTE: This must be base2. */
/* Printf formatting for source code locations. */
#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
#elif defined(HAVE_MSVC_THREAD_LOCAL_STORAGE)
#else
# define CMOCKA_THREAD
#endif
#ifdef HAVE_CLOCK_GETTIME_REALTIME
#else
#endif
/*
* Declare and initialize the pointer member of ValuePointer variable name
* with ptr.
*/
ValuePointer name ; \
/*
* Declare and initialize the value member of ValuePointer variable name
* with val.
*/
ValuePointer name ; \
/* Cast a LargestIntegralType to pointer_type via a ValuePointer. */
#define cast_largest_integral_type_to_pointer( \
/* Used to cast LargetIntegralType to void* and vice versa. */
typedef union ValuePointer {
struct {
unsigned int padding;
#endif
void *pointer;
} x;
} ValuePointer;
/* Doubly linked list node. */
typedef struct ListNode {
const void *value;
int refcount;
} ListNode;
/* Debug information for malloc(). */
typedef struct MallocBlockInfo {
/* State of each test. */
typedef struct TestState {
/* setup function. */
} TestState;
/* Determines whether two values are the same. */
/* Value of a symbol and the place it was declared. */
typedef struct SymbolValue {
} SymbolValue;
/*
* Contains a list of values for a symbol.
* NOTE: Each structure referenced by symbol_values_list_head must have a
* SourceLocation as its' first member.
*/
typedef struct SymbolMapValue {
const char *symbol_name;
/* Used by list_free() to deallocate values referenced by list nodes. */
/* Structure used to check the range of integer types.a */
typedef struct CheckIntegerRange {
/* Structure used to check whether an integer value is in a set. */
typedef struct CheckIntegerSet {
/* Used to check whether a parameter matches the area of memory referenced by
* this structure. */
typedef struct CheckMemoryData {
const void *memory;
const int count);
static ListNode* list_remove(
void * const cleanup_value_data);
static void list_remove_free(
void * const cleanup_value_data);
static int list_find(
void * const cleanup_value_data);
static void add_symbol_value(
static int get_symbol_value(
static void free_symbol_map_value(
const void *value, void *cleanup_value_data);
const size_t number_of_symbol_names);
static int check_for_leftover_values(
const size_t number_of_symbol_names);
/*
* This must be called at the beginning of a test to initialize some data
* structures.
*/
static void initialize_testing(const char *test_name);
/* This must be called at the end of a test to free() allocated structures. */
static void teardown_testing(const char *test_name);
/*
* Keeps track of the calling context returned by setenv() so that the fail()
* method can jump out of a test.
*/
/* Keeps track of the calling context returned by setenv() so that */
/* mock_assert() can optionally jump back to expect_assert_failure(). */
int global_expecting_assert = 0;
static int global_skip_test;
/* Keeps a map of the values that functions will have to return to provide */
/* mocked interfaces. */
/* Location of the last mock value returned was declared. */
/* Keeps a map of the values that functions expect as parameters to their
* mocked interfaces. */
/* Location of last parameter value checked was declared. */
/* List of all currently allocated blocks. */
#ifndef _WIN32
/* Signals caught by exception_handler(). */
static const int exception_signals[] = {
#ifdef SIGBUS
#endif
#ifdef SIGSYS
#endif
};
/* Default signal functions that should be restored after a test is complete. */
#else /* _WIN32 */
/* The default exception filter. */
/* Fatal exceptions. */
typedef struct ExceptionCodeInfo {
const char* description;
};
#endif /* !_WIN32 */
enum CMUnitTestStatus {
};
struct CMUnitTestState {
};
/* Exit the currently executing test. */
{
abort();
} else if (global_running_test) {
} else if (quit_application) {
exit(-1);
}
}
{
global_skip_test = 1;
exit_test(1);
}
/* Initialize a SourceLocation structure. */
}
/* Determine whether a source location is currently set. */
}
/* Set a source location. */
static void set_source_location(
const int line) {
}
/* Create function results and expected parameter lists. */
(void)test_name;
}
int error_occurred = 0;
(void)test_name;
"%s() has remaining non-returned values.\n", 1)) {
error_occurred = 1;
}
"%s parameter still has values that haven't been checked.\n", 2)) {
error_occurred = 1;
}
if (error_occurred) {
exit_test(1);
}
}
(void)test_name;
(void*)0);
(void*)1);
}
/* Initialize a list node. */
return node;
}
/*
* Adds a value at the tail of a given list.
* The node referencing the value is allocated from the heap.
*/
const int refcount) {
}
/* Add new_node to the end of the list. */
return new_node;
}
/* Remove a node from a list. */
void * const cleanup_value_data) {
if (cleanup_value) {
}
return node;
}
/* Remove a list node from a list and free the node. */
static void list_remove_free(
void * const cleanup_value_data) {
}
/*
* Frees memory kept by a linked list The cleanup_value function is called for
* every "value" field of nodes in the list, except for the head. In addition
* to each list value, cleanup_value_data is passed to each call to
* cleanup_value. The head of the list is not deallocated.
*/
void * const cleanup_value_data) {
while (!list_empty(head)) {
}
return head;
}
/* Determine whether a list is empty. */
}
/*
* Find a value in the list using the equal_func to compare each node with the
* value.
*/
return 1;
}
}
return 0;
}
/* Returns the first node of a list */
if (list_empty(head)) {
return 0;
}
*output = target_node;
return 1;
}
/* Deallocate a value referenced by a list. */
(void)cleanup_value_data;
}
/* Releases memory associated to a symbol_map_value. */
void *cleanup_value_data) {
}
/*
* Determine whether a symbol name referenced by a symbol_map_value matches the
* specified function name.
*/
(const char*)symbol);
}
/*
* Adds a value to the queue of values associated with the given hierarchy of
* symbols. It's assumed value is allocated from the heap.
*/
const char * const symbol_names[],
const size_t number_of_symbol_names,
const char* symbol_name;
symbol_name = symbol_names[0];
&target_node)) {
1);
}
if (number_of_symbol_names == 1) {
} else {
refcount);
}
}
/*
* Gets the next value associated with the given hierarchy of symbols.
* The value is returned as an output parameter with the function returning the
* node's old refcount value if a value is found, 0 otherwise. This means that
* a return value of 1 indicates the node was just removed from the list.
*/
static int get_symbol_value(
const char* symbol_name;
symbol_name = symbol_names[0];
int return_value = 0;
if (number_of_symbol_names == 1) {
if (--value_node->refcount == 0) {
}
} else {
output);
}
if (list_empty(child_list)) {
}
return return_value;
} else {
}
return 0;
}
/*
* Traverse down a tree of symbol values and remove the first symbol value
* in each branch that has a refcount < -1 (i.e should always be returned
* and has been returned at least once).
*/
const size_t number_of_symbol_names) {
if (!list_empty(child_list)) {
if (number_of_symbol_names == 1) {
/* If this item has been returned more than once, free it. */
}
} else {
number_of_symbol_names - 1);
}
}
if (list_empty(child_list)) {
}
}
}
/*
* Checks if there are any leftover values set up by the test that were never
* retrieved through execution, and fail the test if that is the case.
*/
static int check_for_leftover_values(
const size_t number_of_symbol_names) {
int symbols_with_leftover_values = 0;
if (!list_empty(child_list)) {
if (number_of_symbol_names == 1) {
": note: remaining item was declared here\n",
}
} else {
number_of_symbol_names - 1);
}
}
}
return symbols_with_leftover_values;
}
/* Get the next return value for the specified mock function. */
const int line) {
void *result;
if (rc) {
if (rc == 1) {
}
return value;
} else {
": note: Previously returned mock value was declared here\n",
} else {
cm_print_error("There were no previously returned mock values for "
"this test.\n");
}
exit_test(1);
}
return 0;
}
/* Add a return value for the specified mock function name. */
const int count) {
}
/*
* Add a custom parameter checking function. If the event parameter is NULL
* the event structure is allocated internally by this function. If event
* parameter is provided it must be allocated on the heap and doesn't need to
* be deallocated by the caller.
*/
void _expect_check(
const LargestIntegralType check_data,
count);
}
/* Returns 1 if the specified values are equal. If the values are not equal
* an error is displayed and 0 is returned. */
const LargestIntegralType right) {
if (!equal) {
}
return equal;
}
/*
* Returns 1 if the specified values are not equal. If the values are equal
* an error is displayed and 0 is returned. */
const LargestIntegralType right) {
if (!not_equal) {
}
return not_equal;
}
/*
* Determine whether value is contained within check_integer_set.
* If invert is 0 and the value is in the set 1 is returned, otherwise 0 is
* returned and an error is displayed. If invert is 1 and the value is not
* in the set 1 is returned, otherwise 0 is returned and an error is
* displayed.
*/
static int value_in_set_display_error(
const LargestIntegralType value,
{
size_t i;
for (i = 0; i < size_of_set; i++) {
/* If invert = 0 and item is found, succeeded = 1. */
/* If invert = 1 and item is found, succeeded = 0. */
break;
}
}
if (succeeded) {
return 1;
}
for (i = 0; i < size_of_set; i++) {
}
cm_print_error(")\n");
}
return 0;
}
/*
* Determine whether a value is within the specified range. If the value is
* within the specified range 1 is returned. If the value isn't within the
* specified range an error is displayed and 0 is returned.
*/
static int integer_in_range_display_error(
const LargestIntegralType range_max) {
return 1;
}
return 0;
}
/*
* Determine whether a value is within the specified range. If the value
* is not within the range 1 is returned. If the value is within the
* specified range an error is displayed and zero is returned.
*/
static int integer_not_in_range_display_error(
const LargestIntegralType range_max) {
return 1;
}
return 0;
}
/*
* Determine whether the specified strings are equal. If the strings are equal
* 1 is returned. If they're not equal an error is displayed and 0 is
* returned.
*/
static int string_equal_display_error(
return 1;
}
return 0;
}
/*
* Determine whether the specified strings are equal. If the strings are not
* equal 1 is returned. If they're not equal an error is displayed and 0 is
* returned
*/
static int string_not_equal_display_error(
return 1;
}
return 0;
}
/*
* Determine whether the specified areas of memory are equal. If they're equal
* 1 is returned otherwise an error is displayed and 0 is returned.
*/
static int memory_equal_display_error(const char* const a, const char* const b,
int differences = 0;
size_t i;
for (i = 0; i < size; i++) {
const char l = a[i];
const char r = b[i];
if (l != r) {
i, l, r);
differences ++;
}
}
if (differences) {
a, b);
return 0;
}
return 1;
}
/*
* Determine whether the specified areas of memory are not equal. If they're
* not equal 1 is returned otherwise an error is displayed and 0 is
* returned.
*/
static int memory_not_equal_display_error(
size_t i;
for (i = 0; i < size; i++) {
const char l = a[i];
const char r = b[i];
if (l == r) {
same ++;
}
}
a, b);
return 0;
}
return 1;
}
/* CheckParameterValue callback to check whether a value is within a set. */
const LargestIntegralType check_value_data) {
return value_in_set_display_error(value,
check_value_data), 0);
}
/* CheckParameterValue callback to check whether a value isn't within a set. */
const LargestIntegralType check_value_data) {
return value_in_set_display_error(value,
check_value_data), 1);
}
/* Create the callback data for check_in_set() or check_not_in_set() and
* register a check event. */
static void expect_set(
(sizeof(values[0]) * number_of_values));
check_integer_set + 1);
}
/* Add an event to check whether a value is in a set. */
void _expect_in_set(
const int count) {
}
/* Add an event to check whether a value isn't in a set. */
void _expect_not_in_set(
const int count) {
}
/* CheckParameterValue callback to check whether a value is within a range. */
const LargestIntegralType check_value_data) {
}
/* CheckParameterValue callback to check whether a value is not within a range. */
const LargestIntegralType check_value_data) {
}
/* Create the callback data for check_in_range() or check_not_in_range() and
* register a check event. */
static void expect_range(
}
/* Add an event to determine whether a parameter is within a range. */
void _expect_in_range(
const int count) {
}
/* Add an event to determine whether a parameter is not within a range. */
void _expect_not_in_range(
const int count) {
}
/* CheckParameterValue callback to check whether a value is equal to an
* expected value. */
const LargestIntegralType check_value_data) {
}
/* Add an event to check a parameter equals an expected value. */
void _expect_value(
count);
}
/* CheckParameterValue callback to check whether a value is not equal to an
* expected value. */
const LargestIntegralType check_value_data) {
}
/* Add an event to check a parameter is not equal to an expected value. */
void _expect_not_value(
}
/* CheckParameterValue callback to check whether a parameter equals a string. */
const LargestIntegralType check_value_data) {
return string_equal_display_error(
}
/* Add an event to check whether a parameter is equal to a string. */
void _expect_string(
const int count) {
}
/* CheckParameterValue callback to check whether a parameter is not equals to
* a string. */
const LargestIntegralType check_value_data) {
return string_not_equal_display_error(
}
/* Add an event to check whether a parameter is not equal to a string. */
void _expect_not_string(
const int count) {
}
/* CheckParameterValue callback to check whether a parameter equals an area of
* memory. */
const LargestIntegralType check_value_data) {
return memory_equal_display_error(
cast_largest_integral_type_to_pointer(const char*, value),
}
/* Create the callback data for check_memory() or check_not_memory() and
* register a check event. */
static void expect_memory_setup(
}
/* Add an event to check whether a parameter matches an area of memory. */
void _expect_memory(
}
/* CheckParameterValue callback to check whether a parameter is not equal to
* an area of memory. */
const LargestIntegralType check_value_data) {
return memory_not_equal_display_error(
cast_largest_integral_type_to_pointer(const char*, value),
}
/* Add an event to check whether a parameter doesn't match an area of memory. */
void _expect_not_memory(
}
/* CheckParameterValue callback that always returns 1. */
const LargestIntegralType check_value_data) {
(void)value;
(void)check_value_data;
return 1;
}
/* Add an event to allow any value for a parameter. */
void _expect_any(
count);
}
void _check_expected(
const char * const function_name, const char * const parameter_name,
void *result;
if (rc) {
int check_succeeded;
if (rc == 1) {
}
if (!check_succeeded) {
": error: Check of parameter %s, function %s failed\n"
": note: Expected parameter declared here\n",
}
} else {
": note: Previously declared parameter value was declared here\n",
} else {
cm_print_error("There were no previously declared parameter values "
"for this test.\n");
}
exit_test(1);
}
}
/* Replacement for assert. */
if (!result) {
if (global_expecting_assert) {
} else {
}
}
}
const char * const expression,
if (!result) {
}
}
const LargestIntegralType error,
const char * const expression,
const char * const file,
const int line)
{
switch (rlen) {
case 1:
valmax = 255;
break;
case 2:
valmax = 32767;
break;
case 4:
valmax = 2147483647;
break;
case 8:
default:
valmax = 2147483647;
} else {
valmax = 9223372036854775807L;
}
break;
}
if (error > 0) {
} else {
}
}
}
void _assert_int_equal(
const LargestIntegralType a, const LargestIntegralType b,
if (!values_equal_display_error(a, b)) {
}
}
void _assert_int_not_equal(
const LargestIntegralType a, const LargestIntegralType b,
if (!values_not_equal_display_error(a, b)) {
}
}
void _assert_string_equal(const char * const a, const char * const b,
if (!string_equal_display_error(a, b)) {
}
}
void _assert_string_not_equal(const char * const a, const char * const b,
if (!string_not_equal_display_error(a, b)) {
}
}
void _assert_memory_equal(const void * const a, const void * const b,
const int line) {
if (!memory_equal_display_error((const char*)a, (const char*)b, size)) {
}
}
void _assert_memory_not_equal(const void * const a, const void * const b,
const int line) {
if (!memory_not_equal_display_error((const char*)a, (const char*)b,
size)) {
}
}
void _assert_in_range(
const int line) {
}
}
void _assert_not_in_range(
const int line) {
}
}
const LargestIntegralType values[],
const int line) {
}
}
const LargestIntegralType values[],
const int line) {
}
}
/* Get the list of allocated blocks. */
/* If it initialized, initialize the list of allocated blocks. */
if (!global_allocated_blocks.value) {
}
return &global_allocated_blocks;
}
{
}
{
}
{
}
static void vcm_print_error(const char* const format,
/* It's important to use the libc malloc and free here otherwise
* the automatic free of leaked blocks can reap the error messages
*/
{
int len;
if (len < 0) {
/* TODO */
return;
}
if (cm_error_message == NULL) {
/* CREATE MESSAGE */
if (cm_error_message == NULL) {
/* TODO */
return;
}
} else {
/* APPEND MESSAGE */
char *tmp;
return;
}
}
/* Use len + 1 to also copy '\0' */
} else {
}
}
{
}
/* Use the real malloc in this function. */
char* ptr;
sizeof(*block_info) + MALLOC_ALIGNMENT;
/* Calculate the returned address. */
/* Initialize the guard blocks. */
sizeof(*block_info)));
return ptr;
}
if (ptr) {
}
return ptr;
}
/* Use the real free in this function. */
unsigned int i;
return;
}
sizeof(*block_info)));
/* Check the guard blocks. */
{
for (i = 0; i < ARRAY_SIZE(guards); i++) {
unsigned int j;
for (j = 0; j < MALLOC_GUARD_SIZE; j++) {
if (diff) {
": error: Guard block of %p size=%lu is corrupt\n"
SOURCE_LOCATION_FORMAT ": note: allocated here at %p\n",
&guard[j]);
}
}
}
}
}
const char *file,
const int line)
{
void *new;
}
if (size == 0) {
return NULL;
}
sizeof(*block_info)));
return NULL;
}
}
/* Free previous memory */
return new;
}
/* Crudely checkpoint the current heap state. */
return get_allocated_blocks_list()->prev;
}
/* Display the blocks allocated after the specified check point. This
* function returns the number of blocks displayed. */
int allocated_blocks = 0;
if (!allocated_blocks) {
cm_print_error("Blocks allocated...\n");
}
block_info->block);
allocated_blocks ++;
}
return allocated_blocks;
}
/* Free all blocks allocated after the specified check point. */
}
}
/* Fail if any any blocks are allocated after the specified check point. */
const char * const test_name) {
if (allocated_blocks) {
exit_test(1);
}
}
exit_test(1);
}
#ifndef _WIN32
#ifdef HAVE_STRSIGNAL
#else
#endif
exit_test(1);
}
#else /* _WIN32 */
unsigned int i;
for (i = 0; i < ARRAY_SIZE(exception_codes); i++) {
static int shown_debug_message = 0;
if (!shown_debug_message) {
"\n"
"To debug in Visual Studio...\n"
"1. Select menu item File->Open Project\n"
"2. Change 'Files of type' to 'Executable Files'\n"
"3. Open this executable.\n"
"4. Select menu item Debug->Start\n"
"\n"
"Alternatively, set the environment variable \n"
"UNIT_TESTING_DEBUG to 1 and rebuild this executable, \n"
"then click 'Debug' in the popup dialog box.\n"
"\n");
shown_debug_message = 1;
}
exit_test(0);
return EXCEPTION_EXECUTE_HANDLER;
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
#endif /* !_WIN32 */
{
if (cm_error_message_enabled) {
} else {
}
}
/* Standard output and error print methods. */
#ifdef _WIN32
#endif /* _WIN32 */
}
#ifdef _WIN32
#endif /* _WIN32 */
}
}
}
/* New formatter */
{
char *env;
}
}
return output;
}
enum cm_printf_type {
};
double total_runtime,
struct CMUnitTestState *cm_tests)
{
int file_opened = 0;
char *env;
size_t i;
file_opened = 1;
} else {
}
} else {
}
}
"tests=\"%u\" failures=\"%u\" errors=\"%u\" skipped=\"%u\" >\n",
(unsigned)total_executed,
(unsigned)total_failed,
(unsigned)total_errors,
(unsigned)total_skipped);
for (i = 0; i < total_executed; i++) {
case CM_TEST_ERROR:
case CM_TEST_FAILED:
} else {
}
break;
case CM_TEST_SKIPPED:
break;
case CM_TEST_PASSED:
case CM_TEST_NOT_STARTED:
break;
}
}
if (file_opened) {
}
}
{
print_message("[==========] Running %u test(s).\n",
(unsigned)num_tests);
}
struct CMUnitTestState *cm_tests)
{
size_t i;
print_error("[ PASSED ] %u test(s).\n",
(unsigned)(total_passed));
if (total_failed) {
for (i = 0; i < total_executed; i++) {
}
}
print_error("\n %u FAILED TEST(S)\n",
(unsigned)(total_failed + total_errors));
}
}
const char *test_name,
const char *error_message)
{
switch (type) {
case PRINTF_TEST_START:
break;
case PRINTF_TEST_SUCCESS:
break;
case PRINTF_TEST_FAILURE:
if (error_message != NULL) {
}
break;
case PRINTF_TEST_SKIPPED:
break;
case PRINTF_TEST_ERROR:
if (error_message != NULL) {
}
break;
}
}
{
}
const char *test_name,
const char *error_message)
{
switch (type) {
case PRINTF_TEST_START:
break;
case PRINTF_TEST_SUCCESS:
break;
case PRINTF_TEST_FAILURE:
if (error_message != NULL) {
char *msg;
char *p;
return;
}
p = msg;
while (p[0] != '\0') {
char *q = p;
p = strchr(q, '\n');
if (p != NULL) {
p[0] = '\0';
}
print_message("# %s\n", q);
if (p == NULL) {
break;
}
p++;
}
}
break;
case PRINTF_TEST_SKIPPED:
break;
case PRINTF_TEST_ERROR:
print_message("not ok %u - %s %s\n",
break;
}
}
const char *test_name,
const char *error_message)
{
switch (type) {
case PRINTF_TEST_START:
break;
case PRINTF_TEST_SUCCESS:
break;
case PRINTF_TEST_FAILURE:
if (error_message != NULL) {
}
break;
case PRINTF_TEST_SKIPPED:
break;
case PRINTF_TEST_ERROR:
break;
}
}
{
output = cm_get_output();
switch (output) {
case CM_OUTPUT_STDOUT:
break;
case CM_OUTPUT_SUBUNIT:
break;
case CM_OUTPUT_TAP:
break;
case CM_OUTPUT_XML:
break;
}
}
double total_runtime,
struct CMUnitTestState *cm_tests)
{
output = cm_get_output();
switch (output) {
case CM_OUTPUT_STDOUT:
cm_tests);
break;
case CM_OUTPUT_SUBUNIT:
case CM_OUTPUT_TAP:
break;
case CM_OUTPUT_XML:
cm_tests);
break;
}
}
const char *test_name,
const char *error_message)
{
output = cm_get_output();
switch (output) {
case CM_OUTPUT_STDOUT:
break;
case CM_OUTPUT_SUBUNIT:
break;
case CM_OUTPUT_TAP:
break;
case CM_OUTPUT_XML:
break;
}
}
{
}
/****************************************************************************
* TIME CALCULATIONS
****************************************************************************/
#ifdef HAVE_STRUCT_TIMESPEC
{
int xsec = 0;
}
}
sign = -1;
}
return ret;
}
{
double ret;
return ret;
}
#endif /* HAVE_STRUCT_TIMESPEC */
/****************************************************************************
* CMOCKA TEST RUNNER
****************************************************************************/
void ** const volatile state,
const void *const heap_check_point)
{
(heap_check_point != NULL ?
int rc = 0;
/* FIXME check only one test or fixture is set */
/* Detect if we should handle exceptions */
#ifdef _WIN32
#endif /* _WIN32 */
#ifdef UNIT_TESTING_DEBUG
handle_exceptions = 0;
#endif /* UNIT_TESTING_DEBUG */
if (handle_exceptions) {
#ifndef _WIN32
unsigned int i;
for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
}
#else /* _WIN32 */
#endif /* !_WIN32 */
}
/* Init the test structure */
global_running_test = 1;
if (setjmp(global_run_test_env) == 0) {
rc = 0;
} else if (setup_func != NULL) {
/*
* For setup we can ignore any allocated blocks. We just need to
* ensure they're deallocated on tear down.
*/
} else if (teardown_func != NULL) {
} else {
/* ERROR */
}
global_running_test = 0;
} else {
/* TEST FAILED */
global_running_test = 0;
rc = -1;
}
if (handle_exceptions) {
#ifndef _WIN32
unsigned int i;
for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
}
#else /* _WIN32 */
if (previous_exception_filter) {
}
#endif /* !_WIN32 */
}
return rc;
}
void **state,
const void *const heap_check_point)
{
int rc;
if (setup_func != NULL) {
NULL,
NULL,
} else {
NULL,
NULL,
}
return rc;
}
{
#ifdef HAVE_STRUCT_TIMESPEC
.tv_sec = 0,
.tv_nsec = 0,
};
.tv_sec = 0,
.tv_nsec = 0,
};
#endif
int rc = 0;
/* Run setup */
/* Setup the memory check point, it will be evaluated on teardown */
NULL,
NULL,
&test_state->state,
if (rc != 0) {
cm_print_error("Test setup failed");
}
}
/* Run test */
#ifdef HAVE_STRUCT_TIMESPEC
#endif
if (rc == 0) {
NULL,
NULL,
&test_state->state,
NULL);
if (rc == 0) {
} else {
if (global_skip_test) {
global_skip_test = 0; /* Do not skip the next test */
} else {
}
}
rc = 0;
}
#ifdef HAVE_STRUCT_TIMESPEC
#endif
/* Run teardown */
NULL,
NULL,
&test_state->state,
if (rc != 0) {
cm_print_error("Test teardown failed");
}
}
return rc;
}
const struct CMUnitTest * const tests,
{
double total_runtime = 0;
size_t i;
int rc;
/* Make sure LargestIntegralType is at least the size of a pointer. */
assert_true(sizeof(LargestIntegralType) >= sizeof(void*));
return -1;
}
/* Setup cmocka test array */
for (i = 0; i < num_tests; i++) {
cm_tests[i] = (struct CMUnitTestState) {
};
}
rc = 0;
/* Run group setup */
if (group_setup != NULL) {
NULL,
}
if (rc == 0) {
/* Execute tests */
for (i = 0; i < num_tests; i++) {
if (group_state != NULL) {
}
if (rc == 0) {
case CM_TEST_PASSED:
total_passed++;
break;
case CM_TEST_SKIPPED:
break;
case CM_TEST_FAILED:
total_failed++;
break;
default:
"Internal cmocka error");
total_errors++;
break;
}
} else {
"Could not run the test - check test fixtures");
total_errors++;
}
}
} else {
group_name, "Group setup failed");
total_errors++;
}
/* Run group teardown */
if (group_teardown != NULL) {
NULL,
}
cm_tests);
for (i = 0; i < num_tests; i++) {
}
return total_failed + total_errors;
}
/****************************************************************************
* DEPRECATED TEST RUNNER
****************************************************************************/
int _run_test(
const void* const heap_check_point) {
#ifdef _WIN32
#endif /* _WIN32 */
#ifdef UNIT_TESTING_DEBUG
handle_exceptions = 0;
#endif /* UNIT_TESTING_DEBUG */
if (handle_exceptions) {
#ifndef _WIN32
unsigned int i;
for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
}
#else /* _WIN32 */
#endif /* !_WIN32 */
}
if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
}
global_running_test = 1;
if (setjmp(global_run_test_env) == 0) {
/* If this is a setup function then ignore any allocated blocks
* only ensure they're deallocated on tear down. */
if (function_type != UNIT_TEST_FUNCTION_TYPE_SETUP) {
}
global_running_test = 0;
if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
}
rc = 0;
} else {
global_running_test = 0;
}
if (handle_exceptions) {
#ifndef _WIN32
unsigned int i;
for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
}
#else /* _WIN32 */
if (previous_exception_filter) {
}
#endif /* !_WIN32 */
}
return rc;
}
/* Whether to execute the next test. */
/* Whether the previous test failed. */
int previous_test_failed = 0;
/* Whether the previous setup failed. */
int previous_setup_failed = 0;
/* Check point of the heap state. */
/* Current test being executed. */
/* Number of tests executed. */
/* Number of failed tests. */
/* Number of setup functions. */
/* Number of teardown functions. */
size_t i;
/*
* A stack of test states. A state is pushed on the stack
* when a test setup occurs and popped on tear down.
*/
/* The number of test states which should be 0 at the end */
long number_of_test_states = 0;
/* Names of the tests that failed. */
sizeof(*failed_names));
/* Count setup and teardown functions */
for (i = 0; i < number_of_tests; i++) {
setups++;
}
teardowns++;
}
}
/* Make sure LargestIntegralType is at least the size of a pointer. */
assert_true(sizeof(LargestIntegralType) >= sizeof(void*));
while (current_test < number_of_tests) {
continue;
}
switch (test->function_type) {
if (! previous_setup_failed) {
run_next_test = 1;
}
break;
case UNIT_TEST_FUNCTION_TYPE_SETUP: {
/* Checkpoint the heap before the setup. */
*current_state = NULL;
run_next_test = 1;
break;
}
/* Check the heap based on the last setup checkpoint. */
break;
default:
print_error("Invalid unit test function type %d\n",
exit_test(1);
break;
}
if (run_next_test) {
if (failed) {
}
switch (test->function_type) {
total_failed += failed;
tests_executed ++;
break;
if (failed) {
total_failed ++;
tests_executed ++;
/* Skip forward until the next test or setup function. */
run_next_test = 0;
}
previous_test_failed = 0;
break;
/* If this test failed. */
if (failed && !previous_test_failed) {
total_failed ++;
}
break;
default:
#ifndef _HPUX
assert_null("BUG: shouldn't be here!");
#endif
break;
}
}
}
if (total_failed > 0) {
for (i = 0; i < total_failed; i++) {
}
} else {
}
if (number_of_test_states != 0) {
}
free((void*)failed_names);
return (int)total_failed;
}
{
const char *setup_name;
const char *teardown_name;
size_t i;
/* Number of tests executed. */
/* Number of failed tests. */
/* Check point of the heap state. */
sizeof(*failed_names));
/* Find setup and teardown function */
for (i = 0; i < number_of_tests; i++) {
num_setups = 1;
} else {
print_error("[ ERROR ] More than one group setup function detected\n");
exit_test(1);
}
}
num_teardowns = 1;
} else {
print_error("[ ERROR ] More than one group teardown function detected\n");
exit_test(1);
}
}
}
int failed;
*current_state = NULL;
if (failed) {
}
total_failed += failed;
}
while (current_test < number_of_tests) {
int run_test = 0;
continue;
}
switch (test->function_type) {
run_test = 1;
break;
break;
default:
print_error("Invalid unit test function type %d\n",
break;
}
if (run_test) {
int failed;
NULL);
if (failed) {
}
total_failed += failed;
}
}
int failed;
if (failed) {
}
total_failed += failed;
}
if (total_failed) {
for (i = 0; i < total_failed; i++) {
}
} else {
}
free((void*)failed_names);
return (int)total_failed;
}