An introduction to the SuperTest MISRA suites

The SuperTest MISRA suites are created to verify the conformance of MISRA checking software. The aim of a, so-called, MISRA checker is to check application software for its compliance with the MISRA guidelines.  The SuperTest MISRA suites in turn verify that such a MISRA checker generates the right diagnostics and not too many false positives or false negatives.

The MISRA suites contain two types of tests: those which a name starting with an 'x', and those which a name that starts with a 't'.

T-tests

The so-called t-tests are fully conforming with the MISRA guidelines and should not trigger any diagnostics in the MISRA checking software. This is an example of a t-test:

 /*

  * Test for MISRA-C:2004 Rule 4.2:

  *     Trigraphs shall not be used

  */

 typedef signed int int32_t;

 static int32_t fun (void);

 static int32_t fun (void) {

     char r[50] = "OK: ??? ??.??+??~??^"; /* Compliant */

     return (r[0] != 'O') ? (int32_t)1 : (int32_t)0;

 }

 int32_t main (void) {

     return fun ();

 }

In this test, the string that initializes the variable r[50] contains a number of character sequences that look like trigraph sequences, which the MISRA guidelines do not allow, but are not trigraphs. Hence, this code is compliant with MISRA Rule 4.2. No diagnostic should be given. The code is also constructed so that no other MISRA rules are violated.

X-tests

The x-tests contain a violation of one of the MISRA rules. When passed to a MISRA checker, they should trigger a diagnostic for a specific rule. Here is an example of an x-test that violates Rule 5.4, which requires that tags are unique.

 /*

  * Test for MISRA-C:2004 Rule 5.4:

  *     A tag name shall be a unique identifier

  * 

  * Notes on test:

  * Check that the following code violates MISRA Rule 5.4

  */

 typedef unsigned short uint16_t;

 typedef signed int int32_t;

 typedef unsigned int uint32_t;

 int32_t main (void) {

     uint32_t aval;

     { 

         enum thetag { x, y, z };

         enum thetag ty = y;

         aval = (ty < x) ? (int32_t)1U : (int32_t)0U;

     } 

     { 

         struct thetag {   /* Not compliant */

             uint16_t a;

             uint16_t b;

         } str = {3U, 4U};

         aval += str.a;

     } 

     return (aval != 3U) ? (int32_t)1 : (int32_t)0;

 }

Note that this x-test is perfectly fine C90 code. C90 allows the reuse of thetag in different scopes. But MISRA does not.

A big effort has been put into making the x-tests as specific as possible, so that they contain only one rule violation, and at the same time keep them concise and understandable. This is not always possible. Sometimes rules partially overlap and an additional diagnostic is triggered.

Undecidable Rules

Some of the MISRA rules are what is called undecidable.  This means that for complex examples of such code, a MISRA checker may not be able to follow the control and data flow with sufficiently detail to decide if a rule is violated or not. For such rules, there are often 'trivial' cases for which a MISRA checker is expected to give a diagnostic. We have tried to include such trivial cases in the suites as well. We have also tried to include more complex cases that are decidable with some effort. The following is an example of a t-test for an undecidable rule, so it should not give a diagnostic:

 /*

  * Test for MISRA-C:2004 Rule 17.3:

  *     >, >=, <, <= shall not be applied to pointer

  *     types except where they point to the same array

  * 

  * Notes on test:

  * Check that the code does not violate MISRA Rule 17.3

  */

 typedef signed int int32_t;

 int32_t main (void) {

     int32_t a[] = {1, 2, 3};

     int32_t *pa = &a[1];

     int32_t r = 9;

     if (&a[2] > pa) {   /* Compliant */

         r = 6;

     } 

     return r - 6;

 }

To verify that the pointer comparison is compliant, requires that a MISRA checker applies non-trivial data flow analysis to the code. If the MISRA checker cannot do that, it might decide to play it safe and generate a false positive: an incorrect diagnostic for a (possible) rule violation. MISRA checker may offer options to suppress false positives.

The MISRA test suite comes in several flavors. By means of (advisory) Rule 6.3, MISRA forces application developers to choose a data model and express that choice in the primitive types used for arithmetic. This can be seen in the examples above, which use the 32-bit integer type "int32_t".

The MISRA suites are supplied both in a generic form and in a form that is specific for a data model. The examples above are all for a specific data model. In the generic form, the previous example looks like this:

 int main (void) {

     int a[] = {1, 2, 3};

     int *pa = &a[1];

     int r = 9;

     if (&a[2] > pa) {   /* Compliant */

         r = 6;

     }

     return r - 6;

 }

In this form, one should tell the MISRA checker that it should ignore Rule 6.3.

Solid Sands can also provide additional instances of the MISRA suites that are specific for another data model, if needed.


Extracts of the MISRA C guidelines used with permission of HORIBA MIRA LIMITED. MISRA is a registered trademark of HORIBA MIRA LIMITED.

For example test code:
(c) Copyright 2015-2017 by Solid Sands B.V.,   
Amsterdam, the Netherlands. All rights reserved.
Subject to conditions in the RESTRICTIONS file.
Copyright (c) 2015 Analog Devices, Inc.  All rights reserved.

(c) Copyright 2017 by Solid Sands B.V., Amsterdam, the Netherlands
SuperTest™ is a trademark of Solid Sands B.V., Amsterdam, The Netherlands.


Related


The Benefits of C and C++ Compiler Qualification

In embedded application development, the correct operation of the compilation toolset is critical to the functional safety of the application. Two options are available to build trust in the corre...

8 Ways to Improve Harness Manufacturing

Harness manufacturing is a low margin business where quality, accuracy, and speed are essential to success. It can benefit from a full, automated and digitally continuous flow from product design to h...

General principles of PCBs design

How to design PCBs correctly, to reach boards which are cost-effective to produce and to populate? Which are the most important PCB design principles? What about production technology of PCB? We have ...

The Next Level of Embedded Software Development

With the rapid expansion of complex technology into everyday life, the importance of software is growing exponentially. This complimentary webinar presented by Siemens PLM Software will show how emb...

Embedded Software for Safety Critical Applications

Production code generation with Model-Based Design has replaced document-based development and manual coding in various domains in automotive, industrial automation, aerospace and medical. Safety-rela...

Coding safe and secure applications

The debate about safety and security concerns in high integrity software applications is a hot topic of discussion in modern software management. The need to address these concerns is present in e...

Best practices for static analysis tools

This paper reviews a number of the growing complexities that embedded software development teams are facing, including the proliferation of third-party code, increased pressures to develop secure ...


Give Your Product a Voice with Alexa

Join us for a deep dive into the system architecture for voice-enabled products with Alexa Built-In. Device makers can use the Alexa Voice Service (AVS) to add conversational AI to a variety of produc...

The two big traps of code coverage

Code coverage is important, and improving coverage is a worthy goal. But simply chasing the percentage is not nearly so valuable as writing stable, maintainable, meaningful tests. By Arthur Hick...

Securing the smart and connected home

With the Internet of Things and Smart Home technologies, more and more devices are becoming connected and therefore can potentially become entry points for attackers to break into the system to steal,...

Accurate and fast power integrity measurements

Increasing demands on power distribution networks have resulted in smaller DC rails, as well as a proliferation of rails that ensure clean power reaches the pins of integrated circuits. Measuring r...

 

DIN-Rail Embedded Computers from MEN Mikro

The DIN-Rail system from MEN is a selection of individual pre-fabricated modules that can variably combine features as required for a range of embedded Rail Onboard and Rail Wayside applications. The ...


Embedded Graphics Accelerates AI at the Edge

The adoption of graphics in embedded and AI applications are growing exponentially. While graphics are widely available in the market, product lifecycle, custom change and harsh operating environments...


ADLINK Optimizes Edge AI with Heterogeneous Computing Platforms

With increasing complexity of applications, no single type of computing core can fulfill all application requirements. To optimize AI performance at the edge, an optimized solution will often employ a...


Synchronized Debugging of Multi-Target Systems

The UDE Multi-Target Debug Solution from PLS provides synchronous debugging of AURIX multi-chip systems. A special adapter handles the communication between two MCUs and the UAD3+ access device and pr...


Smart Panel Fulfills Application Needs with Flexibility

To meet all requirement of vertical applications, ADLINK’s Smart Panel is engineered for flexible configuration and expansion to reduce R&D time and effort and accelerate time to market. The...


AAEON – Spreading Intelligence in the connected World

AAEON is moving from creating the simple hardware to creating the great solutions within Artificial Intelligence and IoT. AAEON is offering the new solutions for emerging markets, like robotics, drone...


ASIC Design Services explains their Core Deep Learning framework for FPGA design

In this video Robert Green from ASIC Design Services describes their Core Deep Learning (CDL) framework for FPGA design at electronica 2018 in Munich, Germany. CDL technology accelerates Convolutional...


Microchip explains some of their latest smart home and facility solutions

In this video Caesar from Microchip talks about the company's latest smart home solutions at electronica 2018 in Munich, Germany. One demonstrator shown highlights the convenience and functionalit...


Infineon explains their latest CoolGaN devices at electronica 2018

In this video Infineon talks about their new CoolGaN 600 V e-mode HEMTs and GaN EiceDRIVER ICs, offering a higher power density enabling smaller and lighter designs, lower overall system cost. The nor...


Analog Devices demonstrates a novel high-efficiency charge pump with hybrid tech

In this video Frederik Dostal from Analog Devices explains a very high-efficiency charge-pump demonstration at their boot at electronica 2018 in Munich, Germany. Able to achieve an operating efficienc...


Microchip demonstrates a flexible motion control platform at electronica

In this video Marcus from Microchip explains a motion control demonstration at their booth at electronica 2018 in Munich, Germany. The demonstration underscores the ability of the solution to rapidly ...


Infineon goes over their latest SiC devices for automotive systems

In this video an Infineon engineer goes over their latest Silicon Carbide (SiC) devices for automotive systems at electronica 2018 in Munich, Germany. Among the devices described are an inverter for a...


Bertrand Lombardo of Honeywell, Sensing requirements of IoT

Bertrand Lombardo, Sales director for EMEA for Honeywell SIOT discusses future sensing trends in relation to IoT at Electronica 2019 with Alix Paultre. Links to more information: Dynamic Hone...


Analog Devices updates their Silent Switcher technology

In this video an FAE from Analog Devices explains the latest version of their Silent Switcher technology, which addresses noise issues in power systems. He describes a live demonstration in their boot...


Western Digital talks about their automotive-grade memory solutions

In this video Martin Booth from Western Digital talks about the company's memory solutions specifically designed for automotive applications and the harsh environments involved. Systems such as ne...


Picotest demonstrates their latest advanced power test solutions

In this video Steve Sandler from Picotest shows us two of the company's latest test solutions at electronica 2018 in Munich, Germany. The first demo is of a micro-Ohm-resolution power rail measure...


STMicro describes their latest smart 48V DC brushless motor driver board

In this video an engineer from STMIcroelectronics explains a motor-driver board setup based on their L9907 smart power device at electronics 2018 in Munich, Germany. Based on BCD-6s technology. the de...


Microchip shows their newest PolarFire FPGAs at electronica 2018

In this video Microchip shows a one of the demos highlighting the capabilities of their newest low-power PolarFire FPGAs at electronica 2018 in Munich, Germany. The demonstration shown here is a kit f...


Western Digital discusses their memory solutions for Cloud-enabled devices

In this video Ze'ev Paas of Western Digital talks to Alix Paultre of Aspencore Media about their latest memory products at electronica 2018 in Munich, Germany. Depending on the application space, ...


Picotest explains a couple of power test systems at electronica 2018

In this video Steve Sandler from Picotest explains a couple of his power test systems at electronica 2018 in Munich, Germany. The first demonstration shows a micro-Ohm measurement system, and the seco...