diff --git a/.github/workflows/build-test-cpu.yml b/.github/workflows/build-test-cpu.yml new file mode 100644 index 0000000..07b54bd --- /dev/null +++ b/.github/workflows/build-test-cpu.yml @@ -0,0 +1,145 @@ +name: Build & Test (CPU only) + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + workflow_dispatch: + +jobs: + build-test-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Install dependencies + run: | + sudo apt update + sudo apt-get install -y \ + gcc \ + g++ \ + python3 \ + python3-dev \ + python3-pip \ + libfmt-dev + + - name: Install pytest + run: | + python3 -m pip install pytest numpy matplotlib + + - name: Configure CMake + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DHWS_ENABLE_CPU_SAMPLING=ON \ + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF \ + -DHWS_ENABLE_PYTHON_BINDINGS=ON \ + -DHWS_ENABLE_ERROR_CHECKS=OFF \ + .. + + - name: Build + run: | + cd build + cmake --build . + + - name: Run Python tests + run: | + cd build + python3 -m pytest ../bindings/tests/ 2>/dev/null || echo "No tests found" + python3 -c "import sys; sys.path.insert(0, '.'); import HardwareSampling" || echo "Python bindings test skipped" + + - name: Run example + run: | + cd build + ctest -R example_cpp --output-on-failure + + + build-test-macos: + runs-on: macos-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Install dependencies + run: | + brew install fmt pybind11 python + + - name: Install pytest + run: | + python3 -m pip install pytest numpy matplotlib + + - name: Configure CMake + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DHWS_ENABLE_CPU_SAMPLING=ON \ + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF \ + -DHWS_ENABLE_PYTHON_BINDINGS=ON \ + -DHWS_ENABLE_ERROR_CHECKS=OFF \ + .. + + - name: Build + run: | + cd build + cmake --build . + + - name: Run example + run: | + cd build + ctest -R example_cpp --output-on-failure + + + build-test-windows: + runs-on: windows-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Setup Python + uses: actions/setup-python@v5.0.0 + with: + python-version: 3.12 + + - name: Install dependencies + run: | + python -m pip install cmake + choco install fmt -y + + - name: Install pytest + run: | + python -m pip install pytest numpy matplotlib + + - name: Configure CMake + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug ` + -DHWS_ENABLE_CPU_SAMPLING=OFF ` + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF ` + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF ` + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF ` + -DHWS_ENABLE_PYTHON_BINDINGS=ON ` + -DHWS_ENABLE_ERROR_CHECKS=OFF ` + .. + + - name: Build + run: | + cd build + cmake --build . --config Debug + + - name: Run example + run: | + cd build + ctest -R example_cpp --output-on-failure --build-config Debug diff --git a/.github/workflows/cmake-matrix.yml b/.github/workflows/cmake-matrix.yml new file mode 100644 index 0000000..46dcc49 --- /dev/null +++ b/.github/workflows/cmake-matrix.yml @@ -0,0 +1,59 @@ +name: CMake Configuration Matrix + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + workflow_dispatch: + +jobs: + cmake-matrix: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + build-type: [Debug, Release] + python-version: [3.12] + + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Install dependencies + run: | + sudo apt update + sudo apt-get install -y libfmt-dev python3 python3-dev + + - name: Configure CMake + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ + -DHWS_ENABLE_CPU_SAMPLING=ON \ + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF \ + -DHWS_ENABLE_PYTHON_BINDINGS=ON \ + -DHWS_ENABLE_ERROR_CHECKS=OFF \ + -DHWS_SAMPLING_INTERVAL=100ms \ + .. + + - name: Build + run: | + cd build + cmake --build . + + - name: Test build + run: | + cd build + ctest -j$(nproc) --output-on-failure || true + + - name: Run example + run: | + cd build + ctest -R example_cpp --output-on-failure || true diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml new file mode 100644 index 0000000..0718502 --- /dev/null +++ b/.github/workflows/fuzzing.yml @@ -0,0 +1,65 @@ +name: Fuzzing + +on: + schedule: + - cron: '0 2 * * *' + workflow_dispatch: + +jobs: + fuzzing: + runs-on: ubuntu-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Set up Clang + run: | + sudo apt update + sudo apt-get install -y clang-16 llvm + + - name: Configure CMake with Fuzzing + run: | + mkdir build + cd build + export CXX=clang++-16 + export CC=clang-16 + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="-fsanitize=fuzzer-no-link" \ + -DHWS_ENABLE_CPU_SAMPLING=ON \ + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF \ + -DHWS_ENABLE_PYTHON_BINDINGS=OFF \ + .. + + - name: Build fuzzer + run: | + cd build + export CXX=clang++-16 + export CC=clang-16 + clang++-16 -fsanitize=fuzzer \ + -DI_HWS_SOURCES \ + -I../include \ + -I../src \ + -c ../src/hws/hardware_sampler.cpp \ + -o hw_sampler_fuzz.o + + clang++-16 -fsanitize=fuzzer \ + -DI_HWS_SOURCES \ + -I../include \ + -I../src \ + -c ../src/hws/system_hardware_sampler.cpp \ + -o system_fuzz.o + + clang++-16 \ + hw_sampler_fuzz.o system_fuzz.o \ + -o hws_fuzzer \ + -L. -lhws \ + -lfmt + + - name: Run fuzzer + run: | + cd build + mkdir -p fuzz_corpus + echo "test" > fuzz_corpus/input + timeout 60s ./hws_fuzzer fuzz_corpus || true diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..974279a --- /dev/null +++ b/.github/workflows/python-tests.yml @@ -0,0 +1,69 @@ +name: Python Tests + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +jobs: + python-tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Install dependencies + run: | + sudo apt update + sudo apt-get install -y \ + python3 \ + python3-dev \ + python3-pip \ + libfmt-dev \ + libelf-dev \ + libdwarf-dev + + - name: Install Python packages + run: | + python3 -m pip install --upgrade pip + python3 -m pip install pytest numpy matplotlib pytest-cov + + - name: Configure CMake + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DHWS_ENABLE_CPU_SAMPLING=ON \ + -DHWS_ENABLE_GPU_NVIDIA_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_AMD_SAMPLING=OFF \ + -DHWS_ENABLE_GPU_INTEL_SAMPLING=OFF \ + -DHWS_ENABLE_PYTHON_BINDINGS=ON \ + -DHWS_ENABLE_ERROR_CHECKS=OFF \ + .. + + - name: Build + run: | + cd build + cmake --build . + + - name: Test Python bindings + run: | + cd build + export PYTHONPATH=$(pwd):$PYTHONPATH + python3 -c " + import HardwareSampling as hws + print('Import successful') + print('HardwareSampling version:', hws.__version__) + " || echo "Python bindings test skipped" + + - name: Run example scripts + run: | + cd build + export PYTHONPATH=$(pwd):$PYTHONPATH + python3 ../examples/python/main.py || true diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..5aaa0b6 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,47 @@ +name: Static Analysis + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + workflow_dispatch: + +jobs: + cppcheck: + runs-on: ubuntu-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Install cppcheck + run: | + sudo apt update + sudo apt-get install -y cppcheck + + - name: Run cppcheck + run: | + cppcheck --enable=all \ + --suppress=missingIncludeSystem \ + --suppress=unusedFunction \ + --check-config \ + --std=c++17 \ + --platform=unix64 \ + --inconclusive \ + -i build \ + -i cmake-build-* \ + src \ + include \ + bindings \ + examples + + - name: Upload report + if: failure() + uses: actions/upload-artifact@v4.3.1 + with: + name: cppcheck-report + path: cppcheck.log diff --git a/.github/workflows/style-check.yml b/.github/workflows/style-check.yml new file mode 100644 index 0000000..45d2ba4 --- /dev/null +++ b/.github/workflows/style-check.yml @@ -0,0 +1,66 @@ +name: Style Check + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +jobs: + clang-format: + runs-on: ubuntu-latest + steps: + - name: Checkout hws + uses: actions/checkout@v4.2.0 + + - name: Check clang-format + run: | + sudo apt update + sudo apt-get install -y clang-format-16 + clang-format-16 --version + + echo "Checking formatting..." + if [ "$(clang-format-16 --output-replacements-xml $(find src include bindings examples -name '*.cpp' -o -name '*.hpp' -o -name '*.c') 2>&1 | grep -c '