this repo has no description
1#!/bin/bash
2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
3
4function die {
5 echo "$@" 1>&2
6 exit 1
7}
8
9SOURCE_DIR="$(realpath "$(dirname "$0")/..")"
10
11if [[ -z $PYRO_BUILD_DIR ]]; then
12 PYRO_BUILD_DIR="$(dirname "$0")/../build"
13fi
14
15if [[ -z $PYTHON_BIN ]]; then
16 PYTHON_BIN="$PYRO_BUILD_DIR/bin/python"
17fi
18
19PYRO_BUILD_DIR="$(realpath "$PYRO_BUILD_DIR")"
20SOURCE_DIR="$(realpath "$SOURCE_DIR")"
21PYTHON_BIN="$(realpath "$PYTHON_BIN")"
22
23if [[ ! -x $PYTHON_BIN ]]; then
24 # Assume that this path is impossible if we're being called by
25 # python_tests_cpython.sh because it does its own validation.
26 die "$PYTHON_BIN is not executable. Please build using 'cmake --build . --target python'"
27fi
28
29PYRO_TEST_FILTER="*_test.py"
30TEST_RUNNING_FILTER="*test*.py"
31CPYTHON_TESTS=(
32 test___future__.py
33 test_abc.py
34 test_augassign.py
35 test_binhex.py
36 test_binop.py
37 test_bisect.py
38 test_c_locale_coercion.py
39 test_cgi.py
40 test_cmd.py
41 test_colorsys.py
42 test_copyreg.py
43 test_crashers.py
44 test_decorators.py
45 test_dictcomps.py
46 test_dtrace.py
47 test_dummy_thread.py
48 test_dynamic.py
49 test_dynamicclassattribute.py
50 test_embed.py
51 test_ensurepip.py
52 test_errno.py
53 test_exception_variations.py
54 test_filecmp.py
55 test_flufl.py
56 test_fnmatch.py
57 test_future3.py
58 test_future4.py
59 test_future5.py
60 test_genericpath.py
61 test_getpass.py
62 test_glob.py
63 test_grp.py
64 test_html.py
65 test_htmlparser.py
66 test_int_literal.py
67 test_linecache.py
68 test_locale.py
69 test_longexp.py
70 test_mailcap.py
71 test_mimetypes.py
72 test_netrc.py
73 test_opcodes.py
74 test_openpty.py
75 test_osx_env.py
76 test_pipes.py
77 test_pkg.py
78 test_pkgimport.py
79 test_pkgutil.py
80 test_popen.py
81 test_smtpnet.py
82 test_stat.py
83 test_strftime.py
84 test_stringprep.py
85 test_syslog.py
86 test_textwrap.py
87 test_typechecks.py
88 test_unicode_file.py
89 test_unicode_identifiers.py
90 test_urllib_response.py
91 test_utf8source.py
92 test_uu.py
93 test_webbrowser.py
94 test_with.py
95 test_xmlrpc_net.py
96 test_zipimport.py
97)
98PYRO_PATCHED_CPYTHON_TESTS=(
99 test_asyncgen.py
100 test_coroutines.py
101 test_dict.py
102 test_eof.py
103 test_hmac.py
104 test_peepholer.py
105 test_range.py
106 test_tuple.py
107)
108
109if [[ -n $1 ]]; then
110 if [[ ! -f "$SOURCE_DIR/library/$1" ]]; then
111 REAL_PATH=$(realpath "$SOURCE_DIR")
112 echo "There's no test file named: $1 in $REAL_PATH/library, checking CPYTHON_TESTS"
113 for i in "${CPYTHON_TESTS[@]}"
114 do
115 if [ "$i" == "$1" ] ; then
116 FOUND=1
117 fi
118 done
119 if [[ ! $FOUND ]]; then
120 die "There's no test file named: $1 in CPYTHON_TESTS"
121 fi
122 fi
123 TEST_RUNNING_FILTER="$1"
124fi
125
126cd "$PYRO_BUILD_DIR" || exit 1
127rm -rf tests
128mkdir tests
129# Add Pyro tests
130find "$SOURCE_DIR/library/" -name "$PYRO_TEST_FILTER" -exec cp {} tests/ \;
131# Add stubbed out CPython tests in Pyro
132for i in "${PYRO_PATCHED_CPYTHON_TESTS[@]}"; do
133 if [[ -d "$SOURCE_DIR/library/test/$i" ]]; then
134 die "We don't support running test directories in CPython yet"
135 fi
136 cp "$SOURCE_DIR/library/test/$i" tests/;
137done
138# Add CPython tests
139for i in "${CPYTHON_TESTS[@]}"; do
140 if [[ -d "$SOURCE_DIR/third-party/cpython/Lib/test/$i" ]]; then
141 die "We don't support running test directories yet"
142 fi
143 cp "$SOURCE_DIR/third-party/cpython/Lib/test/$i" tests/;
144done
145
146cp "$SOURCE_DIR/library/test_support.py" tests/
147
148if command -v parallel >/dev/null; then
149 TEST_RUNNER=(parallel --will-cite -v --halt "now,fail=1")
150else
151 NUM_CPUS="$(python3 -c 'import multiprocessing; print(multiprocessing.cpu_count())')"
152 TEST_RUNNER=(xargs -t -P "$NUM_CPUS")
153fi
154find "$PYRO_BUILD_DIR/tests/" -name "$TEST_RUNNING_FILTER" -print0 |
155 "${TEST_RUNNER[@]}" -0 -n1 "$PYTHON_BIN"