ci: add valgrind check #5
					 4 changed files with 114 additions and 40 deletions
				
			
		
							
								
								
									
										101
									
								
								.drone.yml
									
										
									
									
									
								
							
							
						
						
									
										101
									
								
								.drone.yml
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,38 +1,3 @@
 | 
			
		|||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +31,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
 | 
			
		||||
| 
						 | 
				
			
			@ -93,3 +88,39 @@ steps:
 | 
			
		|||
        -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}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
	};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 . \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								tools/ci/images/valgrind/Dockerfile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								tools/ci/images/valgrind/Dockerfile
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue