circularbuffer
circularbuffer copied to clipboard
This repository contains a circular buffer or a ring buffer implementation in C code suitable for embedded systems.
Circular Buffer
This repository contains a circular buffer or a ring buffer implementation in C code suitable for embedded systems. The implementation using a single empty cell to detect the buffer "full" case; for supporting a single producer thread and single consumer thread without OS lock primitive. For use of efficient algorithms the maximum number of elements in the circular buffer must be a power of 2. The code follows the Google C++ Style Guide with one exception that instead of 2 spaces it use 4 spaces.
Unittest
The added unittest uses the googletest framework and the SCons build system.
Follow the steps below for building the unittest
-
Install the scons, if you run on an Ubuntu machine:
sudo apt install scons -
Go to https://github.com/google/googletest and clone the git repo besides the circularbuffer repo.
-
Create a directory called build_gtest beside the circularbuffer and googletest repos.
-
Now you shall have the following directory structure:
<your path>
| build_gtest
| circularbuffer
| googletest
-
Change directory to the new directory
build_gtest. -
Build the google test framework:
<your path>/build_gtest$ cmake ../googletest/<your path>/build_gtest$ make -
Change directory to
<your path>/circularbuffer. -
Build, run and clean the units test with the scons command:
<your path>/circularbuffer$ scons test<your path>/circularbuffer$ scons test -c -
Optional build, run and clean the units test with the commands:
<your path>/circularbuffer$ scons<your path>/circularbuffer$ ./build/circularbuffer-gtest<your path>/circularbuffer$ scons -c
Follow the steps below for generate code coverage report
-
Install the lcov, if you run on an Ubuntu machine:
sudo apt install lcov -
Generate report:
<your path>/circularbuffer$ ./gen_test_report.sh -
Html output result is found here
<your path>/circularbuffer/build/out$ -
Delete report:
<your path>/circularbuffer$ ./gen_test_report.sh -c