11     static void setUp(
void){
 
   15     static void tearDown(
void){
 
   16         for(
int i = 1; i < 8; ++i){
 
   29     static void test_ShiftLeft(
void){
 
   32         TEST_ASSERT_EQUAL_INT(4, x);
 
   35     static void test_ShiftRightNegative(
void){
 
   38         TEST_ASSERT_EQUAL_INT(-4, x);
 
   41     static void test_ShiftRightUnsignedNumber(
void){
 
   42         volatile unsigned int x = 0xFFFFFFFF;
 
   44         TEST_ASSERT_EQUAL_HEX32(0x0FFFFFFF, x);
 
   48     static void test_ShiftRightSignedPositiveHighBitSet(
void){
 
   49         volatile signed int x = 0xFfffFfff;
 
   51         TEST_ASSERT_EQUAL_HEX32(0xFfffFfff, x);
 
   54     static void test_ShiftRightSignedPositiveHighBitNotSet(
void){
 
   55         volatile signed int x = 0xFfff;
 
   57         TEST_ASSERT_EQUAL_HEX32(0xFf, x);
 
   60     static void test_LeftShiftUnsigned(
void){
 
   61         volatile unsigned int x = 0xF;
 
   63         TEST_ASSERT_EQUAL_HEX32(0xF0000, x);
 
   75     static void test_lockretReturnsLock(
void){
 
   76         int num_first = locknew();
 
   78         int num_second = locknew();
 
   79         TEST_ASSERT_EQUAL_INT(num_first, num_second);
 
   83     static void test_locknewFirstLockIs1(
void){
 
   86         TEST_ASSERT_EQUAL_INT(1, num);
 
   91     static void test_locknewSevenAvailableLocks(
void){
 
   92         for(
int i = 1; i < 8; i++){
 
   93             TEST_ASSERT_EQUAL_INT(i, locknew());
 
   96         TEST_ASSERT_EQUAL_INT(-1, locknew());
 
   98         for(
int i = 1; i < 8; i++){
 
  103     static void test_locksetAndlockclr(
void){
 
  104         int lock = locknew();
 
  105         TEST_ASSERT_TRUE(lock != -1);
 
  107         TEST_ASSERT_FALSE(lockset(lock));
 
  108         TEST_ASSERT_TRUE(lockset(lock));
 
  114     static void test_ReturnSetLock(
void){
 
  115         int lock = locknew();
 
  116         TEST_ASSERT_TRUE(lock != -1);
 
  121         int lock2 = locknew();
 
  122         TEST_ASSERT_EQUAL_INT(lock, lock2);
 
  128     static void test_locksetIsEqualToCTrueFalseConstant(
void){
 
  129         int lock = locknew();
 
  130         TEST_ASSERT_TRUE(lock != -1);
 
  134         TEST_ASSERT_TRUE(lockset(lock) == 
false);
 
  135         TEST_ASSERT_TRUE(lockset(lock) != 
false);
 
  142     static void test_lockretReturnOrderDoesntMatter(
void){
 
  143         int lockA = locknew();
 
  144         int lockB = locknew();
 
  147         TEST_ASSERT_EQUAL_INT(lockB-1, lockA);
 
  150         int lockC = locknew();
 
  152         TEST_ASSERT_EQUAL_INT(lockB-1, lockC);
 
  161     static void test_SizeofInt(
void){
 
  162         TEST_ASSERT_EQUAL_INT(4, 
sizeof(
int));
 
  165     static void test_SizeofUnsignedInt(
void){
 
  166         TEST_ASSERT_EQUAL_INT(4, 
sizeof(
unsigned int));
 
  169     static void test_SizeofChar(
void){
 
  170         TEST_ASSERT_EQUAL_INT(1, 
sizeof(
char));
 
  173     static void test_SizeofUnsignedChar(
void){
 
  174         TEST_ASSERT_EQUAL_INT(1, 
sizeof(
unsigned char));
 
  177     static void test_SizeofBool(
void){
 
  178         TEST_ASSERT_EQUAL_INT(1, 
sizeof(
bool));
 
  181     static void test_SizeofShort(
void){
 
  182         TEST_ASSERT_EQUAL_INT(2, 
sizeof(
short));
 
  185     static void test_SizeofUnsignedShort(
void){
 
  186         TEST_ASSERT_EQUAL_INT(2, 
sizeof(
unsigned short));
 
  189     static void test_SizeofIntPointer(
void){
 
  190         TEST_ASSERT_EQUAL_INT(4, 
sizeof(
int *));
 
  193     static void test_SizeofShortPointer(
void){
 
  194         TEST_ASSERT_EQUAL_INT(4, 
sizeof(
short *));
 
  197     static void test_SizeofCharPointer(
void){
 
  198         TEST_ASSERT_EQUAL_INT(4, 
sizeof(
char *));
 
  203     static void test_WhatIsTrue(
void){
 
  204         TEST_ASSERT_EQUAL_INT(1, 
true);
 
  207     static void test_WhatIsFalse(
void){
 
  208         TEST_ASSERT_EQUAL_INT(0, 
false);
 
  211     static void test_OnlyTrueEqualsTrue(
void){
 
  212         TEST_ASSERT_TRUE(2 != 
true);
 
  215     static void test_AnyNonZeroNumberIsTrue(
void){
 
  218         TEST_ASSERT_TRUE(200);
 
  219         TEST_ASSERT_TRUE(-1);
 
  220         TEST_ASSERT_TRUE(-200);
 
  223     static void test_ZeroIsFalse(
void){
 
  224         TEST_ASSERT_FALSE(0);
 
  227     static void test_BooleanAndIsSameAsBitwiseAnd(
void){
 
  228         TEST_ASSERT_TRUE((
true  && 
false) == (
true  & 
false));
 
  229         TEST_ASSERT_TRUE((
false && 
true ) == (
false & 
true ));
 
  230         TEST_ASSERT_TRUE((
false && 
false) == (
false & 
false));
 
  231         TEST_ASSERT_TRUE((
true  && 
true ) == (
true  & 
true ));
 
  237     static void test_WritingAnIntToACharWillTruncate(
void){
 
  238         char data []= {0,0,0,0,0,0,0,0};
 
  239         data[4] = 0xFFFFFFFF;
 
  240         TEST_ASSERT_EQUAL_HEX8(0, data[0]);
 
  241         TEST_ASSERT_EQUAL_HEX8(0, data[1]);
 
  242         TEST_ASSERT_EQUAL_HEX8(0, data[2]);
 
  243         TEST_ASSERT_EQUAL_HEX8(0, data[3]);
 
  244         TEST_ASSERT_EQUAL_HEX8(0xFF, data[4]);
 
  245         TEST_ASSERT_EQUAL_HEX8(0, data[5]);
 
  246         TEST_ASSERT_EQUAL_HEX8(0, data[6]);
 
  247         TEST_ASSERT_EQUAL_HEX8(0, data[7]);
 
  250     static void test_InitializingACharWith16BitsWillTruncate(
void){
 
  252         TEST_ASSERT_EQUAL_INT(0xCD, data);
 
  258     static void FunctionThatEnds(
void){
 
  259         waitcnt(CLKFREQ/10 + CNT);
 
  262     static void FunctionThatEndsWithCogstop(
void){
 
  263         waitcnt(CLKFREQ/10 + CNT);
 
  267     static void test_WhatHappensWhenACogReachesTheEnd(
void){
 
  268         int stacksize = 
sizeof(_thread_state_t)+
sizeof(
int)*3 + 
sizeof(int)*100;
 
  270         int * stackA = (
int*) malloc(stacksize);        
 
  271         int cogA = cogstart(FunctionThatEnds, NULL, stackA, stacksize);
 
  273         int * stackB = (
int*) malloc(stacksize);        
 
  274         int cogB = cogstart(FunctionThatEnds, NULL, stackB, stacksize);
 
  276         waitcnt(CLKFREQ/10 + CNT);
 
  278         int * stackC = (
int*) malloc(stacksize);        
 
  279         int cogC = cogstart(FunctionThatEnds, NULL, stackC, stacksize);
 
  281         TEST_ASSERT_EQUAL_INT(1, cogA);
 
  282         TEST_ASSERT_EQUAL_INT(2, cogB);
 
  283         TEST_ASSERT_EQUAL_INT(3, cogC);
 
  286         for(
int i = 1; i < 8; ++i){
 
  295     static void test_WhatHappensWhenACogReachesTheEndWithCogstop(
void){
 
  296         int stacksize = 
sizeof(_thread_state_t)+
sizeof(
int)*3 + 
sizeof(int)*100;
 
  298         int * stackA = (
int*) malloc(stacksize);        
 
  299         int cogA = cogstart(FunctionThatEndsWithCogstop, NULL, stackA, stacksize);
 
  301         int * stackB = (
int*) malloc(stacksize);        
 
  302         int cogB = cogstart(FunctionThatEnds, NULL, stackB, stacksize);
 
  304         waitcnt(CLKFREQ/5 + CNT);
 
  306         int * stackC = (
int*) malloc(stacksize);        
 
  307         int cogC = cogstart(FunctionThatEndsWithCogstop, NULL, stackC, stacksize);
 
  309         TEST_ASSERT_EQUAL_INT(1, cogA);
 
  310         TEST_ASSERT_EQUAL_INT(2, cogB);
 
  311         TEST_ASSERT_EQUAL_INT(1, cogC);
 
  314         for(
int i = 1; i < 8; ++i){
 
  324     static void test_64bitIntegerBasic(
void){
 
  325         volatile int64_t 
a = 0x1;
 
  329         TEST_ASSERT_EQUAL_INT(0x1, a);
 
  332     static void test_64bitIntegerAdd(
void){
 
  333         volatile int64_t 
a = 0x100000000;
 
  336     #ifndef UNITY_SUPPORT_64     
  338         TEST_ASSERT_EQUAL_INT(0x2, a);
 
  340         TEST_ASSERT_EQUAL_HEX64(0x200000000, a);
 
  344     static void test_64bitIntegerSubtract(
void){
 
  345         volatile int64_t 
a = 0x500000000;
 
  348     #ifndef UNITY_SUPPORT_64 
  350         TEST_ASSERT_EQUAL_INT(0x4, a);
 
  352         TEST_ASSERT_EQUAL_HEX64(0x400000000, a);
 
  356     static void test_64bitIntegerMultiply(
void){
 
  357         volatile int64_t 
a = 0x3;
 
  358         volatile int64_t 
b = 0x300000000;
 
  361     #ifndef UNITY_SUPPORT_64 
  363         TEST_ASSERT_EQUAL_INT(0x9, a);
 
  365         TEST_ASSERT_EQUAL_HEX64(0x900000000, a);
 
  369     static void test_64bitIntegerDivide(
void){
 
  370         volatile int64_t 
a = 0x3;
 
  371         volatile int64_t 
b = 0x900000000;
 
  374     #ifndef UNITY_SUPPORT_64 
  376         TEST_ASSERT_EQUAL_INT(0x3, a);
 
  378         TEST_ASSERT_EQUAL_HEX64(0x300000000, a);
 
  382     static void test_64bitIntegerAddSpeed(
void){
 
  387         int nothingDelta = endCNT - startCNT;
 
  390         volatile int64_t a64 = 0x500000000;
 
  394         UnityPrint(
"64bit add deltaCNT == ");
 
  395         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  396         UNITY_OUTPUT_CHAR(
'\n');
 
  399         volatile int32_t a32 = 0x50000;
 
  403         UnityPrint(
"32bit add deltaCNT == ");
 
  404         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  405         UNITY_OUTPUT_CHAR(
'\n');
 
  408         TEST_ASSERT_EQUAL_INT(0xA0000, a32);    
 
  409     #ifndef UNITY_SUPPORT_64 
  411         TEST_ASSERT_EQUAL_INT(0xA, a64);
 
  413         TEST_ASSERT_EQUAL_HEX64(0xA00000000, a64);
 
  420     static void test_64bitIntegerDivideSpeed(
void){
 
  424         int nothingDelta = endCNT - startCNT;
 
  428         volatile int64_t a64 = 0x600000000;
 
  432         UnityPrint(
"64bit divide deltaCNT == ");
 
  433         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  434         UNITY_OUTPUT_CHAR(
'\n');
 
  437         volatile int32_t a32 = 0x60000;
 
  441         UnityPrint(
"32bit divide deltaCNT == ");
 
  442         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  443         UNITY_OUTPUT_CHAR(
'\n');
 
  445         TEST_ASSERT_EQUAL_INT(0x20000, a32);
 
  446     #ifndef UNITY_SUPPORT_64 
  448         TEST_ASSERT_EQUAL_INT(0x2, a64);
 
  450         TEST_ASSERT_EQUAL_HEX64(0x200000000, a64);
 
  457     static void test_64bitIntegerMultiplySpeed(
void){
 
  462         int nothingDelta = endCNT - startCNT;
 
  465         volatile int64_t a64 = 0x600000000;
 
  469         UnityPrint(
"64bit multiply deltaCNT == ");
 
  470         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  471         UNITY_OUTPUT_CHAR(
'\n');
 
  475         volatile int32_t a32 = 0x60000;
 
  479         UnityPrint(
"32bit multiply deltaCNT == ");
 
  480         UnityPrintNumber(endCNT - startCNT - nothingDelta);
 
  481         UNITY_OUTPUT_CHAR(
'\n');
 
  483         TEST_ASSERT_EQUAL_HEX32(0x1200000, a32);
 
  484     #ifndef UNITY_SUPPORT_64 
  486         TEST_ASSERT_EQUAL_HEX32(0x120, a64);
 
  488         TEST_ASSERT_EQUAL_HEX64(0x12000000000, a64);
 
  496     static void test_FloatVariableToInt(
void){
 
  498         const float floatNum = 0.01f;
 
  499         int number = *(
int *)&floatNum;
 
  500         TEST_ASSERT_EQUAL_HEX32(0x3C23D70A, number);
 
  505     static void test_SignedVsUnsignedComparison(
void){
 
  509         TEST_ASSERT_TRUE(sB > sA);
 
  511         unsigned int uA = 0xFfffFfff;
 
  512         unsigned int uB = 0x0fffFfff;
 
  514         TEST_ASSERT_TRUE(uA > uB);
 
  517     static void test_UnsignedReverseRolloverSubtraction(
void){
 
  518         unsigned int A = 0xF;
 
  519         unsigned int B = 0x10;
 
  520         unsigned int result = A - B;
 
  521         TEST_ASSERT_EQUAL_HEX32(0xFfffFfff, result);
 
  529     static void test_nullptrIsTheSameAsNULL(
void){
 
  530         TEST_ASSERT_TRUE(
nullptr == NULL);