Software-in-the-Loop System Tests: Step-by-Step Guide to System Virtualization | #VectorTechTutorial
By VECTOR TechTutorial
Summary
Topics Covered
- Test Your Logic, Not Your Wires
- Pinpoint Bugs by Triangulating Test Layers
- Hardware Swappable Through Clean Abstractions
- Run Simulated Time Faster Than Reality
Full Transcript
you have heard of software the loop testing but do not know how to introduce this kind of system level testing into your development don't worry in this video I will explain the relevant
Concepts and show you an example of how to perform system level tests of the software of an ECG device using vector's Cano tool and a sill
[Music] adapter hi my name is Mario I'm working in the research and development department at Vector and have been
specializing in system level testing especially software in the loop in a previous video my colleague Phillip gave an extensive Introduction to System level testing for both the virtualized
device you might want to call it a digital twin and the final Hardware I added the link to his video in the description with our tool canoe in combination with the sill adapter or our
Hill Hardware both software and Hardware the loop tests can be easily added to your development while it is easy to imagine how the device under test must be connected to the test hardware and test tool it might not seem a
straightforward for software and the loop testing let me show you how simple it is to instrument your code to enable system level testing early in development quick reminder the ECG
device that Philip has introduced in his video uses one input the analog signal of the ECG electrodes and two outputs an alarm state that informs about unhealthy heart rates via i squ c and the
connection to a patient monitor over ethernet the the device is simple enough to be an illustrative example one major advantage of software in the loop becomes clear very quickly it is not important what type of
communication is used because we are only testing the application data that is being exchanged for the ECG device this is the ECG signal data and the calculated heart rates nonetheless
software the loop testing allows to check the intricacies of the complete core software or business Logic on system level without the need for Hardware in a latest app Hardware the
loop testing also includes tests of the hardware specific code the hardware drivers these Hardware the loop tests can be performed during development on an evaluation board and as end ofline
test of the final product feel free to take a look at exemplary tests for final Hardware in our linked video through software and the loop high confidence in the software itself can be gained with
early system level testing and due to the higher reusability of test cases almost no additional work is required imagine test test of the final Hardware are performed and some test cases fail
without prior software and loop testing it is impossible to locate the errors in the code with successful testing of the core logic itself on system level it can be safely assumed that the hardware
specific implementations or Hardware integration related issues must have led to the error adding software and loop testing to your development can also greatly reduce Hardware integration
times saving you significant resources the higher reusability of test case faes and the environment simulation between software the loop and Hardware the loop is not necessarily given in every test
tool with the vector test tools Cano and V Studio this can be ensured and softw a loop can be easily incorporated into the development chain Cano enables
communication and data exchange with the system under test in several ways Hill Hardware such as the vector VT and bio systems and Vector network interfaces are available for Hardware access the
vector Sil kit can be used for data exchange with a virtualized system in today's example I would like to focus on software and a loop with the vector Sil kit and Sil adapter with simulations of
the ECG pads the alarm and the patient monitor in canoe in the software the loop example ECG signal data is sent to the system under test and the test tool expects to receive the calculated heart
rates and the alarm State keep in mind that all data is directly transmitted between the test tool canoe and the running executable of the ECG application this means it is irrelevant
that I squ C and ethernet are the chosen transfer protocols in the final product because it is impossible to write the code of a functional ECG device in a few minutes I will start this example with
the C++ code of the final device including the relevant algorithms for hard rate calculation and the hardware specific code AS Philip has already shown in detail it is advantageous to
have a clear separation of Hardware specific code and the core logic with an IO abstraction layer in between here we have three CPP files logic. CPP with the
core algorithms io. CPP with the io abstraction layer and hardware. CPP with
the hardware specific code to read from and write to physical iOS the idea of the instrumentation of code for software Loop testing is to exchange the implementation of for
example hardware. CPP to use the S
example hardware. CPP to use the S adapter to exchange data with the environment the S adapter uses Unix soft for communication instead of the protocols i squ c and ethernet as in the
real device in this example I will use cmake cmake cach variables allow to easily switch between the two code bases as you will see now let's dive into the
code and canoe here we can see the graphical interface of Cano with a graphics window that shows the data that is being exchanged with the system on the test we can see a simple panel to
start for example the curve simulation from the patient data and we can see the Trace window again displaying the data that is being exchanged with the system under
test the variables or the data that is being exchanged with the system on the test is defined in the vcdl file if we take a look we can see that
here we have a namespace smart ECG within this namespace an object smart ECG iio is being created and it contains
the variables of the O members ECG amplitude current heart rate average heart rate and heart rate alarm on the ECG amplitude is a provided data which
means can new sends it to the system on the test while it receives all of the consumed members what we want to do is we want to create the S adapter from
this vcdl file to do so we can use the S adapter Builder which is contained in the installation folder of
Cano so if I start this execut which is located in my case in program
files Vector Cano family 18 18.3 118 XX 64 and then we have the
executable selor Builder as an argument it needs the location the path of the vcdl file which in my case is in D zil
Workshop Cano vcd and smart ECG vcdl as optional arguments we can give the output folder where the S adapter is
being generated to so the cmake project in this case I just want to be the current folder d s workshop and I can specify the language
of the um uh the S adapter in our case I want to use a C++ project so CM project so I just give CPP as the parameter
now the data model is being retrieved and validated and as a Next Step the S adapter is being generated purely from this vcdl file we don't need to Define anything
else so the generation of the sil adapter was successful and we can now take a look at what actually is contained in this folder we have the folder canoe with the
canoe configuration that you can see in the background and that I have shown uh in the beginning we have the folder Su with the system under test as well as the build s adapter and this folder s
adapter.
build within the folder so we can see that uh we have the folden components with libraries that we are using for example for the heartbeat
detection algorithms and in the folder main we have the files that I've mentioned earlier main.cpp logic IO hardware and so
on as you can see we have everywhere these cmake list files so we already have a cmake project running what we want to do now is create a new CAC project which uses the cake
project of the system on a test as well as the S adapter to do so we create a new file
cmakelists.txt and now we can start using visual studio code to change um uh or to generate this
um the cake project so what I want to do is I need to specify some things for cake to to
run for example cmake minimum required which is just an arbitrary version that I set here at 3.
10 I create a project I call this um ECG and I give it a
description um which is in this case s tutorial what I want to do now as I said earlier I want to create a cmake cache variable because it allows us to change
between building for the final device Hardware the loop or for this software the loop case so I create this option I call this option build for
sill um again I give it just a short description um build with sill adapter and I give it the default value of
on what I want to do is add the subdirectories system under test I want to have this both when Hill and S is being
um generated or built and I want to add the subdirectory S adapter but only in the case when I'm building for S so I'm checking if build for
S then I want to add the subdirectory S adapter I can save this and the build files have already been into the folder build the
configuring and the generating has been done successfully now what I need to do is change the cake lists of the system
under test because as you can see here we're always using the implementation currently in hardware. CPP as I've said earlier I want to exchange this with a
new content so what I want to do in the case that I'm building for S so this cache variable set to
on I want to um have the target Source be something different I will uh set this in a
second and in the other case which is um uh the case I want to build for hard window loop I want to have the target
Source uh for this application B main hardware.
CPP so now I can remove this hardware.
CPP from this uh this content here because I only buil this or use this implementation in the hardware for Loop hardware and the loop setup in this other setup I want to use
a new implementation and I want to call this f.
CPP additionally I need to link this s adapter Library again to the application now what I need to do obviously is create this s. CPP what I
want to do is the s. CPP file is Implement hardware.
H identically to how hardware. CPP
implements hardware. H so I will copy hardware.
H paste it into the same folder and rename it to s.
CPP now I can also save this file um because the file exists and the generating is being done
again so in s. CPP what I want to do as a first step is just generate empty implementations I want to include
Hardware H and I want to exchange out of these semicolons as a quickest means with uh parenthesis
and for this function because it returns an integer for now I will just return zero because it might take a while I will build this um very quickly and in
the meantime show you the code that is currently already existing within the main function as a first uh thing we print a welcome message this could be a display on the
ECG device we reset the detection algorithm and we initialize the iOS which means registering call backs Hardware interrupts to read ECG input in
this case every 5 milliseconds for the hardware and the loop case and then we just keep the main thread alive um by uh sleeping in a
loop in logic. h we only have one function read and evaluate ECG sample it's a rather simple program and in logic. CPP we can see see
that this function calls another function evaluate ECG sample which has as a parameter the return value of the function read ECG sample read ECG sample
is defined in i.h as you can see here and in io.
i.h as you can see here and in io.
CPP all it does is call a function that is declared in hardware.
h if we take a look at the implementation Hardware read ECG sample we can see that analog to digital converters are being
used and we can see that it's an ESP um microcontroller specific function that is being called here to send data we're using i squ c so we have a hardware
specific i s c specific implementation as is expected in the case of uh the hardware Loop setup now that the build has finished I
can implement the S adapter into this new file s.
CPP obviously I need to include the S adapter I can use the cell adapter now to connect let me quickly do this so the
Squigly line disappears um I have to connect the system on test with Cano this is rather simple I only
need to call the function Vector Cano s adapter connect now when the function Hardware in it is being called the system on the
test or the S adapter within connects to um Cano for the hardware shutdown we can do a similar thing instead of calling the
function connect we call the function disconnect now the interesting part happens how do we get the variables the data from Cano
in this case the ECG data to the system under test and I will open the vcdl file and
parallel and as I said earlier we have the variables within the namespace smart ECG the object smart ECG iio and we want to have the variable ECG amplitude so
all we need to do is re return in the namespace smart ECG the object smart ECG iio and the variable ECG amplitude this is everything that you need to do to
exchange data from kuu to the system under test within a few minutes I've been able to connect the two and exchange
data to send data back from the system on a test to Cano all we need to do is write two these variables so smart ECG smart ECG iio in
this case we want to send the current heart rate and we just set it to the current heart rate which is given as a parameter in this function so let me close the vcdl file
just so that we can see better what's happening in the system under test for the average heart rate it's exactly the same thing
smart ECG smart ECG iio average heart rate is being set to the average heart rate that is being given as a parameter to this
function the same thing for the alarm so if we want to print a status could be a display on the ECG device here we want to use a terminal
just for debugging purposes so I just call the function print F I say Peak detected and I just print the averaged hard
rate and the alarm State and here obviously I want to print the average heart rate and the heart rate alarm on given as parameters to the
function for the welcome message the only thing I want to do again here print f um application
started and the hardware Loop sleep in this case I just want to use the windows sleep function so I need to include Windows St h
now there is one thing missing in the hardware the loop case we're using Hardware interrupts here there are no Hardware interrupts implemented yet so what we can do is
register update handlers so whenever a member a variable is written in Cano a certain function is being called in the system under test the function that we
want to call is read and evaluate ECG sample this function is declared in logic.
h and we want to do this during the hardware initialization step and we want to do this when the variable ECG amplitude is being written
to in Cano who's the time Giver we do this every 5 milliseconds so this is exact what we have in the hard window the loop case so whenever the variable
smart ECG smart ECG IO ECG amplitude is written to we want to or basically we want to register an update Handler for this uh
variable and here we just want to call the function read and evaluate ECG sample we can save the file build
now that the build has finished we can run the application we are immediately greeted with the welcome message application started now we can also start the measurement in Cano and we can
immediately start the ECG curve simulation from the patient data in the system under test we can see at some point that Peaks are detected
and heart rates are being calculated switching back to Cano we can now simulate an emergency this means we switch the data set for the ECG
signal we can see that the heart rate alarm is being turned on we can also see this in the system under test if we now stop the
emergency switching back to the initial data set we can see that after a certain time as soon as the average heart rate reaches a value below 100 the heart rate
alarm is off and we can also see this in the system under test now this has taken a while we can also automate these steps and write automated
tests with soft Loop we don't need to do this in real time also run these tests in real time we can speed up the process
to do so I will stop the measurement switch to a factor and speed up the time by 100 now when I start the
measurement and start the ECG curve simulation everything happens much more quickly we can again see this in the system under
test the automated tests can be run from Cano and we get the immediate feedback that every test has passed that's all for today on sill
testing now get in touch to talk about your sill use case further links are in the description below thank you for watching there are many more interesting
tutorials on hill and sill testing canoe and other topics on the vector Tech tutorial Channel subscribe now and activate notifications to not miss new videos
Loading video analysis...