Skip to content

Commit f118c2e

Browse files
committed
udpated docs
1 parent 3a6380c commit f118c2e

File tree

9 files changed

+11
-12
lines changed

9 files changed

+11
-12
lines changed

.gitignore

100644100755
File mode changed.

.travis.yml

100644100755
File mode changed.

LICENSE.txt

100644100755
File mode changed.

README.md

100644100755
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
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 Travis-CI). The repo doesn't have a lot of code - there is a simple library which is tested for coverage and integration.
88

99
### Motivation
10+
I just wanted to make a small standalone test project to see tools and workflow for C (or C++) language testing.
1011

11-
I just wanted to make a small standalone test project to see tools and workflow for C language testing.
1212

13-
14-
copyright (C) <2016> <M. A. Chatterjee> <deftio [at] deftio [dot] com>
13+
copyright (C) 2016- <M. A. Chatterjee> <deftio [at] deftio [dot] com>
1514
version 1.0 M. A. Chatterjee
1615

1716

18-
1917
## Features
2018

2119
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.
@@ -46,7 +44,7 @@ Unit Testing is a practice of writting small tests to see that piece of code, ty
4644

4745
Note that its not the goal to create a test that passes every possible permutation of the input parameters - as this could be an impossibly large number or variations even for just a few parameters. This idea of testing all the possible paths of exeuction is called code coverage. Testing code coverage is done with tools which see if the test program has successfully "challenged" the target library code by examing whether each execution path (or line of code) has been run. For example if there is a function like this:
4846

49-
```
47+
```C
5048
int add5ifGreaterThan2 (int a) {
5149
int r;
5250

@@ -60,15 +58,15 @@ int add5ifGreaterThan2 (int a) {
6058
```
6159
6260
Our test program for add5ifGreaterThan2() needs to supply values of a that are both less and great than 2 so both paths of the if statement
63-
```
61+
```C
6462
if (a<2)
6563
```
6664

6765
are tested.
6866

6967
We do this with test code such as this:
7068

71-
```
69+
```C
7270
//code in test program ...
7371
ASSERT (add5ifGreaterThan2(1) == 1) // supplies value of 'a' that tests the if (a<2) case
7472
ASSERT (add5ifGreaterThan2(3) == 8) // supplies value of 'a' that tests the if (a>2) case
@@ -105,7 +103,7 @@ Here is the link to the project source
105103
On Ubuntu Linux you can install gtest using this command. If you are developing on another sytem refer to the documentation link for install procedures. Other than installing, all of the commands and test procedures we'll be using later will be the same (whether Windows / MacOS / POSIX / Linux).
106104
107105
108-
```
106+
```bash
109107
sudo apt-get install libgtest-dev
110108
111109
sudo apt-get install cmake # install cmake
@@ -149,7 +147,7 @@ Travis-CI then runs the example.out and looks for the exit code from the main()
149147
## Code Coverage
150148
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:
151149

152-
```
150+
```bash
153151
make clean
154152
make
155153
./test-library.out
@@ -158,7 +156,7 @@ gcov lib.c
158156

159157
which will generate the file
160158

161-
```
159+
```bash
162160
lib.c.gcov
163161
```
164162

lib.c

100644100755
File mode changed.

lib.h

100644100755
File mode changed.

makefile

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# make file for dioci posix tests (simple interpreter for embedded systems)
1+
# makefile for posix tests (simple test lib coverage for embedded systems)
22
# @author M A Chatterjee <deftio [at] deftio [dot] com>
33

44
# test coverage is achieved usding gcov (part of gcc suite)

run_coverage_test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

3-
#this script calls the code coverage testing program gcov (part of the gcc suite)
3+
#this shell script calls the code coverage testing program gcov (part of the gcc suite)
4+
#you can run each command on your own at the command line
45

56
#fist clean all object files
67
make clean

test-library.c

100644100755
File mode changed.

0 commit comments

Comments
 (0)