From e7a22964136c35169accb50b129725a72350af88 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:00:10 +0330 Subject: [PATCH 01/10] ci: add valgrind ci Dockerfile & refactor: add g++ --version to unit_tests Dockerfile --- tools/ci/images/unit_tests/Dockerfile | 2 +- tools/ci/images/valgrind/Dockerfile | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tools/ci/images/valgrind/Dockerfile diff --git a/tools/ci/images/unit_tests/Dockerfile b/tools/ci/images/unit_tests/Dockerfile index 453253f..e8fc2b6 100644 --- a/tools/ci/images/unit_tests/Dockerfile +++ b/tools/ci/images/unit_tests/Dockerfile @@ -22,9 +22,9 @@ RUN clang --version \ && conan --version \ && pip --version \ && cmake --version \ + && g++ --version \ && clang --version - RUN git clone 'https://git.light7734.com/light7734/light.git' --recursive \ && cd light \ && conan install . \ diff --git a/tools/ci/images/valgrind/Dockerfile b/tools/ci/images/valgrind/Dockerfile new file mode 100644 index 0000000..551d1f7 --- /dev/null +++ b/tools/ci/images/valgrind/Dockerfile @@ -0,0 +1,37 @@ +FROM alpine:latest + +RUN apk add --no-cache \ + bash \ + clang \ + llvm \ + cmake \ + git \ + make \ + g++ \ + python3 \ + py3-pip \ + mesa-dev \ + mesa-gl \ + pkgconf \ + valgrind + +RUN pip install --no-cache-dir --break-system-packages conan gitpython \ + && conan profile detect + +RUN clang --version \ + && conan --version \ + && pip --version \ + && cmake --version \ + && g++ --version \ + && clang --version + +RUN git clone 'https://git.light7734.com/light7734/light.git' --recursive \ + && cd light \ + && conan install . \ + -s build_type=Debug \ + -c tools.system.package_manager:mode=install \ + --build=missing \ + && conan install . \ + -s build_type=Release \ + -c tools.system.package_manager:mode=install \ + --build=missing -- 2.45.3 From 78bf280541202310436aa56c9aa7e79269360f0a Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:05:03 +0330 Subject: [PATCH 02/10] ci: add valgrind check --- .drone.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.drone.yml b/.drone.yml index 8707deb..d97852d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -66,6 +66,36 @@ steps: "$test" done +--- +kind: pipeline +type: docker +name: valgrind +clone: + recursive: true + submodule_update_remote: true + +trigger: + branch: + - main + +steps: +- name: valgrind + image: valgrind:latest + pull: if-not-exists + commands: + - | + set -e + + git submodule update --init --recursive + conan build . \ + -c tools.system.package_manager:mode=install \ + -s build_type=Release \ + -o enable_static_analysis=False \ + -o enable_tests=True \ + --build=missing + + find ./build -type f -name "tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 + --- kind: pipeline type: docker -- 2.45.3 From 160e94680becbb857094723cd25d7b94092f6589 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:07:18 +0330 Subject: [PATCH 03/10] wip: remove other ci checks for quick iterations --- .drone.yml | 96 ------------------------------------------------------ 1 file changed, 96 deletions(-) diff --git a/.drone.yml b/.drone.yml index d97852d..1919a5b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,74 +1,5 @@ kind: pipeline type: docker -name: clang format -clone: - recursive: true - submodule_update_remote: true - -trigger: - branch: - - main - -steps: -- name: clang format - image: clang_format:latest - pull: if-not-exists - commands: - - | - set -e - clang-format --version - has_fomatting_issues=0 - - for file in $(find ./modules -name '*.?pp'); do - echo "Checking format for $file" - if ! clang-format --dry-run --Werror "$file"; then - echo "❌ Formatting issue detected in $file" - has_fomatting_issues=1 - fi - done - - if [ "$has_fomatting_issues" -eq 0 ]; then - echo "✅ All files are properly formatted! Well done! ^~^" - fi - - exit ${has_fomatting_issues} - ---- -kind: pipeline -type: docker -name: unit tests -clone: - recursive: true - submodule_update_remote: true - -trigger: - branch: - - main - -steps: -- name: unit tests - image: unit_tests:latest - pull: if-not-exists - commands: - - | - set -e - - git submodule update --init --recursive - conan build . \ - -c tools.system.package_manager:mode=install \ - -s build_type=Release \ - -o enable_static_analysis=False \ - -o enable_tests=True \ - --build=missing - - for test in $(find ./build -type f -name '*_tests' -executable); do - echo "Running $test" - "$test" - done - ---- -kind: pipeline -type: docker name: valgrind clone: recursive: true @@ -96,30 +27,3 @@ steps: find ./build -type f -name "tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 ---- -kind: pipeline -type: docker -name: static analysis -clone: - recursive: true - submodule_update_remote: true - -trigger: - branch: - - main - -steps: -- name: static_analysis - image: static_analysis:latest - pull: if-not-exists - privileged: true - commands: - - | - git submodule update --init --recursive - - conan build . \ - -c tools.system.package_manager:mode=install \ - -s build_type=Release \ - -o enable_static_analysis=True \ - -o enable_tests=True \ - --build=missing -- 2.45.3 From 6f1a3a291f47104b039f789b350d8e85b4107c70 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:13:31 +0330 Subject: [PATCH 04/10] wip --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 1919a5b..b8cc3f6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -25,5 +25,5 @@ steps: -o enable_tests=True \ --build=missing - find ./build -type f -name "tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 + find ./build -type f -name "*_tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 -- 2.45.3 From 3e79504fac13d4e8e8d84297e67eadfb58664c91 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:26:54 +0330 Subject: [PATCH 05/10] fix: timer tests --- modules/time/src/timer.tests.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/time/src/timer.tests.cpp b/modules/time/src/timer.tests.cpp index bbb16fc..0c84bfe 100644 --- a/modules/time/src/timer.tests.cpp +++ b/modules/time/src/timer.tests.cpp @@ -6,6 +6,12 @@ namespace lt { using lt::test::expect_le; +// error margin is high since run-time may slow down extremely due to +// sanitization/debugging or execution through valgrind... +// +// <1us error margin is tested manually in release builds and it works fine. +constexpr auto max_error_margin = std::chrono::milliseconds { 1 }; + lt::test::Suite raii = [] { using std::chrono::microseconds; @@ -34,14 +40,14 @@ lt::test::Suite reset_and_elapsed_time = [] { }; lt::test::Case { "elapsed time is sane" } = [] { - expect_le(Timer {}.elapsed_time(), microseconds { 1 }); + expect_le(Timer {}.elapsed_time(), max_error_margin); }; lt::test::Case { "elapsed time is sane - constructed with old now" } = [] { const auto timepoint = Timer::Clock::now() - hours { 1 }; // This fails sometimes in debug if error-range is under 10us - expect_le(Timer { timepoint }.elapsed_time(), hours { 1 } + microseconds { 30 }); + expect_le(Timer { timepoint }.elapsed_time(), hours { 1 } + max_error_margin); }; lt::test::Case { "reset -> elapsed time is sane - constructed with old now" } = [] { @@ -49,7 +55,7 @@ lt::test::Suite reset_and_elapsed_time = [] { const auto old_elapsed_time = timer.elapsed_time(); timer.reset(); - expect_le(timer.elapsed_time() - old_elapsed_time, microseconds { 101 }); + expect_le(timer.elapsed_time() - old_elapsed_time, microseconds { 100 } + max_error_margin); }; lt::test::Case { "reset -> elapsed time is sane - reset with future now" } = [] { @@ -57,7 +63,7 @@ lt::test::Suite reset_and_elapsed_time = [] { const auto old_elapsed_time = timer.elapsed_time(); timer.reset(Timer::Clock::now() + microseconds { 100 }); - expect_le(timer.elapsed_time() - old_elapsed_time, microseconds { 101 }); + expect_le(timer.elapsed_time() - old_elapsed_time, microseconds { 100 } + max_error_margin); }; }; -- 2.45.3 From 8ca1ed2bd6121299588f24cc16415fcc59cda74f Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:33:18 +0330 Subject: [PATCH 06/10] wip: checking if valgrind fails --- modules/time/src/timer.tests.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/time/src/timer.tests.cpp b/modules/time/src/timer.tests.cpp index 0c84bfe..e14afb0 100644 --- a/modules/time/src/timer.tests.cpp +++ b/modules/time/src/timer.tests.cpp @@ -28,6 +28,9 @@ lt::test::Suite raii = [] { Timer {}; } }; + + int *leak = new int(42); // Allocated memory, never freed + std::cout << "Hello, Valgrind!" << *leak << std::endl; }; lt::test::Suite reset_and_elapsed_time = [] { -- 2.45.3 From c070b7abffa2c388b0cf8d0830a31bb3241816b7 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:40:17 +0330 Subject: [PATCH 07/10] wip: test if valgrind fails --- modules/time/src/timer.tests.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/time/src/timer.tests.cpp b/modules/time/src/timer.tests.cpp index e14afb0..4d7a98d 100644 --- a/modules/time/src/timer.tests.cpp +++ b/modules/time/src/timer.tests.cpp @@ -12,6 +12,8 @@ using lt::test::expect_le; // <1us error margin is tested manually in release builds and it works fine. constexpr auto max_error_margin = std::chrono::milliseconds { 1 }; +volatile int *volatile global_leak {}; + lt::test::Suite raii = [] { using std::chrono::microseconds; @@ -29,8 +31,8 @@ lt::test::Suite raii = [] { } }; - int *leak = new int(42); // Allocated memory, never freed - std::cout << "Hello, Valgrind!" << *leak << std::endl; + global_leak = new int(42); // Allocated memory, never freed + std::cout << "Hello, Valgrind!" << *global_leak << std::endl; }; lt::test::Suite reset_and_elapsed_time = [] { -- 2.45.3 From e0a177a73f33be5995fc7dca854a8715bd0b05c9 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:44:31 +0330 Subject: [PATCH 08/10] fucking fail ffs! --- modules/time/src/timer.tests.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/time/src/timer.tests.cpp b/modules/time/src/timer.tests.cpp index 4d7a98d..2320342 100644 --- a/modules/time/src/timer.tests.cpp +++ b/modules/time/src/timer.tests.cpp @@ -22,6 +22,13 @@ lt::test::Suite raii = [] { }; lt::test::Case { "unhappy path throws" } = [] { + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed + global_leak = new int(42); // Allocated memory, never freed }; lt::test::Case { "plenty" } = [] { -- 2.45.3 From 72cc558a7ac53c64d7527dbe3ee9f67cf1c56fc4 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:48:44 +0330 Subject: [PATCH 09/10] wip: should pass now --- modules/time/src/timer.tests.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/modules/time/src/timer.tests.cpp b/modules/time/src/timer.tests.cpp index 2320342..0c84bfe 100644 --- a/modules/time/src/timer.tests.cpp +++ b/modules/time/src/timer.tests.cpp @@ -12,8 +12,6 @@ using lt::test::expect_le; // <1us error margin is tested manually in release builds and it works fine. constexpr auto max_error_margin = std::chrono::milliseconds { 1 }; -volatile int *volatile global_leak {}; - lt::test::Suite raii = [] { using std::chrono::microseconds; @@ -22,13 +20,6 @@ lt::test::Suite raii = [] { }; lt::test::Case { "unhappy path throws" } = [] { - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed - global_leak = new int(42); // Allocated memory, never freed }; lt::test::Case { "plenty" } = [] { @@ -37,9 +28,6 @@ lt::test::Suite raii = [] { Timer {}; } }; - - global_leak = new int(42); // Allocated memory, never freed - std::cout << "Hello, Valgrind!" << *global_leak << std::endl; }; lt::test::Suite reset_and_elapsed_time = [] { -- 2.45.3 From 2bd0c39e7a8a0d56db581eb04b308902e3f577c9 Mon Sep 17 00:00:00 2001 From: light7734 Date: Thu, 17 Jul 2025 11:50:09 +0330 Subject: [PATCH 10/10] ci: add back other ci checks --- .drone.yml | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/.drone.yml b/.drone.yml index b8cc3f6..fe3fd6d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,3 +1,37 @@ +--- +kind: pipeline +type: docker +name: unit tests +clone: + recursive: true + submodule_update_remote: true + +trigger: + branch: + - main + +steps: +- name: unit tests + image: unit_tests:latest + pull: if-not-exists + commands: + - | + set -e + + git submodule update --init --recursive + conan build . \ + -c tools.system.package_manager:mode=install \ + -s build_type=Release \ + -o enable_static_analysis=False \ + -o enable_tests=True \ + --build=missing + + for test in $(find ./build -type f -name '*_tests' -executable); do + echo "Running $test" + "$test" + done + +--- kind: pipeline type: docker name: valgrind @@ -27,3 +61,66 @@ steps: find ./build -type f -name "*_tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 +--- +kind: pipeline +type: docker +name: static analysis +clone: + recursive: true + submodule_update_remote: true + +trigger: + branch: + - main + +steps: +- name: static_analysis + image: static_analysis:latest + pull: if-not-exists + privileged: true + commands: + - | + git submodule update --init --recursive + + conan build . \ + -c tools.system.package_manager:mode=install \ + -s build_type=Release \ + -o enable_static_analysis=True \ + -o enable_tests=True \ + --build=missing + +--- +kind: pipeline +type: docker +name: clang format +clone: + recursive: true + submodule_update_remote: true + +trigger: + branch: + - main + +steps: +- name: clang format + image: clang_format:latest + pull: if-not-exists + commands: + - | + set -e + clang-format --version + has_fomatting_issues=0 + + for file in $(find ./modules -name '*.?pp'); do + echo "Checking format for $file" + if ! clang-format --dry-run --Werror "$file"; then + echo "❌ Formatting issue detected in $file" + has_fomatting_issues=1 + fi + done + + if [ "$has_fomatting_issues" -eq 0 ]; then + echo "✅ All files are properly formatted! Well done! ^~^" + fi + + exit ${has_fomatting_issues} -- 2.45.3