Skip to content

Add memory allocation attribution tests (single- and multithreaded) #2334

Add memory allocation attribution tests (single- and multithreaded)

Add memory allocation attribution tests (single- and multithreaded) #2334

name: smoketests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch: # manual execution
# Cancel any in-flight runs for the same PR / branch when a new push arrives.
# Master pushes still run to completion (the ``cancel-in-progress`` predicate
# only fires on PR events).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
smoketests:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
# fail-fast: any matrix entry failure cancels the rest. Trades
# full-coverage-on-failure for faster feedback and lower CI burn —
# if Windows 3.10 spawn-pool flakes we want to know within seconds,
# not 30 minutes later after every other combo finishes.
fail-fast: true
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python: [ '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: |
requirements.txt
pyproject.toml
- name: Work around arm64 support on MacOS
# https://github.com/actions/virtual-environments/issues/2557
if: matrix.os == 'macos-latest'
run: sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install numpy
- name: Build scalene
run: pip -v install -e .
# Steps are ordered fail-fast: the most failure-prone smoketests run
# first so a broken build surfaces in seconds, not minutes. Cheap
# always-passing checks come last as smoke for the lifecycle bits.
# NOTE: This test verifies that spawn-mode Pool.map completes under
# Scalene without hanging (regression test for #998). Most flake-prone:
# multiprocessing resource tracker + spawn workers + signal handlers
# all interact during shutdown.
- name: multiprocessing spawn pool smoke test
run: python test/smoketest_pool_spawn.py
timeout-minutes: 5
# Note: test/smoketest.py only handles single JSON, rather than multiple in sequence.
- name: profile-interval smoke test
run: python -m scalene run --profile-interval=2 test/testme.py && python -m scalene view --cli
timeout-minutes: 3
# NOTE: this is a regression test for signals not being
# restarted properly. It checks whether the program
# halts or runs forever, not for correctness of timing.
- name: signal smoketest
if: matrix.os != 'windows-latest'
run: python test/smoketest.py test/signal_test.py
timeout-minutes: 0.5
- name: multiprocessing smoke test
if: matrix.os != 'windows-latest'
run: python test/smoketest.py test/multiprocessing_test.py
# Regression test for https://github.com/plasma-umass/scalene/discussions/659.
# Uses --memory attribution; verifies that a numpy workload on a
# threading.Thread does not smear allocations onto the main thread's
# time.sleep line. The test self-skips its assertions if memory sampling
# produced zero samples on this runner (avoids flakes when signal timing
# prevents the allocator sampler from firing).
- name: issue #659 per-thread memory attribution
run: python test/smoketest_issue_659.py
# NOTE: The decorator smoke test relies on CPU signal sampling which
# doesn't work reliably on Windows CI (similar to the signal smoketest).
- name: decorator smoke test
if: matrix.os != 'windows-latest'
run: python test/smoketest_profile_decorator.py
- name: cpu-only smoke test
run: python test/smoketest.py test/testme.py --cpu-only
# Note: This test doesn't need to read an output,
# it is meant to determine if there is an ImportError
# or anything related if relative imports are used.
- name: -m invocation smoketest
run: |
python -m pip install git+https://github.com/sternj/import_stress_test
python -m scalene run --- -m import_stress_test && python -m scalene view --cli
- name: --off flag smoke test
# Verify that --off starts with profiling disabled and the program
# still runs to completion. This is the primary cross-platform test
# for the --on/--off lifecycle feature (issue #1009).
run: python -m scalene run --off --cpu-only test/testme.py
# FIXME: these tests are broken under the current Github runner
#
# - name: line invalidation test
# run: python test/smoketest_line_invalidation.py