-
Notifications
You must be signed in to change notification settings - Fork 123
/
check_stack_usage.sh
executable file
·49 lines (41 loc) · 1.51 KB
/
check_stack_usage.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
#!/bin/bash
set -e
PACKAGES="-p radix-common -p radix-sbor-derive -p radix-engine-interface -p radix-engine -p radix-engine-tests"
TARGET=system_folder
FILE=arguments
TEST=vector_of_buckets_argument_should_succeed
# Return error if stack usage greater than
STACK_ERROR_VALUE=1572864
# Display warning if stack usage greater than
STACK_WARN_VALUE=1048576
stack=
output=$(mktemp)
# Running the test for debug variant only as it consumes stack way more greedy than release
function get_stack_usage() {
echo Estimating stack usage...
local low=10000
local high=10000000
while [ $low -lt $high ] ; do
stack=$(( $low + ($high - $low) / 2))
echo checking stack $stack
if RUST_MIN_STACK=$stack cargo test $PACKAGES --test $TARGET $FILE::$TEST -- >$output 2>&1 ; then
if grep 'stack overflow' $output ; then
cat $output
echo "unexpected error occurred"
exit 1
else
high=$(( $stack - 1 ))
fi
else
low=$(( $stack + 1 ))
fi
done
}
get_stack_usage
echo "Estimated debug stack usage $stack"
if [ $stack -ge $STACK_ERROR_VALUE ] ; then
echo "ERROR - this is more than threshold $STACK_ERROR_VALUE! Please refer to stack_size.rs for more information, how to reduce stack usage"
exit 1
elif [ $stack -ge $STACK_WARN_VALUE ] ; then
echo "WARNING - this is more than threshold $STACK_WARN_VALUE. Please refer to stack_size.rs for more information, how to reduce stack usage"
fi