mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
- Moved the "Out of Memory" string into a const to stop repeating it.
- Added test for Out of Memory error - reorder the way we handle includes in CMock internals to match the way it works in Unity
This commit is contained in:
@@ -62,7 +62,9 @@ namespace :test do
|
||||
|
||||
desc "Run C Unit Tests"
|
||||
task :c => [:prep_system_tests] do
|
||||
build_and_test_c_files
|
||||
unless ($cfg['unsupported'].include? "C")
|
||||
build_and_test_c_files
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run System Tests"
|
||||
|
||||
@@ -37,7 +37,7 @@ class CMockGeneratorUtils
|
||||
def code_add_base_expectation(func_name, global_ordering_supported=true)
|
||||
lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
|
||||
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n"
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n"
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
|
||||
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
|
||||
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
|
||||
lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if (@ignore)
|
||||
|
||||
+3
-1
@@ -5,8 +5,10 @@
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include "cmock.h"
|
||||
|
||||
#include "cmock_internals.h"
|
||||
//public constants to be used by mocks
|
||||
const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more.";
|
||||
|
||||
//private variables
|
||||
#ifdef CMOCK_MEM_DYNAMIC
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#ifndef CMOCK_FRAMEWORK_H
|
||||
#define CMOCK_FRAMEWORK_H
|
||||
|
||||
#include "cmock_internals.h"
|
||||
|
||||
//should be big enough to index full range of CMOCK_MEM_MAX
|
||||
#ifndef CMOCK_MEM_INDEX_TYPE
|
||||
#define CMOCK_MEM_INDEX_TYPE unsigned int
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#ifndef CMOCK_FRAMEWORK_INTERNALS_H
|
||||
#define CMOCK_FRAMEWORK_INTERNALS_H
|
||||
|
||||
#include "cmock.h"
|
||||
//These are constants that the generated mocks have access to
|
||||
const char* CMockStringOutOfMemory;
|
||||
|
||||
//define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc
|
||||
//when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total
|
||||
|
||||
@@ -83,6 +83,7 @@ linker:
|
||||
destination: *systest_build_path
|
||||
|
||||
unsupported:
|
||||
- out_of_memory
|
||||
- callingconv
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -50,6 +50,7 @@ linker:
|
||||
destination: *systest_build_path
|
||||
|
||||
unsupported:
|
||||
- out_of_memory
|
||||
- unity_64bit_support
|
||||
- callingconv
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ linker:
|
||||
destination: *systest_build_path
|
||||
|
||||
unsupported:
|
||||
- out_of_memory
|
||||
- callingconv
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
---
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: &systest_generated_path 'test/system/generated/'
|
||||
unit_tests_path: &unit_tests_path 'examples/test/'
|
||||
mocks_path: &systest_mocks_path 'test/system/generated/'
|
||||
build_path: &systest_build_path 'test/system/build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-Wall'
|
||||
- '-Wextra'
|
||||
- '-Wunused-parameter'
|
||||
- '-Wno-address'
|
||||
- '-Wno-invalid-token-paste'
|
||||
- '-std=c99'
|
||||
- '-pedantic'
|
||||
- '-O0'
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- *systest_generated_path
|
||||
- *unit_tests_path
|
||||
- *systest_mocks_path
|
||||
- 'src/'
|
||||
- 'vendor/unity/src/'
|
||||
- 'vendor/c_exception/lib/'
|
||||
- 'test/system/test_compilation/'
|
||||
- 'test/'
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
- 'CMOCK_MEM_STATIC'
|
||||
- 'CMOCK_MEM_SIZE=1024'
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.o'
|
||||
destination: *systest_build_path
|
||||
|
||||
linker:
|
||||
path: gcc
|
||||
options:
|
||||
- -lm
|
||||
includes:
|
||||
prefix: '-I'
|
||||
object_files:
|
||||
path: *systest_build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.exe'
|
||||
destination: *systest_build_path
|
||||
|
||||
unsupported:
|
||||
- all_plugins_but_other_limits
|
||||
- all_plugins_coexist
|
||||
- array_and_pointer_handling
|
||||
- const_primitives_handling
|
||||
- enforce_strict_ordering
|
||||
- expect_and_return_custom_types
|
||||
- expect_and_return_treat_as
|
||||
- expect_and_throw
|
||||
- expect_any_args
|
||||
- fancy_pointer_handling
|
||||
- function_pointer_handling
|
||||
- newer_standards_stuff1
|
||||
- nonstandard_pased_stuff_1
|
||||
- nonstandard_pased_stuff_2
|
||||
- parsing_challenges
|
||||
- return_thru_ptr_and_expect_any_args
|
||||
- return_thru_ptr_ignore_arg
|
||||
- struct_union_enum_expect_and_return
|
||||
- struct_union_enum_expect_and_return_with_plugins
|
||||
- stubs_with_callbacks
|
||||
- unity_64bit_support
|
||||
- unity_ignores
|
||||
- callingconv
|
||||
- C
|
||||
|
||||
colour: true
|
||||
@@ -15,7 +15,7 @@ compiler:
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian little
|
||||
@@ -50,7 +50,7 @@ compiler:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *systest_build_path
|
||||
|
||||
|
||||
linker:
|
||||
path: [*tools_root, 'common\bin\xlink.exe']
|
||||
options:
|
||||
@@ -80,7 +80,7 @@ linker:
|
||||
prefix: '-o'
|
||||
extension: '.d79'
|
||||
destination: *systest_build_path
|
||||
|
||||
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
@@ -100,6 +100,7 @@ simulator:
|
||||
- sim
|
||||
|
||||
unsupported:
|
||||
- out_of_memory
|
||||
- nonstandard_parsed_stuff_1
|
||||
- const
|
||||
- callingconv
|
||||
|
||||
@@ -14,7 +14,7 @@ compiler:
|
||||
- --no_code_motion
|
||||
- --no_tbaa
|
||||
- --no_clustering
|
||||
- --no_scheduling
|
||||
- --no_scheduling
|
||||
- --debug
|
||||
- --cpu_mode thumb
|
||||
- --endian=little
|
||||
@@ -49,7 +49,7 @@ compiler:
|
||||
prefix: '-o'
|
||||
extension: '.r79'
|
||||
destination: *systest_build_path
|
||||
|
||||
|
||||
linker:
|
||||
path: [*tools_root, 'arm\bin\ilinkarm.exe']
|
||||
options:
|
||||
@@ -65,7 +65,7 @@ linker:
|
||||
prefix: '-o'
|
||||
extension: '.out'
|
||||
destination: *systest_build_path
|
||||
|
||||
|
||||
simulator:
|
||||
path: [*tools_root, 'common\bin\CSpyBat.exe']
|
||||
pre_support:
|
||||
@@ -85,6 +85,7 @@ simulator:
|
||||
- sim
|
||||
|
||||
unsupported:
|
||||
- out_of_memory
|
||||
- nonstandard_parsed_stuff_1
|
||||
- const
|
||||
- callingconv
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include "cmock_internals.h"
|
||||
#include "cmock.h"
|
||||
|
||||
#define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
- 'vendor/unity/src/unity.c'
|
||||
:options:
|
||||
- 'TEST'
|
||||
- 'CMOCK_MEM_STATIC'
|
||||
- 'CMOCK_MEM_SIZE=128'
|
||||
- 'CMOCK_MEM_ALIGN=2'
|
||||
- 'CMOCK_MEM_INDEX_TYPE=int'
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins: []
|
||||
:treat_as:
|
||||
custom_type: INT
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
typedef struct _BIG_FAT_STRUCT_T
|
||||
{
|
||||
char bytes[512];
|
||||
} BIG_FAT_STRUCT_T;
|
||||
|
||||
:mockable: |
|
||||
void foo(BIG_FAT_STRUCT_T a);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
void function_b(void);
|
||||
|
||||
:code: |
|
||||
void function_a(void)
|
||||
{
|
||||
BIG_FAT_STRUCT_T stuff = { { 8, 0 } };
|
||||
foo(stuff);
|
||||
}
|
||||
|
||||
void function_b(void)
|
||||
{
|
||||
BIG_FAT_STRUCT_T stuff1 = { { 9, 1, 0 } };
|
||||
BIG_FAT_STRUCT_T stuff2 = { { 9, 2, 0 } };
|
||||
foo(stuff1);
|
||||
foo(stuff2);
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'successfully should be able to run function a because it only takes half the memory'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
BIG_FAT_STRUCT_T expected = { { 8, 0 } };
|
||||
foo_Expect(expected);
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'should error out because we do not have eough memory to handle two of these structures'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
BIG_FAT_STRUCT_T expected1 = { { 9, 1, 0 } };
|
||||
BIG_FAT_STRUCT_T expected2 = { { 9, 2, 0 } };
|
||||
foo_Expect(expected1);
|
||||
foo_Expect(expected2);
|
||||
function_b();
|
||||
}
|
||||
|
||||
...
|
||||
@@ -58,7 +58,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" cmock_call_instance->LineNumber = cmock_line;\n"
|
||||
@@ -70,7 +70,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" Mock.Apple_IgnoreBool = (int)0;\n" +
|
||||
@@ -85,7 +85,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected =
|
||||
" CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
|
||||
" CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
|
||||
" memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
|
||||
" Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
|
||||
" Mock.Apple_IgnoreBool = (int)0;\n" +
|
||||
|
||||
Reference in New Issue
Block a user