2021-03-26 17:04:59 +00:00
|
|
|
#!/bin/bash
|
2020-12-07 12:55:49 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2021-01-05 10:01:59 +00:00
|
|
|
set -e
|
2021-03-26 17:04:59 +00:00
|
|
|
|
|
|
|
# this environment variable allows special tests to run
|
2020-12-07 19:31:54 +00:00
|
|
|
export PL_RUNNING_SPECIAL_TESTS=1
|
2021-03-26 17:04:59 +00:00
|
|
|
# python arguments
|
2021-06-24 16:56:43 +00:00
|
|
|
defaults='-m coverage run --source pytorch_lightning --append -m pytest --verbose --capture=no --disable-warnings'
|
2021-03-26 17:04:59 +00:00
|
|
|
|
|
|
|
# find tests marked as `@RunIf(special=True)`
|
|
|
|
grep_output=$(grep --recursive --line-number --word-regexp 'tests' 'benchmarks' --regexp 'special=True')
|
|
|
|
# file paths
|
|
|
|
files=$(echo "$grep_output" | cut -f1 -d:)
|
|
|
|
files_arr=($files)
|
|
|
|
# line numbers
|
|
|
|
linenos=$(echo "$grep_output" | cut -f2 -d:)
|
|
|
|
linenos_arr=($linenos)
|
|
|
|
|
|
|
|
# tests to skip - space separated
|
|
|
|
blocklist='test_pytorch_profiler_nested_emit_nvtx'
|
|
|
|
report=''
|
|
|
|
|
|
|
|
for i in "${!files_arr[@]}"; do
|
|
|
|
file=${files_arr[$i]}
|
|
|
|
lineno=${linenos_arr[$i]}
|
|
|
|
|
|
|
|
# get code from `@RunIf(special=True)` line to EOF
|
|
|
|
test_code=$(tail -n +"$lineno" "$file")
|
|
|
|
|
|
|
|
# read line by line
|
|
|
|
while read -r line; do
|
|
|
|
# if it's a test
|
|
|
|
if [[ $line == def\ test_* ]]; then
|
|
|
|
# get the name
|
|
|
|
test_name=$(echo $line | cut -c 5- | cut -f1 -d\()
|
|
|
|
|
|
|
|
# check blocklist
|
|
|
|
if echo $blocklist | grep --word-regexp "$test_name" > /dev/null; then
|
|
|
|
report+="Skipped\t$file:$lineno::$test_name\n"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2021-03-30 17:39:02 +00:00
|
|
|
# SPECIAL_PATTERN allows filtering the tests to run when debugging.
|
|
|
|
# use as `SPECIAL_PATTERN="foo_bar" ./special_tests.sh` to run only those
|
|
|
|
# test with `foo_bar` in their name
|
|
|
|
if [[ $line != *$SPECIAL_PATTERN* ]]; then
|
|
|
|
report+="Skipped\t$file:$lineno::$test_name\n"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2021-03-26 17:04:59 +00:00
|
|
|
# run the test
|
|
|
|
report+="Ran\t$file:$lineno::$test_name\n"
|
|
|
|
python ${defaults} "${file}::${test_name}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done < <(echo "$test_code")
|
|
|
|
done
|
|
|
|
|
2021-06-04 17:53:09 +00:00
|
|
|
if nvcc --version; then
|
|
|
|
nvprof --profile-from-start off -o trace_name.prof -- python ${defaults} tests/test_profiler.py::test_pytorch_profiler_nested_emit_nvtx
|
|
|
|
fi
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2021-06-21 16:51:53 +00:00
|
|
|
# needs to run outside of `pytest`
|
|
|
|
python tests/utilities/test_warnings.py
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
report+="Ran\ttests/utilities/test_warnings.py\n"
|
|
|
|
fi
|
|
|
|
|
2021-03-26 17:04:59 +00:00
|
|
|
# echo test report
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf "\n$report"
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf '\n'
|