#!/bin/bash ############################################################################## # MIT License # # Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. ############################################################################## # generate coverage for develop branch - stores file in repo set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [[ "$SCRIPT_DIR" == */projects/rocprofiler-compute/* ]]; then PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" MONOREPO_ROOT="$(cd "$PROJECT_ROOT/../.." && pwd)" IS_MONOREPO=true else PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" MONOREPO_ROOT="" IS_MONOREPO=false fi BUILD_DIR="$PROJECT_ROOT/build" COVERAGE_FILE="$PROJECT_ROOT/coverage/coverage-latest.xml" echo "=== Generating Coverage for rocprofiler-compute ===" echo "Project root: $PROJECT_ROOT" if [ "$IS_MONOREPO" = true ]; then echo "Monorepo root: $MONOREPO_ROOT" fi echo "Setting up clean build..." rm -rf "$BUILD_DIR" mkdir -p "$BUILD_DIR" cd "$BUILD_DIR" echo "Configuring with coverage enabled..." cmake -DENABLE_COVERAGE=ON -DENABLE_TESTS=ON -DPYTEST_NUMPROCS=8 .. echo "Building..." make -j$(nproc) echo "Running ALL tests to generate coverage (this may take a while)..." ctest --verbose --output-on-failure --parallel 1 || { echo "WARNING: Some tests failed, but continuing with coverage generation" } echo "Generating coverage report..." if ctest -R generate_coverage_report --output-on-failure --parallel 2; then echo "Coverage report generated via ctest" else echo "Trying alternative coverage generation..." cd "$PROJECT_ROOT" python3 -m coverage combine || true python3 -m coverage xml -o "$BUILD_DIR/coverage.xml" cd "$BUILD_DIR" fi if [ ! -f "coverage.xml" ]; then echo "ERROR: coverage.xml not generated" exit 1 fi COVERAGE_INFO=$(python3 -c " import xml.etree.ElementTree as ET tree = ET.parse('coverage.xml') root = tree.getroot() line_rate = float(root.get('line-rate', 0)) * 100 print(f'{line_rate:.1f}%') ") mkdir -p "$PROJECT_ROOT/coverage" cp coverage.xml "$COVERAGE_FILE" echo "" echo "=== Coverage Generated Successfully ===" echo "Line Coverage: $COVERAGE_INFO" echo "File: $COVERAGE_FILE" echo "" echo "Coverage file generated: coverage/coverage-latest.xml" echo "To update official coverage:" echo " 1. Commit this file to develop branch" echo " 2. GitHub Actions will automatically upload to CDash"