Python Application Template

Overview

PyPi module N/A
git repository https://bitbucket.org/arrizza-public/devino-app-template
git command git clone git@bitbucket.org:arrizza-public/devino-app-template.git
Verification Report https://arrizza.com/web-ver/devino-app-template-report.html
Version Info
  • Ubuntu 20.04 focal, Python 3.10
  • Ubuntu 22.04 jammy, Python 3.10

Summary

This is a template for a C/C++ Arduino application. It contains a set of scripts and configuration files that make creating, developing and maintaining a C++ app easier.

How to use

  • create a git for your app
  • use a diff tool like meld, and copy contents from this repo into your app.
  • Use the contents as a starting point or replace completely with your app's content

Scripts

# clean it
./do_clean full # start from scratch
./do_clean      # leave venv and python caches

# install it
./do_subm_update full # first time for submodules
./do_subm_update      # ... thereafter
./do_install full     # first time for OS and pip modules
./do_install          # ...thereafter

# doc it
./do_doc # generate doxygen html and PDF

# check it
./do_check # check configs and files are okay
./do_lint  # pylint or clint-tidy
./do_update  # update local python modules in venv

# build it
./do_build         # build using cmake (default: debug)
./do_build debug   # use cmake-build-debug
./do_build release # use cmake-build-release

# run it
./doit         # run the app or sample code to run the module/library (default debug)
./doit debug   # use cmake-build-debug
./doit release # use cmake-build-release
./do_ver # run verification (if implemented)
./do_ut  # run unit tests (if implemented)

Unit Tests

Run It

The unit tests are in a separate directory called "ut".

./do_ut

Typical output - passing

Here's what it looks like when everything is passing. The very bottom line says "do_ut: overall rc=0".

$ ./do_ut
OK   set_env: rc=0
OK   do_ut: out_dir: /home/arrizza/projects/web/arduino/devino-app-template/out
==== do_ut: starting...
     gen: version.h rc=0
==== do_coverage: starting reset...
OK   do_coverage: tech:arduino action:reset rc=0
     do_ut: cov: reset counters rc=0
==== do_ut: starting tech:arduino target:ut...
     do_ut: build debug target:ut
 --  1]  g++ -g -fprofile-arcs -ftest-coverage -I ut/mock_arduino -pthread -c ut/ut.cpp -o cmake-build-debug/ut/ut.o
 --  2]  g++ -g -fprofile-arcs -ftest-coverage -I ut/mock_arduino -pthread -c ut/mock_arduino/mock_arduino.cpp -o cmake-build-debug/ut/mock_arduino.o
 --  3]  g++ cmake-build-debug/ut/ut.o cmake-build-debug/ut/mock_arduino.o -pthread -lgcov -lgtest -lgtest_main -o cmake-build-debug/ut/ut
OK   do_ut: arduino ut_build rc=0
OK   do_ut: build debug rc=0
OK   do_ut: overall rc=0
     do_ut: build unit tests rc=0
cmake-build-debug/ut/ut
Running main() from /build/googletest-j5yxiC/googletest-1.10.0/googletest/src/gtest_main.cc
[==========] Running 4 tests from 3 test suites.
[----------] Global test environment set-up.
[----------] 1 test from get_seed
[ RUN      ] get_seed.simple
[       OK ] get_seed.simple (1 ms)
[----------] 1 test from get_seed (1 ms total)

[----------] 2 tests from setup
[ RUN      ] setup.simple
[       OK ] setup.simple (0 ms)
[ RUN      ] setup.multi
[       OK ] setup.multi (0 ms)
[----------] 2 tests from setup (0 ms total)

[----------] 1 test from loop
[ RUN      ] loop.simple
[       OK ] loop.simple (0 ms)
[----------] 1 test from loop (0 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 3 test suites ran. (1 ms total)
[  PASSED  ] 4 tests.
     do_ut: run unit tests rc=0
==== do_coverage: starting gen...
     do_coverage: summary report:
 --  1]  lines: 100.0% (28 out of 28)
 --  2]  branches: 100.0% (4 out of 4)
     do_coverage: report is located in: out/coverage/ut.html
OK   do_coverage: tech:arduino action:gen rc=0
     do_ut: overall rc=0

Typical output - failing

I modified an expected result to make it fail. The bottom line says "do_ut: overall rc=2" to indicate a failure occurred.

$ ./do_ut
OK   set_env: rc=0
OK   do_ut: out_dir: /home/arrizza/projects/web/arduino/devino-app-template/out
==== do_ut: starting...
     gen: version.h rc=0
==== do_coverage: starting reset...
OK   do_coverage: tech:arduino action:reset rc=0
     do_ut: cov: reset counters rc=0
==== do_ut: starting tech:arduino target:ut...
     do_ut: build debug target:ut
 --  1]  g++ -g -fprofile-arcs -ftest-coverage -I ut/mock_arduino -pthread -c ut/ut.cpp -o cmake-build-debug/ut/ut.o
 --  2]  g++ cmake-build-debug/ut/ut.o cmake-build-debug/ut/mock_arduino.o -pthread -lgcov -lgtest -lgtest_main -o cmake-build-debug/ut/ut
OK   do_ut: arduino ut_build rc=0
OK   do_ut: build debug rc=0
OK   do_ut: overall rc=0
     do_ut: build unit tests rc=0
cmake-build-debug/ut/ut
Running main() from /build/googletest-j5yxiC/googletest-1.10.0/googletest/src/gtest_main.cc
[==========] Running 4 tests from 3 test suites.
[----------] Global test environment set-up.
[----------] 1 test from get_seed
[ RUN      ] get_seed.simple
ut/ut.cpp:10: Failure
Expected equality of these values:
  3
  seed
    Which is: 0
[  FAILED  ] get_seed.simple (0 ms)
[----------] 1 test from get_seed (0 ms total)

[----------] 2 tests from setup
[ RUN      ] setup.simple
[       OK ] setup.simple (0 ms)
[ RUN      ] setup.multi
[       OK ] setup.multi (0 ms)
[----------] 2 tests from setup (0 ms total)

[----------] 1 test from loop
[ RUN      ] loop.simple
[       OK ] loop.simple (0 ms)
[----------] 1 test from loop (0 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 3 test suites ran. (0 ms total)
[  PASSED  ] 3 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] get_seed.simple

 1 FAILED TEST
make: *** [Makefile:72: ut_run] Error 1
     do_ut: run unit tests rc=2
==== do_coverage: starting gen...
     do_coverage: summary report:
 --  1]  lines: 100.0% (28 out of 28)
 --  2]  branches: 100.0% (4 out of 4)
     do_coverage: report is located in: out/coverage/ut.html
OK   do_coverage: tech:arduino action:gen rc=0
     do_ut: overall rc=2

In this example, I changed this line:

EXPECT_EQ(0, seed);

to

EXPECT_EQ(3, seed);

The resulting output shows that the Expected value should have been "3" but actually was "0".

The failure occurred in ut.cpp in line 10 which is the line above.

Expected equality of these values:
  3
  seed
    Which is: 0

Coverage

The source coverage is generated whenever do_ut is run. A summary is printed at the end:

==== do_coverage: starting gen...
do_coverage: summary report:
--  1]  lines: 100.0% (28 out of 28)
--  2]  branches: 100.0% (4 out of 4)
do_coverage: report is located in: out/coverage/ut.html
OK   do_coverage: tech:arduino action:gen rc=0

This indicates that 100% of the lines of the cpp files in src/* are covered by unit tests. It also shows that the number of branches are fully covered.

A detailed report is available in out/coverage/ut.html. Use a browser to display this file. In Clion, I drag'n'drop the file to the Chrome browser URL entry and it works from there. If you re-run ./do_ut then refresh the browser page to see the new results.

- John Arrizza