Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cpp-build-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
# - Add `--warnings-as-errors=*` to exit code 1
# -------------------------------------------------------
- name: Run clang-tidy
continue-on-error: true
# run: |
# echo "Running clang-tidy..."
# clang-tidy \
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ FROM ubuntu:24.04
RUN \
# updates the package lists for upgrades for packages that need upgrading,
apt-get update && \
# install cmake, gcc, g++
# install cmake, gcc, g++, git
apt-get install -y cmake && \
apt-get install -y gcc g++ && \
apt-get install -y git && \
# install cppcheck
apt-get install -y cppcheck && \
# install clang tidy
Expand Down
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@

**Project Hierarchy**
```
includes/ → Header files (.h, .hpp)
include/ → Header files (.h, .hpp)
src/ → Source files (.cpp)
tests/ → GoogleTest test cases
scripts/ → Build and coverage helper scripts
cmake/ → CMake dependency modules
docs/ → Documentation and UML diagrams
```

## 2. Dependencies
Make sure the following tools are installed before building the project:
- **g++ / gcc**
- **CMake**
- **CMake** (>= 3.14)
- **Git**
- **lcov** (for code coverage)
- **cppcheck** (for static analysis)
Expand All @@ -36,7 +39,7 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma
## 3. Setup
### 3.1. Setup the Local Test Environment
- **Ubuntu system**
* Install `gcc`, `cmake`, `git`, and `pthread` (Skip this step if you already install)
* Install `gcc`, `cmake`, `git`, and other tools (skip if already installed)
```bash
$ sudo apt-get update
$ sudo apt-get install g++
Expand All @@ -50,18 +53,17 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma
```
* Build the application and the tests
```bash
$ cd build
$ cmake ..
$ cmake --build .
$ cmake -S . -B build
$ cmake --build build
```
* Run the application and the test
```bash
$ ./bin/cpp_lab_project
$ ./bin/cpp_lab_project_test
$ ./build/bin/cpp_lab_project
$ ./build/bin/cpp_lab_project_unit_test
```
* Detect Memory Leak Using [valgrind](https://valgrind.org/)
```bash
$ valgrind --leak-check=full -v ./cpp-lab
$ valgrind --leak-check=full -v ./build/bin/cpp_lab_project
```
* (Optional) Run static analysis - cppcheck
```bash
Expand All @@ -75,11 +77,14 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma
```bash
$ ./scripts/gen_coverage_lcov.sh
```
* (Optional) Run coverage - gcovr
```bash
$ ./scripts/gen_coverage_gcovr.sh
```
- **Docker**
* Update `Dockerfile`
* Build the Docker image
```
$ cd build
$ docker build --tag cpp-lab .
```
* Run an interactive container
Expand Down Expand Up @@ -234,7 +239,7 @@ Notes:
### 3.3 Documentation with `doxygen`
TBD - Refer to this [Documentation with doxygen](https://www.labri.fr/perso/fleury/posts/programming/using-cmake-googletests-and-gcovr-in-a-c-project.html#:~:text=of%20the%C2%A0project.-,Documentation%20with%20doxygen,-Code%20embedded%20documentation)

## 5. Update Docker Image
## 4. Update Docker Image
```bash
# Navigate to the project that contain your Dockerfile
cd cpp-lab
Expand All @@ -249,19 +254,19 @@ docker image ls
docker push DOCKER_USERNAME/cpp-lab
```

## 6. TroubleShooting
## 5. TroubleShooting
1. `push access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed`
=> docker login / Docker Desktop login

## 7. Evaluate Executable
## 6. Evaluate Executable
- List all sections:
```bash
$ size ./build/cpp-lab
$ size ./build/bin/cpp_lab_project
```
- The expected output should be the following:
```bash
text data bss dec hex filename
14791 792 280 15863 ./build/cpp-lab
14791 792 280 15863 3df7 ./build/bin/cpp_lab_project
```

- `.text`: Text Segment - the executable code size, including: complied function, inline, template, constants, string literals
Expand Down
10 changes: 7 additions & 3 deletions scripts/gen_coverage_gcovr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi
if [ ! -d build ]; then
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="--coverage -O0 -g"
-DENABLE_COVERAGE=ON
fi

# -----------------------------------------------------------------------------
Expand All @@ -41,6 +41,10 @@ gcovr -r . build \
-o coverage_gcovr/index.html

# -----------------------------------------------------------------------------
# Open coverage report
# Open coverage report (skip in headless environments)
# -----------------------------------------------------------------------------
xdg-open coverage_gcovr/index.html
if command -v xdg-open >/dev/null 2>&1; then
xdg-open coverage_gcovr/index.html
else
echo "Coverage report generated at: coverage_gcovr/index.html"
fi
10 changes: 7 additions & 3 deletions scripts/gen_coverage_lcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi
if [ ! -d build ]; then
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="--coverage -O0 -g"
-DENABLE_COVERAGE=ON
fi

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -56,6 +56,10 @@ genhtml coverage_lcov/coverage.info \
--output-directory coverage_lcov

# -----------------------------------------------------------------------------
# Open coverage report
# Open coverage report (skip in headless environments)
# -----------------------------------------------------------------------------
xdg-open coverage_lcov/index.html
if command -v xdg-open >/dev/null 2>&1; then
xdg-open coverage_lcov/index.html
else
echo "Coverage report generated at: coverage_lcov/index.html"
fi
24 changes: 3 additions & 21 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
#!/usr/bin/env bash
## NOTE:
## This file was initially generated with the assistance of AI.
## The code has been reviewed and may have been modified by the developer
## to ensure correctness, readability, and compliance with project requirements.
#!/usr/bin/env bash

set -e # Exit immediately if a command fails

PROJECT_EXEC="./build/bin/cpp_lab_project"
BUILD_DIR="./build"

# if [ ! -d "build" ]; then
# echo "Build directory not found. Creating build directory..."

# rm -rf build
# mkdir build
# cd build || exit

# cmake ..
# cd ..

# else
# echo "Build directory already exists."
# fi

clear
echo "=============================="
echo " Starting build pipeline... "
echo "=============================="

# Check required tools
for tool in cmake cppcheck python3; do
if ! command -v $tool &> /dev/null; then
for tool in cmake cppcheck; do
if ! command -v "$tool" &> /dev/null; then
echo "[ERR]: $tool is not installed."
exit 1
fi
Expand All @@ -53,10 +39,6 @@ cppcheck \

echo "[OK] Static analysis passed"

echo ""
echo "===========>> Generating commit id..."
python3 ./private/genid.py

echo ""
echo "===========>> Running program..."
if [ -f "$PROJECT_EXEC" ]; then
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GoogleTest
- GoogleTest helps you write better C++ tests.
## 1. Basic Concepts
- **assertions:** the statememts that check whether a condition is true. The result can be:
- **assertions:** the statements that check whether a condition is true. The result can be:
- success
- nonfatal failure
- fatal failure
Expand Down