Code Monkey home page Code Monkey logo

stm32_gtest_c_code's Introduction

STM32 C code and Google Test Framework

Language License Test codecov Lizard Flawfinder

This is a sample project for testing C code for STM32 microcontrollers using the Google Test Framework. Some topics covered:

  • Sample project using the NUCLEO-F446ZE board.
  • Embedded system without RTOS (bare metal).
  • Distinct folders for library, executable, and test code.
  • Use of STM32CubeIDE for building and compiling the application project.
  • Use of CMake for building the test code.
  • Testing C code via Google Test Framework.
  • Use GMock for mocking the STM32 HAL functions.
  • Code coverage with Github Actions and Codecov.
  • Code quality analysis with Lizard and Flawfinder tools.
  • Assert verification and prints the failures via huart3.
  • Use of Docker container.

Project structure

./
├── CMakeLists.txt
│
├── cmake
│   └── cmake modules
│
├── docker
│   └── Dockerfile
│
├── docs
│   └── Documentation files
│
├── .github
│   └── workflows
│       └── GitHub workflows
│
├── source
│   ├── CMakeLists.txt
│   │
│   ├── nucleo-f446ze-library
│   │   ├── CMakeLists.txt
│   │   ├── BuildArtifacts
│   │   │   └── Library artifacts
│   │   ├── Drivers 
│   │   │   └── Files generated by STM32CubeIDE
│   │   ├── Inc
│   │   │   └── Files generated by STM32CubeIDE
│   │   ├── Libraries
│   │   │   └── Header and source files
│   │   └── Src
│   │       └── Files generated by STM32CubeIDE
│   │
│   └── stm32-cube-ide
│       ├── Core (Files generated by STM32CubeIDE)
│       │   ├── Inc 
│       │   │   └── Files generated by STM32CubeIDE
│       │   ├── Src
│       │   │   ├── main.c (Sample code)
│       │   │   └── ...
│       │   └── Startup
│       │       └── Files generated by STM32CubeIDE
│       └── Drivers
│           └── Files generated by STM32CubeIDE
│
└── tests
    ├── CMakeLists.txt
    ├── header-overrides
    │   └── Overrides some header files copied from the STM32CubeIDE project that are needed by the mock
    ├── integration
    │   └── integration_hello_test.cpp
    ├── mock
    │   ├── fixture.h
    │   └── hal_gpio_mock.cpp
    └── unit
        ├── gpio_test.cpp
        └── unit_hello_test.cpp

Building tests project via CMake

Clone this repo for your local machine

git clone https://github.com/CharlesDias/stm32_gtest_c_code.git

Access the project folder stm32_gtest_c_code

cd stm32_gtest_c_code

Pull the latest docker image used to build the project.

docker pull charlesdias/stm32_gtest

Run the image docker.

docker run --rm -it -v $(pwd):/home/project -w /home/project charlesdias/stm32_gtest

Run the command below inside the Docker container

make clean && make build && make test

Access the build/coverage/index.html file to see the coverage report.

Dependency graph

Dependency graph for test project.

Dependency graph

Building application project via STM32CubeIDE

Clone this repo for your local machine

git clone https://github.com/CharlesDias/stm32_gtest_c_code.git

Open the STM32CubeIDE and import this project.

Build and load the firmware on NUCLEO-F446ZE board. See the expected output.

STM32 project

Improvement suggestions

  • Add some function example to increase the CCN (cyclomatic complexity number).
  • Add some function example with security weaknesses to test the Flawfinder.
  • Build the application project via CMake.
  • Add Doxygen configuration.

stm32_gtest_c_code's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.