Skip to content

i.smap: Test with cmake llvm sanitizers #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cf4a759
i.smap: fix possible pole error with log in extract function
ymdatta Oct 11, 2024
0af9fc2
Add llvm's prepare-code-coverage-artifact.py script
echoix May 25, 2025
b92c2a4
Format utils/prepare-code-coverage-artifact.py
echoix May 25, 2025
472badd
Apply fixes to utils/prepare-code-coverage-artifact.py
echoix May 25, 2025
742da64
Apply manual fixes to utils/prepare-code-coverage-artifact.py
echoix May 25, 2025
daa33cc
Add json coverage export function to utils/prepare-code-coverage-arti…
echoix May 25, 2025
279da8a
CI(macOS): Add steps to handle coverage
echoix May 25, 2025
b7626bd
CI(macOS): Use modified LLVM coverage script
echoix May 25, 2025
f625e5b
CI(macOS): Add flags for source-based code coverage
echoix May 25, 2025
8d28f8f
Reorder arguments to show flags before object arguments
echoix May 25, 2025
40dd1c2
Use correct export command
echoix May 25, 2025
017d564
CI(macOS): Remove unused lines when using coverage script and format …
echoix May 25, 2025
1454ed9
llvm-cov export doesn't support the output argument -o
echoix May 25, 2025
ff46101
Only upload one coverage file
echoix May 25, 2025
bd267be
Skip exporting functions in json coverage file
echoix May 25, 2025
3dc7a95
Adapt coverage script to output coverage as lcov
echoix May 25, 2025
a5a6bc7
CI(macOS): Delete some extra files before uploading
echoix May 25, 2025
e1c51df
Fix file mode for report file opening in coverage script
echoix May 25, 2025
280e7d2
Add restrict to raster folder
echoix May 25, 2025
8de499e
Add encoding to exported file name
echoix May 25, 2025
f135e48
Add ignore-filename-regex argument for dist folder
echoix May 25, 2025
85e6ddc
CI(macOS): Use previous codecov action version
echoix May 25, 2025
adf09f7
Merge branch 'macos-coverage-llvm-source' of https://github.com/echoi…
echoix May 25, 2025
e5d8247
Change find command to stay on one line
echoix May 25, 2025
0c309a2
Remove restriction on folder name
echoix May 25, 2025
f53d34d
Do not collect binaries, only dylibs
echoix May 25, 2025
b530d68
Downgrade codecov action to 5.4.0
echoix May 25, 2025
a7b8b3d
Downgrade codecov cli version
echoix May 25, 2025
a5e95fd
Output lcov format
echoix May 25, 2025
3a5d9e3
Output json format
echoix May 26, 2025
232091d
Upload both types of files if present
echoix May 26, 2025
c010e9b
Upgrade back codecov/codecov-action to 5.4.3
echoix May 26, 2025
62466a5
Remove dist ignore regex
echoix May 26, 2025
0914e6c
Export lcov for executable and dylib
echoix May 26, 2025
85cec99
Only upload lcov file
echoix May 26, 2025
68fec44
Use v10.4.0 codecov-cli version
echoix May 26, 2025
cd47820
Remove old original cov binaries find
echoix May 26, 2025
f674049
Remove special handling of codecov arguments
echoix May 26, 2025
c92e150
Remove deletion of files
echoix May 26, 2025
f794efb
Reenable gunittest test suite
echoix May 26, 2025
204a197
Merge branch main into macos-coverage-llvm-source
echoix May 28, 2025
3160cd1
Try to only use -object named parameter for export
echoix May 28, 2025
bfaf637
Remove commented-out ignore patterns in script
echoix May 28, 2025
8a95f92
Revert: Try to only use -object named parameter for export
echoix May 28, 2025
45e9413
Merge branch 'main' into macos-coverage-llvm-source
echoix May 30, 2025
ddb16c6
Merge branch 'macos-coverage-llvm-source' into macos-coverage-llvm-so…
echoix May 30, 2025
cba9830
CI(macOS): upload code coverage even on failures
echoix May 30, 2025
6beaea8
Merge branch 'macos-coverage-llvm-source-test1' of https://github.com…
echoix May 30, 2025
56ec158
Pin Codecov action version in macos.yml
echoix May 30, 2025
0dd7627
Move objects list before other arguments in llvm-cov export call
echoix May 30, 2025
38c3896
CI(macOS): Use make -j1 to see if mismatched data dissapears
echoix May 30, 2025
050bb2e
CI(macOS): Use the processid in the profraw files
echoix May 30, 2025
11b6093
CI(cmake): Compile using llvm
echoix May 30, 2025
50871de
CMake: Add compiler flags for llvm source code coverage
echoix May 30, 2025
e39dbd1
CMake: install clang 19 with libomp
echoix May 30, 2025
4e26df5
Remove trailing whitespace
echoix May 30, 2025
595f2d9
Add CMAKE_C_FLAGS for profiling and coverage mapping
echoix May 30, 2025
1135a4d
Add directory creation for LLVM_PROFDATA in CI config
echoix May 30, 2025
bec3f0d
CI: install missing llvm-profdata
echoix May 30, 2025
e14956d
Revert: Add directory creation for LLVM_PROFDATA in CI config
echoix May 30, 2025
c74cb4b
Merge branch 'main' into cppcheck_imagery_log1
echoix May 31, 2025
2582398
Merge branch 'main' into macos-coverage-llvm-source
echoix May 31, 2025
65bbcbb
Merge branch 'main' into macos-coverage-llvm-source
echoix Jun 4, 2025
147124f
Merge branch 'macos-coverage-llvm-source' into macos-coverage-llvm-so…
echoix Jun 4, 2025
5e5f7ab
Merge branch 'macos-coverage-llvm-source-test1' into cmake-llvm-cover…
echoix Jun 4, 2025
00d1616
Use llvm-profdata-19 for llvm-profdata
echoix Jun 5, 2025
f23d173
CI(CMake): BUILD_SHARED_LIBS=OFF
echoix Jun 5, 2025
a0e3286
Update cmake.yml remove trailing whitespace
echoix Jun 5, 2025
ade70a8
Add -dump to Update prepare-code-coverage-artifact.py
echoix Jun 5, 2025
98c5efc
Limit to ./build/output for collecting binaries cmake.yml
echoix Jun 5, 2025
0c4be74
Exclude some tests in .gunittest.cfg
echoix Jun 5, 2025
85156e6
Merge branch 'main' into test-i.smap-cmake-coverage
echoix Jun 22, 2025
9f43f7c
Merge branch 'pr/ymdatta/4499' into test-i.smap-cmake-coverage
echoix Jun 22, 2025
426600e
cmake: Use address sanitizer (ASAN)
echoix Jun 22, 2025
8070295
cmake: ASAN: Do not detect leaks
echoix Jun 22, 2025
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
65 changes: 64 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ jobs:
runs-on: ubuntu-22.04
env:
CMakeVersion: "3.22.0"
CC: clang-${{ matrix.llvm-version }}
CXX: clang++-${{ matrix.llvm-version }}
ASAN_OPTIONS: detect_leaks=0

strategy:
matrix:
llvm-version: [19]
steps:
- name: Checkout GRASS
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -41,10 +48,19 @@ jobs:
echo "$GITHUB_WORKSPACE/cmake-${{ env.CMakeVersion }}-${arch}/bin" >> $GITHUB_PATH
- run: |
cmake --version
- name: Apt LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ matrix.llvm-version }}
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y wget git gawk findutils ninja-build libpq-dev \
clang-${{ matrix.llvm-version }} clang-tools-${{ matrix.llvm-version }} \
libomp-${{ matrix.llvm-version }}-dev lld-${{ matrix.llvm-version }} \
llvm-${{ matrix.llvm-version }} \
gettext unixodbc-dev libnetcdf-dev
xargs -a <(awk '! /^ *(#|$)/' ".github/workflows/apt.txt") -r -- \
sudo apt-get install -y --no-install-recommends --no-install-suggests
Expand All @@ -61,7 +77,9 @@ jobs:
run: |
cmake ${CMAKE_OPTIONS} -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -G Ninja \
-DCMAKE_INSTALL_PREFIX=$HOME/install -DWITH_NLS=ON -DWITH_GUI=OFF -DWITH_DOCS=OFF \
-DWITH_READLINE=ON -DWITH_ODBC=ON -DWITH_NETCDF=ON -DWITH_BZLIB=ON
-DWITH_READLINE=ON -DWITH_ODBC=ON -DWITH_NETCDF=ON -DWITH_BZLIB=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_COMPILER=clang-${{ matrix.llvm-version }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.llvm-version }}
- name: Print CMakeCache.txt
shell: bash -el {0}
run: |
Expand All @@ -75,6 +93,8 @@ jobs:
- name: Add the bin directory to PATH
run: |
echo "$HOME/install/bin" >> $GITHUB_PATH
- name: Set profile file name env var
run: echo "LLVM_PROFILE_FILE=${{ github.workspace }}/grass-prof-%p-%4m.profraw" >> $GITHUB_ENV
- name: Print installed versions
if: always()
run: .github/workflows/print_versions.sh
Expand All @@ -89,3 +109,46 @@ jobs:
name: testreport-CMake
path: testreport
retention-days: 3
- name: Use llvm's coverage script
if: ${{ !cancelled() }}
run: |
WORKSPACE=$GITHUB_WORKSPACE

BUILD_DIR=$(pwd)/dist*
FAST_BUILD_DIR=$(pwd)/clang-build
REPORT_DIR=$(pwd)/coverage-reports
HOST=
LLVM_PROFDATA=llvm-profdata-${{ matrix.llvm-version }}
LLVM_COV=llvm-cov-${{ matrix.llvm-version }}
ARTIFACT_PREP_SCRIPT=$WORKSPACE/utils/prepare-code-coverage-artifact.py

PROFILES_DIR=$WORKSPACE

COV_BINARIES=$(find ./build/output/ -type f \( -executable -o -name "*.dylib" -o -name "*.so*" \) \
-exec file {} + | grep -E 'Mach-O|ELF' | cut -d':' -f1)

rm -rf $REPORT_DIR
mkdir -p $REPORT_DIR
python $ARTIFACT_PREP_SCRIPT $LLVM_PROFDATA $LLVM_COV \
$PROFILES_DIR $REPORT_DIR $COV_BINARIES \
--unified-report \
--lcov=grass.llvm-source.coverage.lcov
- name: Make profile data available
if: ${{ !cancelled() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: >-
profile-data-${{ 'cmake' }}
path: |
*.prof*
*coverage*
llvm_coverage*/**
retention-days: 1
- name: Upload coverage reports to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
verbose: true
flags: linux-cmake
name: linux-cmake
token: ${{ secrets.CODECOV_TOKEN }}
64 changes: 64 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- name: Prepare Conda environment file
env:
test_dependencies: |
findutils
ipython
pytest
pytest-github-actions-annotate-failures
Expand All @@ -73,6 +74,8 @@ jobs:
# Persist on the same period (date).
cache-environment-key: environment-${{ steps.date.outputs.date }}

- name: Set profile file name env var
run: echo "LLVM_PROFILE_FILE=${{ github.workspace }}/grass-prof-%p-%4m.profraw" >> $GITHUB_ENV
- name: Environment info
shell: bash -el {0}
run: |
Expand All @@ -89,6 +92,9 @@ jobs:
if: ${{ !cancelled() }}
shell: micromamba-shell {0}
run: source ./.github/workflows/print_versions.sh
- name: Print config
shell: micromamba-shell {0}
run: grass --config

- name: Run pytest with multiple workers in parallel
shell: micromamba-shell {0}
Expand Down Expand Up @@ -147,3 +153,61 @@ jobs:
name: testreport-macOS
path: testreport
retention-days: 3
# - name: Merge and index profile data
# shell: micromamba-shell {0}
# run: |
# llvm-profdata merge -sparse *.profraw -o merged.profdata
# rm *.profraw
# - name: Export coverage report with llvm-cov export (all, json)
# shell: micromamba-shell {0}
# continue-on-error: true
# run: |
# COV_BINARIES=$(find . -type f \( -executable -o -name "*.dylib" \) \
# -exec file {} + | grep -E 'Mach-O|ELF' | cut -d':' -f1)
# llvm-cov export -format=text -instr-profile=merged.profdata \
# /Users/runner/install/grass85/lib/libgrass_gis.8.5.dylib \
# | tee coverage.all1.json
- name: Use llvm's coverage script
if: ${{ !cancelled() }}
shell: micromamba-shell {0}
run: |
WORKSPACE=$GITHUB_WORKSPACE

BUILD_DIR=$(pwd)/dist*
FAST_BUILD_DIR=$(pwd)/clang-build
REPORT_DIR=$(pwd)/coverage-reports
HOST=
LLVM_PROFDATA=llvm-profdata
LLVM_COV=llvm-cov
ARTIFACT_PREP_SCRIPT=$WORKSPACE/utils/prepare-code-coverage-artifact.py

PROFILES_DIR=$WORKSPACE

COV_BINARIES=$(find . -type f \( -executable -o -name "*.dylib" \) \
-exec file {} + | grep -E 'Mach-O|ELF' | cut -d':' -f1)

rm -rf $REPORT_DIR
mkdir -p $REPORT_DIR
python $ARTIFACT_PREP_SCRIPT $LLVM_PROFDATA $LLVM_COV \
$PROFILES_DIR $REPORT_DIR $COV_BINARIES \
--unified-report \
--lcov=grass.llvm-source.coverage.lcov
- name: Make profile data available
if: ${{ !cancelled() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: >-
profile-data-${{ 'macos-14' }}
path: |
*.prof*
*coverage*
llvm_coverage*/**
retention-days: 1
- name: Upload coverage reports to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
verbose: true
flags: pytest-macos-14
name: pytest-macos-14
token: ${{ secrets.CODECOV_TOKEN }}
10 changes: 8 additions & 2 deletions .github/workflows/macos_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ CONFIGURE_FLAGS="\
--without-x \
"

export EXTRA_COV_FLAGS="-fprofile-instr-generate -fcoverage-mapping"
export CFLAGS="-O2 -pipe -ffp-contract=off -arch ${CONDA_ARCH} -DGL_SILENCE_DEPRECATION -Wall -Wextra -Wpedantic -Wvla"
export CXXFLAGS="-O2 -pipe -ffp-contract=off -stdlib=libc++ -arch ${CONDA_ARCH} -Wall -Wextra -Wpedantic"
export CPPFLAGS="-isystem${CONDA_PREFIX}/include"

./configure $CONFIGURE_FLAGS
export CFLAGS="$EXTRA_COV_FLAGS $CFLAGS"
export CXXFLAGS="$EXTRA_COV_FLAGS $CXXFLAGS"

LDFLAGS="-fprofile-instr-generate $LDFLAGS" ./configure $CONFIGURE_FLAGS

EXEMPT=""
make -j$(sysctl -n hw.ncpu) CFLAGS="$CFLAGS -Werror $EXEMPT" \
# make -j$(sysctl -n hw.ncpu) CFLAGS="$CFLAGS -Werror $EXEMPT" \
# CXXFLAGS="$CXXFLAGS -Werror $EXEMPT"
make -j1 CFLAGS="$CFLAGS -Werror $EXEMPT" \
CXXFLAGS="$CXXFLAGS -Werror $EXEMPT"

make install
3 changes: 3 additions & 0 deletions .gunittest.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ exclude =
vector/v.in.pdal/testsuite/test_v_in_pdal_basic.py
vector/v.in.pdal/testsuite/test_v_in_pdal_filter.py
vector/v.out.lidar/testsuite/test_v_out_lidar.py
temporal/.*
*.sh
raster/r.s*

# Maximum time for execution of one test file (not a test function)
# after which test is terminated (which may not terminate child processes
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-instr-generate -fcoverage-mapping -fno-omit-frame-pointer -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-instr-generate -fcoverage-mapping -fno-omit-frame-pointer -fsanitize=address")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-instr-generate -fno-omit-frame-pointer -fsanitize=address")

set(x11_default_option_enabled ON)
set(nls_default_option_enabled ON)
Expand Down
5 changes: 4 additions & 1 deletion imagery/i.smap/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */
ll[i][j][m] = subll[0];
}
/* compute mixture likelihood */
else {
else if (C->nsubclasses > 1) {
/* find the most likely subclass */
for (k = 0; k < C->nsubclasses; k++) {
if (k == 0)
Expand All @@ -157,6 +157,9 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */

ll[i][j][m] = log(subsum) + maxlike;
}
else {
ll[i][j][m] = 0.0;
}
}
}
}
Expand Down
Loading
Loading