Skip to content

Commit

Permalink
- updated CMock documentation
Browse files Browse the repository at this point in the history
- beefed up 64-bit testing


git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@200 bf332499-1b4d-0410-844d-d2d48d5cc64c
  • Loading branch information
mvandervoord committed Dec 29, 2010
1 parent 53d2c85 commit cee9277
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 37 deletions.
Binary file modified docs/CMock Summary.odt
Binary file not shown.
Binary file modified docs/CMock Summary.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/cmock_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def standard_treat_as_map
'uint32_t' => 'HEX32',
'UINT32' => 'HEX32',
'UINT32_T' => 'HEX32',
'void*' => 'HEX32',
'void*' => 'PTR',
'unsigned short' => 'HEX16',
'uint16' => 'HEX16',
'uint16_t' => 'HEX16',
Expand Down
3 changes: 2 additions & 1 deletion targets/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ linker:
extension: '.exe'
destination: *systest_build_path

unsupported: []
unsupported:
- unity_64bit_support

colour: true
52 changes: 52 additions & 0 deletions targets/gcc_32_with_64_support.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
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'
- '-Wno-address'
- '-std=c99'
- '-pedantic'
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:
- UNITY_SUPPORT_64
- UNITY_LONG_WIDTH=32
- 'CMOCK_MEM_PTR_AS_INT=long'
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: []

colour: true
2 changes: 1 addition & 1 deletion targets/gcc_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ compiler:
prefix: '-D'
items:
- 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64'
- 'UNITY_POINTER_WIDTH=64'
- 'CMOCK_MEM_PTR_AS_INT=long'
object_files:
prefix: '-o'
Expand Down
1 change: 1 addition & 0 deletions targets/iar_arm_v4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ simulator:
unsupported:
- nonstandard_parsed_stuff_1
- const
- unity_64bit_support

colour: true
1 change: 1 addition & 0 deletions targets/iar_arm_v5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ simulator:
unsupported:
- nonstandard_parsed_stuff_1
- const
- unity_64bit_support

colour: true
10 changes: 5 additions & 5 deletions test/c/TestCMockC.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
element[0] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[0]);
first = CMock_Guts_MemChain(first, element[0]);
TEST_ASSERT_EQUAL(element[0], first);
TEST_ASSERT_EQUAL_PTR(element[0], first);
*element[0] = 0;

//verify we're using the right amount of memory
Expand All @@ -79,7 +79,7 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
element[1] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[1]);
TEST_ASSERT_NOT_EQUAL(element[0], element[1]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[1]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[1]));
*element[1] = 1;

//verify we're using the right amount of memory
Expand All @@ -91,7 +91,7 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
TEST_ASSERT_NOT_NULL(element[2]);
TEST_ASSERT_NOT_EQUAL(element[0], element[2]);
TEST_ASSERT_NOT_EQUAL(element[1], element[2]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[2]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[2]));
*element[2] = 2;

//verify we're using the right amount of memory
Expand All @@ -104,7 +104,7 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
TEST_ASSERT_NOT_EQUAL(element[0], element[3]);
TEST_ASSERT_NOT_EQUAL(element[1], element[3]);
TEST_ASSERT_NOT_EQUAL(element[2], element[3]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[3]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[3]));
*element[3] = 3;

//verify we're using the right amount of memory
Expand All @@ -115,7 +115,7 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
next = first;
for (i = 0; i < 4; i++)
{
TEST_ASSERT_EQUAL(element[i], next);
TEST_ASSERT_EQUAL_PTR(element[i], next);
TEST_ASSERT_EQUAL(i, *next);
next = CMock_Guts_MemNext(next);
}
Expand Down
52 changes: 26 additions & 26 deletions test/c/TestCMockCDynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "cmock.h"

#define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
#define TEST_MEM_INDEX_PAD ((sizeof(CMOCK_MEM_INDEX_TYPE) + 3) & ~3) //round up to nearest 4 byte boundary
#define TEST_MEM_INDEX_PAD ((sizeof(CMOCK_MEM_INDEX_TYPE) + 7) & ~7) //round up to nearest 4 byte boundary

unsigned int StartingSize;

Expand Down Expand Up @@ -44,16 +44,16 @@ void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void)

void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void)
{
unsigned int* next = CMock_Guts_MemNew(4);
TEST_ASSERT_EQUAL(4 + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 - TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesFree());
unsigned int* next = CMock_Guts_MemNew(8);
TEST_ASSERT_EQUAL(8 + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 8 - TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesFree());

TEST_ASSERT_NULL( CMock_Guts_MemChain((void*)((unsigned int)next + CMOCK_MEM_SIZE), next) );
TEST_ASSERT_NULL( CMock_Guts_MemChain(next, (void*)((unsigned int)next + CMOCK_MEM_SIZE)) );

//verify we're still the same
TEST_ASSERT_EQUAL(4 + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 - TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(8 + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 8 - TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesFree());
}

void test_MemNextWillReturnNullIfGivenABadRoot(void)
Expand Down Expand Up @@ -82,54 +82,54 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
element[0] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[0]);
first = CMock_Guts_MemChain(first, element[0]);
TEST_ASSERT_EQUAL(element[0], first);
TEST_ASSERT_EQUAL_PTR(element[0], first);
*element[0] = 0;

//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(1 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 1 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(1 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 1 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesFree());

//second element
element[1] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[1]);
TEST_ASSERT_NOT_EQUAL(element[0], element[1]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[1]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[1]));
*element[1] = 1;

//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(2 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 2 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(2 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 2 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesFree());

//third element
element[2] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[2]);
TEST_ASSERT_NOT_EQUAL(element[0], element[2]);
TEST_ASSERT_NOT_EQUAL(element[1], element[2]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[2]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[2]));
*element[2] = 2;

//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(3 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 3 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(3 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 3 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesFree());

//fourth element
element[3] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_NOT_NULL(element[3]);
TEST_ASSERT_NOT_EQUAL(element[0], element[3]);
TEST_ASSERT_NOT_EQUAL(element[1], element[3]);
TEST_ASSERT_NOT_EQUAL(element[2], element[3]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[3]));
TEST_ASSERT_EQUAL_PTR(first, CMock_Guts_MemChain(first, element[3]));
*element[3] = 3;

//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesFree());

//traverse list
next = first;
for (i = 0; i < 4; i++)
{
TEST_ASSERT_EQUAL(element[i], next);
TEST_ASSERT_EQUAL_PTR(element[i], next);
TEST_ASSERT_EQUAL(i, *next);
next = CMock_Guts_MemNext(next);
}
Expand All @@ -138,8 +138,8 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
TEST_ASSERT_NULL(next);

//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 * (TEST_MEM_INDEX_PAD + 4), CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize - 4 * (TEST_MEM_INDEX_PAD + 8), CMock_Guts_MemBytesFree());

//Free it all
CMock_Guts_MemFreeAll();
Expand All @@ -154,8 +154,8 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
unsigned int i;
unsigned int* first = NULL;
unsigned int* next;
unsigned int sizes[10] = {3, 1, 80, 5, 4, 31, 7, 911, 2, 80};
unsigned int sizes_buffered[10] = {8, 8, 84, 12, 8, 36, 12, 916, 8, 84}; //includes counter
unsigned int sizes[10] = {3, 1, 80, 5, 8, 31, 7, 911, 2, 80};
unsigned int sizes_buffered[10] = {16, 16, 88, 16, 16, 40, 16, 920, 16, 88}; //includes counter
unsigned int sum = 0;
unsigned int cap;

Expand All @@ -168,9 +168,9 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
TEST_ASSERT_NOT_NULL(first);

sum += sizes_buffered[i];
cap = (StartingSize > (sum + CMOCK_MEM_SIZE)) ? StartingSize : (sum + CMOCK_MEM_SIZE);
TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed());
TEST_ASSERT(cap >= CMock_Guts_MemBytesFree());
cap = (StartingSize > (sum + CMOCK_MEM_SIZE)) ? StartingSize : (sum + CMOCK_MEM_SIZE);
TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed());
TEST_ASSERT(cap >= CMock_Guts_MemBytesFree());
}

//verify we can still walk through the elements allocated
Expand Down
2 changes: 1 addition & 1 deletion test/c/TestCMockCDynamic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
- 'TEST'
- 'CMOCK_MEM_DYNAMIC'
- 'CMOCK_MEM_SIZE=64'
- 'CMOCK_MEM_ALIGN=2'
- 'CMOCK_MEM_ALIGN=3'
- 'CMOCK_MEM_INDEX_TYPE=short'
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
test()
{
returns_function_ptr_ExpectAndReturn('z', dummy_function2);
TEST_ASSERT_EQUAL(dummy_function2, exercise_function_pointer_return('z'));
TEST_ASSERT_EQUAL_PTR(dummy_function2, exercise_function_pointer_return('z'));
}
Expand Down
2 changes: 1 addition & 1 deletion test/system/test_interactions/parsing_challenges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
ptr_return1_ExpectAndReturn(2, NULL);
ptr_return2_ExpectAndReturn(2, NULL);
ptr_return3_ExpectAndReturn(2, &retval);
TEST_ASSERT_EQUAL(&retval, exercise_return_pointers(2));
TEST_ASSERT_EQUAL_PTR(&retval, exercise_return_pointers(2));
}
- :pass: TRUE
Expand Down
82 changes: 82 additions & 0 deletions test/system/test_interactions/unity_64bit_support.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
#The purpose of this test is to play with things 64-bit integers, which aren't supported by all compilers
:cmock:
:plugins:
- :array
- :ignore

:systest:
:types: |
#if (UNITY_LONG_WIDTH == 32)
typedef unsigned long long TEST64;
#elif (UNITY_LONG_WIDTH == 64)
typedef unsigned long TEST64;
#else
#error This Test Should Not Be Run Unless You Have 64 Bit Support Enabled
#endif
:mockable: |
TEST64 foo(TEST64 a);
TEST64* bar(TEST64* b);
:source:
:header: |
TEST64 function_a(void);
:code: |
TEST64 function_a(void) {
TEST64 a = 0x1234567890123456;
TEST64 b;
TEST64* c;
b = foo(a);
c = bar(&b);
return *c;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle a straightforward 64-bit series of calls'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b, function_a());
}
- :pass: FALSE
:should: 'handle a straightforward 64-bit series of calls with a failure'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543211);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b, function_a());
}
- :pass: FALSE
:should: 'handle a straightforward 64-bit series of calls returning a failure'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b+1, function_a());
}
...

0 comments on commit cee9277

Please sign in to comment.