Skip to content

Commit 70f3dd7

Browse files
authored
Run TSAN in CI (#144)
1 parent 14781ae commit 70f3dd7

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/sanitizers.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Sanitizers
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- "*.md"
8+
pull_request:
9+
branches: ["*"]
10+
paths-ignore:
11+
- "*.md"
12+
workflow_dispatch: # allows you to trigger manually
13+
14+
# When this workflow is queued, automatically cancel any previous running
15+
# or pending jobs from the same branch
16+
concurrency:
17+
group: tsan-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
TSAN:
22+
runs-on: ubuntu-latest
23+
container:
24+
image: ghcr.io/nascheme/numpy-tsan:3.14t
25+
26+
steps:
27+
- name: Check out repo
28+
uses: actions/checkout@v6
29+
30+
- name: Install build dependencies
31+
run: python -m pip install -U build pip setuptools wheel cython
32+
33+
- name: Build wheel
34+
run: |
35+
# See setup.py for special handling in flame-blis modules
36+
export CFLAGS="$CFLAGS -fsanitize=thread"
37+
# Build without isolation to use TSAN-enabled NumPy from the container
38+
python -m build --wheel --no-isolation
39+
40+
- name: Install wheel
41+
run: python -m pip install dist/*.whl
42+
43+
- name: Delete source directory
44+
run: rm -rf blis
45+
46+
- name: Test import
47+
run: python -c "import blis" -Werror
48+
49+
- name: Install test requirements
50+
run: python -m pip install -r requirements.txt
51+
52+
- name: Run pytest-run-parallel
53+
env:
54+
# Reference: https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags
55+
TSAN_OPTIONS: "halt_on_error=0 suppressions=tsan_suppressions.txt"
56+
run: pytest -s --parallel-threads 4

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This repository provides the
77
self-contained Python C-extension.
88

99
[![tests](https://github.com/explosion/cython-blis/actions/workflows/tests.yml/badge.svg)](https://github.com/explosion/cython-blis/actions/workflows/tests.yml)
10+
[![sanitizers](https://github.com/explosion/cython-blis/actions/workflows/sanitizers.yml/badge.svg)](https://github.com/explosion/cython-blis/actions/workflows/sanitizers.yml)
1011
[![pypi Version](https://img.shields.io/pypi/v/blis.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.python.org/pypi/blis)
1112
[![conda](https://img.shields.io/conda/vn/conda-forge/cython-blis.svg?style=flat-square&logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/cython-blis)
1213
[![Python wheels](https://img.shields.io/badge/wheels-%E2%9C%93-4c1.svg?longCache=true&style=flat-square&logo=python&logoColor=white)](https://github.com/explosion/wheelwright/releases)

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ def compile_objects(self, platform, py_arch, obj_dir):
254254
# spec["flags"].append(
255255
# "-D__cpuid=__cpuid_function"
256256
# )
257+
if "-fsanitize=thread" in os.environ.get("CFLAGS", "").split():
258+
# Enable TSAN compilation flag for flame-blis modules.
259+
# Ignore other environmental CFLAGS; for everything else
260+
# use the jsonl specs instead.
261+
# Cython modules use CFLAGS directly instead.
262+
spec["flags"].append("-fsanitize=thread")
263+
257264
objects.append(self.build_object(env=env, **spec))
258265
return objects
259266

tsan_suppressions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file contains suppressions for the TSAN tool
2+
# Reference: https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions
3+
4+
# https://github.com/numpy/numpy/issues/30085
5+
race:mt19937
6+
race:mtrand
7+
# https://github.com/cython/cython/issues/7383
8+
race:__Pyx__CyFunction_SetClassObj

0 commit comments

Comments
 (0)