Skip to content

Commit c352f47

Browse files
committed
travis-ci updated and working, github actions dbg now
1 parent 4782c13 commit c352f47

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: Checkout repository
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v2
1616

1717
- name: Install dependencies
1818
run: |

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@
33
[![License](https://img.shields.io/badge/License-BSD%202--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)
44
![Github Actions Ci](https://github.com/deftio/C-and-Cpp-Tests-with-CI-CD-Example/actions/workflows/ci.yml/badge.svg)
55

6-
# Simple Example for C/C++ Testing with CI/CD
6+
# Simple Example for C/C++ Tests with Continuous Integration (CI)
77

88
This repo covers setting up a basic testing suite with github badges for a C/C++ library. Its not meant to be deep tutorial on testing but just cover some basics of setting up unit tests, coverage tests, and continuous integration (in this case using either GitHub Actions or Travis-CI). The repo doesn't have a lot of code - there is a simple library which is tested for coverage and integration.
99

10-
### Motivation
11-
I just wanted to make a small standalone test project to show continuous integration tools and workflow for C (or C++) language testing.
12-
10+
## Motivation
1311

12+
I just wanted to make a small standalone test project to show continuous integration tools and workflow for C (or C++) language testing.
1413

1514
## Features
1615

1716
The lib.h / lib.c files are broken out as examples of testing an embedded library. Most of the projects I work on are for embedded systems so I wanted a way to get a build badge for these embedded projects. Since many of those compilers and environments are not on Linux I wanted just a simple abstraction of how the CI process works without all the complexities of a "real" project.
1817

19-
2018
## How it works
2119

2220
In this demo project there is a C library (could also be C++ etc). The library code is just a few demo functions which are in the lib.h and lib.c files. They don't really do anything but allow for simple abstraction of what is necessary to build a larger project. This repo and project are meant to provide a quick overview of testing and how to get build badges working on Github.
2321

24-
25-
26-
2722
### Quick Overview of Testing
2823

2924
There are many different phases of testing. Here are a few areas but phrased as questions.
@@ -134,22 +129,31 @@ You can read more about the Google Test project here: [Testing Primer](https://g
134129

135130
## Features
136131

137-
The lib.h / lib.c files are broken out as examples of testing an embedded library. Most of the projects I work on are for embedded systems so I wanted a way to get a build badge for these embedded projects. Since many of those compilers and environments are not on Linux I wanted just a simple abstraction of how the Travis build project works without all the complexities of a "real" project.
138-
132+
The lib.h / lib.c files are broken out as examples of testing an embedded library. Most of the projects I work on are for embedded systems so I wanted a way to get a build badge for these embedded projects. Since many of those compilers and environments are not on Linux I wanted just a simple abstraction of how the Travis build or Github Actions works, but without all the complexities of a "real" project.
139133

140134
## Testing vs Continuous Integration
141135

142136
In this demo project there is a C library (could also be C++ etc). The library code is just a few demo functions which are in the lib.h and lib.c files. They don't really do anything but allow for simple abstraction of what is necessary to build a larger project.
143137

144-
145-
Once you've made unit tests, and gotten your code to run using the local test suite the next step starts. How does an *outsider* know your code passes tests? This is where continuous integration (CI) starts. CI uses services (such as Travis-CI, Circle-CI, Jenkins and many others) to automatically run your test suites and then report the result. When a CI program runs your test suite it can be configured to accept or reject your code based on the tests passing. This in turn can be used to automatically deploy your code. This is called Continuous Deployment (CD) or pipelines. CD and pipelines are beyond this repo and example.
138+
Once you've made unit tests, and gotten your code to run using the local test suite the next step starts. How does an *outsider* know your code passes tests? This is where continuous integration (CI) starts. CI uses services (such as Travis-CI, Github Actions, Circle-CI, Jenkins and many others) to automatically run your test suites and then report the result. When a CI program runs your test suite it can be configured to accept or reject your code based on the tests passing. This in turn can be used to automatically deploy your code. This is called Continuous Deployment (CD) or pipelines. CD and pipelines are beyond the scope of this repo and example.
146139

147140
## Using Travis-CI as an example of build-badge and CI
148141

149-
Travis-CI looks in the .travis.yml (note that is dot travis dot yml) to see how to run the code. In this case it first calls make which compiles lib.c and example.c in to lib.o and example.o and then links them to produce the final executable called example.out. If you look inside the file example.c you will see there are few hand written test cases. They are not meant to be a complete example of how to write test cases just a simple view of how the tests will be run in general. The main() function calls local function run_tests() which in turn calls each individual test case. Rather than link in a larger test case environment such as cppUnit etc there is a trivial set of test functions, one for each function in the lib.c library. If run_tests() is able to run all the tests successfully it will return to main() with a value of S_OK else it will return some failure code. This value is then returned from the main() program in example.out on exit.
142+
### Travis-CI
143+
144+
Travis-CI looks in the .travis.yml (note that is dot travis dot yml) to see how to run the code. In this case it first calls make which compiles lib.c and example.c in to lib.o and example.o and then links them to produce the final executable called example.out.
145+
146+
If you look inside the file example.c you will see there are few hand written test cases. They are not meant to be a complete example of how to write test cases just a simple view of how the tests will be run in general. The main() function calls local function run_tests() which in turn calls each individual test case. Rather than link in a larger test case environment such as cppUnit etc there is a trivial set of test functions, one for each function in the lib.c library. If run_tests() is able to run all the tests successfully it will return to main() with a value of S_OK else it will return some failure code. This value is then returned from the main() program in example.out on exit.
150147

151148
Travis-CI then runs the example.out and looks for the exit code from the main() function. Being a Posix style of system an exit code of zero from example.out is considered passing and hence Travis-ci will then declare the build passing. If a non zero value is returned travis will declare the build failing. So to sum up, the primary means for travis knowing whether the test suite passes is getting the proper exit code from the test suite executable which in our case here is running example.out.
152149

150+
Github Actions works in similar way. When the code is pushed to github (main branch in our case), github triggers and action to look at the file here:
151+
152+
```bash
153+
./github/workflows/ci.yml
154+
```
155+
This very similar to the .travis.yml. It tells the github actions runner to load the correct environment, build the code, run the test script, and then report back success or failure. When github has completed running the ci.yml tasks it reports sucess or failure as shown in the badge.
156+
153157
## Code Coverage
154158
Code coverage is achieved using gcov from the gcc test suite. The example.out test program is compiled with the flags -ftest-coverage -fprofile-arcs. To see the code coverage run gcov:
155159

0 commit comments

Comments
 (0)