Skip to content

Commit

Permalink
Added CMakeLists to build, scripts, github CI, and ceedling unit test…
Browse files Browse the repository at this point in the history
… structure
  • Loading branch information
burke-david committed May 31, 2024
1 parent 6d46544 commit a67a1aa
Show file tree
Hide file tree
Showing 16 changed files with 477 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Makefile CI


on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./scripts/build.sh
test:
permissions:
pull-requests: write
repository-projects: read
contents: read
runs-on: ubuntu-latest
steps:
- name: 'Load testing tools'
run: sudo gem install ceedling
- name: 'run tests'
uses: actions/checkout@v4
- run: ./scripts/test.sh
analysis:
permissions:
pull-requests: write
repository-projects: read
contents: read
runs-on: ubuntu-latest
steps:
- name: 'Load testing tools'
run: |
sudo gem install ceedling
pip install gcovr
- name: 'run results process'
uses: actions/checkout@v4
- run: ./scripts/process_results.sh
- name: Analysis Comment
uses: thollander/actions-comment-pull-request@v2
with:
filePath: ./build/test/process/results.md
comment_tag: analysis
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ dkms.conf

# Don't include the build directory
build/

# CMake-related files
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Add the minimum CMake version required
cmake_minimum_required(VERSION 3.20)

# Set the project name
project(serial_tool)

# Set the output directory for the build executables.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# Add the subdirectories
add_subdirectory(src)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 David Burke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
104 changes: 104 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Notes:
# Sample project C code is not presently written to produce a release artifact.
# As such, release build options are disabled.
# This sample, therefore, only demonstrates running a collection of unit tests.

:project:
:use_exceptions: FALSE
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:build_root: build
# :release_build: TRUE
:test_file_prefix: test_
:which_ceedling: gem
:ceedling_version: 0.31.1
:default_tasks:
- test:all

#:test_build:
# :use_assembly: TRUE

#:release_build:
# :output: MyApp.out
# :use_assembly: FALSE

:environment:

:extension:
:executable: .out

:paths:
:test:
- +:tests/**
- -:tests/support
:source:
- src/**
# - src/module1
# - src/module2

:support:
- tests/support
:libraries: []

:defines:
# in order to add common defines:
# 1) remove the trailing [] from the :common: section
# 2) add entries to the :common: section (e.g. :test: has TEST defined)
:common: &common_defines []
:test:
- *common_defines
- UNIT_TEST
:test_preprocess:
- *common_defines
- UNIT_TEST

:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
# For more information on these options, see docs in plugins/gcov
:gcov:
:reports:
- HtmlDetailed
- Text
:gcovr:
:html_medium_threshold: 75
:html_high_threshold: 90
:branches: false

#:tools:
# Ceedling defaults to using gcc for compiling, linking, etc.
# As [:tools] is blank, gcc will be used (so long as it's in your system path)
# See documentation to configure a given toolchain for use

# LIBRARIES
# These libraries are automatically injected into the build process. Those specified as
# common will be used in all types of builds. Otherwise, libraries can be injected in just
# tests or releases. These options are MERGED with the options in supplemental yaml files.
:libraries:
:placement: :end
:flag: "-l${1}"
:path_flag: "-L ${1}"
:system: [] # for example, you might list 'm' to grab the math library
:test: []
:release: []

:plugins:
:load_paths:
- "#{Ceedling.load_path}"
:enabled:
- stdout_pretty_tests_report
- module_generator
- gcov
22 changes: 22 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Build the project

# verify that this is running in the project root
if [ ! -f "project.yml" ]; then
echo "Error: must be run from the project root."
echo "Note: this script is looking for the project.yml file to determine what directory it's called from."
exit 1
fi

#if the build directory does not exist, create it
if [ ! -d "build" ]; then
mkdir build
fi

# Run cmake to generate the build files
cd build
cmake ..

# Run make to build the project
make
72 changes: 72 additions & 0 deletions scripts/process_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Create a variable that contains the build/test/results directory
results_dir="build/test/results"

# Create a variable that contains the build/test/process directory
process_dir="build/test/process"

script_dir="scripts"

# Create a variable containing a markdown file in the process_dir called results.md
results_md="$process_dir/results.md"

# Initialize counters
total_tests=0
total_passed=0
total_failed=0
total_ignored=0

# Run the test.sh script
$script_dir/test.sh

# Iterate over all *.pass and *.fail files
for file in "$results_dir"/*.pass "$results_dir"/*.fail; do
# Check if the file exists before trying to process it
if [ -f "$file" ]; then
# Extract the counts from the file
total=$(awk -F': ' '/:total:/ {print $2}' "$file")
passed=$(awk -F': ' '/:passed:/ {print $2}' "$file")
failed=$(awk -F': ' '/:failed:/ {print $2}' "$file")
ignored=$(awk -F': ' '/:ignored:/ {print $2}' "$file")

# Add the counts to the totals
((total_tests+=total))
((total_passed+=passed))
((total_failed+=failed))
((total_ignored+=ignored))
fi
done

# Create the process directory if it does not exist
if [ ! -d "$process_dir" ]; then
mkdir -p "$process_dir"
fi

# Create the results markdown file
touch "$results_md"

# Write the test results to the results markdown file
echo "TEST RESULTS:" > "$results_md"
echo "Total tests: $total_tests" >> "$results_md"
echo "Passed: $total_passed" >> "$results_md"
echo "Failed: $total_failed" >> "$results_md"
echo "Ignored: $total_ignored" >> "$results_md"

# Add an extra blank line to the results markdown file
echo "" >> "$results_md"

# Run test coverage analysis
# Use the "ceedling gcov:all" command to generate the coverage report
ceedling gcov:all


# if the gcov command fails, print an error message else generate the coverage report
if [ $? -ne 0 ]; then
echo "Error: gcov command failed."
else
# Use the "ceedling utils:gcov" command to generate the coverage report and dump to the results markdown file
ceedling utils:gcov >> "$results_md"
fi


7 changes: 7 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Change to the root directory
cd "$(dirname "$0")/.."


ceedling
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_subdirectory(app)
add_subdirectory(buffer)
add_subdirectory(cli)
add_subdirectory(serial)
add_subdirectory(time_funcs)
add_executable(serial_tool main.c)
target_link_libraries(serial_tool app buffer cli serial time_funcs)
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(app app_cli.c app.c)
1 change: 1 addition & 0 deletions src/buffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(buffer ring_buf.c)
1 change: 1 addition & 0 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(cli cli.c)
1 change: 1 addition & 0 deletions src/serial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(serial serial.c)
1 change: 1 addition & 0 deletions src/time_funcs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(time_funcs time_funcs.c)
1 change: 1 addition & 0 deletions tests/support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add any unit test support files here
Loading

0 comments on commit a67a1aa

Please sign in to comment.