ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
683 stars 274 forks source link

Ceedling - Memory access error on large arrays #276

Closed alaa137 closed 4 years ago

alaa137 commented 4 years ago

Ceedling won't let me define an array larger than 988 bytes:

#include "unity.h"
#include "my_code.h"

void setUp(void)
{
}

void tearDown(void)
{
}

void test_foo(void)
{
        //uint8_t arr[988] = {0}; //OK
    uint8_t arr[989] = {0}; //<- FAIL
}

This generates the following error:

User error: Memory access error: Trying to write outside linked memory at address 0x200002a4 when PC is 0x9e8. Check your memory configuration. ERROR: Unable to execute: driver error. After the error occurred, the program counter (PC) was 0x9e8.

ERROR: Test executable "test_my_code.out" failed.

Produced no final test result counts in $stdout: IAR C-SPY Command Line Utility V8.0.13.5197 Copyright 2000-2017 IAR Systems AB.

 CSpyBat terminating.

And exited with status: [0] (count of failed tests). This is often a symptom of a bad memory access in source or test code.

rake aborted!

What does this line mean: Check your memory configuration ? Is there a memory configuration in ceedling? How do I configure it?

Thanks!

Letme commented 4 years ago

You kinda need to provide linker script to Ceedling. Ceedling just runs commands, but this is not a ceedling error information I assume anyway.

alaa137 commented 4 years ago

How do I provide it with the linker script? It's an IAR project, and the array definition in the original project works well, so I suppose the configuration there is Ok. Is there a way to provide ceedling with IAR's linker script?

Letme commented 4 years ago

I would say there are parameters to :linker: in :tools: part of the yml that would be interesting to see. If you set verbosity to 3 before test:all in rake you should be able to see commands

alaa137 commented 4 years ago

Running ceedling verbosity[3] test:all produces the same output...

Letme commented 4 years ago

But now you got commands for linking and running simulator that ceedling generates so you can dig into them to confirn that ceedling does not output that information

alaa137 commented 4 years ago

No it didn't show me the commands:

Running test_my_code.out... Call Stack:

0 PC: 0x9e8 [__aeabi_memclr4 + 0x7]

1 PC: 0x9d8 in test_foo() at C:\path\test_my_code.c:18

2 PC: 0x95e in run_test(test_foo (0x9C9), 0xCC4 "test_foo", 14) at C:\path\test_my_code_runner.c:66

3 PC: 0x98c in main() at C:\path\test_my_code_runner.c:83

4 PC: 0xc92 [_call_main + 0xd]

User error: Memory access error: Trying to write outside linked memory at address 0x200002a4 when PC is 0x9e8. Check your memory configuration. ERROR: Unable to execute: driver error. After the error occurred, the program counter (PC) was 0x9e8.

ERROR: Test executable "test_my_code.out" failed.

Produced no final test result counts in $stdout: IAR C-SPY Command Line Utility V8.0.13.5197 Copyright 2000-2017 IAR Systems AB.

 CSpyBat terminating.

And exited with status: [0] (count of failed tests). This is often a symptom of a bad memory access in source or test code.

rake aborted!

C:/Ruby26-x64/bin/ceedling:23:in load' C:/Ruby26-x64/bin/ceedling:23:in

' Tasks: TOP => build/test/results/test_my_code.pass (See full trace by running task with --trace)


OVERALL TEST SUMMARY

No tests executed.

Letme commented 4 years ago

One line before Running test_my_code.out should be the command ceedling runs. Same for linking.

alaa137 commented 4 years ago

Problem solved. This is how to change the linker configuration file in project.yml:

:tools:
  :test_linker:
    :executable: ilinkarm
    :name: 'IAR test linker'
    :arguments:
      - --vfe
      - --redirect _Printf=_PrintfFull
      - --redirect _Scanf=_ScanfFull
      - --semihosting
      - --config "C:/path/to/project/EWARM/stm32f769xx_flash.icf" # <- PATH TO ICF
      - --map "build/test/tests.map"
      - -o "${2}"
      - '"${1}"'