forked from Conflux-Chain/conflux-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·106 lines (84 loc) · 2.72 KB
/
test.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"`
echo "Checking dependent python3 modules ..."
source $SCRIPT_DIR/dep_pip3.sh
set -o pipefail
ROOT_DIR="$( cd $SCRIPT_DIR/.. && pwd )"
TEST_MAX_WORKERS="${1-8}"
TEST_MAX_RETRIES="${2-1}"
TEST_MAX_NODES="${3-24}"
export PYTHONUNBUFFERED=1
export CARGO_TARGET_DIR=$ROOT_DIR/build
export RUSTFLAGS="-g -D warnings"
CHECK_BUILD=1
CHECK_INT_TEST=2
CHECK_PY_TEST=3
function check_build {
local -n inner_result=$1
#rm -rf $ROOT_DIR/build && mkdir -p $ROOT_DIR/build
pushd $ROOT_DIR > /dev/null
local result
result=$(
cargo build --release| tee /dev/stderr
)
local exit_code=$?
popd > /dev/null
if [[ $exit_code -ne 0 ]]; then
result="Build failed."$'\n'"$result"
else
result="Build succeeded."
fi
inner_result=($exit_code "$result")
}
function check_integration_tests {
local -n inner_result=$1
pushd $ROOT_DIR > /dev/null
local result
result=$(
# Make symbolic link for conflux binary to where integration test assumes its existence.
rm -f target; ln -s build target
./tests/test_all.py --max-workers $TEST_MAX_WORKERS --max-retries $TEST_MAX_RETRIES --max-nodes $TEST_MAX_NODES | tee /dev/stderr
)
local exit_code=$?
popd > /dev/null
if [[ $exit_code -ne 0 ]]; then
result="Integration test failed."$'\n'"$result"
fi
inner_result=($exit_code "$result")
}
function check_pytests {
local -n inner_result=$1
pushd $ROOT_DIR > /dev/null
local result
result=$(
pytest ./integration_tests/tests -vv -n $TEST_MAX_WORKERS --dist loadscope | tee /dev/stderr
)
local exit_code=$?
popd > /dev/null
if [[ $exit_code -ne 0 ]]; then
result="Pytest failed."$'\n'"$result"
fi
inner_result=($exit_code "$result")
}
function save_test_result {
local -n inner_result=$1
local stage_number=$2
local exit_code=${inner_result[0]}
local result=${inner_result[1]}
if [[ $exit_code -ne 0 ]]; then
printf "%s\n" "$result" >> $ROOT_DIR/.phabricator-comment
if [[ $exit_code -eq 80 ]] && [[ $stage_number -eq $CHECK_INT_TEST ]]; then
## If the test fails for "test case error in the integration test", return customized exit code
exit 80
fi
exit 1
fi
}
echo -n "" > $ROOT_DIR/.phabricator-comment
mkdir -p $ROOT_DIR/build
# Build
declare -a test_result; check_build test_result; save_test_result test_result $CHECK_BUILD
# Integration test
declare -a test_result; check_integration_tests test_result; save_test_result test_result $CHECK_INT_TEST
# Pytest
declare -a test_result; check_pytests test_result; save_test_result test_result $CHECK_PY_TEST