add initial Setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
niklasschoeningandClaude Opus 5.5 committed 2026-10-16 18:25:42 +02:00
commit bdb5db2009
1955 files changed
+1004711

No files matched your search

@@ -0,0 +1,333 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#include "unity.h"
#include "cmock.h"
#define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
void setUp(void)
{
CMock_Guts_MemFreeAll();
}
void tearDown(void)
{
}
void test_MemNewWillReturnNullIfGivenIllegalSizes(void)
{
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNew(0) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE + 1) );
TEST_ASSERT_NULL( CMock_Guts_GetAddressFor(CMOCK_GUTS_NONE) );
//verify we're cleared still
TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesCapacity());
TEST_ASSERT_EQUAL_UINT32(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
void test_MemShouldProtectAgainstMemoryOverflow(void)
{
(void)CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE);
//verify we've used all the memory
TEST_ASSERT_LESS_OR_EQUAL_UINT32(TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesFree());
TEST_ASSERT_GREATER_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed());
}
void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void)
{
CMOCK_MEM_INDEX_TYPE next = CMock_Guts_MemNew(4);
TEST_ASSERT_EQUAL(4 + TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 4 - TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemChain(next + CMOCK_MEM_SIZE, next) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemChain(next, next + CMOCK_MEM_SIZE) );
//verify we're still the same
TEST_ASSERT_EQUAL(4 + TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 4 - TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesFree());
}
void test_MemNextWillReturnNullIfGivenABadRoot(void)
{
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext(0) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext(2) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext(CMOCK_MEM_SIZE - 4) );
//verify we're cleared still
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
{
unsigned int i;
CMOCK_MEM_INDEX_TYPE next;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE element[4];
//verify we're cleared first
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
//first element
element[0] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_MESSAGE(element[0] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, element[0]);
TEST_ASSERT_EQUAL(element[0], first);
*((unsigned int*)CMock_Guts_GetAddressFor(element[0])) = 0;
//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(1 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 1 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesFree());
//second element
element[1] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_MESSAGE(element[1] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
TEST_ASSERT_NOT_EQUAL(element[0], element[1]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[1]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[1])) = 1;
//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(2 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 2 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesFree());
//third element
element[2] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_MESSAGE(element[2] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
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]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[2])) = 2;
//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(3 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 3 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesFree());
//fourth element
element[3] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_MESSAGE(element[3] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
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]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[3])) = 3;
//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 4 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesFree());
//traverse list
next = first;
for (i = 0; i < 4; i++)
{
TEST_ASSERT_EQUAL(element[i], next);
TEST_ASSERT_EQUAL(i, *((unsigned int*)CMock_Guts_GetAddressFor(element[i])));
next = CMock_Guts_MemNext(next);
}
//verify we get a null at the end of the list
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next);
//verify we're using the right amount of memory
TEST_ASSERT_EQUAL(4 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 4 * (TEST_MEM_INDEX_SIZE + sizeof(unsigned int)), CMock_Guts_MemBytesFree());
//Free it all
CMock_Guts_MemFreeAll();
//verify we're cleared
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void)
{
unsigned int i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
//even though we are asking for one byte, we've told it to align to closest CMOCK_MEM_ALIGN_SIZE bytes, therefore it will waste a byte each time
//so each call will use (CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE) bytes (CMOCK_MEM_INDEX_SIZE for the index, 1 for the data, and (CMOCK_MEM_ALIGN_SIZE - 1) wasted).
//therefore we can safely allocated total/(CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE) times.
for (i = 0; i < (CMOCK_MEM_SIZE / (CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE)); i++)
{
TEST_ASSERT_EQUAL(i*(CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - i*(CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE), CMock_Guts_MemBytesFree());
next = CMock_Guts_MemNew(1);
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, next);
TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
}
//verify we're at top of memory
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
//The very next call will return a NULL, and any after that
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1));
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1));
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1));
//verify nothing has changed
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
//verify we can still walk through the elements allocated
next = first;
for (i = 0; i < (CMOCK_MEM_SIZE / (CMOCK_MEM_INDEX_SIZE + CMOCK_MEM_ALIGN_SIZE)); i++)
{
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
next = CMock_Guts_MemNext(next);
}
//there aren't any after that
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, (UNITY_UINT32)next);
}
void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void)
{
unsigned int i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
//we're asking for (CMOCK_MEM_INDEX_SIZE + 8) bytes each time now (CMOCK_MEM_INDEX_SIZE for index, 8 for data).
//CMOCK_MEM_SIZE/(CMOCK_MEM_INDEX_SIZE + 8) requests will request as much data as possible, while ensuring that there isn't enough
//memory for the next request
for (i = 0; i < CMOCK_MEM_SIZE/(CMOCK_MEM_INDEX_SIZE + 8); i++)
{
TEST_ASSERT_EQUAL(i*(CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - i*(CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesFree());
next = CMock_Guts_MemNew(8);
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, next);
TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
//verify writing data won't screw us up
*((unsigned int*)CMock_Guts_GetAddressFor(next)) = i;
}
//verify we're at top of memory
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - CMOCK_MEM_SIZE % (CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE % (CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesFree());
//The very next call will return a NONE, and any after that
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(8));
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(5));
//verify nothing has changed
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - CMOCK_MEM_SIZE % (CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE % (CMOCK_MEM_INDEX_SIZE + 8), CMock_Guts_MemBytesFree());
//verify we can still walk through the elements allocated
next = first;
for (i = 0; i < CMOCK_MEM_SIZE/(CMOCK_MEM_INDEX_SIZE + 8); i++)
{
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
TEST_ASSERT_EQUAL(i, *((unsigned int*)CMock_Guts_GetAddressFor(next)));
next = CMock_Guts_MemNext(next);
}
//there aren't any after that
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next);
}
void test_ThatWeCanAskForAllSortsOfSizes(void)
{
#if CMOCK_MEM_ALIGN != 2
TEST_IGNORE_MESSAGE("Test relies on a particular environmental setup, which is not present");
#else
unsigned int i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
CMOCK_MEM_INDEX_TYPE sizes[5] = {3, 1, 80, 5, 4};
CMOCK_MEM_INDEX_TYPE sizes_buffered[5] = {4, 4, 80, 8, 4};
CMOCK_MEM_INDEX_TYPE sum = 0;
for (i = 0; i < 5; i++)
{
next = CMock_Guts_MemNew(sizes[i]);
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, next);
TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
sum += sizes_buffered[i] + 4;
TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - sum, CMock_Guts_MemBytesFree());
}
//show that we can't ask for too much memory
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 8));
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 1));
//but we CAN ask for something that will still fit
next = CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum - 4);
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, next);
TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
//verify we're used up now
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
//verify we can still walk through the elements allocated
next = first;
for (i = 0; i < 6; i++)
{
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
next = CMock_Guts_MemNext(next);
}
//there aren't any after that
TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next);
#endif
}
void test_MemEndOfChain(void)
{
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE element[4];
//verify we're cleared first
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
//first element
element[0] = CMock_Guts_MemNew(sizeof(unsigned int));
first = CMock_Guts_MemChain(first, element[0]);
TEST_ASSERT_MESSAGE(element[0] == CMock_Guts_MemEndOfChain(first), "Should have returned element[0]");
//second element
element[1] = CMock_Guts_MemNew(sizeof(unsigned int));
CMock_Guts_MemChain(first, element[1]);
TEST_ASSERT_MESSAGE(element[1] == CMock_Guts_MemEndOfChain(first), "Should have returned element[1]");
//third element
element[2] = CMock_Guts_MemNew(sizeof(unsigned int));
CMock_Guts_MemChain(first, element[2]);
TEST_ASSERT_MESSAGE(element[2] == CMock_Guts_MemEndOfChain(first), "Should have returned element[2]");
//fourth element
element[3] = CMock_Guts_MemNew(sizeof(unsigned int));
CMock_Guts_MemChain(first, element[3]);
TEST_ASSERT_MESSAGE(element[3] == CMock_Guts_MemEndOfChain(first), "Should have returned element[3]");
//Free it all
CMock_Guts_MemFreeAll();
//verify we're cleared
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
@@ -0,0 +1,14 @@
---
:files:
- '../src/cmock.c'
- './c/TestCMockC.c'
- './c/TestCMockC_Runner.c'
- '../vendor/unity/src/unity.c'
:options:
- 'TEST'
- 'CMOCK_MEM_STATIC'
- 'CMOCK_MEM_SIZE=128'
#- 'CMOCK_MEM_SIZE=40000'
- 'CMOCK_MEM_ALIGN=2'
- 'CMOCK_MEM_INDEX_TYPE=int'
@@ -0,0 +1,186 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#include "unity.h"
#include "cmock.h"
#define TEST_MEM_INDEX_SIZE (CMOCK_MEM_INDEX_TYPE)(sizeof(CMOCK_MEM_INDEX_TYPE))
#define TEST_MEM_INDEX_PAD (CMOCK_MEM_INDEX_TYPE)(((CMOCK_MEM_INDEX_TYPE)sizeof(CMOCK_MEM_INDEX_TYPE) + 7) & ~7) //round up to nearest 4 byte boundary
CMOCK_MEM_INDEX_TYPE StartingSize;
void setUp(void)
{
CMock_Guts_MemFreeAll();
StartingSize = CMock_Guts_MemBytesFree();
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
}
void tearDown(void)
{
}
void test_MemNewWillReturnNullIfGivenIllegalSizes(void)
{
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNew(0) );
//verify we're cleared still
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
}
void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void)
{
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
TEST_ASSERT_MESSAGE(CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE + 1) != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
TEST_ASSERT_EQUAL(((CMOCK_MEM_INDEX_TYPE)CMOCK_MEM_SIZE + TEST_MEM_INDEX_PAD), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL((CMOCK_MEM_INDEX_TYPE)CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void)
{
CMOCK_MEM_INDEX_TYPE 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_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemChain(next + CMOCK_MEM_SIZE, next) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemChain(next, next + CMOCK_MEM_SIZE) );
//verify we're still the same
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)
{
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext(0) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext(2) );
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, CMock_Guts_MemNext( CMOCK_MEM_SIZE - 4 ) );
//verify we're cleared still
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize, CMock_Guts_MemBytesFree());
}
void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
{
unsigned int i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
CMOCK_MEM_INDEX_TYPE element[4];
//verify we're cleared first
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize, CMock_Guts_MemBytesFree());
//first element
element[0] = CMock_Guts_MemNew(sizeof(unsigned int));
TEST_ASSERT_MESSAGE(element[0] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, element[0]);
TEST_ASSERT_EQUAL(element[0], first);
*((unsigned int*)CMock_Guts_GetAddressFor(element[0])) = 0;
//verify we're using the right amount of memory
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_MESSAGE(element[1] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
TEST_ASSERT_NOT_EQUAL(element[0], element[1]);
TEST_ASSERT_EQUAL(first, CMock_Guts_MemChain(first, element[1]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[1])) = 1;
//verify we're using the right amount of memory
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_MESSAGE(element[2] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
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]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[2])) = 2;
//verify we're using the right amount of memory
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_MESSAGE(element[3] != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
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]));
*((unsigned int*)CMock_Guts_GetAddressFor(element[3])) = 3;
//verify we're using the right amount of memory
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(i, *((unsigned int*)CMock_Guts_GetAddressFor(element[i])));
next = CMock_Guts_MemNext(next);
}
//verify we get a null at the end of the list
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, next);
//verify we're using the right amount of memory
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();
//verify we're cleared
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(StartingSize, CMock_Guts_MemBytesFree());
}
void test_ThatWeCanAskForAllSortsOfSizes(void)
{
CMOCK_MEM_INDEX_TYPE i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
CMOCK_MEM_INDEX_TYPE sizes[10] = {3, 1, 80, 5, 8, 31, 7, 911, 2, 80};
CMOCK_MEM_INDEX_TYPE sizes_buffered[10] = {16, 16, 88, 16, 16, 40, 16, 920, 16, 88}; //includes counter
CMOCK_MEM_INDEX_TYPE sum = 0;
CMOCK_MEM_INDEX_TYPE cap;
for (i = 0; i < 10; i++)
{
next = CMock_Guts_MemNew(sizes[i]);
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
first = CMock_Guts_MemChain(first, next);
TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
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());
}
//verify we can still walk through the elements allocated
next = first;
for (i = 0; i < 10; i++)
{
TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
next = CMock_Guts_MemNext(next);
}
//there aren't any after that
TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, next);
}
@@ -0,0 +1,12 @@
---
:files:
- '../src/cmock.c'
- './c/TestCMockCDynamic.c'
- './c/TestCMockCDynamic_Runner.c'
- '../vendor/unity/src/unity.c'
:options:
- 'TEST'
- 'CMOCK_MEM_DYNAMIC'
- 'CMOCK_MEM_SIZE=64'
- 'CMOCK_MEM_ALIGN=3'
- 'CMOCK_MEM_INDEX_TYPE=short'
@@ -0,0 +1,36 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#include "unity.h"
#include "cmock.h"
#include <setjmp.h>
#include <stdio.h>
extern void setUp(void);
extern void tearDown(void);
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
extern void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void);
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
int main(void)
{
UnityBegin("TestCMockDynamic.c");
RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 26);
RUN_TEST(test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize, 35);
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 45);
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 59);
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 70);
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 152);
UnityEnd();
CMock_Guts_MemFreeFinal();
return 0;
}
@@ -0,0 +1,41 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#include "unity.h"
#include <setjmp.h>
#include <stdio.h>
extern void setUp(void);
extern void tearDown(void);
extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void);
extern void test_MemShouldProtectAgainstMemoryOverflow(void);
extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void);
extern void test_MemNextWillReturnNullIfGivenABadRoot(void);
extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void);
extern void test_MemEndOfChain(void);
extern void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void);
extern void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void);
extern void test_ThatWeCanAskForAllSortsOfSizes(void);
int main(void)
{
Unity.TestFile = "TestCMock.c";
UnityBegin(Unity.TestFile);
RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 21);
RUN_TEST(test_MemShouldProtectAgainstMemoryOverflow, 33);
RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 42);
RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 56);
RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 67);
RUN_TEST(test_MemEndOfChain, 149);
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory, 195);
RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd, 244);
RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 298);
UnityEnd();
return 0;
}
@@ -0,0 +1,71 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : SAM7_FLASH.mac
// Object : Generic Macro File for IAR
// 1.0 17/Aug/05 FBr : Creation
// ----------------------------------------------------------------------------
/*********************************************************************
*
* _InitRSTC()
*
* Function description
* Initializes the RSTC (Reset controller).
* This makes sense since the default is to not allow user resets, which makes it impossible to
* apply a second RESET via J-Link
*/
_InitRSTC() {
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory"); // Allow user reset
}
/*********************************************************************
*
* _InitPLL()
* Function description
* Initializes the PMC.
* 1. Enable the Main Oscillator
* 2. Configure PLL to 96MHz
* 3. Switch Master Clock (MCK) on PLL/2 = 48MHz
*/
_InitPLL() {
__message "Enable Main Oscillator";
__writeMemory32(0x00000601,0xFFFFFc20,"Memory"); // MOSC
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1) );
__message "Set PLL to 96MHz";
__writeMemory32(0x10191c05,0xFFFFFc2c,"Memory"); // LOCK
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4) );
__message "Set Master Clock to 48MHz";
__writeMemory32(0x00000004,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
__writeMemory32(0x00000007,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
}
/*********************************************************************
*
* execUserReset() : JTAG set initially to Full Speed
*/
execUserReset() {
__message "execUserReset()";
__emulatorSpeed(30000); // Set JTAG speed to 30kHz to make a hardware reset
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
_InitPLL(); // Allow to debug at JTAG Full Speed
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
__emulatorSpeed(0); // Set JTAG speed to full speed
}
@@ -0,0 +1,94 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : SAM7_RAM.mac
// Object : Generic Macro File for IAR
// 1.0 17/Aug/05 FBr : Creation
// ----------------------------------------------------------------------------
/*********************************************************************
*
* _MapRAMAt0()
*
* Function description
* Maps RAM at 0.
*/
_MapRAMAt0(){
__message "Changing mapping: RAM mapped to 0";
__writeMemory32(0x00000001,0xFFFFFF00,"Memory");
}
/*********************************************************************
*
* _InitRSTC()
*
* Function description
* Initializes the RSTC (Reset controller).
* This makes sense since the default is to not allow user resets, which makes it impossible to
* apply a second RESET via J-Link
*/
_InitRSTC() {
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory"); // Allow user reset
}
/*********************************************************************
*
* _InitPLL()
* Function description
* Initializes the PMC.
* 1. Enable the Main Oscillator
* 2. Configure PLL to 96MHz
* 3. Switch Master Clock (MCK) on PLL/2 = 48MHz
*/
_InitPLL() {
__message "Set Main Oscillator";
__writeMemory32(0x00004001,0xFFFFFc20,"Memory"); // MOSC
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1) );
__message "Set PLL to 96MHz";
__writeMemory32(0x10483f0e,0xFFFFFc2c,"Memory"); // LOCK
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4) );
__message "Set Master Clock to 48MHz";
__writeMemory32(0x00000004,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
__writeMemory32(0x00000007,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
}
/*********************************************************************
*
* execUserReset() : JTAG set initially to Full Speed
*/
execUserReset() {
__message "execUserReset()";
__emulatorSpeed(30000); // Set JTAG speed to 30kHz to make a hardware reset
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset
_InitPLL(); // Allow to debug at JTAG Full Speed
_MapRAMAt0(); // Remap RAM to address 0
__emulatorSpeed(0); // Set JTAG speed to full speed
}
/*********************************************************************
*
* execUserPreload() : JTAG set initially to 32kHz
*/
execUserPreload() {
__message "execUserPreload()";
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
_InitPLL(); // Allow to load Code at JTAG Full Speed
_MapRAMAt0(); // Remap RAM to address 0
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
}
@@ -0,0 +1,67 @@
//=========================================================
// Simulation setup file for esc07_demo project
//=========================================================
__var _timer0_interrupt_ID;
irqBreak()
{
__var __AIC_SMR;
__var __AIC_IECR;
__var __AIC_IVR;
// read AIC_IECR instead, since not fully supported by simulator
__AIC_IECR = __readMemory32(0xFFFFF120, "Memory");
if(__AIC_IECR & 0x1000)
{
__AIC_SMR = __readMemory32(0xFFFFF060, "Memory");
__AIC_IVR = __readMemory32(0xFFFFF0B0, "Memory"); //AIC_IVR = AIC_SVR[x]
__writeMemory32(__AIC_IVR, 0xFFFFF100, "Memory"); //AIC_IVR
__writeMemory32(0x1000, 0xFFFFF10C, "Memory"); //AIC_IPR
__writeMemory32(0x2, 0xFFFFF114, "Memory"); //AIC_CISR
}
return 0;
}
setupProcessorRegisters()
{
// Write TC0_SR.CPCS with correct status for ISR (Clock enabled; RC Compare Flag = TRUE)
__writeMemory32(0x00010010, 0xfffa0020, "Memory");
// Set TX ready flag in USART0 status register
// USART0_BASE->US_CSR = AT91C_US_TXRDY
__writeMemory32(0x00000002, 0xfffc0014, "Memory");
}
configureTimer0Interrupt()
{
__var _master_clock_frequency;
__var _timer0_period_cycles;
// Calculate timer0 frequency in master clock cycles
_master_clock_frequency = 48054857;
_timer0_period_cycles = _master_clock_frequency / 100;
if((_master_clock_frequency % 100) >= 50)
{
_timer0_period_cycles++;
}
__cancelAllInterrupts();
__enableInterrupts();
_timer0_interrupt_ID = __orderInterrupt("IRQ", _timer0_period_cycles, _timer0_period_cycles, 0, 0, 0, 100);
if(-1 == _timer0_interrupt_ID)
{
__message "ERROR: failed to order timer 0 interrupt";
}
__setCodeBreak("0x18", 0, "irqBreak()", "TRUE", "");
}
execUserReset()
{
setupProcessorRegisters();
configureTimer0Interrupt();
}
@@ -0,0 +1,185 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : at91SAM7X256_FLASH.xcl
// Object : Generic Linker Command File for IAR
// 1.0 30/Aug/05 FBr : Creation for 4.30A
// ----------------------------------------------------------------------------
//*************************************************************************
// XLINK command file template for EWARM/ICCARM
//
// Usage: xlink -f lnkarm <your_object_file(s)>
// -s <program start label> <C/C++ runtime library>
//*************************************************************************
//
// -------------
// Code segments - may be placed anywhere in memory.
// -------------
//
// INTVEC -- Exception vector table.
// SWITAB -- Software interrupt vector table.
// ICODE -- Startup (cstartup) and exception code.
// DIFUNCT -- Dynamic initialization vectors used by C++.
// CODE -- Compiler generated code.
// CODE_I -- Compiler generated code declared __ramfunc (executes in RAM)
// CODE_ID -- Initializer for CODE_I (ROM).
//
// -------------
// Data segments - may be placed anywhere in memory.
// -------------
//
// CSTACK -- The stack used by C/C++ programs (system and user mode).
// IRQ_STACK -- The stack used by IRQ service routines.
// SVC_STACK -- The stack used in supervisor mode
// (Define other exception stacks as needed for
// FIQ, ABT, UND).
// HEAP -- The heap used by malloc and free in C and new and
// delete in C++.
// INITTAB -- Table containing addresses and sizes of segments that
// need to be initialized at startup (by cstartup).
// CHECKSUM -- The linker places checksum byte(s) in this segment,
// when the -J linker command line option is used.
// DATA_y -- Data objects.
//
// Where _y can be one of:
//
// _AN -- Holds uninitialized located objects, i.e. objects with
// an absolute location given by the @ operator or the
// #pragma location directive. Since these segments
// contain objects which already have a fixed address,
// they should not be mentioned in this linker command
// file.
// _C -- Constants (ROM).
// _I -- Initialized data (RAM).
// _ID -- The original content of _I (copied to _I by cstartup) (ROM).
// _N -- Uninitialized data (RAM).
// _Z -- Zero initialized data (RAM).
//
// Note: Be sure to use end values for the defined address ranges.
// Otherwise, the linker may allocate space outside the
// intended memory range.
//*************************************************************************
//*************************************************************************
// Inform the linker about the CPU family used.
// AT91SAM7X256 Memory mapping
// No remap
// ROMSTART
// Start address 0x0000 0000
// Size 256 Kbo 0x0004 0000
// RAMSTART
// Start address 0x0020 0000
// Size 64 Kbo 0x0001 0000
// Remap done
// RAMSTART
// Start address 0x0000 0000
// Size 64 Kbo 0x0001 0000
// ROMSTART
// Start address 0x0010 0000
// Size 256 Kbo 0x0004 0000
//*************************************************************************
-carm
//*************************************************************************
// Internal Ram segments mapped AFTER REMAP 64 K.
//*************************************************************************
-Z(CONST)INTRAMSTART_REMAP=00200000
-Z(CONST)INTRAMEND_REMAP=0020FFFF
//*************************************************************************
// Read-only segments mapped to Flash 256 K.
//*************************************************************************
-DROMSTART=00000000
-DROMEND=0003FFFF
//*************************************************************************
// Read/write segments mapped to 64 K RAM.
//*************************************************************************
-DRAMSTART=00200000
-DRAMEND=0020FFFF
//*************************************************************************
// Address range for reset and exception
// vectors (INTVEC).
// The vector area is 32 bytes,
// an additional 32 bytes is allocated for the
// constant table used by ldr PC in cstartup.s79.
//*************************************************************************
-Z(CODE)INTVEC=00-3F
//*************************************************************************
// Startup code and exception routines (ICODE).
//*************************************************************************
-Z(CODE)ICODE,DIFUNCT=ROMSTART-ROMEND
-Z(CODE)SWITAB=ROMSTART-ROMEND
//*************************************************************************
// Code segments may be placed anywhere.
//*************************************************************************
-Z(CODE)CODE=ROMSTART-ROMEND
//*************************************************************************
// Various constants and initializers.
//*************************************************************************
-Z(CONST)INITTAB,DATA_ID,DATA_C=ROMSTART-ROMEND
-Z(CONST)CHECKSUM=ROMSTART-ROMEND
//*************************************************************************
// Data segments.
//*************************************************************************
-Z(DATA)DATA_I,DATA_Z,DATA_N=RAMSTART-RAMEND
//*************************************************************************
// __ramfunc code copied to and executed from RAM.
//*************************************************************************
-Z(DATA)CODE_I=RAMSTART-RAMEND
-Z(CONST)CODE_ID=ROMSTART-ROMEND // Initializer for
-QCODE_I=CODE_ID
//*************************************************************************
// ICCARM produces code for __ramfunc functions in
// CODE_I segments. The -Q XLINK command line
// option redirects XLINK to emit the code in the
// debug information associated with the CODE_I
// segment, where the code will execute.
//*************************************************************************
//*************************************************************************
// Stack and heap segments.
//*************************************************************************
-D_CSTACK_SIZE=(100*4)
-D_IRQ_STACK_SIZE=(3*8*4)
-D_HEAP_SIZE=(1024*1)
-Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND
-Z(DATA)IRQ_STACK+_IRQ_STACK_SIZE=RAMSTART-RAMEND
-Z(DATA)HEAP+_HEAP_SIZE=RAMSTART-RAMEND
//*************************************************************************
// ELF/DWARF support.
//
// Uncomment the line "-Felf" below to generate ELF/DWARF output.
// Available format specifiers are:
//
// "-yn": Suppress DWARF debug output
// "-yp": Multiple ELF program sections
// "-yas": Format suitable for debuggers from ARM Ltd (also sets -p flag)
//
// "-Felf" and the format specifiers can also be supplied directly as
// command line options, or selected from the Xlink Output tab in the
// IAR Embedded Workbench.
//*************************************************************************
// -Felf
@@ -0,0 +1,185 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : at91SAM7X256_RAM.xcl
// Object : Generic Linker Command File for IAR
// 1.0 30/Aug/05 FBr : Creation for 4.30A
// ----------------------------------------------------------------------------
//*************************************************************************
// XLINK command file template for EWARM/ICCARM
//
// Usage: xlink -f lnkarm <your_object_file(s)>
// -s <program start label> <C/C++ runtime library>
//*************************************************************************
//
// -------------
// Code segments - may be placed anywhere in memory.
// -------------
//
// INTVEC -- Exception vector table.
// SWITAB -- Software interrupt vector table.
// ICODE -- Startup (cstartup) and exception code.
// DIFUNCT -- Dynamic initialization vectors used by C++.
// CODE -- Compiler generated code.
// CODE_I -- Compiler generated code declared __ramfunc (executes in RAM)
// CODE_ID -- Initializer for CODE_I (ROM).
//
// -------------
// Data segments - may be placed anywhere in memory.
// -------------
//
// CSTACK -- The stack used by C/C++ programs (system and user mode).
// IRQ_STACK -- The stack used by IRQ service routines.
// SVC_STACK -- The stack used in supervisor mode
// (Define other exception stacks as needed for
// FIQ, ABT, UND).
// HEAP -- The heap used by malloc and free in C and new and
// delete in C++.
// INITTAB -- Table containing addresses and sizes of segments that
// need to be initialized at startup (by cstartup).
// CHECKSUM -- The linker places checksum byte(s) in this segment,
// when the -J linker command line option is used.
// DATA_y -- Data objects.
//
// Where _y can be one of:
//
// _AN -- Holds uninitialized located objects, i.e. objects with
// an absolute location given by the @ operator or the
// #pragma location directive. Since these segments
// contain objects which already have a fixed address,
// they should not be mentioned in this linker command
// file.
// _C -- Constants (ROM).
// _I -- Initialized data (RAM).
// _ID -- The original content of _I (copied to _I by cstartup) (ROM).
// _N -- Uninitialized data (RAM).
// _Z -- Zero initialized data (RAM).
//
// Note: Be sure to use end values for the defined address ranges.
// Otherwise, the linker may allocate space outside the
// intended memory range.
//*************************************************************************
//*************************************************************************
// Inform the linker about the CPU family used.
// AT91SAM7X256 Memory mapping
// No remap
// ROMSTART
// Start address 0x0000 0000
// Size 256 Kbo 0x0004 0000
// RAMSTART
// Start address 0x0020 0000
// Size 64 Kbo 0x0001 0000
// Remap done
// RAMSTART
// Start address 0x0000 0000
// Size 64 Kbo 0x0001 0000
// ROMSTART
// Start address 0x0010 0000
// Size 256 Kbo 0x0004 0000
//*************************************************************************
-carm
//*************************************************************************
// Internal Ram segments mapped AFTER REMAP 64 K.
//*************************************************************************
-Z(CONST)INTRAMSTART_REMAP=00000000
-Z(CONST)INTRAMEND_REMAP=0000FFFF
//*************************************************************************
// Read-only segments mapped to Flash 256 K.
//*************************************************************************
-DROMSTART=00000000
-DROMEND=0003FFFF
//*************************************************************************
// Read/write segments mapped to 64 K RAM.
//*************************************************************************
-DRAMSTART=00000000
-DRAMEND=0000FFFF
//*************************************************************************
// Address range for reset and exception
// vectors (INTVEC).
// The vector area is 32 bytes,
// an additional 32 bytes is allocated for the
// constant table used by ldr PC in cstartup.s79.
//*************************************************************************
-Z(CODE)INTVEC=00-3F
//*************************************************************************
// Startup code and exception routines (ICODE).
//*************************************************************************
-Z(CODE)ICODE,DIFUNCT=ROMSTART-ROMEND
-Z(CODE)SWITAB=ROMSTART-ROMEND
//*************************************************************************
// Code segments may be placed anywhere.
//*************************************************************************
-Z(CODE)CODE=ROMSTART-ROMEND
//*************************************************************************
// Various constants and initializers.
//*************************************************************************
-Z(CONST)INITTAB,DATA_ID,DATA_C=ROMSTART-ROMEND
-Z(CONST)CHECKSUM=ROMSTART-ROMEND
//*************************************************************************
// Data segments.
//*************************************************************************
-Z(DATA)DATA_I,DATA_Z,DATA_N=RAMSTART-RAMEND
//*************************************************************************
// __ramfunc code copied to and executed from RAM.
//*************************************************************************
-Z(DATA)CODE_I=RAMSTART-RAMEND
-Z(CONST)CODE_ID=ROMSTART-ROMEND // Initializer for
-QCODE_I=CODE_ID
//*************************************************************************
// ICCARM produces code for __ramfunc functions in
// CODE_I segments. The -Q XLINK command line
// option redirects XLINK to emit the code in the
// debug information associated with the CODE_I
// segment, where the code will execute.
//*************************************************************************
//*************************************************************************
// Stack and heap segments.
//*************************************************************************
-D_CSTACK_SIZE=(100*4)
-D_IRQ_STACK_SIZE=(3*8*4)
-D_HEAP_SIZE=(1024*2)
-Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND
-Z(DATA)IRQ_STACK+_IRQ_STACK_SIZE=RAMSTART-RAMEND
-Z(DATA)HEAP+_HEAP_SIZE=RAMSTART-RAMEND
//*************************************************************************
// ELF/DWARF support.
//
// Uncomment the line "-Felf" below to generate ELF/DWARF output.
// Available format specifiers are:
//
// "-yn": Suppress DWARF debug output
// "-yp": Multiple ELF program sections
// "-yas": Format suitable for debuggers from ARM Ltd (also sets -p flag)
//
// "-Felf" and the format specifiers can also be supplied directly as
// command line options, or selected from the Xlink Output tab in the
// IAR Embedded Workbench.
//*************************************************************************
// -Felf
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\cmock_demo.ewp</path>
</project>
<batchBuild/>
</workspace>
@@ -0,0 +1,61 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : AT91SAM7X-EK.h
// Object : AT91SAM7X-EK Evaluation Board Features Definition File
//
// ----------------------------------------------------------------------------
#ifndef AT91SAM7X_EK_H
#define AT91SAM7X_EK_H
/*-----------------*/
/* LEDs Definition */
/*-----------------*/
#define AT91B_LED1 (1<<19) // AT91C_PIO_PB19 AT91C_PB19_PWM0 AT91C_PB19_TCLK1
#define AT91B_LED2 (1<<20) // AT91C_PIO_PB20 AT91C_PB20_PWM1 AT91C_PB20_PWM1
#define AT91B_LED3 (AT91C_PIO_PB21) // AT91C_PIO_PB21 AT91C_PB21_PWM2 AT91C_PB21_PCK1
#define AT91B_LED4 (AT91C_PIO_PB22) // AT91C_PIO_PB22 AT91C_PB22_PWM3 AT91C_PB22_PCK2
#define AT91B_NB_LEB 4
#define AT91B_LED_MASK (AT91B_LED1|AT91B_LED2|AT91B_LED3|AT91B_LED4)
#define AT91D_BASE_PIO_LED (AT91C_BASE_PIOB)
#define AT91B_POWERLED (1<<25) // PB25
/*-------------------------------*/
/* JOYSTICK Position Definition */
/*-------------------------------*/
#define AT91B_SW1 (1<<21) // PA21 Up Button AT91C_PA21_TF AT91C_PA21_NPCS10
#define AT91B_SW2 (1<<22) // PA22 Down Button AT91C_PA22_TK AT91C_PA22_SPCK1
#define AT91B_SW3 (1<<23) // PA23 Left Button AT91C_PA23_TD AT91C_PA23_MOSI1
#define AT91B_SW4 (1<<24) // PA24 Right Button AT91C_PA24_RD AT91C_PA24_MISO1
#define AT91B_SW5 (1<<25) // PA25 Push Button AT91C_PA25_RK AT91C_PA25_NPCS11
#define AT91B_SW_MASK (AT91B_SW1|AT91B_SW2|AT91B_SW3|AT91B_SW4|AT91B_SW5)
#define AT91D_BASE_PIO_SW (AT91C_BASE_PIOA)
/*------------------*/
/* CAN Definition */
/*------------------*/
#define AT91B_CAN_TRANSCEIVER_RS (1<<2) // PA2
/*--------------*/
/* Clocks */
/*--------------*/
#define AT91B_MAIN_OSC 18432000 // Main Oscillator MAINCK
#define AT91B_MCK ((18432000*73/14)/2) // Output PLL Clock
#endif /* AT91SAM7X-EK_H */
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Project>
<Desktop>
<Static>
<Debug-Log/>
<Workspace>
<ColumnWidths>
<Column0>185</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<Disassembly>
<MixedMode>1</MixedMode><CodeCovEnabled>0</CodeCovEnabled><CodeCovShow>0</CodeCovShow></Disassembly>
<Build>
<ColumnWidth0>20</ColumnWidth0>
<ColumnWidth1>1115</ColumnWidth1>
<ColumnWidth2>297</ColumnWidth2>
<ColumnWidth3>74</ColumnWidth3>
</Build>
<TerminalIO><InputSource>1</InputSource><InputMode>10</InputMode><Filename>$PROJ_DIR$\TermIOInput.txt</Filename><InputEcho>1</InputEcho><ShowReset>0</ShowReset></TerminalIO></Static>
<Windows>
<Wnd0>
<Tabs>
<Tab>
<Identity>TabID-23656-3537</Identity>
<TabName>Debug Log</TabName>
<Factory>Debug-Log</Factory>
<Session/>
</Tab>
<Tab>
<Identity>TabID-22088-3567</Identity>
<TabName>Build</TabName>
<Factory>Build</Factory>
<Session/>
</Tab>
<Tab><Identity>TabID-16970-5692</Identity><TabName>Terminal I/O</TabName><Factory>TerminalIO</Factory><Session/></Tab></Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd1>
<Tabs>
<Tab>
<Identity>TabID-1637-3541</Identity>
<TabName>Workspace</TabName>
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>cmock_demo</ExpandedNode><ExpandedNode>cmock_demo/source</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd1><Wnd2>
<Tabs>
<Tab>
<Identity>TabID-12385-3544</Identity>
<TabName>Disassembly</TabName>
<Factory>Disassembly</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd2></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>C:\svn\cmock\examples\src\Main.c</Filename><XPos>0</XPos><YPos>27</YPos><SelStart>806</SelStart><SelEnd>806</SelEnd></Tab><ActiveTab>0</ActiveTab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-008fe8c8><key>iaridepm1</key></Toolbar-008fe8c8></Sizes></Row0><Row1><Sizes><Toolbar-02331890><key>debuggergui1</key></Toolbar-02331890></Sizes></Row1></Top><Left><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>509</Bottom><Right>276</Right><x>-2</x><y>-2</y><xscreen>179</xscreen><yscreen>148</yscreen><sizeHorzCX>129149</sizeHorzCX><sizeHorzCY>173302</sizeHorzCY><sizeVertCX>200577</sizeVertCX><sizeVertCY>598361</sizeVertCY></Rect></Wnd1></Sizes></Row0></Left><Right><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>509</Bottom><Right>177</Right><x>-2</x><y>-2</y><xscreen>179</xscreen><yscreen>148</yscreen><sizeHorzCX>129149</sizeHorzCX><sizeHorzCY>173302</sizeHorzCY><sizeVertCX>129149</sizeVertCX><sizeVertCY>598361</sizeVertCY></Rect></Wnd2></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>277</Bottom><Right>1388</Right><x>-2</x><y>-2</y><xscreen>1390</xscreen><yscreen>279</yscreen><sizeHorzCX>1002886</sizeHorzCX><sizeHorzCY>326698</sizeHorzCY><sizeVertCX>129149</sizeVertCX><sizeVertCY>173302</sizeVertCY></Rect></Wnd0></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Project>
@@ -0,0 +1,42 @@
[JLinkDriver]
WatchCond=_ 0
Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
[DisAssemblyWindow]
NumStates=_ 1
State 1=_ 1
[StackPlugin]
Enabled=1
OverflowWarningsEnabled=1
WarningThreshold=90
SpWarningsEnabled=1
WarnHow=0
UseTrigger=1
TriggerName=main
LimitSize=0
ByteLimit=50
[Log file]
LoggingEnabled=_ 0
LogFile=_ ""
Category=_ 0
[TermIOLog]
LoggingEnabled=_ 0
LogFile=_ ""
[Interrupts]
Enabled=1
Irq0=_ 0 480549 0 480549 0 0 0 100 0 1 "IRQ 1 0x18 CPSR.I"
Count=1
[MemoryMap]
Enabled=0
Base=0
UseAuto=0
TypeViolation=1
UnspecRange=1
ActionState=1
[Disassemble mode]
mode=0
[Breakpoints]
Count=0
[TraceHelper]
Enabled=0
ShowSource=1
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Workspace>
<ConfigDictionary>
<CurrentConfigs><Project>cmock_demo/Debug</Project></CurrentConfigs></ConfigDictionary>
<Desktop>
<Static>
<Workspace>
<ColumnWidths>
<Column0>237</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<Build>
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1115</ColumnWidth1><ColumnWidth2>297</ColumnWidth2><ColumnWidth3>74</ColumnWidth3></Build>
<Debug-Log/>
<TerminalIO/>
<CodeCoveragePlugin/>
<Profiling/>
<Disassembly><MixedMode>1</MixedMode><CodeCovEnabled>0</CodeCovEnabled><CodeCovShow>0</CodeCovShow></Disassembly></Static>
<Windows>
<Wnd1>
<Tabs>
<Tab>
<Identity>TabID-20770-112</Identity>
<TabName>Workspace</TabName>
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>cmock_demo</ExpandedNode><ExpandedNode>cmock_demo/Source</ExpandedNode><ExpandedNode>cmock_demo/source</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd1><Wnd3>
<Tabs>
<Tab>
<Identity>TabID-10733-1323</Identity>
<TabName>Build</TabName>
<Factory>Build</Factory>
<Session/>
</Tab>
<Tab>
<Identity>TabID-27316-3469</Identity>
<TabName>Debug Log</TabName>
<Factory>Debug-Log</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>C:\svn\cmock\examples\src\Main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>568</SelStart><SelEnd>568</SelEnd></Tab><ActiveTab>0</ActiveTab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-008fe830><key>iaridepm1</key></Toolbar-008fe830></Sizes></Row0></Top><Left><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>554</Bottom><Right>328</Right><x>-2</x><y>-2</y><xscreen>179</xscreen><yscreen>148</yscreen><sizeHorzCX>129149</sizeHorzCX><sizeHorzCY>173302</sizeHorzCY><sizeVertCX>238095</sizeVertCX><sizeVertCY>651054</sizeVertCY></Rect></Wnd1></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>256</Bottom><Right>1388</Right><x>-2</x><y>-2</y><xscreen>1390</xscreen><yscreen>258</yscreen><sizeHorzCX>1002886</sizeHorzCX><sizeHorzCY>302108</sizeHorzCY><sizeVertCX>129149</sizeVertCX><sizeVertCY>173302</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>
@@ -0,0 +1,266 @@
;- ----------------------------------------------------------------------------
;- ATMEL Microcontroller Software Support - ROUSSET -
;- ----------------------------------------------------------------------------
;- DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
;- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
;- DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
;- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
;- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
;- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;- ----------------------------------------------------------------------------
;- File source : Cstartup.s79
;- Object : Generic CStartup
;- 1.0 01/Sep/05 FBr : Creation
;- 1.1 09/Sep/05 JPP : Change Interrupt management
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Include your AT91 Library files
;------------------------------------------------------------------------------
#include "AT91SAM7X256_inc.h"
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; ?RESET
; Reset Vector.
; Normally, segment INTVEC is linked at address 0.
; For debugging purposes, INTVEC may be placed at other addresses.
; A debugger that honors the entry point will start the
; program in a normal way even if INTVEC is not at address 0.
;------------------------------------------------------------------------------
PROGRAM ?RESET ;- Begins a program module
RSEG INTRAMEND_REMAP ;- Begins a relocatable segment
RSEG ICODE:CODE (2) ;- Begins a relocatable segment : corresponding address is 32-bit aligned
CODE32 ;- Always ARM mode after reset
ORG 0 ;- Sets the location counter: corresponds to the RESET vector address
;------------------------------------------------------------------------------
;- Exception vectors
;------------------------------------------------------------------------------
;- These vectors can be read at address 0 or at RAM address
;- They ABSOLUTELY requires to be in relative addresssing mode in order to
;- guarantee a valid jump. For the moment, all are just looping.
;- If an exception occurs before remap, this would result in an infinite loop.
;- To ensure if a exeption occurs before start application to infinite loop.
;------------------------------------------------------------------------------
reset
B InitReset ; 0x00 Reset handler
undefvec:
B undefvec ; 0x04 Undefined Instruction
swivec:
B swivec ; 0x08 Software Interrupt
pabtvec:
B pabtvec ; 0x0C Prefetch Abort
dabtvec:
B dabtvec ; 0x10 Data Abort
rsvdvec:
B rsvdvec ; 0x14 reserved
irqvec:
B IRQ_Handler_Entry ; 0x18 IRQ
fiqvec: ; 0x1c FIQ
;------------------------------------------------------------------------------
;- Function : FIQ_Handler_Entry
;- Treatments : FIQ Controller Interrupt Handler.
;- Called Functions : AIC_FVR[interrupt]
;------------------------------------------------------------------------------
FIQ_Handler_Entry:
;- Switch in SVC/User Mode to allow User Stack access for C code
; because the FIQ is not yet acknowledged
;- Save and r0 in FIQ_Register
mov r9,r0
ldr r0 , [r8, #AIC_FVR]
msr CPSR_c,#I_BIT | F_BIT | ARM_MODE_SVC
;- Save scratch/used registers and LR in User Stack
stmfd sp!, { r1-r3, r12, lr}
;- Branch to the routine pointed by the AIC_FVR
mov r14, pc
bx r0
;- Restore scratch/used registers and LR from User Stack
ldmia sp!, { r1-r3, r12, lr}
;- Leave Interrupts disabled and switch back in FIQ mode
msr CPSR_c, #I_BIT | F_BIT | ARM_MODE_FIQ
;- Restore the R0 ARM_MODE_SVC register
mov r0,r9
;- Restore the Program Counter using the LR_fiq directly in the PC
subs pc,lr,#4
;------------------------------------------------------------------------------
;- Manage exception: The exception must be ensure in ARM mode
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;- Function : IRQ_Handler_Entry
;- Treatments : IRQ Controller Interrupt Handler.
;- Called Functions : AIC_IVR[interrupt]
;------------------------------------------------------------------------------
IRQ_Handler_Entry:
;-------------------------
;- Manage Exception Entry
;-------------------------
;- Adjust and save LR_irq in IRQ stack
sub lr, lr, #4
stmfd sp!, {lr}
;- Save r0 and SPSR (need to be saved for nested interrupt)
mrs r14, SPSR
stmfd sp!, {r0,r14}
;- Write in the IVR to support Protect Mode
;- No effect in Normal Mode
;- De-assert the NIRQ and clear the source in Protect Mode
ldr r14, =AT91C_BASE_AIC
ldr r0 , [r14, #AIC_IVR]
str r14, [r14, #AIC_IVR]
;- Enable Interrupt and Switch in Supervisor Mode
msr CPSR_c, #ARM_MODE_SVC
;- Save scratch/used registers and LR in User Stack
stmfd sp!, { r1-r3, r12, r14}
;----------------------------------------------
;- Branch to the routine pointed by the AIC_IVR
;----------------------------------------------
mov r14, pc
bx r0
;----------------------------------------------
;- Manage Exception Exit
;----------------------------------------------
;- Restore scratch/used registers and LR from User Stack
ldmia sp!, { r1-r3, r12, r14}
;- Disable Interrupt and switch back in IRQ mode
msr CPSR_c, #I_BIT | ARM_MODE_IRQ
;- Mark the End of Interrupt on the AIC
ldr r14, =AT91C_BASE_AIC
str r14, [r14, #AIC_EOICR]
;- Restore SPSR_irq and r0 from IRQ stack
ldmia sp!, {r0,r14}
msr SPSR_cxsf, r14
;- Restore adjusted LR_irq from IRQ stack directly in the PC
ldmia sp!, {pc}^
InitReset:
;------------------------------------------------------------------------------
;- Low level Init is performed in a C function: AT91F_LowLevelInit
;- Init Stack Pointer to a valid memory area before calling AT91F_LowLevelInit
;------------------------------------------------------------------------------
;- Retrieve end of RAM address
__iramend EQU SFB(INTRAMEND_REMAP) ;- Segment begin
EXTERN AT91F_LowLevelInit
ldr r13,=__iramend ;- Temporary stack in internal RAM for Low Level Init execution
ldr r0,=AT91F_LowLevelInit
mov lr, pc
bx r0 ;- Branch on C function (with interworking)
;------------------------------------------------------------------------------
;- Top of Stack Definition
;------------------------------------------------------------------------------
;- Interrupt and Supervisor Stack are located at the top of internal memory in
;- order to speed the exception handling context saving and restoring.
;- ARM_MODE_SVC (Application, C) Stack is located at the top of the external memory.
;------------------------------------------------------------------------------
IRQ_STACK_SIZE EQU (3*8*4) ; 3 words to be saved per interrupt priority level
ARM_MODE_FIQ EQU 0x11
ARM_MODE_IRQ EQU 0x12
ARM_MODE_SVC EQU 0x13
I_BIT EQU 0x80
F_BIT EQU 0x40
;------------------------------------------------------------------------------
;- Setup the stack for each mode
;------------------------------------------------------------------------------
ldr r0, =__iramend
;- Set up Fast Interrupt Mode and set FIQ Mode Stack
msr CPSR_c, #ARM_MODE_FIQ | I_BIT | F_BIT
;- Init the FIQ register
ldr r8, =AT91C_BASE_AIC
;- Set up Interrupt Mode and set IRQ Mode Stack
msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
mov r13, r0 ; Init stack IRQ
sub r0, r0, #IRQ_STACK_SIZE
;- Enable interrupt & Set up Supervisor Mode and set Supervisor Mode Stack
msr CPSR_c, #ARM_MODE_SVC
mov r13, r0
;------------------------------------------------------------------------------
; Initialize segments.
;------------------------------------------------------------------------------
; __segment_init is assumed to use
; instruction set and to be reachable by BL from the ICODE segment
; (it is safest to link them in segment ICODE).
;------------------------------------------------------------------------------
EXTERN __segment_init
ldr r0,=__segment_init
mov lr, pc
bx r0
;------------------------------------------------------------------------------
;- Branch on C code Main function (with interworking)
;------------------------------------------------------------------------------
EXTERN main
PUBLIC __main
?jump_to_main:
ldr lr,=?call_exit
ldr r0,=main
__main:
bx r0
;------------------------------------------------------------------------------
;- Loop for ever
;------------------------------------------------------------------------------
;- End of application. Normally, never occur.
;- Could jump on Software Reset ( B 0x0 ).
;------------------------------------------------------------------------------
?call_exit:
End
b End
;------------------------------------------------------------------------------
;- Exception Vectors
;------------------------------------------------------------------------------
PUBLIC AT91F_Default_FIQ_handler
PUBLIC AT91F_Default_IRQ_handler
PUBLIC AT91F_Spurious_handler
CODE32 ; Always ARM mode after exeption
AT91F_Default_FIQ_handler
b AT91F_Default_FIQ_handler
AT91F_Default_IRQ_handler
b AT91F_Default_IRQ_handler
AT91F_Spurious_handler
b AT91F_Spurious_handler
ENDMOD ;- Terminates the assembly of the current module
END ;- Terminates the assembly of the last module in a file
@@ -0,0 +1,98 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : Cstartup_SAM7.c
// Object : Low level initialisations written in C for IAR Tools
// Creation : FBr 01-Sep-2005
// 1.0 08-Sep-2005 JPP : Suppress Reset
// ----------------------------------------------------------------------------
#include "AT91SAM7X256.h"
// The following functions must be write in ARM mode this function called directly by exception vector
extern void AT91F_Spurious_handler(void);
extern void AT91F_Default_IRQ_handler(void);
extern void AT91F_Default_FIQ_handler(void);
//*----------------------------------------------------------------------------
//* \fn AT91F_LowLevelInit
//* \brief This function performs very low level HW initialization
//* this function can use a Stack, depending the compilation
//* optimization mode
//*----------------------------------------------------------------------------
void AT91F_LowLevelInit(void)
{
unsigned char i;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// EFC Init
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_MC->MC_FMR = AT91C_MC_FWS_1FWS; // 1 Wait State necessary to work at 48MHz
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Init PMC Step 1. Enable Main Oscillator
// Main Oscillator startup time is board specific:
// Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms (0x40 for AT91C_CKGR_OSCOUNT field)
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
#ifndef SIMULATE
// Wait Main Oscillator stabilization
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Init PMC Step 2.
// Set PLL to 96MHz (96,109MHz) and UDP Clock to 48MHz
// PLL Startup time depends on PLL RC filter: worst case is choosen
// UDP Clock (48,058MHz) is compliant with the Universal Serial Bus Specification (+/- 0.25% for full speed)
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 | AT91C_CKGR_OUT_0 | AT91C_CKGR_PLLCOUNT |
(AT91C_CKGR_MUL & (72 << 16)) | (AT91C_CKGR_DIV & 14);
#ifndef SIMULATE
// Wait for PLL stabilization
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) );
// Wait until the master clock is established for the case we already turn on the PLL
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Init PMC Step 3.
// Selection of Master Clock MCK (equal to Processor Clock PCK) equal to PLL/2 = 48MHz
// The PMC_MCKR register must not be programmed in a single write operation (see. Product Errata Sheet)
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
#ifndef SIMULATE
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
#endif
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
#ifndef SIMULATE
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Disable Watchdog (write once register)
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Init AIC: assign corresponding handler for each interrupt source
/////////////////////////////////////////////////////////////////////////////////////////////////////
AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler ;
for (i = 1; i < 31; i++) {
AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler ;
}
AT91C_BASE_AIC->AIC_SPU = (unsigned int) AT91F_Spurious_handler;
}
@@ -0,0 +1,71 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : SAM7_FLASH.mac
// Object : Generic Macro File for IAR
// 1.0 17/Aug/05 FBr : Creation
// ----------------------------------------------------------------------------
/*********************************************************************
*
* _InitRSTC()
*
* Function description
* Initializes the RSTC (Reset controller).
* This makes sense since the default is to not allow user resets, which makes it impossible to
* apply a second RESET via J-Link
*/
_InitRSTC() {
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory"); // Allow user reset
}
/*********************************************************************
*
* _InitPLL()
* Function description
* Initializes the PMC.
* 1. Enable the Main Oscillator
* 2. Configure PLL to 96MHz
* 3. Switch Master Clock (MCK) on PLL/2 = 48MHz
*/
_InitPLL() {
__message "Enable Main Oscillator";
__writeMemory32(0x00000601,0xFFFFFc20,"Memory"); // MOSC
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1) );
__message "Set PLL to 96MHz";
__writeMemory32(0x10191c05,0xFFFFFc2c,"Memory"); // LOCK
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4) );
__message "Set Master Clock to 48MHz";
__writeMemory32(0x00000004,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
__writeMemory32(0x00000007,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
}
/*********************************************************************
*
* execUserReset() : JTAG set initially to Full Speed
*/
execUserReset() {
__message "execUserReset()";
__emulatorSpeed(30000); // Set JTAG speed to 30kHz to make a hardware reset
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
_InitPLL(); // Allow to debug at JTAG Full Speed
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
__emulatorSpeed(0); // Set JTAG speed to full speed
}
@@ -0,0 +1,94 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : SAM7_RAM.mac
// Object : Generic Macro File for IAR
// 1.0 17/Aug/05 FBr : Creation
// ----------------------------------------------------------------------------
/*********************************************************************
*
* _MapRAMAt0()
*
* Function description
* Maps RAM at 0.
*/
_MapRAMAt0(){
__message "Changing mapping: RAM mapped to 0";
__writeMemory32(0x00000001,0xFFFFFF00,"Memory");
}
/*********************************************************************
*
* _InitRSTC()
*
* Function description
* Initializes the RSTC (Reset controller).
* This makes sense since the default is to not allow user resets, which makes it impossible to
* apply a second RESET via J-Link
*/
_InitRSTC() {
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory"); // Allow user reset
}
/*********************************************************************
*
* _InitPLL()
* Function description
* Initializes the PMC.
* 1. Enable the Main Oscillator
* 2. Configure PLL to 96MHz
* 3. Switch Master Clock (MCK) on PLL/2 = 48MHz
*/
_InitPLL() {
__message "Set Main Oscillator";
__writeMemory32(0x00004001,0xFFFFFc20,"Memory"); // MOSC
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1) );
__message "Set PLL to 96MHz";
__writeMemory32(0x10483f0e,0xFFFFFc2c,"Memory"); // LOCK
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4) );
__message "Set Master Clock to 48MHz";
__writeMemory32(0x00000004,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
__writeMemory32(0x00000007,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8) );
}
/*********************************************************************
*
* execUserReset() : JTAG set initially to Full Speed
*/
execUserReset() {
__message "execUserReset()";
__emulatorSpeed(30000); // Set JTAG speed to 30kHz to make a hardware reset
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset
_InitPLL(); // Allow to debug at JTAG Full Speed
_MapRAMAt0(); // Remap RAM to address 0
__emulatorSpeed(0); // Set JTAG speed to full speed
}
/*********************************************************************
*
* execUserPreload() : JTAG set initially to 32kHz
*/
execUserPreload() {
__message "execUserPreload()";
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
_InitPLL(); // Allow to load Code at JTAG Full Speed
_MapRAMAt0(); // Remap RAM to address 0
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
}
@@ -0,0 +1,67 @@
//=========================================================
// Simulation setup file for esc07_demo project
//=========================================================
__var _timer0_interrupt_ID;
irqBreak()
{
__var __AIC_SMR;
__var __AIC_IECR;
__var __AIC_IVR;
// read AIC_IECR instead, since not fully supported by simulator
__AIC_IECR = __readMemory32(0xFFFFF120, "Memory");
if(__AIC_IECR & 0x1000)
{
__AIC_SMR = __readMemory32(0xFFFFF060, "Memory");
__AIC_IVR = __readMemory32(0xFFFFF0B0, "Memory"); //AIC_IVR = AIC_SVR[x]
__writeMemory32(__AIC_IVR, 0xFFFFF100, "Memory"); //AIC_IVR
__writeMemory32(0x1000, 0xFFFFF10C, "Memory"); //AIC_IPR
__writeMemory32(0x2, 0xFFFFF114, "Memory"); //AIC_CISR
}
return 0;
}
setupProcessorRegisters()
{
// Write TC0_SR.CPCS with correct status for ISR (Clock enabled; RC Compare Flag = TRUE)
__writeMemory32(0x00010010, 0xfffa0020, "Memory");
// Set TX ready flag in USART0 status register
// USART0_BASE->US_CSR = AT91C_US_TXRDY
__writeMemory32(0x00000002, 0xfffc0014, "Memory");
}
configureTimer0Interrupt()
{
__var _master_clock_frequency;
__var _timer0_period_cycles;
// Calculate timer0 frequency in master clock cycles
_master_clock_frequency = 48054857;
_timer0_period_cycles = _master_clock_frequency / 100;
if((_master_clock_frequency % 100) >= 50)
{
_timer0_period_cycles++;
}
__cancelAllInterrupts();
__enableInterrupts();
_timer0_interrupt_ID = __orderInterrupt("IRQ", _timer0_period_cycles, _timer0_period_cycles, 0, 0, 0, 100);
if(-1 == _timer0_interrupt_ID)
{
__message "ERROR: failed to order timer 0 interrupt";
}
__setCodeBreak("0x18", 0, "irqBreak()", "TRUE", "");
}
execUserReset()
{
setupProcessorRegisters();
configureTimer0Interrupt();
}
@@ -0,0 +1,43 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000100;
define symbol __ICFEDIT_region_ROM_end__ = 0x0003FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x00200000;
define symbol __ICFEDIT_region_RAM_end__ = 0x0020FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_svcstack__ = 0x100;
define symbol __ICFEDIT_size_irqstack__ = 0x100;
define symbol __ICFEDIT_size_fiqstack__ = 0x40;
define symbol __ICFEDIT_size_undstack__ = 0x40;
define symbol __ICFEDIT_size_abtstack__ = 0x40;
define symbol __ICFEDIT_size_heap__ = 0x400;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block SVC_STACK with alignment = 8, size = __ICFEDIT_size_svcstack__ { };
define block IRQ_STACK with alignment = 8, size = __ICFEDIT_size_irqstack__ { };
define block FIQ_STACK with alignment = 8, size = __ICFEDIT_size_fiqstack__ { };
define block UND_STACK with alignment = 8, size = __ICFEDIT_size_undstack__ { };
define block ABT_STACK with alignment = 8, size = __ICFEDIT_size_abtstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block SVC_STACK, block IRQ_STACK, block FIQ_STACK,
block UND_STACK, block ABT_STACK, block HEAP };
@@ -0,0 +1,42 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00;
define symbol __ICFEDIT_region_ROM_end__ = 0x00;
define symbol __ICFEDIT_region_RAM_start__ = 0x00000100;
define symbol __ICFEDIT_region_RAM_end__ = 0x0000FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_svcstack__ = 0x100;
define symbol __ICFEDIT_size_irqstack__ = 0x100;
define symbol __ICFEDIT_size_fiqstack__ = 0x40;
define symbol __ICFEDIT_size_undstack__ = 0x40;
define symbol __ICFEDIT_size_abtstack__ = 0x40;
define symbol __ICFEDIT_size_heap__ = 0x800;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block SVC_STACK with alignment = 8, size = __ICFEDIT_size_svcstack__ { };
define block IRQ_STACK with alignment = 8, size = __ICFEDIT_size_irqstack__ { };
define block FIQ_STACK with alignment = 8, size = __ICFEDIT_size_fiqstack__ { };
define block UND_STACK with alignment = 8, size = __ICFEDIT_size_undstack__ { };
define block ABT_STACK with alignment = 8, size = __ICFEDIT_size_abtstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in RAM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block SVC_STACK, block IRQ_STACK, block FIQ_STACK,
block UND_STACK, block ABT_STACK, block HEAP };
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\cmock_demo.ewp</path>
</project>
<batchBuild>
<batchDefinition>
<name>All</name>
<member>
<project>cmock_demo</project>
<configuration>Binary</configuration>
</member>
<member>
<project>cmock_demo</project>
<configuration>FLASH_Debug</configuration>
</member>
<member>
<project>cmock_demo</project>
<configuration>RAM_Debug</configuration>
</member>
</batchDefinition>
</batchBuild>
</workspace>
@@ -0,0 +1,61 @@
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : AT91SAM7X-EK.h
// Object : AT91SAM7X-EK Evaluation Board Features Definition File
//
// ----------------------------------------------------------------------------
#ifndef AT91SAM7X_EK_H
#define AT91SAM7X_EK_H
/*-----------------*/
/* LEDs Definition */
/*-----------------*/
#define AT91B_LED1 (1<<19) // AT91C_PIO_PB19 AT91C_PB19_PWM0 AT91C_PB19_TCLK1
#define AT91B_LED2 (1<<20) // AT91C_PIO_PB20 AT91C_PB20_PWM1 AT91C_PB20_PWM1
#define AT91B_LED3 (AT91C_PIO_PB21) // AT91C_PIO_PB21 AT91C_PB21_PWM2 AT91C_PB21_PCK1
#define AT91B_LED4 (AT91C_PIO_PB22) // AT91C_PIO_PB22 AT91C_PB22_PWM3 AT91C_PB22_PCK2
#define AT91B_NB_LEB 4
#define AT91B_LED_MASK (AT91B_LED1|AT91B_LED2|AT91B_LED3|AT91B_LED4)
#define AT91D_BASE_PIO_LED (AT91C_BASE_PIOB)
#define AT91B_POWERLED (1<<25) // PB25
/*-------------------------------*/
/* JOYSTICK Position Definition */
/*-------------------------------*/
#define AT91B_SW1 (1<<21) // PA21 Up Button AT91C_PA21_TF AT91C_PA21_NPCS10
#define AT91B_SW2 (1<<22) // PA22 Down Button AT91C_PA22_TK AT91C_PA22_SPCK1
#define AT91B_SW3 (1<<23) // PA23 Left Button AT91C_PA23_TD AT91C_PA23_MOSI1
#define AT91B_SW4 (1<<24) // PA24 Right Button AT91C_PA24_RD AT91C_PA24_MISO1
#define AT91B_SW5 (1<<25) // PA25 Push Button AT91C_PA25_RK AT91C_PA25_NPCS11
#define AT91B_SW_MASK (AT91B_SW1|AT91B_SW2|AT91B_SW3|AT91B_SW4|AT91B_SW5)
#define AT91D_BASE_PIO_SW (AT91C_BASE_PIOA)
/*------------------*/
/* CAN Definition */
/*------------------*/
#define AT91B_CAN_TRANSCEIVER_RS (1<<2) // PA2
/*--------------*/
/* Clocks */
/*--------------*/
#define AT91B_MAIN_OSC 18432000 // Main Oscillator MAINCK
#define AT91B_MCK ((18432000*73/14)/2) // Output PLL Clock
#endif /* AT91SAM7X-EK_H */
@@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
//-----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
// File Name : project.h
// Object : project specific include file to AT91SAM7X256
// Creation : JPP 14-Sep-2006
//-----------------------------------------------------------------------------
#ifndef _PROJECT_H
#define _PROJECT_H
/// Include your AT91 Library files and specific compiler definitions
#include <intrinsics.h>
#include "AT91SAM7X-EK.h"
#include "AT91SAM7X256.h"
#define __inline inline
#include "lib_AT91SAM7X256.h"
#endif // _PROJECT_H
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Project/>
@@ -0,0 +1,18 @@
[JLinkDriver]
WatchCond=_ 0
Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
[TermIOLog]
LoggingEnabled=_ 0
LogFile=_ ""
[Log file]
LoggingEnabled=_ 0
LogFile=_ ""
Category=_ 0
[Disassemble mode]
mode=0
[Breakpoints]
Count=0
[TraceHelper]
Enabled=0
ShowSource=1
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Workspace>
<ConfigDictionary>
<CurrentConfigs><Project>BasicInterrupt_SAM7X/FLASH_Debug</Project></CurrentConfigs></ConfigDictionary>
<Desktop>
<Static>
<Workspace>
<ColumnWidths>
<Column0>271</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<Build>
<ColumnWidth0>20</ColumnWidth0>
<ColumnWidth1>995</ColumnWidth1>
<ColumnWidth2>265</ColumnWidth2>
<ColumnWidth3>66</ColumnWidth3>
</Build>
<TerminalIO/>
<Debug-Log/>
</Static>
<Windows>
<Wnd0>
<Tabs>
<Tab>
<Identity>TabID-26686-579</Identity>
<TabName>Workspace</TabName>
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>BasicInterrupt_SAM7X</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd1>
<Tabs>
<Tab>
<Identity>TabID-13847-615</Identity>
<TabName>Build</TabName>
<Factory>Build</Factory>
<Session/>
</Tab>
<Tab>
<Identity>TabID-20936-687</Identity>
<TabName>Debug Log</TabName>
<Factory>Debug-Log</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>1</SelectedTab></Wnd1></Windows>
<Editor>
<Pane/><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00aa8dd8><key>iaridepm.enu1</key></Toolbar-00aa8dd8></Sizes></Row0></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>612</Bottom><Right>345</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>144300</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>250361</sizeVertCX><sizeVertCY>718970</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1388</Right><x>-2</x><y>-2</y><xscreen>1390</xscreen><yscreen>200</yscreen><sizeHorzCX>1002886</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>144300</sizeVertCX><sizeVertCY>234192</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>
@@ -0,0 +1,12 @@
[FLASH]
SkipProgOnCRCMatch = 1
VerifyDownload = 1
AllowCaching = 1
EnableFlashDL = 2
Override = 0
Device="ADUC7020X62"
[BREAKPOINTS]
ShowInfoWin = 1
EnableFlashBP = 2
[CPU]
AllowSimulation = 1
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Project>
<Desktop>
<Static>
<Debug-Log/>
<Build>
<ColumnWidth0>20</ColumnWidth0>
<ColumnWidth1>995</ColumnWidth1>
<ColumnWidth2>265</ColumnWidth2>
<ColumnWidth3>66</ColumnWidth3>
</Build>
<Workspace>
<ColumnWidths>
<Column0>124</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<Disassembly>
<MixedMode>1</MixedMode><CodeCovShow>0</CodeCovShow></Disassembly>
</Static>
<Windows>
<Wnd0>
<Tabs>
<Tab>
<Identity>TabID-27249-27051</Identity>
<TabName>Debug Log</TabName>
<Factory>Debug-Log</Factory>
<Session/>
</Tab>
<Tab>
<Identity>TabID-4707-27064</Identity>
<TabName>Build</TabName>
<Factory>Build</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd0><Wnd1>
<Tabs>
<Tab>
<Identity>TabID-5230-27054</Identity>
<TabName>Workspace</TabName>
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>cmock_demo</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd1><Wnd2>
<Tabs>
<Tab>
<Identity>TabID-15978-27058</Identity>
<TabName>Disassembly</TabName>
<Factory>Disassembly</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd2></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>C:\svn\cmock\examples\src\Main.c</Filename><XPos>0</XPos><YPos>25</YPos><SelStart>835</SelStart><SelEnd>835</SelEnd></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>C:\svn\cmock\examples\src\TaskScheduler.c</Filename><XPos>0</XPos><YPos>43</YPos><SelStart>981</SelStart><SelEnd>981</SelEnd></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00aa9190><key>iaridepm.enu1</key></Toolbar-00aa9190></Sizes></Row0><Row1><Sizes><Toolbar-021dff40><key>debuggergui.enu1</key></Toolbar-021dff40></Sizes></Row1></Top><Left><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>588</Bottom><Right>198</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>144300</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>144300</sizeVertCX><sizeVertCY>690867</sizeVertCY></Rect></Wnd1></Sizes></Row0></Left><Right><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>588</Bottom><Right>198</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>144300</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>144300</sizeVertCX><sizeVertCY>690867</sizeVertCY></Rect></Wnd2></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1388</Right><x>-2</x><y>-2</y><xscreen>1390</xscreen><yscreen>200</yscreen><sizeHorzCX>1002886</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>144300</sizeVertCX><sizeVertCY>234192</sizeVertCY></Rect></Wnd0></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Project>
@@ -0,0 +1,44 @@
[JLinkDriver]
WatchCond=_ 0
Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
[DisAssemblyWindow]
NumStates=_ 1
State 1=_ 1
[CodeCoverage]
Enabled=_ 0
[Profiling]
Enabled=0
[StackPlugin]
Enabled=1
OverflowWarningsEnabled=1
WarningThreshold=90
SpWarningsEnabled=1
WarnHow=0
UseTrigger=1
TriggerName=main
LimitSize=0
ByteLimit=50
[Interrupts]
Enabled=1
[MemoryMap]
Enabled=0
Base=0
UseAuto=0
TypeViolation=1
UnspecRange=1
ActionState=1
[Log file]
LoggingEnabled=_ 0
LogFile=_ ""
Category=_ 0
[TermIOLog]
LoggingEnabled=_ 0
LogFile=_ ""
[Disassemble mode]
mode=0
[Breakpoints]
Count=0
[TraceHelper]
Enabled=0
ShowSource=1
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<Workspace>
<ConfigDictionary>
<CurrentConfigs><Project>cmock_demo/RAM_Debug</Project></CurrentConfigs></ConfigDictionary>
<Desktop>
<Static>
<Build>
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>995</ColumnWidth1><ColumnWidth2>265</ColumnWidth2><ColumnWidth3>66</ColumnWidth3></Build>
<Workspace>
<ColumnWidths>
<Column0>216</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<Debug-Log/>
<TerminalIO/></Static>
<Windows>
<Wnd2>
<Tabs>
<Tab>
<Identity>TabID-7530-24964</Identity>
<TabName>Build</TabName>
<Factory>Build</Factory>
<Session/>
</Tab>
<Tab>
<Identity>TabID-25388-26881</Identity>
<TabName>Debug Log</TabName>
<Factory>Debug-Log</Factory>
<Session/>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd2><Wnd3>
<Tabs>
<Tab>
<Identity>TabID-18278-24968</Identity>
<TabName>Workspace</TabName>
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>cmock_demo</ExpandedNode><ExpandedNode>cmock_demo/Source</ExpandedNode><ExpandedNode>cmock_demo/src</ExpandedNode><ExpandedNode>cmock_demo/srcIAR</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>C:\svn\cmock\examples\src\Main.c</Filename><XPos>0</XPos><YPos>25</YPos><SelStart>820</SelStart><SelEnd>820</SelEnd></Tab><ActiveTab>0</ActiveTab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00aa9198><key>iaridepm.enu1</key></Toolbar-00aa9198></Sizes></Row0></Top><Left><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>513</Bottom><Right>307</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>144300</sizeHorzCX><sizeHorzCY>234192</sizeHorzCY><sizeVertCX>222944</sizeVertCX><sizeVertCY>603044</sizeVertCY></Rect></Wnd3></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>297</Bottom><Right>1388</Right><x>-2</x><y>-2</y><xscreen>1390</xscreen><yscreen>299</yscreen><sizeHorzCX>1002886</sizeHorzCX><sizeHorzCY>350117</sizeHorzCY><sizeVertCX>144300</sizeVertCX><sizeVertCY>234192</sizeVertCY></Rect></Wnd2></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>
@@ -0,0 +1,12 @@
[FLASH]
SkipProgOnCRCMatch = 1
VerifyDownload = 1
AllowCaching = 1
EnableFlashDL = 2
Override = 0
Device="ADUC7020X62"
[BREAKPOINTS]
ShowInfoWin = 1
EnableFlashBP = 2
[CPU]
AllowSimulation = 1
@@ -0,0 +1,12 @@
[FLASH]
SkipProgOnCRCMatch = 1
VerifyDownload = 1
AllowCaching = 1
EnableFlashDL = 2
Override = 0
Device="ADUC7020X62"
[BREAKPOINTS]
ShowInfoWin = 1
EnableFlashBP = 2
[CPU]
AllowSimulation = 1
@@ -0,0 +1,12 @@
[FLASH]
SkipProgOnCRCMatch = 1
VerifyDownload = 1
AllowCaching = 1
EnableFlashDL = 2
Override = 0
Device="ADUC7020X62"
[BREAKPOINTS]
ShowInfoWin = 1
EnableFlashBP = 2
[CPU]
AllowSimulation = 1
@@ -0,0 +1,299 @@
;* ----------------------------------------------------------------------------
;* ATMEL Microcontroller Software Support - ROUSSET -
;* ----------------------------------------------------------------------------
;* Copyright (c) 2006, Atmel Corporation
;
;* All rights reserved.
;*
;* Redistribution and use in source and binary forms, with or without
;* modification, are permitted provided that the following conditions are met:
;*
;* - Redistributions of source code must retain the above copyright notice,
;* this list of conditions and the disclaimer below.
;*
;* - Redistributions in binary form must reproduce the above copyright notice,
;* this list of conditions and the disclaimer below in the documentation and/or
;* other materials provided with the distribution.
;*
;* Atmel's name may not be used to endorse or promote products derived from
;* this software without specific prior written permission.
;*
;* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
;* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
;* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
;* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
;* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
;* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;* ----------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Include your AT91 Library files
;------------------------------------------------------------------------------
#include "AT91SAM7X256_inc.h"
;------------------------------------------------------------------------------
#define TOP_OF_MEMORY (AT91C_ISRAM + AT91C_ISRAM_SIZE)
#define IRQ_STACK_SIZE (3*8*4)
; 3 words to be saved per interrupt priority level
; Mode, correspords to bits 0-5 in CPSR
MODE_BITS DEFINE 0x1F ; Bit mask for mode bits in CPSR
USR_MODE DEFINE 0x10 ; User mode
FIQ_MODE DEFINE 0x11 ; Fast Interrupt Request mode
IRQ_MODE DEFINE 0x12 ; Interrupt Request mode
SVC_MODE DEFINE 0x13 ; Supervisor mode
ABT_MODE DEFINE 0x17 ; Abort mode
UND_MODE DEFINE 0x1B ; Undefined Instruction mode
SYS_MODE DEFINE 0x1F ; System mode
I_BIT DEFINE 0x80
F_BIT DEFINE 0x40
;------------------------------------------------------------------------------
; ?RESET
; Reset Vector.
; Normally, segment INTVEC is linked at address 0.
; For debugging purposes, INTVEC may be placed at other addresses.
; A debugger that honors the entry point will start the
; program in a normal way even if INTVEC is not at address 0.
;------------------------------------------------------------------------------
SECTION .intvec:CODE:NOROOT(2)
PUBLIC __vector
PUBLIC __iar_program_start
ARM
__vector:
ldr pc,[pc,#+24] ;; Reset
__und_handler:
ldr pc,[pc,#+24] ;; Undefined instructions
__swi_handler:
ldr pc,[pc,#+24] ;; Software interrupt (SWI/SVC)
__prefetch_handler:
ldr pc,[pc,#+24] ;; Prefetch abort
__data_handler:
ldr pc,[pc,#+24] ;; Data abort
DC32 0xFFFFFFFF ;; RESERVED
__irq_handler:
ldr pc,[pc,#+24] ;; IRQ
__fiq_handler:
ldr pc,[pc,#+24] ;; FIQ
DC32 __iar_program_start
DC32 __und_handler
DC32 __swi_handler
DC32 __prefetch_handler
DC32 __data_handler
B .
DC32 IRQ_Handler_Entry
DC32 FIQ_Handler_Entry
;------------------------------------------------------------------------------
;- Manage exception: The exception must be ensure in ARM mode
;------------------------------------------------------------------------------
SECTION text:CODE:NOROOT(2)
ARM
;------------------------------------------------------------------------------
;- Function : FIQ_Handler_Entry
;- Treatments : FIQ Controller Interrupt Handler.
;- R8 is initialize in Cstartup
;- Called Functions : None only by FIQ
;------------------------------------------------------------------------------
FIQ_Handler_Entry:
;- Switch in SVC/User Mode to allow User Stack access for C code
; because the FIQ is not yet acknowledged
;- Save and r0 in FIQ_Register
mov r9,r0
ldr r0 , [r8, #AIC_FVR]
msr CPSR_c,#I_BIT | F_BIT | SVC_MODE
;- Save scratch/used registers and LR in User Stack
stmfd sp!, { r1-r3, r12, lr}
;- Branch to the routine pointed by the AIC_FVR
mov r14, pc
bx r0
;- Restore scratch/used registers and LR from User Stack
ldmia sp!, { r1-r3, r12, lr}
;- Leave Interrupts disabled and switch back in FIQ mode
msr CPSR_c, #I_BIT | F_BIT | FIQ_MODE
;- Restore the R0 ARM_MODE_SVC register
mov r0,r9
;- Restore the Program Counter using the LR_fiq directly in the PC
subs pc,lr,#4
;------------------------------------------------------------------------------
;- Function : IRQ_Handler_Entry
;- Treatments : IRQ Controller Interrupt Handler.
;- Called Functions : AIC_IVR[interrupt]
;------------------------------------------------------------------------------
IRQ_Handler_Entry:
;-------------------------
;- Manage Exception Entry
;-------------------------
;- Adjust and save LR_irq in IRQ stack
sub lr, lr, #4
stmfd sp!, {lr}
;- Save r0 and SPSR (need to be saved for nested interrupt)
mrs r14, SPSR
stmfd sp!, {r0,r14}
;- Write in the IVR to support Protect Mode
;- No effect in Normal Mode
;- De-assert the NIRQ and clear the source in Protect Mode
ldr r14, =AT91C_BASE_AIC
ldr r0 , [r14, #AIC_IVR]
str r14, [r14, #AIC_IVR]
;- Enable Interrupt and Switch in Supervisor Mode
msr CPSR_c, #SVC_MODE
;- Save scratch/used registers and LR in User Stack
stmfd sp!, { r1-r3, r12, r14}
;----------------------------------------------
;- Branch to the routine pointed by the AIC_IVR
;----------------------------------------------
mov r14, pc
bx r0
;----------------------------------------------
;- Manage Exception Exit
;----------------------------------------------
;- Restore scratch/used registers and LR from User Stack
ldmia sp!, { r1-r3, r12, r14}
;- Disable Interrupt and switch back in IRQ mode
msr CPSR_c, #I_BIT | IRQ_MODE
;- Mark the End of Interrupt on the AIC
ldr r14, =AT91C_BASE_AIC
str r14, [r14, #AIC_EOICR]
;- Restore SPSR_irq and r0 from IRQ stack
ldmia sp!, {r0,r14}
msr SPSR_cxsf, r14
;- Restore adjusted LR_irq from IRQ stack directly in the PC
ldmia sp!, {pc}^
;------------------------------------------------------------------------------
;- Exception Vectors
;------------------------------------------------------------------------------
PUBLIC AT91F_Default_FIQ_handler
PUBLIC AT91F_Default_IRQ_handler
PUBLIC AT91F_Spurious_handler
ARM ; Always ARM mode after exeption
AT91F_Default_FIQ_handler
b AT91F_Default_FIQ_handler
AT91F_Default_IRQ_handler
b AT91F_Default_IRQ_handler
AT91F_Spurious_handler
b AT91F_Spurious_handler
;------------------------------------------------------------------------------
; ?INIT
; Program entry.
;------------------------------------------------------------------------------
SECTION FIQ_STACK:DATA:NOROOT(3)
SECTION IRQ_STACK:DATA:NOROOT(3)
SECTION SVC_STACK:DATA:NOROOT(3)
SECTION ABT_STACK:DATA:NOROOT(3)
SECTION UND_STACK:DATA:NOROOT(3)
SECTION CSTACK:DATA:NOROOT(3)
SECTION text:CODE:NOROOT(2)
REQUIRE __vector
EXTERN ?main
PUBLIC __iar_program_start
EXTERN AT91F_LowLevelInit
__iar_program_start:
;------------------------------------------------------------------------------
;- Low level Init is performed in a C function: AT91F_LowLevelInit
;- Init Stack Pointer to a valid memory area before calling AT91F_LowLevelInit
;------------------------------------------------------------------------------
;- Retrieve end of RAM address
ldr r13,=TOP_OF_MEMORY ;- Temporary stack in internal RAM for Low Level Init execution
ldr r0,=AT91F_LowLevelInit
mov lr, pc
bx r0 ;- Branch on C function (with interworking)
; Initialize the stack pointers.
; The pattern below can be used for any of the exception stacks:
; FIQ, IRQ, SVC, ABT, UND, SYS.
; The USR mode uses the same stack as SYS.
; The stack segments must be defined in the linker command file,
; and be declared above.
mrs r0,cpsr ; Original PSR value
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#SVC_MODE ; Set SVC mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(SVC_STACK) ; End of SVC_STACK
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#UND_MODE ; Set UND mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(UND_STACK) ; End of UND_STACK
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#ABT_MODE ; Set ABT mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(ABT_STACK) ; End of ABT_STACK
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#FIQ_MODE ; Set FIQ mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(FIQ_STACK) ; End of FIQ_STACK
;- Init the FIQ register
ldr r8, =AT91C_BASE_AIC
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#IRQ_MODE ; Set IRQ mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(IRQ_STACK) ; End of IRQ_STACK
bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#SYS_MODE ; Set System mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(CSTACK) ; End of CSTACK
#ifdef __ARMVFP__
; Enable the VFP coprocessor.
mov r0, #0x40000000 ; Set EN bit in VFP
fmxr fpexc, r0 ; FPEXC, clear others.
; Disable underflow exceptions by setting flush to zero mode.
; For full IEEE 754 underflow compliance this code should be removed
; and the appropriate exception handler installed.
mov r0, #0x01000000 ; Set FZ bit in VFP
fmxr fpscr, r0 ; FPSCR, clear others.
#endif
; Add more initialization here
; Continue to ?main for more IAR specific system startup
ldr r0,=?main
bx r0
END ;- Terminates the assembly of the last module in a file
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
//-----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
// File Name : Cstartup_SAM7.c
// Object : Low level initialisations written in C for Tools
// For AT91SAM7X256 with 2 flash plane
// Creation : JPP 14-Sep-2006
//-----------------------------------------------------------------------------
#include "project.h"
// The following functions must be write in ARM mode this function called
// directly by exception vector
extern void AT91F_Spurious_handler(void);
extern void AT91F_Default_IRQ_handler(void);
extern void AT91F_Default_FIQ_handler(void);
//*----------------------------------------------------------------------------
//* \fn AT91F_LowLevelInit
//* \brief This function performs very low level HW initialization
//* this function can use a Stack, depending the compilation
//* optimization mode
//*----------------------------------------------------------------------------
void AT91F_LowLevelInit(void) @ "ICODE"
{
unsigned char i;
///////////////////////////////////////////////////////////////////////////
// EFC Init
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_MC->MC_FMR = AT91C_MC_FWS_1FWS ;
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 1. Enable Main Oscillator
// Main Oscillator startup time is board specific:
// Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms
// (0x40 for AT91C_CKGR_OSCOUNT field)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
// Wait Main Oscillator stabilization
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 2.
// Set PLL to 96MHz (96,109MHz) and UDP Clock to 48MHz
// PLL Startup time depends on PLL RC filter: worst case is choosen
// UDP Clock (48,058MHz) is compliant with the Universal Serial Bus
// Specification (+/- 0.25% for full speed)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 |
(16 << 8) |
(AT91C_CKGR_MUL & (72 << 16)) |
(AT91C_CKGR_DIV & 14);
// Wait for PLL stabilization
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) );
// Wait until the master clock is established for the case we already
// turn on the PLL
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 3.
// Selection of Master Clock MCK equal to (Processor Clock PCK) PLL/2=48MHz
// The PMC_MCKR register must not be programmed in a single write operation
// (see. Product Errata Sheet)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
///////////////////////////////////////////////////////////////////////////
// Disable Watchdog (write once register)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
///////////////////////////////////////////////////////////////////////////
// Init AIC: assign corresponding handler for each interrupt source
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler ;
for (i = 1; i < 31; i++) {
AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler ;
}
AT91C_BASE_AIC->AIC_SPU = (unsigned int) AT91F_Spurious_handler;
}
@@ -0,0 +1,147 @@
# ==============================================================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007-2014 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==============================================================================
require '../config/test_environment'
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require './rakefile_helper'
include RakefileHelpers
DEFAULT_CONFIG_FILE = 'gcc.yml'
CMOCK_TEST_ROOT = File.expand_path(File.dirname(__FILE__))
SYSTEM_TEST_SUPPORT_DIRS = [
File.join(CMOCK_TEST_ROOT, 'system/generated'),
File.join(CMOCK_TEST_ROOT, 'system/build')
]
SYSTEM_TEST_SUPPORT_DIRS.each do |dir|
directory(dir)
CLOBBER.include(dir)
end
task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS
configure_clean
configure_toolchain(DEFAULT_CONFIG_FILE)
task :default => [:test]
task :ci => [:no_color, :default, 'test:examples', 'style:check']
task :cruise => :ci
desc "Load configuration"
task :config, :config_file do |t, args|
args = {:config_file => DEFAULT_CONFIG_FILE} if args[:config_file].nil?
args = {:config_file => args[:config_file] + '.yml'} unless args[:config_file] =~ /\.yml$/i
configure_toolchain(args[:config_file])
end
# Still support testing everything with just 'test' but switch default to ceedling-like test:all
task :test => ['test:all']
namespace :test do
desc "Run all unit, c, and system tests"
task :all => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
desc "Run Unit Tests"
Rake::TestTask.new('units') do |t|
t.pattern = 'unit/*_test.rb'
t.verbose = true
end
#individual unit tests
FileList['unit/*_test.rb'].each do |test|
Rake::TestTask.new(File.basename(test,'.*').sub('_test','')) do |t|
t.pattern = test
t.verbose = true
end
end
desc "Run C Unit Tests"
task :c => [:prep_system_tests] do
unless ($cfg['unsupported'].include? "C")
build_and_test_c_files
end
end
desc "Run System Tests"
task :system => [:clobber, :prep_system_tests] do
#get a list of all system tests, removing unsupported tests for this compiler
sys_unsupported = $cfg['unsupported'].map {|a| 'system/test_interactions/'+a+'.yml'}
sys_tests_to_run = FileList['system/test_interactions/*.yml'] - sys_unsupported
compile_unsupported = $cfg['unsupported'].map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'}
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported
unless (sys_unsupported.empty? and compile_unsupported.empty?)
report "\nIgnoring these system tests..."
sys_unsupported.each {|a| report a}
compile_unsupported.each {|a| report a}
end
report "\nRunning system tests..."
tests_failed = run_system_test_interactions(sys_tests_to_run)
raise "System tests failed." if (tests_failed > 0)
run_system_test_compilations(compile_tests_to_run)
end
desc "Test cmock examples"
task :examples => [:prep_system_tests] do
run_examples()
end
#individual system tests
FileList['system/test_interactions/*.yml'].each do |test|
basename = File.basename(test,'.*')
#desc "Run system test #{basename}"
task basename do
run_system_test_interactions([test])
end
end
desc "Profile Mock Generation"
task :profile => [:clobber, :prep_system_tests] do
run_system_test_profiles(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'])
end
end
task :no_color do
$colour_output = false
end
################### CODING STYLE VALIDATION
namespace :style do
desc "Check style"
task :check do
report "\nVERIFYING RUBY STYLE"
report execute("rubocop ../lib ../examples ../config ../scripts --config ../vendor/unity/test/.rubocop.yml", true)
report "Styling Ruby:PASS"
end
desc "Fix Style of all C Code"
task :c do
run_astyle("../src/*.* ../extras/fixture/src/*.*")
end
desc "Attempt to Autocorrect style"
task :auto => ['style:clean'] do
report execute("rubocop ../lib ../examples ../config ../scripts --auto-correct --config ../vendor/unity/test/.rubocop.yml", true)
report "Autocorrected What We Could."
end
desc "Update style todo list"
task :todo => ['style:clean'] do
report execute("rubocop ../lib ../examples ../config ../scripts --auto-gen-config --config ../vendor/unity/test/.rubocop.yml", true)
report "Updated Style TODO List."
end
task :clean do
File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
end
end
task :style => ['style:check']
@@ -0,0 +1,403 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
require 'yaml'
require 'fileutils'
require '../vendor/unity/auto/generate_test_runner'
require '../vendor/unity/auto/unity_test_summary'
require '../vendor/unity/auto/colour_reporter.rb'
require './system/systest_generator'
module RakefileHelpers
SYSTEST_GENERATED_FILES_PATH = './system/generated/'
SYSTEST_BUILD_FILES_PATH = './system/build/'
SYSTEST_COMPILE_MOCKABLES_PATH = './system/test_compilation/'
C_EXTENSION = '.c'
RESULT_EXTENSION = '.result'
def load_configuration(config_file)
$cfg_file = config_file
$cfg = YAML.load(File.read('./targets/' + $cfg_file))
$colour_output = false unless $cfg['colour']
end
def configure_clean
CLEAN.include(SYSTEST_GENERATED_FILES_PATH + '*.*')
CLEAN.include(SYSTEST_BUILD_FILES_PATH + '*.*')
end
def configure_toolchain(config_file)
load_configuration(config_file)
configure_clean
end
def get_local_include_dirs
include_dirs = $cfg['compiler']['includes']['items'].dup
include_dirs.delete_if {|dir| dir.is_a?(Array)}
return include_dirs
end
def extract_headers(filename)
includes = []
lines = File.readlines(filename)
lines.each do |line|
m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/)
if not m.nil?
includes << m[1]
end
end
includes << File.basename(filename,".c").slice(5,256) + "_unity_helper.h"
return includes
end
def find_source_file(header, paths)
paths.each do |dir|
src_file = dir + header.ext(C_EXTENSION)
if (File.exists?(src_file))
return src_file
end
end
return nil
end
def squash(prefix, items)
result = ''
items.each { |item| result += " #{prefix}#{tackit(item)}" }
return result
end
def build_compiler_fields
command = tackit($cfg['compiler']['path'])
if $cfg['compiler']['defines']['items'].nil?
defines = ''
else
defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'])
end
options = squash('', $cfg['compiler']['options'])
includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items'])
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :defines => defines, :options => options, :includes => includes}
end
def compile(file, defines=[])
compiler = build_compiler_fields
cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{defines.inject(''){|all, a| ' -D'+a+all }}#{compiler[:options]}#{compiler[:includes]} #{file} " +
"#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}"
obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}"
execute(cmd_str + obj_file)
return obj_file
end
def build_linker_fields
command = tackit($cfg['linker']['path'])
if $cfg['linker']['options'].nil?
options = ''
else
options = squash('', $cfg['linker']['options'])
end
if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?)
includes = ''
else
includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items'])
end
includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR)
return {:command => command, :options => options, :includes => includes}
end
def link_it(exe_name, obj_list)
linker = build_linker_fields
cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " +
(obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).uniq.join +
$cfg['linker']['bin_files']['prefix'] + ' ' +
$cfg['linker']['bin_files']['destination'] +
exe_name + $cfg['linker']['bin_files']['extension']
execute(cmd_str)
end
def build_simulator_fields
return nil if $cfg['simulator'].nil?
if $cfg['simulator']['path'].nil?
command = ''
else
command = (tackit($cfg['simulator']['path']) + ' ')
end
if $cfg['simulator']['pre_support'].nil?
pre_support = ''
else
pre_support = squash('', $cfg['simulator']['pre_support'])
end
if $cfg['simulator']['post_support'].nil?
post_support = ''
else
post_support = squash('', $cfg['simulator']['post_support'])
end
return {:command => command, :pre_support => pre_support, :post_support => post_support}
end
def execute(command_string, verbose=true, raise_on_failure=true)
#report command_string
output = `#{command_string}`.chomp
report(output) if (verbose && !output.nil? && (output.length > 0))
if ($?.exitstatus != 0) and (raise_on_failure)
raise "#{command_string} failed. (Returned #{$?.exitstatus})"
end
return output
end
def tackit(strings)
case(strings)
when Array
"\"#{strings.join}\""
when /^-/
strings
when /\s/
"\"#{strings}\""
else
strings
end
end
def run_astyle(style_what)
report "Styling C Code..."
command = "AStyle " \
"--style=allman --indent=spaces=4 --indent-switches --indent-preproc-define --indent-preproc-block " \
"--pad-oper --pad-comma --unpad-paren --pad-header " \
"--align-pointer=type --align-reference=name " \
"--add-brackets --mode=c --suffix=none " \
"#{style_what}"
execute(command, false)
report "Styling C:PASS"
end
def report_summary
summary = UnityTestSummary.new
summary.root = File.expand_path(File.dirname(__FILE__)) + '/'
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/')
results = Dir[results_glob]
summary.targets = results
summary.run
fail_out "FAIL: There were failures" if (summary.failures > 0)
end
def run_system_test_interactions(test_case_files)
load '../lib/cmock.rb'
SystemTestGenerator.new.generate_files(test_case_files)
test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c')
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
include_dirs = get_local_include_dirs
# Build and execute each unit test
test_files.each do |test|
obj_list = []
test_base = File.basename(test, C_EXTENSION)
cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml'
report "Executing system tests in #{File.basename(test)}..."
# Detect dependencies and build required required modules
extract_headers(test).each do |header|
# Generate any needed mocks
if header =~ /^mock_(.*)\.h/i
module_name = $1
cmock = CMock.new(SYSTEST_GENERATED_FILES_PATH + cmock_config)
cmock.setup_mocks("#{$cfg['compiler']['source_path']}#{module_name}.h")
end
# Compile corresponding source file if it exists
src_file = find_source_file(header, include_dirs)
if !src_file.nil?
obj_list << compile(src_file)
end
end
# Generate and build the test suite runner
runner_name = test_base + '_runner.c'
runner_path = $cfg['compiler']['source_path'] + runner_name
UnityTestRunnerGenerator.new(SYSTEST_GENERATED_FILES_PATH + cmock_config).run(test, runner_path)
obj_list << compile(runner_path)
# Build the test module
obj_list << compile(test)
# Link the test executable
link_it(test_base, obj_list)
# Execute unit test and generate results file
simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
if simulator.nil?
cmd_str = executable
else
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end
output = execute(cmd_str, false, false)
test_results = $cfg['compiler']['build_path'] + test_base + RESULT_EXTENSION
File.open(test_results, 'w') { |f| f.print output }
end
# Parse and report test results
total_tests = 0
total_failures = 0
failure_messages = []
test_case_files.each do |test_case|
tests = (YAML.load_file(test_case))[:systest][:tests][:units]
total_tests += tests.size
test_file = 'test_' + File.basename(test_case).ext(C_EXTENSION)
result_file = test_file.ext(RESULT_EXTENSION)
test_results = File.readlines(SYSTEST_BUILD_FILES_PATH + result_file).reject {|line| line.size < 10 } # we're rejecting lines that are too short to be realistic, which handles line ending problems
tests.each_with_index do |test, index|
# compare test's intended pass/fail state with pass/fail state in actual results;
# if they don't match, the system test has failed
this_failed = case(test[:pass])
when :ignore
(test_results[index] =~ /:IGNORE/).nil?
when true
(test_results[index] =~ /:PASS/).nil?
when false
(test_results[index] =~ /:FAIL/).nil?
end
if (this_failed)
total_failures += 1
test_results[index] =~ /test#{index+1}:(.+)/
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}"
end
# some tests have additional requirements to check for (checking the actual output message)
if (test[:verify_error]) and not (test_results[index] =~ /test#{index+1}:.*#{test[:verify_error]}/)
total_failures += 1
failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:should have output matching '#{test[:verify_error]}' but was '#{test_results[index]}'"
end
end
end
report "\n"
report "------------------------------------\n"
report "SYSTEM TEST MOCK INTERACTION SUMMARY\n"
report "------------------------------------\n"
report "#{total_tests} Tests #{total_failures} Failures 0 Ignored\n"
report "\n"
if (failure_messages.size > 0)
report 'System test failures:'
failure_messages.each do |failure|
report failure
end
end
report ''
return total_failures
end
def profile_this(filename)
profile = true
begin
require 'ruby-prof'
RubyProf.start
rescue
profile = false
end
yield
if (profile)
profile_result = RubyProf.stop
File.open("Profile_#{filename}.html", 'w') do |f|
RubyProf::GraphHtmlPrinter.new(profile_result).print(f)
end
end
end
def run_system_test_compilations(mockables)
load '../lib/cmock.rb'
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
report "\n"
report "------------------------------------\n"
report "SYSTEM TEST MOCK COMPILATION SUMMARY\n"
report "------------------------------------\n"
mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c')
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end
end
def run_system_test_profiles(mockables)
load '../lib/cmock.rb'
load_configuration($cfg_file)
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
report "\n"
report "--------------------------\n"
report "SYSTEM TEST MOCK PROFILING\n"
report "--------------------------\n"
mockables.each do |header|
mock_filename = 'mock_' + File.basename(header).ext('.c')
profile_this(mock_filename.gsub('.c','')) do
10.times do
CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header)
end
end
report "Compiling #{mock_filename}..."
compile(SYSTEST_GENERATED_FILES_PATH + mock_filename)
end
end
def build_and_test_c_files
report "\n"
report "----------------\n"
report "UNIT TEST C CODE\n"
report "----------------\n"
errors = false
FileList.new("c/*.yml").each do |yaml_file|
test = YAML.load(File.read(yaml_file))
report "\nTesting #{yaml_file.sub('.yml','')}"
report "(#{test[:options].join(', ')})"
test[:files].each { |f| compile(f, test[:options]) }
obj_files = test[:files].map { |f| f.gsub!(/.*\//,'').gsub!(C_EXTENSION, $cfg['compiler']['object_files']['extension']) }
link_it('TestCMockC', obj_files)
if $cfg['simulator'].nil?
execute($cfg['linker']['bin_files']['destination'] + 'TestCMockC' + $cfg['linker']['bin_files']['extension'])
else
execute(tackit($cfg['simulator']['path'].join) + ' ' +
$cfg['simulator']['pre_support'].map{|o| tackit(o)}.join(' ') + ' ' +
$cfg['linker']['bin_files']['destination'] +
'TestCMockC' +
$cfg['linker']['bin_files']['extension'] + ' ' +
$cfg['simulator']['post_support'].map{|o| tackit(o)}.join(' ') )
end
end
end
def run_examples()
[ "cd #{File.join("..","examples","make_example")} && make clean && make setup && make test",
"cd #{File.join("..","examples","temp_sensor")} && rake ci"
].each do |cmd|
report "Testing '#{cmd}'"
execute(cmd, false)
end
end
def fail_out(msg)
puts msg
exit(-1)
end
end
@@ -0,0 +1,205 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
require 'yaml'
SYS_TEST_GEN_ROOT = File.expand_path( File.dirname( __FILE__ ) ) + '/'
GENERATED_PATH = SYS_TEST_GEN_ROOT + 'generated/'
BUILD_PATH = SYS_TEST_GEN_ROOT + 'build/'
CASES_PATH = SYS_TEST_GEN_ROOT + 'cases/'
TYPES_H = 'types.h'
UNITY_H = 'unity.h'
CMOCK_H = 'cmock.h'
UNITY_HELPER_H = 'unity_helper.h'
UNITY_HELPER_C = 'unity_helper.c'
MOCKABLE_H = 'mockable.h'
YAML_EXTENSION = '.yml'
TEST_PREFIX = 'test_'
MOCK_PREFIX = 'mock_'
H_EXTENSION = '.h'
C_EXTENSION = '.c'
class SystemTestGenerator
def generate_files(test_cases)
test_cases.each do |filename|
yaml_hash = YAML.load_file(filename)
name = File.basename(filename, YAML_EXTENSION)
namix = "#{name}_"
generate_cmock_config(yaml_hash, namix)
generate_code(yaml_hash, namix, name)
end
end
private
def generate_cmock_config(yaml_hash, namix)
cmock_yaml = yaml_hash.clone
cmock_yaml.delete(:systest)
cmock = cmock_yaml[:cmock]
cmock[:mock_path] = GENERATED_PATH
cmock[:includes] = (cmock[:includes] || []) + [namix + TYPES_H]
cmock[:mock_prefix] = MOCK_PREFIX
if not yaml_hash[:systest][:unity_helper].nil?
cmock[:includes] << namix + UNITY_HELPER_H
cmock[:unity_helper_path] = GENERATED_PATH + namix + UNITY_HELPER_H
end
File.open(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION, 'w') do |out|
YAML.dump(cmock_yaml, out)
end
end
def generate_code(yaml_hash, namix, name)
generate_types_file(yaml_hash, namix)
generate_mockable_file(yaml_hash, namix)
generate_unity_helper_files(yaml_hash, namix)
generate_test_file(yaml_hash, namix, name)
generate_source_file(yaml_hash, namix, name)
generate_skeleton_file(yaml_hash, namix, name)
end
def generate_types_file(yaml_hash, namix)
types = yaml_hash[:systest][:types]
return if types.nil?
write_header_file(GENERATED_PATH + namix + TYPES_H, namix.upcase + 'TYPES_H') do |out|
out.puts(types)
end
end
def generate_mockable_file(yaml_hash, namix)
mockable = yaml_hash[:systest][:mockable]
return if mockable.nil?
write_header_file(GENERATED_PATH + namix + MOCKABLE_H, namix.upcase + 'MOCKABLE_H', [namix + TYPES_H]) do |out|
out.puts(mockable)
end
end
def generate_unity_helper_files(yaml_hash, namix)
unity_helper = yaml_hash[:systest][:unity_helper]
return if unity_helper.nil?
write_header_file(GENERATED_PATH + namix + UNITY_HELPER_H, namix.upcase + 'UNITY_HELPER_H', [namix + TYPES_H]) do |out|
out.puts(unity_helper[:header])
end
write_source_file(GENERATED_PATH + namix + UNITY_HELPER_C, ["unity.h", namix + UNITY_HELPER_H]) do |out|
out.puts(unity_helper[:code])
end
end
def generate_test_file(yaml_hash, namix, name)
tests = yaml_hash[:systest][:tests]
return if tests.nil?
includes = [UNITY_H, CMOCK_H]
includes << [MOCK_PREFIX + namix + MOCKABLE_H]
includes << [name + H_EXTENSION]
write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes.flatten) do |out|
out.puts(tests[:common])
out.puts('')
tests[:units].each_with_index do |test, index|
out.puts('// should ' + test[:should])
out.puts(test[:code].gsub!(/test\(\)/, "void test#{index+1}(void)"))
out.puts('')
end
end
end
def generate_source_file(yaml_hash, namix, name)
source = yaml_hash[:systest][:source]
return if source.nil?
header_file = name + H_EXTENSION
includes = yaml_hash[:systest][:types].nil? ? [] : [(namix + TYPES_H)]
write_header_file(GENERATED_PATH + header_file, name.upcase, includes) do |out|
out.puts(source[:header])
end
includes = []
includes << (namix + TYPES_H) if not yaml_hash[:systest][:types].nil?
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
includes << header_file
unless (source[:code].nil?)
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
out.puts(source[:code])
end
end
end
def generate_skeleton_file(yaml_hash, namix, name)
source = yaml_hash[:systest][:skeleton]
return if source.nil?
require 'cmock.rb'
cmock = CMock.new(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION)
cmock.setup_skeletons("#{$cfg['compiler']['source_path']}#{name}.h")
end
def write_header_file(filename, upcase_name, include_list=[])
File.open(filename, 'w') do |out|
out.puts("#ifndef _#{upcase_name}")
out.puts("#define _#{upcase_name}")
out.puts('')
include_list.each do |include|
out.puts("#include \"#{include}\"")
end
out.puts('')
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
out.puts("#if !defined(__clang__)")
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
out.puts("#endif")
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
out.puts("#endif")
out.puts('')
yield(out)
out.puts('')
out.puts("#endif // _#{upcase_name}")
out.puts('')
end
end
def write_source_file(filename, include_list=[])
File.open(filename, 'w') do |out|
include_list.each do |include|
out.puts("#include \"#{include}\"")
end
out.puts('')
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
out.puts("#if !defined(__clang__)")
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
out.puts("#endif")
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
out.puts("#endif")
out.puts('')
yield(out)
out.puts('')
end
end
end
if ($0 == __FILE__)
SystemTestGenerator.new.generate_files(Dir[CASES_PATH + "*#{YAML_EXTENSION}"])
end
@@ -0,0 +1,11 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#ifndef __stdcall
#define __stdcall
#endif
int __stdcall this_uses_calling_conventions(int b);
@@ -0,0 +1,10 @@
---
:cmock:
:plugins: []
:includes: []
:mock_path: ./system/generated/
:mock_prefix: mock_
:treat_inlines: :include
:treat_as_void:
- OSEK_TASK
- VOID_TYPE_CRAZINESS
@@ -0,0 +1,37 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#if defined(__GNUC__) && !defined(__ICC)
#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"
#endif
struct _DUMMY_T { unsigned int a; float b; };
void const_variants1( const char* a, int const, unsigned short const * c );
void const_variants2(
struct _DUMMY_T const * const param1,
const unsigned long int const * const param2,
const struct _DUMMY_T const * param3 );
const int * const_retval1(void); /* nicety version for pointer to constant int */
int const * const_retval2(void); /* formal version for pointer to constant int */
//int * const const_retval3(void); /* formal version for constant pointer to int */
//int const * const const_retval4(void); /* formal version for constant pointer to constant int */
const int* const_retval5(void); /* sticky-left nicety version for pointer to constant int */
int const* const_retval6(void); /* sticky-left formal version for pointer to constant int */
//int* const const_retval7(void); /* sticky-left formal version for constant pointer to int */
//int const* const const_retval8(void); /* sticky-left formal version for constant pointer to constant int */
const int *const_retval9(void); /* sticky-right nicety version for pointer to constant int */
int const *const_retvalA(void); /* sticky-right formal version for pointer to constant int */
//int *const const_retvalB(void); /* sticky-right formal version for constant pointer to int */
//int const *const const_retvalC(void); /* sticky-right formal version for constant pointer to constant int */
@@ -0,0 +1,23 @@
static inline int dummy_func_0(void) {
return 5;
}
inline static int dummy_func_1(int a) {
int a = dummy_func_0();
int b = 10;
return a + b;
}
int inline static dummy_func_2(int a, char b, float c) {
c += 3.14;
b -= 32;
return a + (int)(b) + (int)c;
}
void dummy_normal_func(int a);
inline void dummy_func_3(void) {
//NOP
}
@@ -0,0 +1,275 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
typedef unsigned char OSServiceIdType;
typedef void (*OSEKOS_VOIDFUNCPTR)(void);
typedef unsigned char StatusType;
typedef unsigned char OSEK_U8;
typedef unsigned short OSEK_U16;
typedef unsigned long OSEK_U32;
void OSEKOSDisableAll(void);
void OSEKOSEnableAll(void);
typedef unsigned long * OSEKOSSaveType;
typedef void OSEK_TASK;
typedef OSEK_U8 OSEKOSPrioType;
enum {
Task_DbgCAN
,
Task_ALS
,
CalibrateMagTask
,
Task_IAQ
,
SmartBeam
,
Task_QbertTestImage
,
Task_TestQbertMem
,
Task_Cyclic1000
,
ProcessMagForCompass
,
ReadMag
,
Task_Cyclic10
,
Task_Wdm
,
BackgroundTask
,
Task_Cyclic20
,
Task_Cyclic2
};
OSEK_TASK OSEKOS_T_Task_DbgCAN(void);
OSEK_TASK OSEKOS_T_Task_ALS(void);
OSEK_TASK OSEKOS_T_CalibrateMagTask(void);
OSEK_TASK OSEKOS_T_Task_IAQ(void);
OSEK_TASK OSEKOS_T_SmartBeam(void);
OSEK_TASK OSEKOS_T_Task_QbertTestImage(void);
OSEK_TASK OSEKOS_T_Task_TestQbertMem(void);
OSEK_TASK OSEKOS_T_Task_Cyclic1000(void);
OSEK_TASK OSEKOS_T_ProcessMagForCompass(void);
OSEK_TASK OSEKOS_T_ReadMag(void);
OSEK_TASK OSEKOS_T_Task_Cyclic10(void);
OSEK_TASK OSEKOS_T_Task_Wdm(void);
OSEK_TASK OSEKOS_T_BackgroundTask(void);
OSEK_TASK OSEKOS_T_Task_Cyclic20(void);
OSEK_TASK OSEKOS_T_Task_Cyclic2(void);
OSEK_TASK OSEKOS_Twrap_Task_DbgCAN(void);
OSEK_TASK OSEKOS_Twrap_Task_ALS(void);
OSEK_TASK OSEKOS_Twrap_CalibrateMagTask(void);
OSEK_TASK OSEKOS_Twrap_Task_IAQ(void);
OSEK_TASK OSEKOS_Twrap_SmartBeam(void);
OSEK_TASK OSEKOS_Twrap_Task_QbertTestImage(void);
OSEK_TASK OSEKOS_Twrap_Task_TestQbertMem(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic1000(void);
OSEK_TASK OSEKOS_Twrap_ProcessMagForCompass(void);
OSEK_TASK OSEKOS_Twrap_ReadMag(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic10(void);
OSEK_TASK OSEKOS_Twrap_Task_Wdm(void);
OSEK_TASK OSEKOS_Twrap_BackgroundTask(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic20(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic2(void);
typedef OSEK_U8 TaskType;
typedef OSEK_U8 TaskStateType;
typedef OSEK_U16 EventMaskType;
typedef OSEK_U8 ResourceType;
void OSEKOSEnableSystemTimers(void);
typedef OSEK_U8 CounterType;
typedef OSEK_U32 TickType;
typedef OSEK_U8 AlarmType;
void OSEKOS_ISR_CanTxInterrupt(void);
void OSEKOS_ISR_CanRxInterrupt(void);
void OSEKOS_ISR_CanErrInterrupt(void);
void OSEKOS_ISR_SCIRxInterrupt(void);
void OSEKOS_ISR_SCITxInterrupt(void);
void OSEKOS_ISR_UP_DMA_Interrupt_0(void);
void OSEKOS_ISR_UP_DMA_Interrupt_1(void);
void OSEKOS_ISR_UP_DMA_Interrupt_2(void);
void OSEKOS_ISR_UP_DMA_Interrupt_3(void);
void OSEKOS_ISR_CompFreqHandler(void);
void OSEKOS_ISR_AmbientReturnInt(void);
void OSEKOS_ISR_GlareReturnInt(void);
void OSEKOS_ISR_ALSTimeoutInt(void);
void OSEKOS_ISR_LINTimerInt(void);
void OSEKOS_ISR_LINDelayInt(void);
void OSEKOS_ISR_TimerMExpire(void);
void OSEKOS_ISR_LINRxTx_SCI1(void);
void OSEKOS_ISR_CanRxInterrupt_1(void);
void OSEKOS_ISR_LINError_SCI1(void);
void OSEKOS_ISR_SysCounter(void);
// defined multiple times (slightly different forms) These should be ignored because they are externed
extern void OSEKOS_ISR_CanTxInterrupt( void );
extern void OSEKOS_ISR_CanRxInterrupt( void );
unsigned long OSEKOSrtcGetSeconds ( void );
void OSEKOSrtcIncrement ( unsigned long nsec );
enum
{
E_OS_ACCESS = 1,
E_OS_CALLEVEL = 2,
E_OS_ID = 3,
E_OS_LIMIT = 4,
E_OS_NOFUNC = 5,
E_OS_RESOURCE = 6,
E_OS_STATE = 7,
E_OS_VALUE = 8,
E_OS_SYS_StackOverflow = 20,
E_OS_SYS_StackUnderflow = 21,
E_OS_SYS_INIT = 22,
E_OS_SYS_CONFIG = 23,
E_OS_SYS_CODE = 24,
E_OS_SYS_TOOL = 25,
E_OS_SYS_TimerRange = 26
};
enum
{
SUSPENDED = 0x00,
READY = 0x01,
RUNNING = 0x02,
WAITING = 0x03,
INTSTART = 0x08,
SETSTART = 0x10,
NPRTASK = 0x20,
USEFP = 0x40
};
typedef struct
{
TickType maxallowedvalue;
TickType ticksperbase;
} AlarmBaseType;
typedef TaskType *TaskRefType;
typedef TaskStateType *TaskStateRefType;
typedef EventMaskType *EventMaskRefType;
typedef TickType *TickRefType;
typedef AlarmBaseType *AlarmBaseRefType;
typedef OSEK_U8 AppModeType;
typedef OSEK_U8 OSEKOSTaskActCntType;
TaskType OSEKOStidact;
OSEKOSPrioType OSEKOSrunprio;
StatusType OSEKOSError ( register StatusType );
void ErrorHook ( StatusType );
void StartupHook ( void );
void ShutdownHook ( StatusType );
int getUsedTaskStack ( TaskType );
int getUnusedTaskStack ( TaskType );
int getUsedIsrStack ( void );
int getUnusedIsrStack ( void );
void OSEKOStaskStackCheckInit ( void );
signed char OSEKOStaskStackCheck ( OSEK_U8 * );
signed char OSEKOSisrStackCheck ( OSEK_U8 * );
void OSEKOStaskStackCheckFatal ( OSEK_U8 * );
void OSEKOSisrStackCheckFatal ( OSEK_U8 * );
OSEK_U8 * OSEKOSgetStackPointer ( void );
void OSEKOSTaskSwitch ( void );
StatusType OSEKOSReturn ( StatusType );
StatusType OSEKOSActivateTask ( register TaskType );
void OSEKOSTerminateTask ( TaskType, TaskType );
extern void OSEKOSGetResource ( ResourceType );
extern void OSEKOSReleaseResource ( ResourceType );
int OSEKOSSetEvent ( TaskType, EventMaskType );
int OSEKOSWaitEvent ( EventMaskType );
TickType OSEKOSGetAlarm(register AlarmType);
void OSEKOSSetAlarm ( AlarmType, TickType, TickType );
StatusType OSEKOSSetAbsAlarm ( AlarmType a, TickType b, TickType c );
StatusType OSEKOSCancelAlarm ( register AlarmType );
void OSEKOSAdvCntr ( void );
AppModeType GetActiveApplicationMode ( void );
void StartOS ( AppModeType );
void OSEKOSShutdownOS ( StatusType );
StatusType ActivateTask ( TaskType A );
StatusType TerminateTask ( void );
StatusType ChainTask ( TaskType A );
StatusType GetTaskState ( TaskType A, TaskStateRefType B );
StatusType GetTaskID ( TaskRefType A );
StatusType Schedule ( void );
StatusType GetResource ( ResourceType A );
StatusType ReleaseResource ( ResourceType A );
StatusType SetEvent ( TaskType A, EventMaskType B );
StatusType ClearEvent ( EventMaskType A );
StatusType WaitEvent ( EventMaskType A );
StatusType GetEvent ( TaskType A, EventMaskRefType B );
StatusType GetAlarm ( AlarmType A, TickRefType B );
StatusType GetAlarmBase ( AlarmType A, AlarmBaseRefType B );
StatusType SetRelAlarm ( AlarmType A, TickType B, TickType C );
StatusType SetAbsAlarm ( AlarmType A, TickType B, TickType C );
StatusType CancelAlarm ( AlarmType A );
StatusType AdvCntr ( CounterType A );
StatusType IAdvCntr ( CounterType A );
void SuspendOSInterrupts ( void );
void ResumeOSInterrupts ( void );
void SuspendAllInterrupts ( void );
void ResumeAllInterrupts ( void );
void DisableAllInterrupts ( void );
void EnableAllInterrupts ( void );
void OSEKOSDisable(void);
void OSEKOSEnable(void);
void OSEKOSAsmIDispatch(unsigned long *);
void OSEKOSAsmDispatch(OSEKOSPrioType p);
void OSEKOSStartupEnable(void);
void OSEKOSNop(void);
unsigned int OSEKOSV850CheckIsrSwitch(void);
void OSEKOSV850InitInterrupts(void);
void OSEKOSV850SetupInterrupts();
void OSEKOSV850SyncContextLoad(OSEKOSSaveType);
void OSEKOSV850SyncContextLoadFromIRQ(OSEKOSSaveType);
void OSEKOSV850ASyncContextLoad(OSEKOSSaveType);
void OSEKOSV850ASyncContextLoadFromIRQ(OSEKOSSaveType);
// arrays of function pointers - they look like function prototypes
void ( ( * const OSEKOStaskStartAddress [10] ) ( void ) );
StatusType (* OSEKOStaskStatuses [10][5]) ( void );
void OSEKOSV850StartContext
(
OSEK_TASK (( * const ) ( void )),
OSEK_U8 * const
);
void OSEKOSV850StartContextFromIRQ
(
OSEK_TASK (( * const ) ( void )),
OSEK_U8 * const
);
void OSEKOSSuspendOSInterrupts(void);
void OSEKOSResumeOSInterrupts(void);
void OSEKOSSuspendAllInterrupts(void);
void OSEKOSResumeAllInterrupts(void);
void OSEKOScheckSuspendResumeNesting(void);
void OSEKOSgetSR(void);
void OSEKOSEnableInterrupt_intern(int nr);
void OSEKOSDisableInterrupt_intern(int nr);
@@ -0,0 +1,89 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
typedef unsigned short U16;
typedef signed int int32_t;
/* CMock should handle UTF-8 characters in comments. The world is an awesomely diverse place! */
/* my µC Rocks! Open Source, not ©! My language has no Ümlauts! ǺƜǝƧǾɱɛ! */ /**! Illegal: åäö */
typedef struct _POINT_T
{
int x;
int y;
} POINT_T;
// typedef edge case;
// not ANSI C but it has been done and will break cmock if not handled
typedef void VOID_TYPE_CRAZINESS;
/* fun parsing & mock generation cases */
void var_args1(int a, ...);
void var_args2(int a, int b, ...);
VOID_TYPE_CRAZINESS void_type_craziness1(int, float, double, char, short, long, long int, long long, void*);
int void_type_craziness2( VOID_TYPE_CRAZINESS );
void crazy_whitespace ( int lint, double shot , short stack ) ;
char
crazy_multiline
(
int a,
unsigned int b);
U16 *ptr_return1(int a);
U16* ptr_return2(int a);
U16 * ptr_return3(int a);
unsigned int** ptr_ptr_return1(unsigned int** a);
unsigned int* *ptr_ptr_return2(unsigned int* *a);
unsigned int **ptr_ptr_return3(unsigned int **a);
unsigned int ** ptr_ptr_return4(unsigned int ** a);
extern unsigned long int incredible_descriptors(register const unsigned short a);
int32_t example_c99_type(int32_t param1);
void I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
/* these are function pointers, not function declarations USING a function pointer, and so should NOT get mocked */
int (* func_pointer)(void);
extern int (*another_func_pointer)(unsigned int argument);
struct struct_to_be_ignored {
union {
int i32;
void *p;
} variant;
void (*a_function_pointer_in_a_struct)(void *);
};
typedef struct
{
uint32_t a;
struct
{
uint32_t bb;
float bc;
float bd;
} b;
int (*another_function_pointer_in_a_struct) (void);
} another_thing_that_should_get_ignored;
inline int stuff(int num)
{
int reg = 0x12;
if (num > 0)
{
reg |= (0x0Eu);
}
else
{
reg |= (0x07u);
}
return reg;
}
@@ -0,0 +1,375 @@
---
#this test is different than all_plugins_coexist primarily because of these options
:cmock:
:enforce_strict_ordering: 1
:treat_externs: :include
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char * a);
extern const char* bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
void function_e(void) {
foos("Hello");
foos("Tuna");
foos("Oranges");
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing'
:code: |
test()
{
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
const char* constretval = "This is a silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
function_c();
}
- :pass: FALSE
:should: 'fail strict ordering problems even though we would otherwise have passed'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'properly ExpectAnyArgs first function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_ExpectAnyArgs();
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'properly ExpectAnyArgs last function but the other will work properly'
:code: |
test()
{
no_pointers_Expect(1, "silly");
mixed_ExpectAnyArgsAndReturn(13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'be ok if we ExpectAnyArgs a call each because we are counting calls'
:code: |
test()
{
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
- :pass: TRUE
:should: 'be ok if we ExpectAnyArgs and Expect intermixed because we are counting calls'
:code: |
test()
{
foos_Expect("Hello");
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
- :pass: FALSE
:should: 'be able to detect Expect problem if we ExpectAnyArgs and Expect intermixed'
:code: |
test()
{
foos_Expect("Hello");
foos_ExpectAnyArgs();
foos_Expect("Wrong");
function_e();
}
- :pass: FALSE
:should: 'fail if we do not ExpectAnyArgs a call once because we are counting calls'
:code: |
test()
{
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
...
@@ -0,0 +1,460 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:callback_after_arg_check: true
:callback_include_count: false
:treat_externs: :include
:treat_inlines: :include
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
extern void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
int function_f(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
void function_e(void) {
foos("Hello");
foos("Tuna");
foos("Oranges");
}
int function_f(void) {
int a = 1;
int b = 2;
int c;
POINT_T* pt = bar();
c = pt->x;
c = mixed(a, &b, c);
return b + c;
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
int my_mixed_callback(int a, int* b, int c) { return a + *b + c; }
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing'
:code: |
test()
{
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
function_c();
}
- :pass: FALSE
:should: 'fail strict ordering problems even though we would otherwise have passed'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore last function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Ignore();
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore first function but the other will work properly'
:code: |
test()
{
mixed_IgnoreAndReturn(13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we just have to ignore a call once because we are not counting calls'
:code: |
test()
{
foos_Ignore();
function_e();
}
- :pass: TRUE
:should: 'that we can use a callback and an expect'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {2, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if we want to expect call but did not and we are checking that'
:code: |
test()
{
POINT_T pt = {2, 3};
bar_ExpectAndReturn(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if args are wrong and we are checking those'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {1, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail from the callback itself'
:code: |
test()
{
POINT_T pt = {3, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAndReturn'
:code: |
test()
{
int b = 2;
POINT_T pt1 = {3, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAndReturn(1,&b,3,100);
TEST_ASSERT_EQUAL(8, function_f());
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAndReturn AND ReturnThruPtr still works'
:code: |
test()
{
int b_in = 2;
int b_out = 3;
POINT_T pt1 = {3, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAndReturn(1,&b_in,3,100);
mixed_ReturnThruPtr_b(&b_out);
TEST_ASSERT_EQUAL(9, function_f()); // (a=1, bin=2, c=pt.x=3, bout=3, sum=9)
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAnyArgs'
:code: |
test()
{
POINT_T pt1 = {5, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAnyArgsAndReturn(100);
TEST_ASSERT_EQUAL(10, function_f()); // (a=1, bin=2, c=pt.x=5, bout=2, sum=10)
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAnyArgs AND ReturnThruPtr still works'
:code: |
test()
{
int b_out = 3;
POINT_T pt1 = {5, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAnyArgsAndReturn(100);
mixed_ReturnThruPtr_b(&b_out);
TEST_ASSERT_EQUAL(11, function_f()); // (a=1, bin=2, c=pt.x=5, bout=3, sum=11)
}
...
@@ -0,0 +1,446 @@
---
:cmock:
:when_ptr: :smart
:plugins:
- :array
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
#define ARRAY_A_SIZE (5)
:mockable: |
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[ARRAY_A_SIZE+1-1]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void potential_packing_problem(short *a);
void voidpointerfunc(void* a);
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
void function_f(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
foos(bars());
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
void function_e(void) {
short test_list[] = {-1, -2, -3, -4};
potential_packing_problem(&test_list[1]);
}
void function_f(void) {
char arg[6] = "hello";
voidpointerfunc(arg);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where it falls back to pointers because you asked it to compare 0 elements'
:code: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&ex);
foo_ExpectWithArray(&ex, 0);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where it fails because you asked it to compare zero elements and the pointers do not match'
:code: |
test()
{
POINT_T ex = {1, 2};
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 0);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at start'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{9, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong in middle'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 9}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to pointers and fail'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass nulls to arrays'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass single array element with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to arrays and fail'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle a passing version of a potential packing problem (particularly try with ARM simulators)'
:code: |
test()
{
short expect_list[] = { -2, -3, -4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
- :pass: FALSE
:should: 'handle a failing version of a potential packing problem (particularly try with ARM simulators)'
:code: |
test()
{
short expect_list[] = { -2, -3, 4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
- :pass: TRUE
:should: 'handle a void pointers as arguments and still be able to use the array plugin'
:code: |
test()
{
char expect_list[6] = "hello";
voidpointerfunc_ExpectWithArray(expect_list, 5);
function_f();
}
- :pass: TRUE
:should: 'handle a void pointers as arguments and still be able to use the array plugin (short)'
:code: |
test()
{
char expect_list[6] = "help!";
voidpointerfunc_ExpectWithArray(expect_list, 3);
function_f();
}
- :pass: FALSE
:should: 'handle a void pointers as arguments and still be able to use the array plugin (fail)'
:code: |
test()
{
char expect_list[6] = "help!";
voidpointerfunc_ExpectWithArray(expect_list, 4);
function_f();
}
- :pass: TRUE
:should: 'handle a void pointer with a standard expectation (pass)'
:code: |
test()
{
char expect_list[2] = "h";
voidpointerfunc_Expect(expect_list);
function_f();
}
- :pass: FALSE
:should: 'handle a void pointer with a standard expectation (fail)'
:code: |
test()
{
char expect_list[2] = "g";
voidpointerfunc_Expect(expect_list);
function_f();
}
...
@@ -0,0 +1,124 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
UINT32 foo_varargs(custom_type a, ...);
const char* foo_char_strings(const char a[], const char* b);
:source:
:header: |
UINT32 function_a(int a, int b);
void function_b(void);
UINT32 function_c(int a);
const char* function_d(const char a[], const char* b);
:code: |
UINT32 function_a(int a, int b)
{
return foo((custom_type)a) + bar((custom_type)b);
}
void function_b(void) { }
UINT32 function_c(int a)
{
return foo_varargs((custom_type)a, "ignored", 5);
}
const char* function_d(const char a[], const char* b)
{
return foo_char_strings(a, b);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is not called but is expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called but is not expected'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)1, 10);
function_b();
}
- :pass: TRUE
:should: 'consume var args passed to mocked function'
:code: |
test()
{
foo_varargs_ExpectAndReturn((custom_type)3, 10);
TEST_ASSERT_EQUAL(10, function_c(3));
}
- :pass: TRUE
:should: 'handle char strings'
:code: |
test()
{
const char* retval = "moe";
foo_char_strings_ExpectAndReturn("larry", "curly", (char*)retval);
TEST_ASSERT_EQUAL_STRING("moe", function_d("larry", "curly"));
}
- :pass: TRUE
:should: 'successfully exercise multiple cycles of expecting and mocking and pass'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4));
}
- :pass: FALSE
:should: 'successfully exercise multiple cycles of expecting and mocking and fail'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 5));
}
...
@@ -0,0 +1,87 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
:mockable: |
// no argument names
void foo(char const*, char* const, const char*);
// argument names
void bar(char const* param1, char* const param2, const char* param3);
:source:
:header: |
void exercise_const1(char const* param1, char* const param2, const char* param3);
void exercise_const2(char const* param1, char* const param2, const char* param3);
:code: |
char value1 = '1';
char value2 = '2';
const char* A = &value1;
char* const B = &value2;
const char* C = "C";
const char* D = "D";
void exercise_const1(char const* param1, char* const param2, const char* param3)
{
foo(param1, param2, param3);
}
void exercise_const2(char const* param1, char* const param2, const char* param3)
{
bar(param1, param2, param3);
}
:tests:
:common: |
extern const char* A;
extern char* const B;
extern const char* C;
extern const char* D;
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully pass several const parameters'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( A, B, C );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( (const char*)B, (char * const)A, C );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( A, B, D );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
bar_Expect( A, B, C );
exercise_const2( A, (char * const)C, (const char *)B );
}
...
@@ -0,0 +1,308 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:callback_after_arg_check: false
:callback_include_count: false
:treat_externs: :include
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
extern void foo(POINT_T* a);
POINT_T* bar(void);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
int function_b(void);
:code: |
void function_a(void)
{
foo(bar());
no_args();
}
int function_b(void)
{
POINT_T pt = { 1, 2 };
foo(&pt);
return (pt.x + pt.y);
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
:units:
- :pass: TRUE
:should: 'just pass if we do not insert anything ugly into it'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect and return'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw expectation'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
Try { function_a(); } Catch(e) {}
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after a mock call'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
Try { function_a(); } Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignore'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored mock'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after callback setup'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock with callback'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after expect any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which expected any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which ignored an arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which threw a CException'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndThrow(0x12);
Try {
function_a();
}
Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which used a return thru ptr'
:verify_error: 'FAIL: Expected 3 Was 7. CustomFail'
:code: |
test()
{
POINT_T pt1 = { 1, 2 };
POINT_T pt2 = { 3, 4 };
foo_Expect(&pt1);
foo_ReturnThruPtr_a(&pt2);
TEST_ASSERT_EQUAL_INT_MESSAGE(3, function_b(), "CustomFail");
}
...
@@ -0,0 +1,247 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :ignore
- :cexception
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
#include "CException.h"
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
void baz(custom_type c);
:source:
:header: |
#include "CException.h"
UINT32 function_a(int a, int b);
void function_b(void);
void function_c(void);
void function_d(void);
:code: |
UINT32 function_a(int a, int b)
{
return foo((custom_type)a) + bar((custom_type)b);
}
void function_b(void)
{
baz((custom_type)1);
foo((custom_type)2);
bar((custom_type)3);
baz((custom_type)4);
foo((custom_type)5);
bar((custom_type)6);
baz((custom_type)7);
}
void function_c(void)
{
foo((custom_type)1);
foo((custom_type)2);
bar((custom_type)3);
bar((custom_type)4);
foo((custom_type)5);
}
void function_d(void)
{
CEXCEPTION_T e;
Try
{
foo((custom_type)1);
}
Catch(e) {}
Try
{
bar((custom_type)2);
}
Catch(e) {}
Try
{
foo((custom_type)3);
}
Catch(e) {}
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called but is not expected'
:verify_error: 'Called more times than expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called twice but is expected once'
:verify_error: 'Called fewer times than expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
bar_ExpectAndReturn((custom_type)3, 30);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar and foo called in reverse order'
:verify_error: 'Called earlier than expected'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: TRUE
:should: 'pass because bar and foo called in order with multiple params'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)4, 10);
foo_ExpectAndReturn((custom_type)5, 10);
function_c();
}
- :pass: FALSE
:should: 'fail because bar and foo called out of order at end'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)4, 10);
function_c();
}
- :pass: FALSE
:should: 'fail because bar and foo called out of order at start'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)2, 10);
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)4, 10);
foo_ExpectAndReturn((custom_type)5, 10);
function_c();
}
- :pass: TRUE
:should: 'pass because we are properly ignoring baz'
:code: |
test()
{
baz_Ignore();
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)6, 10);
function_b();
}
- :pass: FALSE
:should: 'fail because bar and foo out of order, even though baz is ignored'
:code: |
test()
{
baz_Ignore();
foo_ExpectAndReturn((custom_type)2, 10);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)6, 10);
function_b();
}
- :pass: TRUE
:should: 'pass when using cexception, as long as the order is right'
:code: |
test()
{
foo_ExpectAndThrow((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndReturn((custom_type)3, 10);
function_d();
}
- :pass: FALSE
:should: 'fail when an throw call is made out of order'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)3, 10);
function_d();
}
- :pass: TRUE
:should: 'successfully handle back to back ExpectAndReturn setup and mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4));
foo_ExpectAndReturn((custom_type)1, 50);
bar_ExpectAndReturn((custom_type)9, 60);
TEST_ASSERT_EQUAL(110, function_a(1, 9));
}
- :pass: FALSE
:should: 'successfully catch errors during back to back ExpectAndReturn setup and mock calls'
:verify_error: 'Called earlier than expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4));
bar_ExpectAndReturn((custom_type)9, 60);
foo_ExpectAndReturn((custom_type)1, 50);
TEST_ASSERT_EQUAL(110, function_a(1, 9));
}
...
@@ -0,0 +1,108 @@
---
:cmock:
:plugins:
- # none
:memcmp_if_unknown: false
:unity_helper_path: expect_and_return_custom_types_unity_helper.h
:systest:
:types: |
typedef struct _EXAMPLE_STRUCT_T { int x; int y; } EXAMPLE_STRUCT_T;
:mockable: |
EXAMPLE_STRUCT_T foo(EXAMPLE_STRUCT_T a);
:source:
:header: |
EXAMPLE_STRUCT_T function_a(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b);
EXAMPLE_STRUCT_T function_b(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b);
:code: |
EXAMPLE_STRUCT_T function_a(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
{
EXAMPLE_STRUCT_T retval = foo(a);
retval.x += b.x;
retval.y += b.y;
return retval;
}
EXAMPLE_STRUCT_T function_b(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
{
EXAMPLE_STRUCT_T retval = foo(b);
retval.x *= a.x;
retval.y *= a.y;
return retval;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {5,8};
foo_ExpectAndReturn(c, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_a(c,d));
}
- :pass: FALSE
:should: 'fail because it is expecting to call foo with c not d'
:code: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {5,8};
foo_ExpectAndReturn(d, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_a(c,d));
}
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls on other function'
:code: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {2,8};
foo_ExpectAndReturn(d, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_b(c,d));
}
- :pass: FALSE
:should: 'fail because it is expecting to call foo with d not c'
:code: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {2,8};
foo_ExpectAndReturn(c, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_b(c,d));
}
:unity_helper:
:header: |
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line);
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) {AssertEqualExampleStruct(expected, actual, (unsigned short)line);}
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
:code: |
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line)
{
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y");
}
...
@@ -0,0 +1,173 @@
---
:cmock:
:plugins:
- # none
:treat_as:
MY_STRING: STRING
MY_INT: INT
PTR_INT: INT*
MY_HEX: HEX32
:systest:
:types: |
typedef const char* MY_STRING;
typedef int MY_INT;
typedef unsigned int MY_HEX;
typedef int* PTR_INT;
:mockable: |
MY_INT foo(MY_HEX a);
MY_INT bar(MY_HEX b);
MY_STRING foo_char_strings(MY_STRING a, MY_STRING b);
float float_adder(float a, float b);
MY_INT* pointer_foo(MY_HEX* a);
void pointer_bar(PTR_INT a);
:source:
:header: |
MY_INT function_a(MY_INT a, MY_INT b);
MY_STRING function_b(MY_STRING a, MY_STRING b);
float function_c(float a, float b);
MY_INT function_d(MY_HEX a);
void function_e(PTR_INT a);
:code: |
MY_INT function_a(MY_INT a, MY_INT b)
{
return foo((MY_HEX)a) + bar((MY_HEX)b);
}
MY_STRING function_b(MY_STRING a, MY_STRING b)
{
return foo_char_strings(a, b);
}
float function_c(float a, float b)
{
return float_adder(b, a);
}
MY_INT function_d(MY_HEX a)
{
MY_HEX b = a;
MY_INT* c = pointer_foo(&b);
return *c;
}
void function_e(PTR_INT a)
{
pointer_bar(a);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((MY_HEX)1, 10);
bar_ExpectAndReturn((MY_HEX)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is expected but not called'
:code: |
test()
{
foo_ExpectAndReturn((MY_HEX)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because foo_char_strings() is called but is not expected'
:code: |
test()
{
foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
function_a(1,2);
}
- :pass: TRUE
:should: 'handle char strings'
:code: |
test()
{
foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
TEST_ASSERT_EQUAL_STRING("boing!", function_b((MY_STRING)"jello", (MY_STRING)"jiggle"));
}
- :pass: TRUE
:should: 'handle floating point numbers with Unity support: pass'
:code: |
test()
{
float_adder_ExpectAndReturn(1.2345f, 6.7890f, 8.0235f);
TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
}
- :pass: FALSE
:should: 'handle floating point numbers with Unity support: fail'
:code: |
test()
{
float_adder_ExpectAndReturn(1.2345f, 6.7892f, 8.0235f);
TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
}
- :pass: TRUE
:should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for passes'
:code: |
test()
{
MY_HEX TestHex = (MY_HEX)45;
MY_INT TestInt = (MY_INT)33;
pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
TEST_ASSERT_EQUAL_INT(33, function_d(45));
}
- :pass: FALSE
:should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for failures'
:verify_error: 'Element 0 Expected 0x0000002D Was 0x0000002B'
:code: |
test()
{
MY_HEX TestHex = (MY_HEX)45;
MY_INT TestInt = (MY_INT)33;
pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
TEST_ASSERT_EQUAL_INT(33, function_d(43));
}
- :pass: TRUE
:should: 'handle treat_as values containing pointers for passes'
:code: |
test()
{
MY_INT ExpInt = (MY_INT)33;
PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
MY_INT ActInt = (MY_INT)33;
PTR_INT ActPtr = (PTR_INT)(&ActInt);
pointer_bar_Expect(ExpPtr);
function_e(ActPtr);
}
- :pass: FALSE
:should: 'handle treat_as values containing pointers for failures'
:verify_error: 'Element 0 Expected 33 Was 45'
:code: |
test()
{
MY_INT ExpInt = (MY_INT)33;
PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
MY_INT ActInt = (MY_INT)45;
PTR_INT ActPtr = (PTR_INT)(&ActInt);
pointer_bar_Expect(ExpPtr);
function_e(ActPtr);
}
...
@@ -0,0 +1,170 @@
---
:cmock:
:plugins:
- :cexception
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
#include "CException.h"
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
UINT32 foo_varargs(custom_type a, ...);
:source:
:header: |
#include "CException.h"
UINT32 function_a(int a);
void function_b(char a);
:code: |
UINT32 function_a(int a)
{
UINT32 r = 0;
CEXCEPTION_T e;
Try
{
r = (UINT32)foo((custom_type)a);
}
Catch(e)
{
r = (UINT32)e*2;
}
return r;
}
void function_b(char a)
{
if (a)
{
Throw((CEXCEPTION_T)a);
}
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise a simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(10, function_a(1));
}
- :pass: TRUE
:should: 'successfully throw an error on first call'
:code: |
test()
{
foo_ExpectAndThrow((custom_type)1, 55);
TEST_ASSERT_EQUAL(110, function_a(1));
}
- :pass: TRUE
:should: 'successfully throw an error on later calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 15);
foo_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(30, function_a(3));
TEST_ASSERT_EQUAL(40, function_a(4));
}
- :pass: TRUE
:should: 'pass because we nothing happens'
:code: |
test()
{
function_b(0);
}
- :pass: FALSE
:should: 'fail because we did not expect function B to throw'
:code: |
test()
{
function_b(1);
}
- :pass: TRUE
:should: 'fail because we expect function B to throw'
:code: |
test()
{
CEXCEPTION_T e;
Try
{
function_b(3);
TEST_FAIL_MESSAGE("Should Have Thrown");
}
Catch(e)
{
TEST_ASSERT_EQUAL(3, e);
}
}
- :pass: TRUE
:should: 'successfully throw an error on consecutive calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
foo_ExpectAndThrow((custom_type)1, 15);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
TEST_ASSERT_EQUAL(30, function_a(1));
TEST_ASSERT_EQUAL(80, function_a(3));
}
- :pass: TRUE
:should: 'successfully throw an error on later calls and after a previous mock call'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
foo_ExpectAndThrow((custom_type)1, 15);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
TEST_ASSERT_EQUAL(30, function_a(1));
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(80, function_a(3));
}
- :pass: TRUE
:should: 'successfully throw an error if expects and mocks called before it'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(80, function_a(3));
}
...
@@ -0,0 +1,238 @@
---
:cmock:
:plugins:
- 'expect_any_args'
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
void func_b(int a);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
void func_b(int a)
{
bar(a);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 10);
foo_ExpectAndReturn(2, 20);
foo_ExpectAndReturn(3, 30);
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
}
- :pass: TRUE
:should: 'ignore foo() call details'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(10);
foo_ExpectAnyArgsAndReturn(40);
foo_ExpectAnyArgsAndReturn(80);
TEST_ASSERT_EQUAL(130, function(3, 4, 3));
}
- :pass: FALSE
:should: 'ignore foo() call details and notice if we called foo() more times than expected'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(30);
TEST_ASSERT_EQUAL(50, function(3, 4, 9));
}
- :pass: FALSE
:should: 'ignore foo() call details and notice if we called foo() fewer times than expected'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(10);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(60);
TEST_ASSERT_EQUAL(70, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore bar() and foo() call details'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
TEST_ASSERT_EQUAL(150, function(0, 0, 0));
}
- :pass: TRUE
:should: 'be able to handle an expect after ignore calls since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(3, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle an ignore after an expect call since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle an ignore within expect calls since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(3, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: FALSE
:should: 'be able to detect problems with an expect even when using ignores'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(4, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle a lone ExpectAnyArg call'
:code: |
test()
{
bar_ExpectAnyArgs();
func_b(1);
}
- :pass: FALSE
:should: 'be able to handle a lone ExpectAnyArg call that does not get called'
:code: |
test()
{
bar_ExpectAnyArgs();
}
- :pass: FALSE
:should: 'be able to handle a missing ExpectAnyArg call'
:code: |
test()
{
func_b(1);
}
- :pass: TRUE
:should: 'ignore foo() calls over multiple mock calls'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(60);
foo_ExpectAnyArgsAndReturn(70);
TEST_ASSERT_EQUAL(180, function(0, 0, 0));
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(30);
foo_ExpectAnyArgsAndReturn(80);
foo_ExpectAnyArgsAndReturn(10);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(70);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(20);
TEST_ASSERT_EQUAL(110, function(0, 0, 0));
}
- :pass: TRUE
:should: 'have multiple cycles of expects still pass when this plugin enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'have multiple cycles of expects still fail when this plugin enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(0, 8, 9));
}
...
@@ -0,0 +1,210 @@
---
:cmock:
:plugins:
- # none
:treat_as:
INT_PTR: INT*
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
typedef int* INT_PTR;
:mockable: |
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char *a);
const char* bars(void);
INT_PTR zoink(INT_PTR a);
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
foos(bars());
}
int function_d(void) {
int i = 456;
INT_PTR ptr = (INT_PTR)(&i);
return (int)(*(zoink(ptr)));
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to pointers and fail'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass nulls to arrays'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass single array element with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to arrays and fail'
:code: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle handle typedefs that ARE pointers by using treat_as'
:code: |
test()
{
int e = 456;
int r = 789;
INT_PTR ptr_e = (INT_PTR)(&e);
INT_PTR ptr_r = (INT_PTR)(&r);
zoink_ExpectAndReturn(ptr_e, ptr_r);
TEST_ASSERT_EQUAL(r, function_d());
}
- :pass: FALSE
:should: 'handle handle typedefs that ARE pointers by using treat_as and catch failures'
:code: |
test()
{
int e = 457;
int r = 789;
INT_PTR ptr_e = (INT_PTR)(&e);
INT_PTR ptr_r = (INT_PTR)(&r);
zoink_ExpectAndReturn(ptr_e, ptr_r);
TEST_ASSERT_EQUAL(r, function_d());
}
...
@@ -0,0 +1,83 @@
---
:cmock:
:plugins:
- # none
:treat_as:
FUNCTION_T: PTR
:systest:
:types: |
typedef void (*FUNCTION_T)(void);
:mockable: |
void takes_function_type( FUNCTION_T myfunc );
void takes_function_ptr( unsigned int (*func_ptr)(int, char) );
void takes_function_ptr_shorthand( unsigned int func_ptr(int, char*) );
void takes_const_function_ptr( unsigned int (* const)(int, char) );
unsigned short (*returns_function_ptr( const char op_code ))( int, long int );
:source:
:header: |
void exercise_function_pointer_param(void);
unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int );
// functions for function pointer tests
unsigned int dummy_function1(int a, char b);
unsigned short dummy_function2(int a, long int b);
:code: |
/*
* functions used in tests
*/
unsigned int dummy_function1(int a, char b)
{
// prevent compiler warnings by using everything
return (unsigned int)a + (unsigned int)b;
}
unsigned short dummy_function2(int a, long int b)
{
// prevent compiler warnings by using everything
return (unsigned short)a + (unsigned short)b;
}
/*
* functions executed by tests
*/
void exercise_function_pointer_param(void)
{
takes_function_ptr(dummy_function1);
}
unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int )
{
return returns_function_ptr(op_code);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'expect a function pointer param'
:code: |
test()
{
takes_function_ptr_Expect(dummy_function1);
exercise_function_pointer_param();
}
- :pass: TRUE
:should: 'return a function pointer'
:code: |
test()
{
returns_function_ptr_ExpectAndReturn('z', dummy_function2);
TEST_ASSERT_EQUAL_PTR(dummy_function2, exercise_function_pointer_return('z'));
}
...
@@ -0,0 +1,329 @@
---
:cmock:
:plugins:
- 'ignore'
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 10);
foo_ExpectAndReturn(2, 20);
foo_ExpectAndReturn(3, 30);
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
}
- :pass: TRUE
:should: 'ignore foo() calls'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(10);
foo_IgnoreAndReturn(40);
foo_IgnoreAndReturn(80);
TEST_ASSERT_EQUAL(130, function(3, 4, 3));
}
- :pass: TRUE
:should: 'ignore the situation where foo() is not called even though we explicitly ignored it'
:code: |
test()
{
foo_IgnoreAndReturn(20);
//notice we do not call foo
}
- :pass: TRUE
:should: 'ignore foo() calls and always return last item if we run out'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(20);
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(80, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore foo() calls and always return only item if only one specified'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(60, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore bar() and foo() calls'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(50);
TEST_ASSERT_EQUAL(150, function(0, 0, 0));
}
- :pass: TRUE
:should: 'ignore foo() calls over multiple mock calls'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(50);
foo_IgnoreAndReturn(60);
foo_IgnoreAndReturn(70);
TEST_ASSERT_EQUAL(180, function(0, 0, 0));
bar_Ignore();
foo_IgnoreAndReturn(30);
foo_IgnoreAndReturn(80);
foo_IgnoreAndReturn(10);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
foo_IgnoreAndReturn(70);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(110, function(0, 0, 0));
}
- :pass: TRUE
:should: 'multiple cycles of expects still pass when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'multiple cycles of expects still fail when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(0, 8, 9));
}
- :pass: FALSE
:should: 'With "fail_on_unexpected_calls" enabled, Expect/Ignore/... of bar is required and test fails.'
:code: |
test()
{
function(1, 2, 3);
}
- :pass: TRUE
:should: 'we can override an ignore with an expect and pass'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore with an expect and fail'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an ignore and return with an expect and pass'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(90, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore and return with an expect and fail'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(0, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an an expect with an ignore'
:code: |
test()
{
bar_Expect(5);
bar_Ignore();
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore and return and pass'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(0, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_IgnoreAndReturn(10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Ignore();
foo_IgnoreAndReturn(60);
TEST_ASSERT_EQUAL(180, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an expect with an ignore and return and fail after'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(100, function(4, 5, 6));
bar_Expect(5);
foo_ExpectAndReturn(9, 30); //THIS ONE WILL FAIL
foo_ExpectAndReturn(2, 80);
foo_ExpectAndReturn(3, 60);
TEST_ASSERT_EQUAL(170, function(1, 2, 3));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore and return and the expected values are ignored'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(2, 30); //NOTE THIS WOULD NORMALLY FAIL
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20); //BUT WE SAID WE NO LONGER CARE
TEST_ASSERT_EQUAL(100, function(4, 5, 6));
}
...
@@ -0,0 +1,325 @@
---
:cmock:
:plugins:
- 'ignore_stateless'
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 10);
foo_ExpectAndReturn(2, 20);
foo_ExpectAndReturn(3, 30);
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
}
- :pass: TRUE
:should: 'ignore foo() calls'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(40);
TEST_ASSERT_EQUAL(120, function(3, 4, 3));
}
- :pass: TRUE
:should: 'ignore the situation where foo() is not called even though we explicitly ignored it'
:code: |
test()
{
foo_IgnoreAndReturn(20);
//notice we do not call foo
}
- :pass: TRUE
:should: 'ignore foo() calls and always return last item'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(20);
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(90, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore bar() and foo() calls'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(50);
TEST_ASSERT_EQUAL(150, function(0, 0, 0));
}
- :pass: TRUE
:should: 'multiple cycles of expects still pass when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'multiple cycles of expects still fail when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(0, 8, 9));
}
- :pass: FALSE
:should: 'With "fail_on_unexpected_calls" enabled, Expect/Ignore/... of bar is required and test fails.'
:code: |
test()
{
function(1, 2, 3);
}
- :pass: TRUE
:should: 'we can override an ignore with an expect and pass'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore with an expect and fail'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an ignore and return with an expect and pass'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(90, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore and return with an expect and fail'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(0, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore'
:code: |
test()
{
bar_Expect(5);
bar_Ignore();
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
}
- :pass: FALSE
:should: 'we can override an expect with an ignore and return and fail after'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(100, function(4, 5, 6));
bar_Expect(5);
foo_ExpectAndReturn(9, 30); //THIS ONE WILL FAIL
foo_ExpectAndReturn(2, 80);
foo_ExpectAndReturn(3, 60);
TEST_ASSERT_EQUAL(170, function(1, 2, 3));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore and return and only the ignore and return is acknowledged'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(2, 30); //NOTE THIS WOULD NORMALLY FAIL
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20); //BUT WE SAID WE NO LONGER CARE
TEST_ASSERT_EQUAL(60, function(4, 5, 6));
}
# StopIgnore
- :pass: FALSE
:should: 'fail when function is called after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(10);
function(0, 0, 0);
bar_StopIgnore();
function(0, 0, 0);
}
- :pass: FALSE
:should: 'delete expect after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_ExpectAndReturn(0, 40);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
foo_IgnoreAndReturn(20);
foo_StopIgnore();
TEST_ASSERT_EQUAL(110, function(0, 0, 0)); // THIS SHOULD FAIL
}
- :pass: TRUE
:should: 'delete expected return values after ignore is stopped'
:code: |
test()
{
bar_Ignore();
foo_ExpectAndReturn(0, 40);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
foo_IgnoreAndReturn(20);
foo_StopIgnore();
foo_ExpectAndReturn(0, 50);
foo_ExpectAndReturn(0, 30);
foo_ExpectAndReturn(0, 40);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
}
...
@@ -0,0 +1,37 @@
---
:cmock:
:plugins:
- 'ignore'
:fail_on_unexpected_calls: FALSE
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'With "fail_on_unexpected_calls" disabled, Expect/Ignore/... of bar is NOT required.'
:code: |
test()
{
function(1, 2, 3);
}
...
@@ -0,0 +1,52 @@
---
#The purpose of this test is to pull in some standard library stuff from C99
:cmock:
:includes:
- "<stdint.h>"
- "<limits.h>"
:systest:
:types: |
#include <stdint.h>
#include <limits.h>
:mockable: |
int32_t foo(int32_t a);
:source:
:header: |
int8_t function_a(void);
:code: |
int8_t function_a(void) {
return (int8_t)(INT_MIN == foo(INT_MAX));
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle handle a simple comparison of C99 types which pass'
:code: |
test()
{
foo_ExpectAndReturn(INT_MAX, INT_MIN);
TEST_ASSERT_TRUE(function_a());
}
- :pass: FALSE
:should: 'handle handle a simple comparison of C99 types which fail'
:code: |
test()
{
foo_ExpectAndReturn(INT_MIN, INT_MIN);
TEST_ASSERT_TRUE(function_a());
}
...
@@ -0,0 +1,91 @@
---
#The purpose of this test is to play with things like "const char const *" which isn't supported by some compilers
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
void foos(const char const * a);
const char const * bars(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
bars_ExpectAndReturn("This is a silly string");
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
function_c();
}
...
@@ -0,0 +1,59 @@
---
#The purpose of this test is to play with our really rough multidimensional array support, which involves an implicit cast not supported everywhere
:cmock:
:plugins:
- :array
:systest:
:types: |
:mockable: |
void foo(unsigned char** a);
unsigned char** bar(void);
:source:
:header: |
void function_a(void);
:code: |
void function_a(void) {
foo(bar());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char** pa = (unsigned char**)(&a);
bar_ExpectAndReturn(pa);
foo_Expect(pa);
function_a();
}
- :pass: FALSE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect as failures (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char b[] = { 5, 6, 7, 8, 9, 0 };
unsigned char** pa = (unsigned char**)(&a);
unsigned char** pb = (unsigned char**)(&b);
bar_ExpectAndReturn(pa);
foo_Expect(pb);
function_a();
}
...
@@ -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();
}
...
@@ -0,0 +1,242 @@
---
:cmock:
:plugins:
- # no plugins
:treat_as_void:
- VOID_TYPE_CRAZINESS_CFG
:treat_as:
TypeDefInt: HEX8
VOID_TYPE_CRAZINESS_CFG*: PTR
:systest:
:types: |
typedef unsigned short U16;
typedef struct _POINT_T
{
int x;
int y;
} POINT_T;
typedef void VOID_TYPE_CRAZINESS_CFG;
typedef int TypeDefInt;
:mockable: |
/* Make sure we ignore the following
#include "NonExistantFile.h
*/
//#include "AndIgnoreThisToo.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SHOULD_IGNORE_NEXT_FUNC_DEF_AS_PART_OF_MACRO \
void IgnoredFunction(NotAValidType ToMakeItFailIfWeActuallyMockedThis);
// typedef edge case; must be in mockable.h for test to compile
// not ANSI C but it has been done and will break cmock if not handled
typedef void VOID_TYPE_CRAZINESS_LCL;
VOID_TYPE_CRAZINESS_LCL void_type_craziness1(int * a, int *b, int* c);
void void_type_craziness2(VOID_TYPE_CRAZINESS_CFG);
void void_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a);
// pointer parsing exercise
U16 *ptr_return1(int a);
U16* ptr_return2(int a);
U16 * ptr_return3(int a);
unsigned int** ptr_ptr_return1(unsigned int** a);
unsigned int* *ptr_ptr_return2(unsigned int* *a);
unsigned int **ptr_ptr_return3(unsigned int **a);
unsigned int ** ptr_ptr_return4(unsigned int ** a);
// variable argument lists
void var_args1(int a, ...);
void var_args2(int a, int b, ...);
// parsing "stress tests"
char
crazy_multiline(
int a,
unsigned int b);
unsigned long int incredible_descriptors(register const unsigned short a);
TypeDefInt uses_typedef_like_names(TypeDefInt typedefvar);
void oh_brackets1(int fudge[5]);
void oh_brackets2(int caramel[]);
void oh_brackets3(int toffee[(32)]);
void oh_brackets4(int taffy[ (64) ]);
#ifdef __cplusplus
}
#endif
:source:
:header: |
U16* exercise_return_pointers(int a);
void exercise_var_args(int a, int b);
void exercise_arglist_pointers(void);
char exercise_multiline_declarations(int a, unsigned int b);
void exercise_double_pointers(unsigned int** a);
int exercise_many_descriptors(int a);
void exercise_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a);
TypeDefInt exercise_typedef_like_names(TypeDefInt a);
:code: |
int A, B, C;
unsigned int *pA, *pB, *pC;
U16* exercise_return_pointers(int a)
{
ptr_return1(a);
ptr_return2(a);
return ptr_return3(a);
}
void exercise_var_args(int a, int b)
{
var_args1(a, 3);
var_args2(a, b, 'c');
}
void exercise_arglist_pointers(void)
{
void_type_craziness1(&A, &B, &C);
void_type_craziness2();
}
char exercise_multiline_declarations(int a, unsigned int b)
{
return crazy_multiline(a, b);
}
void exercise_double_pointers(unsigned int** a)
{
ptr_ptr_return1((unsigned int**)a);
ptr_ptr_return2((unsigned int**)a);
ptr_ptr_return3((unsigned int**)a);
ptr_ptr_return4((unsigned int**)a);
}
int exercise_many_descriptors(int a)
{
return (int)incredible_descriptors((unsigned short)a);
}
void exercise_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a)
{
void_type_craziness3(a);
}
TypeDefInt exercise_typedef_like_names(TypeDefInt a)
{
return uses_typedef_like_names(a);
}
:tests:
:common: |
extern int A, B, C;
extern unsigned int *pA, *pB, *pC;
void setUp(void)
{
A = 100;
B = 200;
C = 300;
pA = (unsigned int*)(&A);
pB = (unsigned int*)(&B);
pC = (unsigned int*)(&C);
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'execute simple pointer return value check'
:code: |
test()
{
U16 retval;
ptr_return1_ExpectAndReturn(2, NULL);
ptr_return2_ExpectAndReturn(2, NULL);
ptr_return3_ExpectAndReturn(2, &retval);
TEST_ASSERT_EQUAL_PTR(&retval, exercise_return_pointers(2));
}
- :pass: TRUE
:should: 'ignore var args in expect prototype generation'
:code: |
test()
{
var_args1_Expect(2);
var_args2_Expect(2, 3);
exercise_var_args(2, 3);
}
- :pass: TRUE
:should: "not process a typedef'd void as anything other than void"
:code: |
test()
{
void_type_craziness1_Expect(&A, &B, &C);
void_type_craziness2_Expect();
exercise_arglist_pointers();
}
- :pass: TRUE
:should: 'successfully mock crazy multline function prototypes'
:code: |
test()
{
crazy_multiline_ExpectAndReturn(-10, 11, 'z');
TEST_ASSERT_EQUAL('z', exercise_multiline_declarations(-10, 11));
}
- :pass: TRUE
:should: 'mock double pointers just fine'
:code: |
test()
{
ptr_ptr_return1_ExpectAndReturn(&pA, &pB);
ptr_ptr_return2_ExpectAndReturn(&pA, &pB);
ptr_ptr_return3_ExpectAndReturn(&pA, &pB);
ptr_ptr_return4_ExpectAndReturn(&pA, &pB);
exercise_double_pointers((unsigned int**)(&pA));
}
- :pass: TRUE
:should: 'mock prototypes with long lists of return and parameter type descriptors'
:code: |
test()
{
incredible_descriptors_ExpectAndReturn(888, 777);
TEST_ASSERT_EQUAL(777, exercise_many_descriptors(888));
}
- :pass: TRUE
:should: 'handle words like typdef as PART of a variable or type'
:code: |
test()
{
uses_typedef_like_names_ExpectAndReturn((TypeDefInt)54, (TypeDefInt)53);
TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54));
}
- :pass: FALSE
:should: 'handle words like typdef as PART of a variable or type during failing tests'
:code: |
test()
{
uses_typedef_like_names_ExpectAndReturn((TypeDefInt)52, (TypeDefInt)53);
TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54));
}
- :pass: TRUE
:should: 'handle typedef of void used as a void pointer'
:code: |
test()
{
char blah[5] = "blah";
void_type_craziness3_Expect(blah);
exercise_type_craziness3(blah);
}
...
@@ -0,0 +1,235 @@
---
:cmock:
:mock_path: test/mocks
:mock_prefix: mock_
:treat_as:
abs_struct: PTR
intptr: INT*
:when_ptr: :smart
:plugins:
- :array
- :ignore_arg
- :return_thru_ptr
:systest:
:types: |
typedef int *intptr;
struct a_struct
{
int i1;
int i2;
int i3;
};
struct _abs_struct
{
int abs_i1;
int abs_i2;
};
typedef struct _abs_struct abs_struct;
:mockable: |
void ptr_ret_int(int *r);
void ptr_ret_ints(int *r, int *s);
void ptr_ret_array(char r[], int len);
void ptr_ret_typedef(intptr r);
void ptr_ret_struct(struct a_struct *r);
void ptr_ret_abstract(abs_struct *r);
void ptr_ret_abstract_array(abs_struct *r, int len);
void ptr_ret_const_int(int *r, const int *s);
void ptr_ret_string(char *s);
:source:
:header: |
#include <string.h>
#define lengthof(x) (sizeof(x)/sizeof((x)[0]))
:code: |
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: "handle a single int* argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple calls"
:code: |
test()
{
int r = 1;
int res1 = 4;
int res2 = 8;
int res3 = 16;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res1);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res2);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res3);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(8, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(16, r);
}
- :pass: TRUE
:should: "ignore an argument"
:code: |
test()
{
int r = 1, s = 2;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&s);
TEST_ASSERT_EQUAL(4, s);
}
- :pass: TRUE
:should: "ignore a null pointer argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(NULL);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple int* arguments"
:code: |
test()
{
int r, s = 0x0880AA55;
int r_res = 4;
int s_res = 6;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints_ReturnThruPtr_s(&s_res);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(6, s);
}
- :pass: TRUE
:should: "only return through pointer when asked to"
:code: |
test()
{
int r = 0x0880AA55;
int s = 0xAA55;
int r_res = 4;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(0xAA55, s);
}
- :pass: TRUE
:should: "return an array through a pointer correctly"
:code: |
test()
{
char r_a[] = "booboorooboo";
char r_a_ret[] = "FEEFI";
ptr_ret_array_Expect(r_a, lengthof(r_a));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
- :pass: TRUE
:should: "handle structs"
:code: |
test()
{
struct a_struct r_s = { .i1 = 2, .i2 = 3, .i3 = 4, };
struct a_struct r_s_ret = { .i1 = 8, .i2 = 16, .i3 = 32, };
ptr_ret_struct_Expect(&r_s);
ptr_ret_struct_ReturnThruPtr_r(&r_s_ret);
ptr_ret_struct(&r_s);
TEST_ASSERT_EQUAL_MEMORY(&r_s_ret, &r_s, sizeof(struct a_struct));
}
- :pass: TRUE
:should: "handle typedefs"
:code: |
test()
{
abs_struct r_as = {.abs_i1 = 0x1234, .abs_i2 = 0x4567};
abs_struct r_as_ret = {.abs_i1 = 0xFFAA55, .abs_i2 = 0xAAFFAA};
ptr_ret_abstract_Expect(&r_as);
ptr_ret_abstract_ReturnMemThruPtr_r(&r_as_ret, sizeof(abs_struct));
ptr_ret_abstract(&r_as);
TEST_ASSERT_EQUAL_MEMORY(&r_as_ret, &r_as, sizeof(abs_struct));
}
- :pass: TRUE
:should: "only generate ReturnThruPtr definitions for non-const arguments"
:code: |
test()
{
#if !defined(ptr_ret_const_int_ReturnThruPtr_r)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a pointer argument.");
#endif
#if defined(ptr_ret_const_int_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr defined for a const pointer argument.");
#endif
}
- :pass: TRUE
:should: "generate ReturnThruPtr definitions for string arguments"
:code: |
test()
{
#if !defined(ptr_ret_string_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a string argument.");
#endif
}
- :pass: TRUE
:should: "generate IgnoreArg definitions"
:code: |
test()
{
#if !defined(ptr_ret_array_IgnoreArg_r) \
|| !defined(ptr_ret_array_IgnoreArg_len) \
|| !defined(ptr_ret_const_int_IgnoreArg_s)
TEST_FAIL_MESSAGE("IgnoreArg not defined for an argument.");
#endif
}
@@ -0,0 +1,231 @@
---
:cmock:
:mock_path: test/mocks
:mock_prefix: mock_
:treat_as:
abs_struct: PTR
intptr: INT*
:when_ptr: :smart
:plugins:
- :array
- :expect_any_args
- :return_thru_ptr
:systest:
:types: |
typedef int *intptr;
struct a_struct
{
int i1;
int i2;
int i3;
};
struct _abs_struct
{
int abs_i1;
int abs_i2;
};
typedef struct _abs_struct abs_struct;
:mockable: |
void ptr_ret_int(int *r);
void ptr_ret_ints(int *r, int *s);
void ptr_ret_array(char r[], int len);
void ptr_ret_typedef(intptr r);
void ptr_ret_struct(struct a_struct *r);
void ptr_ret_abstract(abs_struct *r);
void ptr_ret_abstract_array(abs_struct *r, int len);
void ptr_ret_const_int(int *r, const int *s);
void ptr_ret_string(char *s);
:source:
:header: |
#include <string.h>
#define lengthof(x) (sizeof(x)/sizeof((x)[0]))
:code: |
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: "handle a single int* argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple calls"
:code: |
test()
{
int r = 1;
int res1 = 4;
int res2 = 8;
int res3 = 16;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res1);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res2);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res3);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(8, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(16, r);
}
- :pass: TRUE
:should: "ignore an argument"
:code: |
test()
{
int s = 2;
int res = 4;
ptr_ret_int_ExpectAnyArgs();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&s);
TEST_ASSERT_EQUAL(4, s);
}
- :pass: TRUE
:should: "ignore a null pointer argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_ExpectAnyArgs();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple int* arguments"
:code: |
test()
{
int r, s = 0x0880AA55;
int r_res = 4;
int s_res = 6;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints_ReturnThruPtr_s(&s_res);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(6, s);
}
- :pass: TRUE
:should: "only return through pointer when asked to"
:code: |
test()
{
int r = 0x0880AA55;
int s = 0xAA55;
int r_res = 4;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(0xAA55, s);
}
- :pass: TRUE
:should: "return an array through a pointer correctly"
:code: |
test()
{
char r_a[] = "booboorooboo";
char r_a_ret[] = "FEEFI";
ptr_ret_array_Expect(r_a, lengthof(r_a));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
- :pass: TRUE
:should: "handle structs"
:code: |
test()
{
struct a_struct r_s = { .i1 = 2, .i2 = 3, .i3 = 4, };
struct a_struct r_s_ret = { .i1 = 8, .i2 = 16, .i3 = 32, };
ptr_ret_struct_Expect(&r_s);
ptr_ret_struct_ReturnThruPtr_r(&r_s_ret);
ptr_ret_struct(&r_s);
TEST_ASSERT_EQUAL_MEMORY(&r_s_ret, &r_s, sizeof(struct a_struct));
}
- :pass: TRUE
:should: "handle typedefs"
:code: |
test()
{
abs_struct r_as = {.abs_i1 = 0x1234, .abs_i2 = 0x4567};
abs_struct r_as_ret = {.abs_i1 = 0xFFAA55, .abs_i2 = 0xAAFFAA};
ptr_ret_abstract_Expect(&r_as);
ptr_ret_abstract_ReturnMemThruPtr_r(&r_as_ret, sizeof(abs_struct));
ptr_ret_abstract(&r_as);
TEST_ASSERT_EQUAL_MEMORY(&r_as_ret, &r_as, sizeof(abs_struct));
}
- :pass: TRUE
:should: "only generate ReturnThruPtr definitions for non-const arguments"
:code: |
test()
{
#if !defined(ptr_ret_const_int_ReturnThruPtr_r)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a pointer argument.");
#endif
#if defined(ptr_ret_const_int_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr defined for a const pointer argument.");
#endif
}
- :pass: TRUE
:should: "generate ReturnThruPtr definitions for string arguments"
:code: |
test()
{
#if !defined(ptr_ret_string_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a string argument.");
#endif
}
- :pass: TRUE
:should: "generate ExpectAnyArgs definitions"
:code: |
test()
{
#if !defined(ptr_ret_array_ExpectAnyArgs)
TEST_FAIL_MESSAGE("ExpectAnyArgs not defined for an argument.");
#endif
}
@@ -0,0 +1,55 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# we are purposefully not including a :code section because it will be generated with skeleton
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'return null for pointer return values'
:code: |
test()
{
TEST_ASSERT_NULL(function_c());
}
...
@@ -0,0 +1,76 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton_update.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# note that this code section exists and will be updated by the skeleton generator
:code: |
const char* donuts = "donuts";
const char* function_c(void)
{
return donuts;
}
int function_d(void)
{
return 77;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
extern int function_d();
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'not overwrite functions that already exist'
:code: |
test()
{
TEST_ASSERT_EQUAL_STRING("donuts", function_c());
}
- :pass: TRUE
:should: 'leave functions it has never heard of'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(77, function_d());
}
...
@@ -0,0 +1,277 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
struct THING { int a; int b; };
union STARS_AND_STRIPES { int a; char b; };
enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };
:mockable: |
void foo_struct(struct THING*, struct THING);
struct THING foobar_struct(void);
void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
union STARS_AND_STRIPES foobar_union(void);
void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY foobar_enum(void);
:source:
:header: |
void exercise_struct(struct THING* a, struct THING b);
struct THING return_struct(void);
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
union STARS_AND_STRIPES return_union(void);
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY return_enum(void);
:code: |
void exercise_struct(struct THING* a, struct THING b)
{
foo_struct(a, b);
}
struct THING return_struct(void)
{
return foobar_struct();
}
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
{
foo_union(a, b);
}
union STARS_AND_STRIPES return_union(void)
{
return foobar_union();
}
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
{
foo_enum(a, b);
}
enum HOKEY_POKEY return_enum(void)
{
return foobar_enum();
}
:tests:
:common: |
struct THING struct1;
struct THING struct2;
struct THING struct3;
struct THING struct4;
struct THING struct5;
struct THING struct6;
union STARS_AND_STRIPES union1;
union STARS_AND_STRIPES union2;
union STARS_AND_STRIPES union3;
union STARS_AND_STRIPES union4;
union STARS_AND_STRIPES union5;
union STARS_AND_STRIPES union6;
enum HOKEY_POKEY enum1;
enum HOKEY_POKEY enum2;
void setUp(void)
{
struct1.a = 1;
struct1.b = 2;
struct2.a = 3;
struct2.b = 4;
struct3.a = 5;
struct3.b = 6;
struct4.a = 7;
struct4.b = 8;
struct5.a = 9;
struct5.b = 10;
struct6.a = 9;
struct6.b = 10;
union1.a = 1;
union2.a = 2;
union3.a = 3;
union4.a = 4;
union5.a = 5;
union6.a = 5;
enum1 = OUT;
enum2 = IN;
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully compare structs'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct2);
}
- :pass: FALSE
:should: 'blow up on bad struct pointer comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct3, struct2);
}
- :pass: FALSE
:should: 'blow up on bad structure comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct4);
}
- :pass: TRUE
:should: 'compare returned structs as equal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct5);
TEST_ASSERT_EQUAL_THING(struct6, return_struct());
}
- :pass: FALSE
:should: 'compare returned structs as unequal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct4);
TEST_ASSERT_EQUAL_THING(struct5, return_struct());
}
- :pass: TRUE
:should: 'successfully compare unions'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union2);
}
- :pass: FALSE
:should: 'blow up on bad union pointer comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union3, union2);
}
- :pass: FALSE
:should: 'blow up on bad union comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union4);
}
- :pass: TRUE
:should: 'compare returned unions as equal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union5);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union4);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
}
- :pass: TRUE
:should: 'successfully pass enum values'
:code: |
test()
{
foo_enum_Expect(OUT, &enum1);
exercise_enum(OUT, &enum1);
}
- :pass: FALSE
:should: 'blow up on bad enum pointer comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(IN, &enum2);
}
- :pass: FALSE
:should: 'blow up on bad enum comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
}
- :pass: TRUE
:should: 'compare returned enums as equal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(OUT, return_enum());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(IN, return_enum());
}
:unity_helper:
:header: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);
#define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
#define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}
:code: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual struct member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
}
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
}
...
@@ -0,0 +1,280 @@
---
:cmock:
:plugins:
- :array
- :ignore
- :callback
- :return_thru_ptr
:systest:
:types: |
struct THING { int a; int b; };
union STARS_AND_STRIPES { int a; char b; };
enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };
:mockable: |
void foo_struct(struct THING*, struct THING);
struct THING foobar_struct(void);
void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
union STARS_AND_STRIPES foobar_union(void);
void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY foobar_enum(void);
:source:
:header: |
void exercise_struct(struct THING* a, struct THING b);
struct THING return_struct(void);
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
union STARS_AND_STRIPES return_union(void);
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY return_enum(void);
:code: |
void exercise_struct(struct THING* a, struct THING b)
{
foo_struct(a, b);
}
struct THING return_struct(void)
{
return foobar_struct();
}
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
{
foo_union(a, b);
}
union STARS_AND_STRIPES return_union(void)
{
return foobar_union();
}
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
{
foo_enum(a, b);
}
enum HOKEY_POKEY return_enum(void)
{
return foobar_enum();
}
:tests:
:common: |
struct THING struct1;
struct THING struct2;
struct THING struct3;
struct THING struct4;
struct THING struct5;
struct THING struct6;
union STARS_AND_STRIPES union1;
union STARS_AND_STRIPES union2;
union STARS_AND_STRIPES union3;
union STARS_AND_STRIPES union4;
union STARS_AND_STRIPES union5;
union STARS_AND_STRIPES union6;
enum HOKEY_POKEY enum1;
enum HOKEY_POKEY enum2;
void setUp(void)
{
struct1.a = 1;
struct1.b = 2;
struct2.a = 3;
struct2.b = 4;
struct3.a = 5;
struct3.b = 6;
struct4.a = 7;
struct4.b = 8;
struct5.a = 9;
struct5.b = 10;
struct6.a = 9;
struct6.b = 10;
union1.a = 1;
union2.a = 2;
union3.a = 3;
union4.a = 4;
union5.a = 5;
union6.a = 5;
enum1 = OUT;
enum2 = IN;
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully compare structs'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct2);
}
- :pass: FALSE
:should: 'blow up on bad struct pointer comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct3, struct2);
}
- :pass: FALSE
:should: 'blow up on bad structure comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct4);
}
- :pass: TRUE
:should: 'compare returned structs as equal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct5);
TEST_ASSERT_EQUAL_THING(struct6, return_struct());
}
- :pass: FALSE
:should: 'compare returned structs as unequal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct4);
TEST_ASSERT_EQUAL_THING(struct5, return_struct());
}
- :pass: TRUE
:should: 'successfully compare unions'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union2);
}
- :pass: FALSE
:should: 'blow up on bad union pointer comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union3, union2);
}
- :pass: FALSE
:should: 'blow up on bad union comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union4);
}
- :pass: TRUE
:should: 'compare returned unions as equal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union5);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union4);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
}
- :pass: TRUE
:should: 'successfully pass enum values'
:code: |
test()
{
foo_enum_Expect(OUT, &enum1);
exercise_enum(OUT, &enum1);
}
- :pass: FALSE
:should: 'blow up on bad enum pointer comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(IN, &enum2);
}
- :pass: FALSE
:should: 'blow up on bad enum comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
}
- :pass: TRUE
:should: 'compare returned enums as equal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(OUT, return_enum());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(IN, return_enum());
}
:unity_helper:
:header: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);
#define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
#define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}
:code: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual struct member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
}
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
}
...
@@ -0,0 +1,221 @@
---
:cmock:
:plugins:
- :callback
:treat_as:
custom_type: INT
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type* a);
UINT32 bar(custom_type* b);
int baz(void);
void fuz(int* args, int num);
:source:
:header: |
void function_a(int a, int b);
UINT32 function_b(void);
int function_c(void);
:code: |
void function_a(int a, int b)
{
int args[6] = {0, 1, 2, 3, 5, 5};
args[0] = a;
fuz(args, b);
}
UINT32 function_b(void)
{
UINT32 sum = 0;
custom_type a = 0;
custom_type b = 0;
sum = foo(&a) + bar(&b);
return (UINT32)((custom_type)sum + a + b);
}
int function_c(void)
{
return (baz() + baz() + baz());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
UINT32 FooAndBarHelper(custom_type* data, int num)
{
num++;
*data = (custom_type)(num * 2);
return (UINT32)(*data * 2);
}
int BazCallbackPointless(int num)
{
return num;
}
int BazCallbackComplainsIfCalledMoreThanTwice(int num)
{
TEST_ASSERT_MESSAGE(num < 2, "Do Not Call Baz More Than Twice");
return num;
}
void FuzVerifier(int* args, int num_args, int num_calls)
{
int i;
TEST_ASSERT_MESSAGE(num_args < 5, "No More Than 5 Args Allowed");
for (i = 0; i < num_args; i++)
{
TEST_ASSERT_EQUAL(num_calls + i, args[i]);
}
}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls the normal way'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: FALSE
:should: 'successfully exercise two simple ExpectAndReturn mock calls and catch failure the normal way'
:code: |
test()
{
custom_type exp = 1;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(12, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks even if there were expects'
:code: |
test()
{
custom_type exp = 500;
foo_ExpectAndReturn(&exp, 10);
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(12, function_b());
}
- :pass: FALSE
:should: 'successfully exercise using some basic callbacks and notice failures'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(10, function_b());
}
- :pass: TRUE
:should: 'successfully exercise a callback with no arguments'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: FALSE
:should: 'successfully throw a failure from within a callback function'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackComplainsIfCalledMoreThanTwice);
function_c();
}
- :pass: TRUE
:should: 'be usable for things like dynamically sized memory checking for passing conditions'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 5);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions 2'
:code: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(1, 4);
}
- :pass: TRUE
:should: 'run them interlaced'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 20);
bar_ExpectAndReturn(&exp, 40);
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(30, function_b());
TEST_ASSERT_EQUAL(55, function_b());
function_a(0, 4);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: TRUE
:should: 'run them back to back'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 40);
TEST_ASSERT_EQUAL(55, function_b());
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
...
@@ -0,0 +1,77 @@
---
#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: |
#include "unity_internals.h"
typedef UNITY_UINT64 TEST64;
: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,0 +1,139 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 foo(UINT32 a);
void bar(void);
:source:
:header: |
UINT32 function_a(int a);
void function_b(void);
:code: |
UINT32 function_a(int a)
{
bar();
return foo((UINT32)a);
}
void function_b(void)
{
bar();
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: :ignore
:should: 'ignore incorrect expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore missing expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore no expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call even if it happens later'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(30);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are missing expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore if extra expects before the TEST_IGNORE because it ignored the rest of the test that might have made calls to it'
:code: |
test()
{
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
...
@@ -0,0 +1,91 @@
---
#The purpose of this test is to verify we handle void pointers as memory compares
:cmock:
:plugins:
- :array
:treat_as_array:
VOID_PTR: unsigned char
:systest:
:types: |
#include "unity_internals.h"
typedef void* VOID_PTR;
:mockable: |
void* ret_v_ptr(void);
void get_v_ptr(void* ptr);
void get_v_ptr_typedefed(VOID_PTR ptr);
:source:
:header: |
void function_a(void);
:code: |
void function_a(void) {
void* stuff = ret_v_ptr();
get_v_ptr(stuff);
get_v_ptr_typedefed((VOID_PTR)stuff);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle passing working expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_Expect(b);
get_v_ptr_typedefed_Expect((VOID_PTR)b);
function_a();
}
- :pass: TRUE
:should: 'handle passing array expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_ExpectWithArray(b,5);
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
function_a();
}
- :pass: FALSE
:should: 'handle failing expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Jello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_Expect(b);
get_v_ptr_typedefed_Expect((VOID_PTR)b);
function_a();
}
- :pass: FALSE
:should: 'handle failing array expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hella";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_ExpectWithArray(b,5);
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
function_a();
}
...
@@ -0,0 +1,90 @@
---
compiler:
path: clang
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './system/build/'
options:
- '-c'
- '-Wall'
- '-Wextra'
- '-Werror'
#- '-Wcast-qual'
- '-Wconversion'
- '-Wtautological-compare'
#- '-Wtautological-pointer-compare'
- '-Wdisabled-optimization'
- '-Wformat=2'
- '-Winit-self'
- '-Winline'
- '-Winvalid-pch'
- '-Wmissing-declarations'
- '-Wmissing-include-dirs'
- '-Wmissing-prototypes'
- '-Wnonnull'
- '-Wpacked'
- '-Wpointer-arith'
- '-Wredundant-decls'
- '-Wswitch-default'
- '-Wstrict-aliasing=2'
- '-Wstrict-overflow=5'
- '-Wuninitialized'
- '-Wunused'
- '-Wunreachable-code'
- '-Wreturn-type'
- '-Wshadow'
- '-Wundef'
- '-Wwrite-strings'
- '-Wbad-function-cast'
- '-Wno-missing-prototypes' #we've been lazy about things like setUp and tearDown
- '-Wno-invalid-token-paste'
- '-fms-extensions'
- '-fno-omit-frame-pointer'
#- '-ffloat-store'
- '-fno-common'
- '-fstrict-aliasing'
- '-std=gnu99'
- '-pedantic'
- '-O0'
includes:
prefix: '-I'
items:
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- '../src/'
- '../vendor/unity/src/'
- '../vendor/c_exception/lib/'
- './system/test_compilation/'
- './'
defines:
prefix: '-D'
items:
- CMOCK
- 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64'
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:
- out_of_memory
- callingconv
colour: true
@@ -0,0 +1,58 @@
---
compiler:
path: gcc
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './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/'
- './system/test_compilation/'
- './'
defines:
prefix: '-D'
items:
- CMOCK
- 'UNITY_SUPPORT_64'
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:
- out_of_memory
- unity_64bit_support
- callingconv
colour: true
@@ -0,0 +1,58 @@
---
compiler:
path: gcc
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './system/build/'
options:
- '-c'
- '-m64'
- '-Wall'
- '-Wunused-parameter'
- '-Wno-address'
- '-Wno-invalid-token-paste'
- '-std=c99'
- '-pedantic'
includes:
prefix: '-I'
items:
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- '../src/'
- '../vendor/unity/src/'
- '../vendor/c_exception/lib/'
- './system/test_compilation/'
- './'
defines:
prefix: '-D'
items:
- CMOCK
- 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64'
object_files:
prefix: '-o'
extension: '.o'
destination: *systest_build_path
linker:
path: gcc
options:
- -lm
- '-m64'
includes:
prefix: '-I'
object_files:
path: *systest_build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.exe'
destination: *systest_build_path
unsupported:
- out_of_memory
- callingconv
colour: true
@@ -0,0 +1,80 @@
---
compiler:
path: gcc
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './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/'
- './system/test_compilation/'
- './'
defines:
prefix: '-D'
items:
- CMOCK
- '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
@@ -0,0 +1,110 @@
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0\'
compiler:
path: [*tools_root, 'arm\bin\iccarm.exe']
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './system/build/'
options:
- --dlib_config
- [*tools_root, 'arm\lib\dl4tptinl8n.h']
- -z3
- --no_cse
- --no_unroll
- --no_inline
- --no_code_motion
- --no_tbaa
- --no_clustering
- --no_scheduling
- --debug
- --cpu_mode thumb
- --endian little
- --cpu ARM7TDMI
- --stack_align 4
- --interwork
- -e
- --silent
- --warnings_are_errors
- --fpu None
#We are supressing some warnings here because we test CMock against some questionable code to make sure it still works
- --diag_suppress Pa050
- --diag_suppress Pe191
- --diag_suppress=Pe494
- --diag_suppress=Pe083
includes:
prefix: '-I'
items:
- [*tools_root, 'arm\inc\']
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- '../src/'
- '../vendor/unity/src/'
- '../vendor/c_exception/lib/'
- './system/test_compilation/'
- './'
defines:
prefix: '-D'
items:
- CMOCK
object_files:
prefix: '-o'
extension: '.r79'
destination: *systest_build_path
linker:
path: [*tools_root, 'common\bin\xlink.exe']
options:
- -rt
- [*tools_root, 'arm\lib\dl4tptinl8n.r79']
- -D_L_EXTMEM_START=0
- -D_L_EXTMEM_SIZE=0
- -D_L_HEAP_SIZE=120
- -D_L_STACK_SIZE=32
- -e_small_write=_formatted_write
- -s
- __program_start
- '-f iar\iar_v4\Resource\at91SAM7X256_FLASH.xcl'
includes:
prefix: '-I'
items:
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- 'vendor/unity/src/'
- [*tools_root, 'arm\config\']
- [*tools_root, 'arm\lib\']
object_files:
path: *systest_build_path
extension: '.r79'
bin_files:
prefix: '-o'
extension: '.d79'
destination: *systest_build_path
simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support:
- --silent
- [*tools_root, 'arm\bin\armproc.dll']
- [*tools_root, 'arm\bin\armsim.dll']
post_support:
- --plugin
- [*tools_root, 'arm\bin\armbat.dll']
- --macro
- 'iar\iar_v4\Resource\SAM7_SIM.mac'
- --backend
- -B
- -p
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
- -d
- sim
unsupported:
- out_of_memory
- nonstandard_parsed_stuff_1
- const
- callingconv
- unity_64bit_support
colour: true
@@ -0,0 +1,95 @@
tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 5.3\'
compiler:
path: [*tools_root, 'arm\bin\iccarm.exe']
source_path: &systest_generated_path './system/generated/'
unit_tests_path: &unit_tests_path '../examples/test/'
mocks_path: &systest_mocks_path './system/generated/'
build_path: &systest_build_path './system/build/'
options:
- --dlib_config
- [*tools_root, 'arm\inc\DLib_Config_Normal.h']
- --no_cse
- --no_unroll
- --no_inline
- --no_code_motion
- --no_tbaa
- --no_clustering
- --no_scheduling
- --debug
- --cpu_mode thumb
- --endian=little
- --cpu=ARM7TDMI
- --interwork
- --warnings_are_errors
- --fpu=None
- -e
- -On
#We are supressing some warnings here because we test CMock against some questionable code to make sure it still works
- --diag_suppress=Pa050
- --diag_suppress=Pe191
- --diag_suppress=Pe494
- --diag_suppress=Pe083
includes:
prefix: '-I'
items:
- [*tools_root, 'arm\inc\']
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- '../src/'
- '../vendor/unity/src/'
- '../vendor/c_exception/lib/'
- './system/test_compilation/'
- './'
- '.\iar\iar_v5\incIAR\'
defines:
prefix: '-D'
items:
- CMOCK
object_files:
prefix: '-o'
extension: '.r79'
destination: *systest_build_path
linker:
path: [*tools_root, 'arm\bin\ilinkarm.exe']
options:
- --redirect _Printf=_PrintfLarge
- --redirect _Scanf=_ScanfSmall
- --semihosting
- --entry __iar_program_start
- --config iar\iar_v5\Resource\at91SAM7X256_RAM.icf
object_files:
path: *systest_build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.out'
destination: *systest_build_path
simulator:
path: [*tools_root, 'common\bin\CSpyBat.exe']
pre_support:
- --silent
- [*tools_root, 'arm\bin\armproc.dll']
- [*tools_root, 'arm\bin\armsim.dll']
post_support:
- --plugin
- [*tools_root, 'arm\bin\armbat.dll']
- --macro
- 'iar\iar_v5\Resource\SAM7_SIM.mac'
- --backend
- -B
- -p
- [*tools_root, 'arm\config\debugger\Atmel\ioat91sam7X256.ddf']
- -d
- sim
unsupported:
- out_of_memory
- nonstandard_parsed_stuff_1
- const
- callingconv
- unity_64bit_support
colour: true
@@ -0,0 +1,44 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
require 'minitest/autorun'
def create_mocks(*mocks)
mocks.each do |mock|
eval "@#{mock} = Minitest::Mock.new"
end
end
def create_stub(funcs)
stub = Class.new
blob = "class << stub\n"
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
blob += "end"
eval blob
stub
end
def test_return
{
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
:string => {:type => "const char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
}
end
def test_arg
{
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false, :const_ptr? => false},
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false, :const_ptr? => false},
:const_ptr => {:type => "int*", :name => 'MyConstPtr', :ptr? => true, :const? => false, :const_ptr? => true},
:double_ptr => {:type => "int const**", :name => 'MyDoublePtr', :ptr? => true, :const? => true, :const_ptr? => false},
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true, :const_ptr? => false},
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false, :const_ptr? => false},
:string => {:type => "const char*", :name => 'MyStr', :ptr? => false, :const? => true, :const_ptr? => false},
}
end
Loaded 100 of 1955 files, more files were not shown because too many files have changed in this diff. Show more