Author Topic: Unit testing embedded software  (Read 4890 times)

0 Members and 1 Guest are viewing this topic.

Offline RemarkTopic starter

  • Contributor
  • Posts: 29
  • Country: lt
Unit testing embedded software
« on: February 21, 2023, 06:41:14 am »
Hello everyone!

For some time now I have been interested in how I could test software (or its individual modules) using dedicated unit testing frameworks. I've seen a few of them in use online: gtest, unity, CppUTest, MinUnit, Unity and so on... Maybe you have tried something and could suggest which one to choose and why? I'm going to test software for ARM processors, m0-m4.

As far as I understand, for embedded targets, code 'modules' should be compiled on my desktop target. And I should pull in the modules into my tests and stub out/mock hardware specific ones. I probably still need a separate build system for tests?

Thanks for the suggestions :)

Remark.
 
The following users thanked this post: pcbcrew

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: Unit testing embedded software
« Reply #1 on: February 21, 2023, 07:14:26 am »
Well, spammers got their hands on ChatGPT. This sucks.

On topic - yes, ideally you would need a separate build environment unless your actual CPU has enough memory to support the test code as well.

Setting up a custom test environment suited for your project is not that hard, I don't see why you would want to use a standard environment/framework and adapt to its requirements.

The details depend on what your software is doing and how it is structured. The number of cases where unit tests make sense is very limited in reality. You can try to use them everywhere, but you are likely to suffer for not a lot of gain.

Automated functional tests of the complete system are way better in most cases.
Alex
 
The following users thanked this post: tellurium

Offline RemarkTopic starter

  • Contributor
  • Posts: 29
  • Country: lt
Re: Unit testing embedded software
« Reply #2 on: February 21, 2023, 09:37:44 am »
Well, spammers got their hands on ChatGPT. This sucks.

On topic - yes, ideally you would need a separate build environment unless your actual CPU has enough memory to support the test code as well.

Setting up a custom test environment suited for your project is not that hard, I don't see why you would want to use a standard environment/framework and adapt to its requirements.

The details depend on what your software is doing and how it is structured. The number of cases where unit tests make sense is very limited in reality. You can try to use them everywhere, but you are likely to suffer for not a lot of gain.

Automated functional tests of the complete system are way better in most cases.


Yeah, exactly.

Thanks for the answer!

And what about the portability of project? The main project will be compiled using f.e. STM32 Cube IDE, and the unit tests f.e. Cmake with ninja?
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26909
  • Country: nl
    • NCT Developments
Re: Unit testing embedded software
« Reply #3 on: February 21, 2023, 09:41:30 am »
Well, spammers got their hands on ChatGPT. This sucks.

On topic - yes, ideally you would need a separate build environment unless your actual CPU has enough memory to support the test code as well.

Setting up a custom test environment suited for your project is not that hard, I don't see why you would want to use a standard environment/framework and adapt to its requirements.

The details depend on what your software is doing and how it is structured. The number of cases where unit tests make sense is very limited in reality. You can try to use them everywhere, but you are likely to suffer for not a lot of gain.

Automated functional tests of the complete system are way better in most cases.


Yeah, exactly.

Thanks for the answer!

And what about the portability of project? The main project will be compiled using f.e. STM32 Cube IDE, and the unit tests f.e. Cmake with ninja?
You can create desktop C projects with STM32 Cude IDE just fine (and any other project in a language that is supported by Eclipse which Cube IDE is based on). There might even be an Eclipse plugin that can help doing the tests.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: Unit testing embedded software
« Reply #4 on: February 21, 2023, 06:40:23 pm »
And what about the portability of project? The main project will be compiled using f.e. STM32 Cube IDE, and the unit tests f.e. Cmake with ninja?
It does not matter, use whatever works.

At the same time, I personally prefer testing on the hardware. Rig up your code to accept automated inputs and provide outputs. And then run the tests scripts on the PC that generate test outputs and accept the results and compare them to the reference.

Majority of stuff that causes real issues in the embedded system can't be accurately replicated outside of the device.

There are exceptions, of course. If you have some heavily algorithmic code, then it is possible to test its functionality outside, but the code like this usually does not depend on the hardware in a first place.
Alex
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3712
  • Country: nl
Re: Unit testing embedded software
« Reply #5 on: February 21, 2023, 06:55:31 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended? And therefore can only be done on the actual hardware?

All other testing should be part of the development phase, where parts of the code could be tested on a simulation of the device, but timing related code like interrupt handlers basically need the actual hardware, especially if mechanical interfacing is done. Like motors with feedback on speed, position etc.

The hardest bugs to catch are of course glitches. Things that only happen once in a while under difficult to determine circumstances. Things that are missed in simulations.

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: Unit testing embedded software
« Reply #6 on: February 21, 2023, 07:00:54 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended? And therefore can only be done on the actual hardware?
Unit testing is testing of individual software "units" in isolation.

The whole test driven development methodology is based on writing the unit tests firsts and then writing the code to fulfill those tests. TDD is BS, of course.
Alex
 
The following users thanked this post: pcprogrammer, tellurium

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: be
Re: Unit testing embedded software
« Reply #7 on: February 21, 2023, 07:37:08 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended?

That last one would be validation testing, where you prove that the manufactured device meets the requirements. And not just the software requirements, for that matter.
 

Offline gpr

  • Contributor
  • Posts: 21
  • Country: gb
Re: Unit testing embedded software
« Reply #8 on: February 21, 2023, 08:25:20 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended? And therefore can only be done on the actual hardware?
Unit testing is testing of individual software "units" in isolation.

The whole test driven development methodology is based on writing the unit tests firsts and then writing the code to fulfill those tests. TDD is BS, of course.
This is highly subjective. Pure TDD (when you write tests first before writing any code) is questionable, but can be useful sometimes, and I certainly would not call it BS.
 
The following users thanked this post: fastbike

Online tellurium

  • Regular Contributor
  • *
  • Posts: 232
  • Country: ua
Re: Unit testing embedded software
« Reply #9 on: February 21, 2023, 10:29:40 pm »
May I recommend to read two sections of my tutorial:

https://github.com/cpq/bare-metal-programming-guide#automated-firmware-builds-software-ci - how to do automated builds
https://github.com/cpq/bare-metal-programming-guide#automated-firmware-tests-hardware-ci - how to do automated tests on a real target hardware
Open source embedded network library https://mongoose.ws
TCP/IP stack + TLS1.3 + HTTP/WebSocket/MQTT in a single file
 
The following users thanked this post: DC1MC, dobsonr741

Offline cantata.tech

  • Regular Contributor
  • *
  • Posts: 75
  • Country: au
Re: Unit testing embedded software
« Reply #10 on: February 22, 2023, 07:41:59 am »
Hello everyone!

For some time now I have been interested in how I could test software (or its individual modules) using dedicated unit testing frameworks. I've seen a few of them in use online: gtest, unity, CppUTest, MinUnit, Unity and so on...

Try CppUTest first and see how you go.

Quote
I probably still need a separate build system for tests?

Not really.

Just modify your Makefile to include tests as targets, ie

> make tests

and then run them from the command line on your development system.
« Last Edit: February 22, 2023, 07:43:33 am by cantata.tech »
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6266
  • Country: fi
    • My home page and email address
Re: Unit testing embedded software
« Reply #11 on: February 22, 2023, 09:00:36 am »
Here's what I do.  Apologies for the wall of text, feel free to skip if TLDR.

I implement and test algorithms in fully hosted environments (i.e. running under an OS on full-featured computers, almost always Linux in my case), individually ("in units").  I archive them one per directory, with a README describing the thing, and any test/example executable showing short usage when run with a single -h or --help command-line argument.  For more complicated stuff, I often have images and data in the same directory too.

For complex data structures like trees, heaps, directed graphs, etc., these test and example programs often output data structure information in Graphviz format (DOT language), for easy visual verification.

The ones I write in C or C++ for use in microcontrollers, are never in library form, because I always end up adapting them for the use case at hand.  So, instead of focusing on the same code being able to handle all situations I can imagine, I write them to do one thing, in as simple (but robust/secure/non-buggy) form as possible, so that it is maximally adaptable to my future needs, whatever they may be.

When integrating various pieces into a functional firmware, I use a mixed approach: not purely top-down or bottom-up, but a mix of the two.  At this phase, I consider the various pieces via their requirements, inputs, and outputs, and piece it together like an interwoven puzzle, and often develop the underlying structural "scaffold" code in tandem or slightly ahead of the functional units I add – by "scaffold" I mean things like bus interfaces, interrupt handlers, with temporary timing and memory use measurements to make sure I do not unexpectedly run out of computing resources.  When there are details I am unsure of, for example using a single timer for two different purposes, or maybe examining the computational cost of a specific approach, I do write test firmwares (often in the Arduino environment for rapid testing) to examine that case and that case only, without anything else.  These too go into the same archive of tests and examples.  (I do have thousands of these already, but only keep the most interesting/useful few hundred on my work machine, and move the rest to offline storage.)

Whenever I have added a functional piece, I do test the whole in practice, concentrating on the edge cases.  For example, with button interfaces I test contact bounce (brushing two ends of multistrand wires is a pretty good stress test) and multiple simultaneous keypresses.  I never proceed while there are misbehaving edge cases, but some of my colleagues and former colleagues disagree with that, because they believe getting the product on the market is more important than having it behave exactly as desired.  I understand their viewpoint, but that is just not how I develop stuff.

I have also created simulation test benches I can run on fully-features OSes, before implementing it on the hardware.  This is particularly useful for GUI development, where one can use GTK or QT (or any similar toolkit, or even SDL) for the UI, with mouse clicks as touches on the touch screen (with randomness added to model limited resolution), and key presses to simulate physical buttons.  (For pure mockups, to illustrate intended final product interface without reusing any of the code, I recommend HTML + CSS + JS, so that it can be demonstrated on any device with a standard web browser.  This is especially useful for touch-based interfaces, since you can get a real physical feel for the UI by using e.g. a phone for the demonstration.  I also like to use local/serverless HTML+CSS+JS "tool pages", because JS is pretty darned well optimized in current browsers, and such tool pages work everywhere.)

During the development, I like to keep a diary of sorts, listing any interesting or frustrating bits.  This is a very recent addition to my workflow, in the last year or two, after almost three decades of paid professional software development.  I "stole" this from the diaries of historical explorers, as I saw it an excellent way of self-reflection and analysis of my own performance afterwards, something I've always struggled with.  You don't need to mention it to anybody else, especially your employers, if you don't want to; but it is an excellent tool to work on ones time estimates, for example.  (My own time estimates have always been off the mark: most often underestimating the time needed, but sometimes overestimating [when I forget checking my test case archive before making the estimate].)

Finally, one of my favourite real world tests is just describing a problem, then telling an unsuspecting victim tester that this gadget can solve it, and then see how they (try to) use the gadget to solve the issue.  I try not to intervene, although sometimes a couple of sentences outlining the idea of how I'd find the solution may be necessary.  Theory gives us possibilities, and is therefore very useful (and I do still read peer-reviewed papers in physics and cs, even though I'm no longer in academia), but practical reality rules.
 
The following users thanked this post: enz, elecdonia, Neomys Sapiens, spostma, 8goran8, tellurium, BadeBhaiya

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Unit testing embedded software
« Reply #12 on: February 22, 2023, 09:33:24 am »
Here's what I do.  Apologies for the wall of text, feel free to skip if TLDR.

It would be a mistake for other readers to skip that.

It is a refreshing change to see a practical and pragmatic approach that is free of cargo-cult engineering and religious practices.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 


Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: Unit testing embedded software
« Reply #14 on: February 22, 2023, 07:49:45 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended? And therefore can only be done on the actual hardware?
Unit testing is testing of individual software "units" in isolation.

The whole test driven development methodology is based on writing the unit tests firsts and then writing the code to fulfill those tests. TDD is BS, of course.
This is highly subjective. Pure TDD (when you write tests first before writing any code) is questionable, but can be useful sometimes, and I certainly would not call it BS.

This certainly is a controversial approach. "Questionable" is about right, but "subjective"? Not sure there should be anything much subjective about it.
"BS" is a bit strong, sure, something I could have said myself. ;D

One problem with TDD is that it promotes bottom-up development almost exclusively, because 1/ writing tests for small units is easier than for larger ones, and 2/ if writing tests for larger units first, then people would have to do more work, like mocking up the smaller bits, etc. So in practice, that's almost 100% bottom-up.

Which sucks. Bottom-up can be done concurrently to top-down for some parts of the development, but should not be used exclusively IMHO. It leads to horrible piles of code stitched together with almost no architecture.

So, here is why I think TDD is a mess. Not that thinking of testing before coding is not a valid idea. But it just doesn't work, because we are lazy (/have no time/have no budget to do better.)

TDD would be more interesting in a top-down approach as I mentioned above. That would mean designing larger blocks first, then the required tests, then coding - which essentially means having to mock up a lot of stuff at the beginning, and refining as development progresses. That's a lot of work. So people rarely do that. They just use whatever method is trendy and will look cool on their resume.
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Unit testing embedded software
« Reply #15 on: February 22, 2023, 08:54:45 pm »
Is unit testing not a last step in a development process to see if the manufactured devices work as intended? And therefore can only be done on the actual hardware?
Unit testing is testing of individual software "units" in isolation.

The whole test driven development methodology is based on writing the unit tests firsts and then writing the code to fulfill those tests. TDD is BS, of course.
This is highly subjective. Pure TDD (when you write tests first before writing any code) is questionable, but can be useful sometimes, and I certainly would not call it BS.

This certainly is a controversial approach. "Questionable" is about right, but "subjective"? Not sure there should be anything much subjective about it.
"BS" is a bit strong, sure, something I could have said myself. ;D

One problem with TDD is that it promotes bottom-up development almost exclusively, because 1/ writing tests for small units is easier than for larger ones, and 2/ if writing tests for larger units first, then people would have to do more work, like mocking up the smaller bits, etc. So in practice, that's almost 100% bottom-up.

Which sucks. Bottom-up can be done concurrently to top-down for some parts of the development, but should not be used exclusively IMHO. It leads to horrible piles of code stitched together with almost no architecture.

So, here is why I think TDD is a mess. Not that thinking of testing before coding is not a valid idea. But it just doesn't work, because we are lazy (/have no time/have no budget to do better.)

TDD would be more interesting in a top-down approach as I mentioned above. That would mean designing larger blocks first, then the required tests, then coding - which essentially means having to mock up a lot of stuff at the beginning, and refining as development progresses. That's a lot of work. So people rarely do that. They just use whatever method is trendy and will look cool on their resume.

My opinion is that TDD is good for minor variations on what has been done before, and elaboration of an existing skeleton. That's pretty similar to your statements.

TDD has some major blind spots...
 
Obviously it is dependent on the quality of the specifications and tests, and they can easily be skimped.

Slightly less obviously, some thing simply cannot be tested. One classic case is demonstrating database ACID properties. Another is graceful degradation in the presence of random failures. Yet another is worst case latencies.

Nonetheless, used wisely TDD can help avoid problems.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: Unit testing embedded software
« Reply #16 on: February 22, 2023, 09:09:48 pm »
Obviously it is dependent on the quality of the specifications and tests, and they can easily be skimped.

That's one important point I didn't mention. But it goes beyond TDD anyway - whether you start by writing tests, or code directly, specifications are what you're going to base development on.

And it has been shown again and again that - at least for teams of reasonable competency - the main source of software flaws was incorrect or incomplete specifications, well above implementation errors.
 

Offline pcbcrew

  • Contributor
  • Posts: 32
  • Country: cn
  • Engineer @ PCBCrew
    • PCBCrew - meet the best Chinese PCB Manufacturers
Re: Unit testing embedded software
« Reply #17 on: February 22, 2023, 09:24:29 pm »
In automobile industry, TDD is commonly used.
(This might be like off-topic of this thread, as I am considering the hardware development, not embedded software only)

Differences between software TDD and hardware TDD are:

1. Unlike in software where unit testing is a big portion, the TDD I experienced in automobile industry was something like component-testing and BDD. It may be a problem of how we define a "unit" in systems. But in my view, each component was too big and complex to call it as a "unit". A electrical and control system of a car consists of many components. The system designers write test specifications. Actual hardware and testing instruments are designed and manufactured by different suppliers. Both DUT and Testing equipment are mixture of hardware and software, that are, components.

2. TDD in software uses common libs and tools. For example, PyTest in Python, JUnit in Java, Mocha in JS, etc. But for the automobile TDD, we had to design and deliver a new testing instruements for the given specification. It differs per company, per model, per DUT (device under test)

3. TDD in software is mainly done during development process. And some during continuous delivery process. But TDD in automobile industry is both for development and production. Engineers use specialized testing equipments during development, workers also use it in production line to test each care before release.

As my hardware TDD experience is limited to a automobile testing equipment provider (ART-Logics - http://www.art-logics.com), these are some key differences I can tell now.
I think medical, defence, aerospace industries will apply similar processes that we can consider as TDD in hardware development.
« Last Edit: February 22, 2023, 09:27:15 pm by pcbcrew »
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3147
  • Country: ca
Re: Unit testing embedded software
« Reply #18 on: February 23, 2023, 04:43:48 am »
If you really do something with hardware, it's hardly a good idea to try to do it on PC.

You need to observe how your hardware works. Visually, by effects in the real world, or by analyzing signals with a scope. In theory, you can simulate all that, but using real hardware seems much easier to me.

Also, when you test a unit, it doesn't guarantee that the code will work when put together with other units - interrupts may clash, timing may be different, data may not arrive when needed.

Therefore, the flow is different for hardware. I design everything as a whole, making sure that all the requirements can be met, mostly timing, then start from empty program, to the blinking led, and so on, in small increments, testing what I wrote frequently.
« Last Edit: February 23, 2023, 04:46:34 am by NorthGuy »
 

Offline BadeBhaiya

  • Contributor
  • Posts: 47
  • Country: in
Re: Unit testing embedded software
« Reply #19 on: February 23, 2023, 07:45:49 am »
Many excellent points in this thread. I would just like to elaborate on a topic which may be valuable, one which I learned far too late.

The term "unit testing" is used a lot, but always remember that the "unit" part comes first. If the code is not properly partitioned, testing can be a massive chore, and something that is dreaded.

To avoid this, compartmentalise the code as soon as possible. No matter if you're starting a project from ground up, or taking over someone's old spaghetti code (the latter may be difficult, you may need to convince multiple team members but it is worth it). Make everything into a logical unit, and try to have as many units as possible (within reason, of course).

The sign of good modular code is, say if the code needs to be ported over to another hardware, the process only requires changing a few functions/HAL bindings in a single file. ie very little code that is hardware dependant. Abstract the code to the extent where anything above the drivers doesn't really care what hardware you're running on. Business logic, config etc should be just that, logic, stuff that should be able to compile for any architecture in the world
 
The following users thanked this post: elecdonia

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Unit testing embedded software
« Reply #20 on: February 23, 2023, 08:59:48 am »
Many excellent points in this thread. I would just like to elaborate on a topic which may be valuable, one which I learned far too late.

The term "unit testing" is used a lot, but always remember that the "unit" part comes first. If the code is not properly partitioned, testing can be a massive chore, and something that is dreaded.

To avoid this, compartmentalise the code as soon as possible. No matter if you're starting a project from ground up, or taking over someone's old spaghetti code (the latter may be difficult, you may need to convince multiple team members but it is worth it). Make everything into a logical unit, and try to have as many units as possible (within reason, of course).

The sign of good modular code is, say if the code needs to be ported over to another hardware, the process only requires changing a few functions/HAL bindings in a single file. ie very little code that is hardware dependant. Abstract the code to the extent where anything above the drivers doesn't really care what hardware you're running on. Business logic, config etc should be just that, logic, stuff that should be able to compile for any architecture in the world

Agreed.

And to emphasise...

The "unit" can be any size up to the complete application, not just a couple of lines of code.

Event driven applications, especially FSMs, can be tested and explored on a PC using all the debugging facilities and techniques available. The events and actions associated with hardware are simulated, or "mocked" in TDD parlance. That's the benefit of good HAL partitioning and interface.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6266
  • Country: fi
    • My home page and email address
Re: Unit testing embedded software
« Reply #21 on: February 23, 2023, 12:38:30 pm »
Simulations are most useful during the design phase, less so during the implementation phase.

That is, I do not use simulations or mockups as an implementation tool, but as a design tool – and experimental test setup, when I have multiple possible approaches and I want to find out the effects of selecting one versus another.

The exception is algorithms.  For example an FFT routine, or frequency responses of FIR or IIR filters, or anything math-intensive, like sensor fusion.  For these, I see no real difference between simulation and an unit test.  I very, very often experiment with various algorithms, with usually a naïve implementation, plus one or more "optimized"/"tricky" implementations, for example using C implementation on x86-64 for Cortex-M7 VFP4 SIMD (two 16 bit integers in each 32 bit register), often looking at what Clang and GCC actually generate for the target ARM architecture (see ACLE and #include <acle.h>), and "simulating" the instructions, even down to theoretical cycle counts (not taking things like cache effects into account, so theoretical minimum cycle counts or theoretical maximum performace).  Mostly, I'm worried about correctness and edge cases, rather than maximum performance, though; performance really only when the question is "can this hardware do this".
« Last Edit: February 23, 2023, 12:40:32 pm by Nominal Animal »
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Unit testing embedded software
« Reply #22 on: February 23, 2023, 01:05:57 pm »
I will simulate events during design and implementation and maintenance of high-level FSMs. Sometimes they are quick and dirty poke it and see tests, sometimes more formal and repeatable unit tests.

Thus, if implementing a lung ventilator, I will verify if the FSM behaves as expected when there is and isn't an inhalation of sufficient volume with appropriate timing. For example, if the patient is assumed to be capable and is being passively monitored, but doesn't inhale, then the FSM should revert to a more pessimistic mode where the patient is actively helped to inspire (so they don't expire :) ).

Depending on the complexity of creating an event such as "start of inhalation" or "volume of last breath", I may or may not simulate hardware inputs.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6266
  • Country: fi
    • My home page and email address
Re: Unit testing embedded software
« Reply #23 on: February 23, 2023, 02:13:47 pm »
I will simulate events during design and implementation and maintenance of high-level FSMs.
Yup, I classify FSM's in the same bin I do algorithms, and do simulate those as well; especially if I want to check for end-states (where the FSM would get "stuck") and state chains that are not accessible, or are accessible in undesired situations.  Granted, I use FSMs mostly for parsing structured data and for user interfaces.  Again, I consider these simulations closer to unit tests, as I'm usually worrying about correctness here.

I wonder if I'm the only one who mumbles and waves their fingers in the air when working out particularly complex FSMs.  I do like to use pen and paper sketches as a swap file, too; those "notes" become gibberish as soon as I move on, even for myself: I literally sketch something to represent a detail whose inner complexity I cannot hold in my mind while working on higher-level structure...  I also like to walk in circles (increases blood flow) when thinking hard.  These make me utterly incompatible with cubicle farms ;D
« Last Edit: February 23, 2023, 02:17:34 pm by Nominal Animal »
 

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Unit testing embedded software
« Reply #24 on: February 23, 2023, 03:07:58 pm »
Back to the original question:

Quote
I probably still need a separate build system for tests?

No, the same build system can do. This guys below shows a great starter example with cmocka and cmake. I adopted it to one of my projects, the test build takes up a sub second and breaks the build if the test is failing.

https://admantium.com/blog/pico03_testing_with_cmocka/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf