Code Coverage with the ARM C/C++ Compiler (2024)

Back to All Posts

    Sébastien FrickerPublishedFeb 19, 2014UpdatedMay 15, 2023

    Introduction

    Developing for an embedded environment can often leave you juggling for space. Squish Coco is designed with such constraints in mind, making instrumentation and code coverage possible even on embedded environments.

    Squish Coco separates the coverage data creation from the analysis, enabling users performing cross-compilation to host the compiler on a separate platform. The execution data is gathered on the target platform, while the analysis occurs on the desktop platform and can be viewed using the CoverageBrowser.

    The detection of sequential blocks creates a more compact instrumentation than the traditional line coverage approach. Additional size reductions are implemented using command-line parameters to disable the condition, decision and statement coverage analysis. Because Squish Coco instruments the source code utilizing the user's toolchain, both debug and release, or optimized code can be used. The only requirement for the target system is the malloc() function. Filesystems and Ethernet devices are not necessary.

    This article demonstrates how to instrument a small ARM application that reads data from an AD device on a simulator.

    Getting started with ARM Keil μVision

    To setup the playground you'll need the ARM Keil μVision toolchain and Squish Coco v3.0.1 Beta. The new Squish Coco release already includes the Blinky example.

    Setup the Squish Coco toolchain

    Squish Coco provides compiler and linker wrappers which replace the ARM command-line tools. It behaves identical to the original toolchain except when activated with the command-line switch --cs-on.

    Specify the path of the Squish Coco toolchain in ARM Keil uVision:
    1. Open the ARM Keil μVision IDE
    2. Click Project > Manage and select Components, Environments, Books…
    3. Select Folders/Extensions, click the ARMCC Folder: box, and replace .ARMCCbin with .SquishCocobin.
    Activate the code coverage analysis for the compiler and linker:
    1. Click Project and select Option for Target…
    2. Select the C/C++ tab
    3. Click the Misc Controls box and enter <strong--cs-on.
    4. Select the Linker tab
    5. Click the Misc Controls box and enter --cs-on.

    Generate an execution report

    For desktop applications, the default instrumentation behavior is to save an execution report to a file when the application closes. This does not apply to embedded devices because most embedded applications never close and also lack a file system. This is why it's necessary necessary to define how and when the execution reports are generated.

    Report generation trigger

    For a real application it is necessary to define a trigger to save the execution report. Triggers can consist of keyboard events, digital input signals, CAN-Bus messages, etc. The trigger handler contains the following code snippet to save the code coverage information:
    #ifdef __COVERAGESCANNER__
    __coveragescanner_save();
    __coveragescanner_clear();
    #endif

    The __COVERAGESCANNER__ definition is automatically defined in instrumented code. The execution report saves using __coveragescanner_save(), while the __coveragescanner_clear() resets all execution counters paving the way for a clean report in the future.

    Communication link

    The function __coveragescanner_set_custom_io() setups up the communication link used to transmit the coverage information. Typically three functions are required (fopen(), fputs() and fclose()) allowing an UART or CAN identifier to upload the data. The use of more sophisticated protocols, such as SFTP for networking devices, is also available.

    In the simulated device, you'll use the ITMLOG channel, a virtual serial device between an application and the ARM simulator. Only the fputs() function needs to be implemented because this channel does not require initialization or being closed:

    #if defined( __COVERAGESCANNER__ )
    static int csfputs(const char *s, void *stream) {
    #define COVERAGESCANNER_ITM_CHANNEL 10
    if (
    (ITM->TCR & ITM_TCR_ITMENA_Msk) /* ITM enabled */
    &&
    (ITM->TER & (1UL << COVERAGESCANNER_ITM_CHANNEL) ) /* ITM Port enabled */
    )
    {
    while ( *s != '' )
    {
    while (ITM->PORT[COVERAGESCANNER_ITM_CHANNEL].u32 == 0);
    ITM->PORT[COVERAGESCANNER_ITM_CHANNEL].u8 = (uint8_t) *s;
    s++;
    }
    }
    return 0;
    }
    static void *csfopenappend(const char *path) { return (void*)1;}
    static int csfclose(void *fp) { return 1; }
    #endif

    int main (void) {
    .....
    #ifdef __COVERAGESCANNER__
    __coveragescanner_set_custom_io(
    NULL,
    csfputs,
    csfopenappend,
    NULL,
    NULL,
    csfclose,
    NULL );
    #endif

    Test and inspect the coverage report

    Simulation
    1. Setup the ITMLOG output file in the simulator command prompt prior to starting the simulation to capture the output of the channel to a file:
      ITMLOG 10 &gt; c:coverage.csexe
    2. Start the simulation and wait approximately thirty seconds for it to complete.
    3. A message displays in the debug output window upon completion, at which time the simulation can be stopped.

    Inspect the code coverage

    1. In CoverageBrowser open Blinky.axf.csmes and load the coverage.csexe execution report
    2. The executed and un-executed Blinky example code display.

    Demonstration Video

    Click to view a video of this tutorial:
    Code Coverage with the ARM C/C++ Compiler (1)

    Click here to request the latest version of Squish Coco containing this example

    Comments

    Code Coverage with the ARM C/C++ Compiler (2024)
    Top Articles
    Verizon Connect Log In
    107 Aesthetic Drawing Ideas For Beginners And Pros - Sharmell Day
    Devotion Showtimes Near Xscape Theatres Blankenbaker 16
    Bubble Guppies Who's Gonna Play The Big Bad Wolf Dailymotion
    Body Rubs Austin Texas
    Hendersonville (Tennessee) – Travel guide at Wikivoyage
    Optimal Perks Rs3
    Victoria Secret Comenity Easy Pay
    What's New on Hulu in October 2023
    Bed Bath And Body Works Hiring
    Paketshops | PAKET.net
    Bill Devane Obituary
    Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
    Oriellys St James Mn
    Taylor Swift Seating Chart Nashville
    6th gen chevy camaro forumCamaro ZL1 Z28 SS LT Camaro forums, news, blog, reviews, wallpapers, pricing – Camaro5.com
    Directions To 401 East Chestnut Street Louisville Kentucky
    Mail.zsthost Change Password
    Spoilers: Impact 1000 Taping Results For 9/14/2023 - PWMania - Wrestling News
    50 Shades Of Grey Movie 123Movies
    Parentvue Clarkston
    Keurig Refillable Pods Walmart
    Where Is The Nearest Popeyes
    Best Mechanics Near You - Brake Masters Auto Repair Shops
    Juicy Deal D-Art
    eHerkenning (eID) | KPN Zakelijk
    1973 Coupe Comparo: HQ GTS 350 + XA Falcon GT + VH Charger E55 + Leyland Force 7V
    Fleet Farm Brainerd Mn Hours
    Garden Grove Classlink
    Aes Salt Lake City Showdown
    Wbap Iheart
    By.association.only - Watsonville - Book Online - Prices, Reviews, Photos
    Myaci Benefits Albertsons
    Jt Closeout World Rushville Indiana
    Chapaeva Age
    MethStreams Live | BoxingStreams
    Upstate Ny Craigslist Pets
    Muma Eric Rice San Mateo
    Waffle House Gift Card Cvs
    Andhra Jyothi Telugu News Paper
    Plead Irksomely Crossword
    Final Jeopardy July 25 2023
    The Angel Next Door Spoils Me Rotten Gogoanime
    Valls family wants to build a hotel near Versailles Restaurant
    Quaally.shop
    Dyi Urban Dictionary
    Leland Westerlund
    Stoughton Commuter Rail Schedule
    Google Flights Missoula
    Hkx File Compatibility Check Skyrim/Sse
    Southwind Village, Southend Village, Southwood Village, Supervision Of Alcohol Sales In Church And Village Halls
    Factorio Green Circuit Setup
    Latest Posts
    Article information

    Author: Nathanael Baumbach

    Last Updated:

    Views: 5826

    Rating: 4.4 / 5 (75 voted)

    Reviews: 82% of readers found this page helpful

    Author information

    Name: Nathanael Baumbach

    Birthday: 1998-12-02

    Address: Apt. 829 751 Glover View, West Orlando, IN 22436

    Phone: +901025288581

    Job: Internal IT Coordinator

    Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

    Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.