We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Embedded Software

Embedded Software

Test harness – A new approach to testing in Scade One

    • SolutionSolution
      Participant

      Introduction

      As we release Ansys Scade One 2025 R1, we would like to tell you about testing in Scade One, which is one of the highlights of this version. In this blog, we’ll explore the concept of test harness, where tests are models leveraging the full power of the Swan language enabling significantly more efficient and streamlined testing workflow.



      Photo credit: Panumas Nikhomkhai @ Pexels

      Testing & Simulation Workflows in Scade One

      Before we talk about the concept of test harness, let’s take a step back and consider the various ways that you can execute a model in Scade One.

      Run

      In Scade One, you can execute a scenario and observe the traces of the model inputs and outputs as plots, as you would in any simulation tool. A rich trace viewer allows to stack multiple plots and supports the various types defined in Swan like integers, floats, Booleans or enums.



      Debug

      Executing a model in debug mode gives more possibilities:

      • The model can be executed step-by-step or in continuous mode
      • All local flows inside the model are observable, as well as the active states and transitions.

      Scade One 2025 R1 brings many improvements to debug capabilities, focused on navigation in the model during debug and more observability of the model, including for instance the iterations of a forward block:



      Graphical simulation panels

      SCADE Rapid Prototyper is bundled with Scade One Studio. It allows to create graphical panels to set the inputs and visualize the outputs of a simulation, by assembling predefined and custom widgets. Graphical panels can be used in run and debug mode, but also in standalone executables that can be used by stakeholders that are not Scade One users to validate the behavior of the software.



      Export for system-level simulation

      Another way to simulate a Swan model is to embed it inside a system-level simulation, including models of the physical system and its environment as well as other software components. This can be achieved by exporting the model as a Functional Mock-up Unit (FMU), which is a standard for exchange of simulation models. This is also a new feature in Scade One 2025 R1.

      Test

      A test case not only defines a scenario, but also checks that the model complies with the excepted behavior, typically defined in high-level requirements. Executing a test procedure consists in executing each test case and checking if it is passed or failed.

      In Scade One 2025 R1, tests can be executed on host and generate test results (as a JSON file), that can be read using a dedicated Python library, for instance to generate a custom report.



      What is a test harness?

      The concept of test harness is a new approach in Scade One for scenarios and test cases. A test harness describes stimuli and checks using a Swan model:



      Test harnesses are used for defining scenarios for run and debug modes, as well as for defining test cases. The test harness contains one (or more) operator under test (highlighted in purple) and defines its inputs using a library of pre-defined stimuli (like a ramp, a sine wave, etc.), using data read from a file or user-defined stimuli, using any construct in the Swan language. Similarly, the checks for a test case can be defined using pre-defined checks, by comparing with a file or using a Swan model.

      A test harness can also include specific constructs, that can only be used inside a test harness:



      Read the current cycle index



      End the simulation/test when the condition is true



      Data source: Read data from a file



      Assert: Checks that the Boolean input is always true



      Oracle: Checks that the inputs are always equal to data from a file

      Using test harnesses for testing

      To illustrate the benefits of this new approach and the features of Scade One 2025 R1, we will take a look at a few examples of test harnesses, using operators from the Swan standard library.

      Checking properties

      The simplest test case consists in setting an input value and checking that the output is equal to the expected one. We are here considering the Inv3x3 operator, which inverts a square matrix of size 3:



      Since we can use any construct of the Swan language in a test harness, we are not restricted to checking that the output is an expected value. We can also check a property of the output. For instance, we can check that when a matrix cannot be inverted, the error output is true and that the output matrix is equal to the input one:



      Here is another example considering the NormVector operator, which computes a normalized vector of same direction and length/norm equal to 1. We are checking here that the norm of the output is 1:



      Checking equivalence

      Now let us consider the Sine operator from the Math::Trigo::Cordic module (with the alias Trigo below). This module implements trigonometric functions using the CORDIC algorithm. To test our implementation, we will compare it with the C standard library implementation (from the Math::Common::StdC module, with alias TrigoC).



      This example shows that the test harness can contain other operators than the operator under test (remember that the operator under test is highlighted in purple). We are also using operators from the standard library to create the inputs (here a ramp) and to check the outputs (here a comparison on floats with absolute tolerance). This standard library simplifies the creation of a test harness.

      Using simulation data files

      Another way to build a test harness is to read data from a simulation data file. Such a file contains the values of flows, as a list of values, and can be used as input for the operator under test (with a data source) or as a reference for checks (with an oracle).

      For instance, let us consider the Implies operator. The truth table of the operator defines the expected values for any input:

      $p$

      $q$

      $p \Rightarrow q$

      true

      true

      true

      true

      false

      false

      false

      true

      true

      false

      false

      true

      We can easily create a simulation data file for the inputs, using the dedicated signal editor:



      And similarly, another file for the expected output:



      Finally, we create a test harness using a data source and an oracle, and connect them to an instance of the Implies operator:



      It is also possible to use an oracle block but not check the inputs at all cycles. This is done by using a special Don’t care value (DC) for the flow in the simulation data file. If the expected value is DC, then no check is performed:



      In this example using the Delay operator (equivalent to the fby operator in Scade 6), we will not check anything during the first five cycles, and then check that the output flow is equal to 1, then 2, etc.

      Using Python to generate expected data

      Apart from the signal editor, you can also use a dedicated Python library to generate simulation data. Let us get back to the Sine example to illustrate the usage of this Python library. We will now generate the expected values (100 values between 0 and 2Ï€) using a small Python script:

      expf = sd.create_file('../resources/TestSinExpected.sd')
      v = expf.add_element('v', sd.Float32)
      vs = [math.sin(i/100 * math.pi * 2) for i in range(100)]
      v.append_values(vs)
      expf.close()
      

      You could also take advantage of the Python ecosystem (with libraries like NumPy or SciPy) to generate advanced stimuli or import data stored in another format (e.g. read from a CSV file).

      Importing SCADE Test test procedures

      Ansys SCADE Test is the testing environment used with Ansys SCADE Suite. Migration from SCADE Suite to Scade One is an important concern for users. That’s why importing models is possible since the first version. In Scade One 2025 R1, it is now also possible to import test records (in the SSS format) into the corresponding simulation data file. This allows reuse of existing tests.



      Note that only the simulation data files are automatically generated for now. Some steps (like the creation of the test harness) are manual, and will be automated in a future release.

      Why use test harnesses?

      To conclude this blog, let us summarize the benefits of the test harness approach:

      • It offers a real expressive language to define the stimuli and checks in a test case. This makes the testing process more efficient and allows for faster bug detection.
      • Using a more structured definition of test cases makes reviewing and updating them easier.
      • The editing of test cases benefits from all the features in the Swan language and the modeler (like auto-layout, smart services).
      • The traditional SCADE Test approach is still possible using simulation data. An automated migration path from SCADE Test into Scade One is available.

      Want to learn more?

      You can download the examples from this blog here.

      If you are a SCADE user, access Scade One Essential with your existing licenses on the Ansys Download Portal.

      You may also schedule a live demo of Scade One using this link.

      About the author



      Cédric Pasteur (LinkedIn) is a Senior Product Manager at Ansys. He has been working on Scade One, Ansys’ latest-generation model-based embedded software development product, since its inception. He specializes in programming language theory and its application to safe embedded systems.