Unit test in Microchip studio

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, all

 

I am working on a project with an Atmega328p in Microchip studio and would like to write some unit tests.

 

Is it possible to use google unit test (gtest), in microchip studio, and if so, how to do it or what do others use to write unit tests?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use google test for unit testing. I just have a separate make system for building the unit tests and running them.

For writing the tests and having a test runner I just use Visual Studio Code, this calls my makefile and shows the test results.

 

I have never looked into integrating the unit tests into microchip studio, nor atmel studio, but I am happy with this solution.

Considering that every now and then it is handy to jump with the PC native debugger into the code and see what's going on, if something is messed up. Visual Studio Code can just easily do this for you.

 

For the make system for your unit tests just use whatever suits you the best, cmake, make, or whatever.

 

Myself I use waf.io as I find the pure python implementation of that builder appealing.

 

BTW: thumbs up for unit testing!

Cheers!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Multiple personality poster??? surprise

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

school project?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Coincidence:
Well there IP addresses put them about 4,000 miles apart so, yeah, I'd say it were a coincidence.

 

I think that because of Agile etc there is a lot more focus on unit tests these days so I'm not surprised to see multiple threads about it.

 

The problem with unit testing something like an AVR though is that the vast majority of the code in most projects is very hardware centric. So to unit test you are going to end up mocking large swathes of the code to the point where what you probably end up doing is unit testing whatever AVR simulator it is you have based your unit test system on and not the AVR code itself. Course if you have a high level module doing a non-hardware function (FAT filing? JPEG decode, etc) then I guess that can be fully tested in isolation but as soon as you start getting involved with timer/ADC/SPI/I2C/UART/external devices/etc/etc then you may find it very difficult to mock the realtime aspects of these things.

 

The thread linked in #3 has a link through to "buserror"s stand alone AVR simulator (much easier to integrate with than the AS7 sim) and I think this has been the core of a lot of unit testing solutions in the past.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The problem with unit testing something like an AVR though is that the vast majority of the code in most projects is very hardware centric.

Indeed.

 

So to unit test you are going to end up mocking large swathes of the code to the point where what you probably end up doing is unit testing whatever AVR simulator it is

An alternative would be to to unit-test in-circuit, and have your test framework control hardware (test equipment) to generate stimuli & observe responses.

 

"Hardware in the loop" ?

 

You might have a word with these guys: https://www.bermondseyelectronics.com/ - they are doing that stuff ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
"Hardware in the loop" ?
HIL indeed. The advantage of SIL is that you can usually do it all on a headless build server (like Jenkins) while doing HIL tends to need things to be a bit more "hands on" as you inevitably need a way to kick it back into life when the hardware dies for some reason - something that does not happen with Software On the Loop testing.

 

(I spend a lot of my life working on SIL and swearing a lot at HIL !)

 

PS HIL is not helped by Covid when the "Hardware" in the loop is actually 120 miles away in an office with no one present to give it a swift kick when it needs it! We obviously use a lot of remote controlled power supplies and stuff like that but it's difficult to cater for all eventualities!

Last Edited: Tue. May 4, 2021 - 08:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not know the other guy and no it is not a school project!

 

Okay, I might give gtest and visual code a try, if it's not straightforward in Microchip studio 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For unit testing in general I would advise to also consider the following:

 

There are various sanitizers both for llvm and gcc compilers, mainly under linux. Currently some of them are rolled out for Windows platform also.

Let's say you already have your make system, your unit tests and everything. Using linux you are only one compiler switch away to use the memory sanitizer: -fsanitize=address

 

Building with the -fsanitize=address option, you just run your unit tests executable as usual, and should there be for example a read over array boundary, you will instantly get a console dump and a program return value -1.

 

If you are running on win10, then just install Windows Subsystem for Linux and start your build command like this: bash make, which will build your unit test in a linux environment where you can use the various sanitizers.

Check here about the sanitizers: https://clang.llvm.org/docs/inde...

I think most of them exist already for gcc (it seems even more than for llvm): https://gcc.gnu.org/onlinedocs/g...

 

Cheers

Last Edited: Tue. May 4, 2021 - 11:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Easyanton wrote:
I do not know the other guy

the main point is that it's basically the same topic - so worth watching that discussion, too ...

 

eg,

sikolymester wrote:
you just run your unit tests executable as usual

that's assuming that you've got your code running on the host - which is discussed in the other thread ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Easyanton wrote:
Is it possible to use google unit test (gtest), in microchip studio, ...
That's possible.

Easyanton wrote:
... and if so, how to do it ...
A Visual Studio 2015 extension might work with Microchip Studio 7 (Visual Studio Isolated Shell 2015)

 

P.S.

Easyanton wrote:
I am working on a project with an Atmega328p in Microchip studio ...
mega328P is in VisualGDB (Visual Studio extension) at a relatively low price.

 


https://marketplace.visualstudio.com/search?term=%22Google%20Test%22&target=VS&category=All%20categories&vsVersion=vs2015&sortBy=Relevance

 

adding an extension not in the Studio gallery | AVR Freaks

Installing a generic Visual Studio extension | AVR Freaks

Viewing CR, LF, and CRLF inside Atmel Studio's Editor? - SOLVED | AVR Freaks

AS7 updating gallery and ASF | AVR Freaks

 

Debugging Arduino AVR boards with Visual Studio – VisualGDB Tutorials

AVR Devices | Choosing a Debug Method – VisualGDB Documentation

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sikolymester wrote:
... and should there be for example a read over array boundary, ...
also in Valgrind

Valgrind: Tool Suite - Experimental Tools

[bottom]

SGCheck

SGCheck is a tool for finding overruns of stack and global arrays. It works by using a heuristic approach derived from an observation about the likely forms of stack and global array accesses.

due to

Hardware and software tools for embedded developers | Static Analysis and Metrics Tools by Jack Ganssle

...

 

Matthew MacClary uses these checkers:

[1. GCC, 2. a linter, 3. Valgrind]

 

...

fyi, GCC has a linter :

GCC 10 Introduces A Static Analyzer - Static Analysis On C Code With "-fanalyzer" Option - Phoronix

Static Analyzer Options (Using the GNU Compiler Collection (GCC))

 

8. Using Valgrind to Debug your Code | GitHub - akiratwang/COMP20003: WSL2 installation tutorial for Algorithms & Data Structures (COMP20003)

 


Install Windows Subsystem for Linux (WSL) on Windows 10 | Microsoft Docs

 

"Dare to be naïve." - Buckminster Fuller