-
Notifications
You must be signed in to change notification settings - Fork 2
/
run
executable file
·216 lines (193 loc) · 5.93 KB
/
run
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
source commons.bash
# Parse args
export FILTER_DATASETS=""
export TAGS="latest"
export DOCKER_IMAGE="opendronemap/odm"
export CMD_OPTIONS=""
export CLEAR=NO
export BUILD=NO
export TESTRUN=NO
export NUKE=NO
export USE_LOCAL_VOLUME=NO
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--datasets)
# Split string using ',' separator
IFS=',' read -ra DST <<< "$2"
export FILTER_DATASETS=("${DST[@]}")
shift # past argument
shift # past value
;;
--tags)
# Split string using ',' separator
IFS=',' read -ra DST <<< "$2"
export TAGS=("${DST[@]}")
shift # past argument
shift # past value
;;
--image_name)
export DOCKER_IMAGE="$2"
shift # past argument
shift # past value
;;
--options)
export CMD_OPTIONS="$2"
shift # past argument
shift # past value
;;
--clear)
export CLEAR=YES
shift # past argument
;;
--build)
# Split string using ',' separator
IFS=',' read -ra DST <<< "$2"
export BUILD=("${DST[@]}")
shift # past argument
shift # past value
;;
--test)
export TESTRUN=YES
shift # past argument
;;
--nuke)
export NUKE=YES
shift # past argument
;;
--use_local_volume)
export USE_LOCAL_VOLUME=YES
shift # past argument
;;
--help)
export HELP=YES
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameter
usage(){
echo "Usage: $0 [options] <group>"
echo
echo "OpenDroneMap Automated Testing Suite."
echo
echo "Group:"
for group in groups/*.bash; do
source $group
echo " $(basename $group .bash) ${DATASETS[@]}"
done
echo
echo "Options:"
echo " --datasets <dataset1,dataset2,...> Test only the specified datasets from the group"
echo " --tags <tag1,tag2,...> docker tag images to test. Each tag is tested against each dataset. (default: latest)"
echo " --options \"--odm-option 1 --rerun-from odm_meshing ...\" Options to append to each OpenDroneMap invocation (for example to rerun from a certain step of the pipeline). Make sure to add these in quotes. (default: \"\")"
echo " --image_name <docker image> Docker image to use. (default: opendronemap/odm)"
echo " --use_local_volume Copy dataset inputs to a temporary location within the docker container instead of directly binding to the host directory. Windows users should use this option to avoid having tests failing due to missing files. (default: no)"
echo " --clear Delete previous test results. (default: no)"
echo " --build Build these branches (comma separated) before running tests. (default: no)"
echo " --test Do not execute docker commands, but simply write them in oats.log. (default: no)"
echo " --nuke Clear test results, datasets files and any other file in the workspace. (default: no)"
exit
}
environment_check(){
check_command "docker" "https://www.docker.com/"
check_command "wget" "Run \033[1msudo apt install -y wget\033[0m" "sudo apt install -y wget"
check_command "git" "Run \033[1msudo apt install -y git\033[0m" "sudo apt install -y git"
check_command "rsync" "Run \033[1msudo apt install -y rsync\033[0m" "sudo apt install -y rsync"
check_command "sed" "Run \033[1msudo apt install -y sed\033[0m" "sudo apt install -y sed"
check_command "unzip" "Run \033[1msudo apt install -y unzip\033[0m" "sudo apt install -y unzip"
}
build_tests(){
rm -f tests/build/*.bats
# Create test files for each tag
# Split string using ',' separator
for tag in "${TAGS[@]}"; do
for test_file in tests/*.oat; do
[ -e "$test_file" ] || continue
test_basename=$(basename $test_file .oat)
out_file="tests/build/$test_basename""_$tag.bats"
# Header
echo "load functions" > $out_file
# Replace calls to $run_test with run_test appended by a tag parameter
sed "s/\$run_test\(.*\)/run_test\1 \"$tag\"/g" $test_file >> $out_file
# Add BATS_TEST_BASENAME to each test case description
#sed -i.bak "s/@test \"\(.*\)\"/@test \"\1 (\$BATS_BASENAME\)\"/g" $out_file
done
done
#rm tests/build/*.bak
cp functions.bash tests/build/
}
if [ ! -e ./bats ]; then
git clone --depth 1 https://github.com/sstephenson/bats.git
fi
environment_check
if [ "$HELP" == "YES" ]; then
usage
fi
if [ "$NUKE" == "YES" ]; then
rm -vfr results/* datasets/* tests/build/*
exit 0
fi
if [ "$BUILD" != "NO" ]; then
if [ ! -e ./ODM_src ]; then
git clone https://github.com/OpenDroneMap/ODM ODM_src
fi
cd ODM_src
for branch in "${BUILD[@]}"; do
git checkout $branch
docker build -t opendronemap/odm:$branch -f portable.Dockerfile . --no-cache
done
cd ..
fi
# Path to bats executable
BATS=./bats/bin/bats
if [ ! -e "$BATS" ]; then
echo "Bats not found: $BATS"
exit 1
fi
# Clean previous logs
rm -f *.log
build_tests
# Get datasets group
if [ -e "groups/$POSITIONAL.bash" ]; then
get_datasets_for_group "$POSITIONAL" "${FILTER_DATASETS[@]}"
for dataset in "${datasets[@]}"; do
if [ -e tests/$dataset.oat ]; then
# For each tag
for test_file in $(echo "tests/build/$dataset""_*.bats"); do
main() {
echo
echo Begin dataset: $dataset
printf '%0.s-' $(seq 1 $COLUMNS)
echo Free Memory: $(awk '/MemFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo)GB
echo Free SWAP: $(awk '/SwapFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo)GB
printf '%0.s-' $(seq 1 $COLUMNS)
echo
[ -e "$test_file" ] || continue
$BATS $test_file
echo
echo End dataset: $dataset
printf '%0.s-' $(seq 1 $COLUMNS)
echo Free Memory: $(awk '/MemFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo)GB
echo Free SWAP: $(awk '/SwapFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo)GB
}
time main
printf '%0.s=' $(seq 1 $COLUMNS)
printf '%0.s=' $(seq 1 $COLUMNS)
echo
echo
done
else
echo "WARNING: tests/$dataset.oat does not exist. Ignoring."
fi
done
else
usage
fi