Repository contains implementation of few STL like containers but main reason is build skills of constructing scripts generating build systems using CMake and basics of building CI/CD infrastructure.
Tabble of content:
- using Containers library in other projects
- minimal requirements
- how to run project
- recommended way of using CMake on Linux
- generating code-coverage locally on Linux
- results of code-coverage pipeline
- using valgrind on Linux
- using sanitizers on Linux
- using docker container
- working with python scripts
To install and use Containers library in other C++ projects based on CMake there are need for two steps:
- Add step for downloading this repository. Example of use:
# Download Containers repository to testsing
include(FetchContent)
FetchContent_Declare(
Containers
GIT_REPOSITORY https://github.com/milosz-barylowicz/Containers.git
GIT_TAG main)
FetchContent_MakeAvailable(Containers)
- Link downloaded library to executable that containers should be used. Example of use:
# Linking Containers Library
target_link_libraries(${EXECUTABLE_NAME}
PRIVATE
Containers)
- Last thing is just use #include statemnet with container that is needed. Example:
#include <iostream>
#include "vector.hpp"
int main() {
containers::Vector<int> numbers { 1, 2, 3, 4, 5, 6, 7 };
std::cout << "numbers: ";
for (const auto& number : numbers) {
std::cout << number << " ";
}
std::cout << std::endl;
return 0;
}
- CMake 3.24 installed [build project]
- gcc 4.8 installed [gcov and sanitizers are included according to sanitizers README]
- gcc 11.x installed [C++20 support is enabled but compilers support can be found here]
- Linux: install CMake, gcc and editor of your choice and follow Recommended way of using CMake paragraph
- Windows: install Visual Studio with C++ support (include CMake support for C++)
- To generate project:
cmake -B <build-dir> -S <source-dir>
- To compile generated project:
cmake --build <build-dir>
To generate code coverage using lcov you need to use linux OS and follow steps:
- Generate project with 'COVERAGE' option included:
cmake -B <build-dir> -S <source-dir> -DCOVERAGE=ON
- Compile project:
cmake --build <build-dir>
- Install lcov tool
- Navigate into and invoke:
generate_code_coverage.py
script- It will create new directory: code_coverage which will contain essential files.
- Navigate into code_coverage directory and use your web-browser to inspect
index.html
file which will contain code-coverage for the project
Code-coverage pipeline is creating code coverage report and deploying it on GitHub-pages. It can be found here
To check if project contains any memory corrution issues valgrind tool can be used.
- Build project with CMake following Recommended way of using CMake paragraph
- Execute command
valgrind -s -v --error-exitcode=1 --leak-check=full <path-to-certain-unit-test-suite>
To use sanitizers checks first of all project have to be build with additional flags:
- For Addess Sanitizers:
cmake -B <build-dir> -S <source-dir> -DASan=ON
- For Leak Sanitizers:
cmake -B <build-dir> -S <source-dir> -DLSan=ON
- For UndefinedBehavior Sanitizer
cmake -B <build-dir> -S <source-dir> -DUBSan=ON
After successful build and tests execution there will be available logs with sanitizers output printed. More information about sanitizers can be found in officall GitHub repository
Follow instructions here to install Docker on your Ubuntu distribution
After successful installation and setup of docker execute build_and_run.py
script to build project and run all unit-tests. This method won't produce output directory.
- To build docker image run
docker build --tag containers-docker --build-arg UID=$(id -u) --build-arg GID=$(id -g) .
- To run previously builded image run
docker run --user $(id -u):$(id -g) --rm --volume $(pwd):/workspace/containers:rw containers-docker /bin/bash
In repository there are planty of python scripts to execute. Recommended way to work with them is to create virtual environment for python3 by following instructions:
- install python3.x and python3.x-venv on OS
- create virtual environment by calling
python3.x -m venv <name-of-local-venv>
- activate virtual environment by calling
source <name-of-local-venv>/bin/activate