Debian Codegraph @

util/android-scripts/run-tests.sh

raw
1 #!/bin/bash
2
3 # spell-checker:ignore nextest watchplus PIPESTATUS
4
5 echo "PATH: $PATH"
6
7 export PATH=$HOME/.cargo/bin:$PATH
8 export RUST_BACKTRACE=full
9 export CARGO_TERM_COLOR=always
10 export CARGO_INCREMENTAL=0
11
12 echo "PATH: $PATH"
13
14 run_with_retry() {
15 tries=$1
16 shift 1
17
18 for i in $(seq 1 $tries); do
19 echo "Try #$i of $tries: run $*"
20 "$@" && echo "Done in try#$i" && return 0
21 done
22
23 exit_code=$?
24
25 echo "Still failing after $tries. Code: $exit_code"
26
27 return $exit_code
28 }
29
30 run_tests_in_subprocess() (
31
32 # limit virtual memory to 3GB to avoid that OS kills sshd
33 ulimit -v $((1024 * 1024 * 3))
34
35 watchplus() {
36 # call: watchplus <interval> <command>
37 while true; do
38 "${@:2}"
39 sleep "$1"
40 done
41 }
42
43 kill_all_background_jobs() {
44 jobs -p | xargs -I{} kill -- {}
45 }
46
47 # observe (log) every 2 seconds the system resource usage to judge if we are at a limit
48 watchplus 2 df -h &
49 watchplus 2 free -hm &
50
51 nextest_params=(--profile ci --hide-progress-bar --features feat_os_unix_android)
52
53 # run tests
54 cd ~/coreutils && \
55 run_with_retry 3 timeout --preserve-status --verbose -k 1m 10m \
56 cargo nextest run --no-run "${nextest_params[@]}" &&
57 timeout --preserve-status --verbose -k 1m 60m \
58 cargo nextest run "${nextest_params[@]}"
59
60 result=$?
61
62 kill_all_background_jobs
63
64 return $result
65 )
66
67 # run sub-shell to be able to use ulimit without affecting the sshd
68 run_tests_in_subprocess