Skip to content

Commit d487fa0

Browse files
committed
Rewrite test_libs.sh
This rewritten version improves upon the previous one in the following ways: - Automatically determines whether to exclude AVX and SSE cases from what it builds and tests. It queries the host computer about the features it supports in order to make this determination. - Doesn't uses a hardwired list of cases to build and test. Instead, it uses Bazel filters based on tags. - Adds a `--help` option.
1 parent 0d5734f commit d487fa0

1 file changed

Lines changed: 47 additions & 10 deletions

File tree

dev_tools/test_libs.sh

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,64 @@ Run the programs in tests/, and on Linux, also build the programs in apps/.
2020
2121
If the first option on the command line is -h, --help, or help, this help text
2222
will be printed and the program will exit. Any other options on the command
23-
line are passed directly to Bazel.
24-
25-
Note: the MacOS VMs in GitHub runners may run on different-capability CPUS, so
26-
all AVX versions of programs in tests/ are automatically excluded."
23+
line are passed directly to Bazel."
2724

2825
# Exit early if the user requested help.
2926
if [[ "$1" == "-h" || "$1" == "--help" || "$1" == "help" ]]; then
3027
echo "$usage"
3128
exit 0
3229
fi
3330

34-
declare filter_avx=""
35-
if [[ "$OSTYPE" == "darwin"* ]]; then
36-
filter_avx="--test_tag_filters=-avx"
31+
# Unless we can tell this system supports AVX, we skip those tests.
32+
declare avx=false
33+
declare sse=false
34+
shopt -s nocasematch
35+
# Note: can't use Bash's $OSTYPE here b/c the value is "linux-gnu" on Win 10.
36+
case "$(uname -s)" in
37+
darwin*)
38+
features=$(sysctl machdep.cpu.features)
39+
[[ "$features" == *"avx2"* ]] && avx=true
40+
[[ "$features" == *"sse"* ]] && sse=true
41+
;;
42+
43+
linux*)
44+
flags=$(grep -qi flags /proc/cpuinfo)
45+
[[ "$flags" == *"avx2"* ]] && avx=true
46+
[[ "$flags" == *"sse"* ]] && sse=true
47+
;;
48+
49+
windows*|cygwin*|mingw32*|msys*|mingw*)
50+
if wmic cpu get Caption /value | grep -qi "avx2"; then
51+
avx=true
52+
elif wmic cpu get InstructionSet /value | grep -qi "avx2"; then
53+
avx=true
54+
fi
55+
if wmic cpu get Caption /value | grep -qi "sse"; then
56+
sse=true
57+
elif wmic cpu get InstructionSet /value | grep -qi "sse"; then
58+
sse=true
59+
fi
60+
;;
61+
esac
62+
63+
declare build_filters=""
64+
declare test_filters=""
65+
if ! $avx; then
66+
build_filters="--build_tag_filters=-avx"
67+
test_filters="--test_tag_filters=-avx"
68+
fi
69+
if ! $sse; then
70+
build_filters+=",-sse"
71+
test_filters+=",-sse"
3772
fi
3873

3974
# Apps are sample programs and are only meant to run on Linux.
75+
# shellcheck disable=SC2086
4076
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
41-
bazel build --config=sse $filter_avx "$@" apps:all
42-
bazel build $filter_avx "$@" apps:all
77+
bazel build $build_filters --config=sse "$@" apps:all
78+
bazel build $build_filters "$@" apps:all
4379
fi
4480

4581
# Run all basic tests. This should work on all platforms.
46-
bazel test $filter_avx "$@" tests:all
82+
# shellcheck disable=SC2086
83+
bazel test $build_filters $test_filters "$@" tests:all

0 commit comments

Comments
 (0)