Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

C/C++ Unit Test runtime error (Keil, ARM, CMSIS)

sketkar
sketkar Posts: 16

Hello,

we used the QuickStart MDK-ARM unit test example and applied it to our project. We are using Keil uVision 5.26.2 with Parasoft C/C++ Test 10.4.1. The project builds in Keil and executes on the target without any issues. The Parasoft project (Keil uVision import using Batch File output) is setup for Static Analysis and this run without issues as well.

I have auto-generated unit test cases for various module (c-file). When I try to execute the test cases using the Keil uVision Tests - ULINKPRo or Simulator (ITM) configuration, I seem to get the follow error.

C/C++test analysis errors in 
    1. Test execution: error compiling file.
"C:\\Keil_v5\\ARM\\PACK\\ARM\\CMSIS\\4.5.0\\CMSIS\\Include\core_cm3.h", line 128: Error:  #35: #error directive: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
      #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
       ^
C:\Program Files\Parasoft\C++test\10.4\engine\runtime\src\transport\CppTestTransportITM.c: 0 warnings, 1 error

Our project uses the nRF52832 chipset and pretty sure __FPU_PRESENT is set correctly. We get this error no matter what module is selected for execution.

Is there something I'm missing in the configuration in Keil uVision and/or Parasoft?

Thanks,

Comments

  • sketkar
    sketkar Posts: 16

    Hello,

    FYI, I was able to do the following as a work around.

    modified the CppTestTransportITM.c

    line 38 from #include "core_cm3.h" to #include "core_cm4.h"

    line 40 #if (__CM3_CMSIS_VERSION ... to #if (__CM4_CMSIS_VERSION ...

  • sketkar
    sketkar Posts: 16

    Hello,

    After the fix mentioned in my previous post, we tried to execute test cases on a module (single c-file, 5 units, 15 test cases total). It started Keil uVision and after a few seconds exited. Parasoft reports 0 (zero) cases executed.

    We are also trying the file-scope approach - disabling the additional symbol sources option as below

    1). Generate Unit Tests for the given module (c-file), works okay
    2). Generate stubs (file-scope), work okay
    3). Run Unit Tests - Keil uVision Tests - ULINKPRo or Simulator (ITM) (file-scope)

    We get the following error

    C/C++test analysis errors in
        1. Test execution: error linking test executable for Test unit for selected sources.
    Error: L6218E: Undefined symbol _sys_exit (referred from cpptest_testrunner.o).
    Error: L6218E: Undefined symbol SystemInit (referred from arm_startup_nrf52.o).
    Not enough information to list image symbols.
    Not enough information to list load addresses in the image map.
    Finished: 2 information, 0 warning and 2 error messages.
    

    There are a lot of 3rd party libraries and SDK calls that we want to stub out, so the file-scope method would be ideal. Any suggestions?

    Thanks,

  • JoshScoggins
    JoshScoggins Posts: 20

    sys_exit must be retargeted as does SystemInit (although I have never encountered that symbol before). Keil uVision will sometimes just decide to exit without invoking anything, it's very puzzling.

  • sketkar
    sketkar Posts: 16

    Hello,

    Ah okay. So our guess is that since both SystemInit and _sys_exit are provided by the SDK (nrf52/Keil), and we are disabling additional symbols, there is no test harness getting associated for them. Wonder why no stubs?. As for re-targeting these, what's the best way without modifying the source under test, maybe some code we can add to the test bench itself? Or is there a way to disable additional symbols except these two symbols?

    Thanks,

  • JoshScoggins
    JoshScoggins Posts: 20

    C++test provides the ability to generate a retargeting library. Check the manual. It will describe all the steps involved.

  • sketkar
    sketkar Posts: 16

    Hello,

    Thanks for the information. We were able to generate the run-time re-target (cpp_rtget.c) and include a stubbed SystemInit (this looks like another custom SDK function). The re-target file already included a _sys_exit. The errors above went away but we are still not getting any test execution. Keil starts, it looks like it's trying to step through some disassembly then exits after a few seconds. 0 (zero) test cases executed.

  • sketkar
    sketkar Posts: 16

    Hello,

    So, one thing we tried was to modify the memory area for since we don't need to reserve any memory for the MBR/Soft Device (nRF52832 specific) when we are Unit Testing. When running with this configuration, keil starts and gets stuck in the startup code at the __main symbol, not sure if something is causing a hard fault (also high-lighted with green marker). Have stop debugging to exit out. still no text execution. See attached screen shot of Keil.

  • Mirek
    Mirek Posts: 141 admin

    Hi @sketkar ,

    What is your current configuration for stack and heap?

  • sketkar
    sketkar Posts: 16

    Hello,

    Both are set to 8192. __START_CONFIG, __STARTUP_CONFIG_STACK_SIZE __STACK_SIZE, __STARTUP_CONFIG_HEAP_SIZE and __HEAP_SIZE are **not** defined.

    Here is the snippet from arm_startup_nrf52.s.

                    IF :DEF: __STARTUP_CONFIG
    #ifdef  __STARTUP_CONFIG
    #include "startup_config.h"
    #ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
    #define __STARTUP_CONFIG_STACK_ALIGNEMENT 3
    #endif
    #endif
                    ENDIF
    
                    IF :DEF: __STARTUP_CONFIG
    Stack_Size      EQU __STARTUP_CONFIG_STACK_SIZE
                    ELIF :DEF: __STACK_SIZE
    Stack_Size      EQU __STACK_SIZE
                    ELSE
    Stack_Size      EQU 8192
                    ENDIF
    
                    IF :DEF: __STARTUP_CONFIG
    Stack_Align     EQU __STARTUP_CONFIG_STACK_ALIGNEMENT
                    ELSE
    Stack_Align     EQU 3
                    ENDIF
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=Stack_Align
    Stack_Mem       SPACE   Stack_Size
    __initial_sp
    
                    IF :DEF: __STARTUP_CONFIG
    Heap_Size       EQU __STARTUP_CONFIG_HEAP_SIZE
                    ELIF :DEF: __HEAP_SIZE
    Heap_Size       EQU __HEAP_SIZE
                    ELSE
    Heap_Size       EQU 8192
                    ENDIF
    
                    AREA    HEAP, NOINIT, READWRITE, ALIGN=3
    __heap_base
    Heap_Mem        SPACE   Heap_Size
    __heap_limit
    
                    PRESERVE8
                    THUMB
    

    One question we have is do we need to rebuild the Parasoft runtime library specifically for the nRF52/Cortex M4 manually? We were unable to open the C++testRtLib_Keil.Uv2 in Keil uVision (5.26.2) and have made the assumption that the library would be built by C/C++ Test when we run the tests. See screenshot.

    Thanks,

  • sketkar
    sketkar Posts: 16

    Hello,

    stepping through the test execution in Keil uVision IDE, it looks like the test hits the HardFault interrupt (see snippet below)

    HardFault_Handler\
                    PROC
                    EXPORT  HardFault_Handler         [WEAK]
                    B       .
                    ENDP
    

    in the cpptest_testrunner.c file, specific function is static void __CPTR_Do_Tests_TestSuite_main_c_a23b0b65(void) and the specific macro called is CPPTEST_RUN_TEST_SUITE_BEGIN(TestSuite_main_c_a23b0b65, "/nrf52832_example/main.c", 4)

    unit under test is main.c - auto-generated unit tests with file-scope stubs and file-scope test execution (Run Keil uVision Test - Simulator). We have created custom runtime re-targeting library (cpptest_retgt.c) as mentioned in a previous post but we have not created any custom runtime initialization & finalization.

  • Andrey Madan
    Andrey Madan Posts: 388 ✭✭✭

    @sketkar - It will require a more thorough debugging session as this gets into low level details. I sense that those downstream errors could potentially be avoided given the proper setup upstream. I suggest opening a support case an CC your account manager for visibility.

  • sketkar
    sketkar Posts: 16

    @Andrey Madan - I have created a new support ticket in the customer portal. I appreciate your help.