summaryrefslogtreecommitdiff
path: root/share/spack/qa/run-unit-tests
blob: 61638a53e0f7e9c5622ca31c58ab90f1295d9809 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash -e
#
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

#
# Description:
#     Runs Spack unit tests.
#
# Usage:
#     run-unit-tests [test ...]
#
# Options:
#     Optionally add one or more unit tests
#     to only run these tests.
#

#-----------------------------------------------------------
# Run a few initial commands and set up test environment
#-----------------------------------------------------------
ORIGINAL_PATH="$PATH"

. "$(dirname $0)/setup.sh"
check_dependencies $coverage git hg svn

# Move to root directory of Spack
# Allows script to be run from anywhere
cd "$SPACK_ROOT"

# Print compiler information
spack config get compilers

# Run spack help to cover command import
bin/spack -h
bin/spack help -a

# Profile and print top 20 lines for a simple call to spack spec
spack -p --lines 20 spec mpileaks%gcc ^dyninst@10.0.0 ^elfutils@0.170
$coverage_run $(which spack) bootstrap status --dev --optional

# Check that we can import Spack packages directly as a first import
$coverage_run $(which spack) python -c "import spack.pkg.builtin.mpileaks; repr(spack.pkg.builtin.mpileaks.Mpileaks)"

#-----------------------------------------------------------
# Run unit tests with code coverage
#-----------------------------------------------------------
if [[ "$SPACK_TEST_SOLVER" == "original" ]]; then
  echo "ORIGINAL CONCRETIZER [skipping slow unit tests]"
  export PYTEST_ADDOPTS='-m "not maybeslow"'
fi

# Check if xdist is available
if python -m pytest --trace-config 2>&1 | grep xdist; then
  export PYTEST_ADDOPTS="$PYTEST_ADDOPTS --dist loadfile --tx '${SPACK_TEST_PARALLEL:=3}*popen//python=./bin/spack-tmpconfig python -u ./bin/spack python'"
fi

# We are running pytest-cov after the addition of pytest-xdist, since it integrates
# other pugins for pytest automatically. We still need to use "coverage" explicitly
# for the commands above.
#
# There is a need to pass the configuration file explicitly due to a bug:
# https://github.com/pytest-dev/pytest-cov/issues/243
# https://github.com/pytest-dev/pytest-cov/issues/237
# where it seems that otherwise the configuration file might not be located by subprocesses
# in some, not better specified, cases.
if [[ "$UNIT_TEST_COVERAGE" == "true" ]]; then
  $(which spack) unit-test -x --verbose --cov --cov-config=pyproject.toml --cov-report=xml:coverage.xml
else
  $(which spack) unit-test -x --verbose
fi



bash "$QA_DIR/test-env-cfg.sh"