Repository navigation
Expand file tree
/
Copy pathfunctions.bash
More file actions
135 lines (110 loc) · 3.22 KB
/
Copy pathfunctions.bash
File metadata and controls
135 lines (110 loc) · 3.22 KB
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
BATS_BASENAME=$(basename $BATS_TEST_FILENAME .bats)
run_test(){
options="$1"
tag="$2"
# Remove tag from dataset name
dataset=$(sed "s/_$tag\$//" <<< $BATS_BASENAME)
# Param check...
if [ -z $tag ]; then
log 'run_test called without tag parameter. Did you forget to add $ in front of $run_test?' 'error'
return 1
fi
# Sync dataset images to test directory
# Publish output directory (for people to check files, do extra test logic)
export output_dir="$OATS_RUN_DIR/tests/$dataset/$BATS_TEST_NAME/"
mkdir -p $output_dir
if [ "$TESTRUN" == "NO" ]; then
check_download_dataset $dataset
rsync -a --delete datasets/$dataset/* $output_dir
fi
DOCKER_CMD="docker run -i --rm \
-v $(pwd)/$output_dir:/datasets/code \
$DOCKER_IMAGE:$tag \
--project-path /datasets \
$options \
$CMD_OPTIONS"
wall_time_s=0
result_dir_bytes=0
if [ "$TESTRUN" == "YES" ]; then
log "About to run: $DOCKER_CMD"
run echo "$output_dir output"
else
log "About to run: $DOCKER_CMD"
local start
start=$SECONDS
run eval $DOCKER_CMD
wall_time_s=$((SECONDS - start))
sleep 1
# Assign permissions to local user
docker run -i --rm \
-v $(pwd)/$output_dir:/dataset \
--entrypoint /bin/chown \
$DOCKER_IMAGE:$tag \
-R $(id -u):$(id -u) /dataset
result_dir_bytes=$(du -sb "$output_dir" 2>/dev/null | cut -f1)
fi
# Save command output to log
echo "$output" > $output_dir/task_output.txt
# The ODM exit code, used to tell an ODM failure from a failed post-run
# check. The manifest row is written in teardown, which is the only
# place that knows whether the post-run checks passed.
odm_status=$status
# Basic check
[ "$status" -eq 0 ]
}
# Runs a tool from the ODM image under test, with the current test's output
# directory mounted at /dataset. Paths given to the tool are container paths.
# Images built with pixi put their tools on PATH through the shell hook; older
# images keep them under SuperBuild/install.
odm_tool(){
docker run --rm \
-v "$(pwd)/$output_dir:/dataset" \
--entrypoint bash \
"$DOCKER_IMAGE:$tag" \
-c '
if [ -f /code/scripts/pixi-shell-hook ]; then
. /code/scripts/pixi-shell-hook
else
export PATH="/code/SuperBuild/install/bin:$PATH"
fi
exec "$@"' bash "$@"
}
teardown(){
[ -n "${odm_status:-}" ] || return 0
if [ -n "${OATS_MANIFEST:-}" ]; then
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' \
"$tag" "$dataset" "$BATS_TEST_DESCRIPTION" "$output_dir" "$odm_status" \
"${wall_time_s:-0}" "${result_dir_bytes:-0}" \
"$([ -n "${BATS_TEST_COMPLETED:-}" ] && echo pass || echo fail)" >> "$OATS_MANIFEST"
fi
}
check_download_dataset(){
dataset="$1"
if [ ! -e ./datasets/$dataset/images ] && [ ! -z $DATASET_URL ]; then
if [ ! -e ./datasets/$dataset ]; then
mkdir ./datasets/$dataset
fi
wget $DATASET_URL -q -O ./datasets/$dataset/download.zip
cd ./datasets/$dataset/
unzip -q ./download.zip 2>/dev/null
rm ./download.zip
# Remove top level directory if needed
for dir in $(ls -d */); do
if [ "$dir" != "images/" ]; then
mv "$dir"/* .
rm -fr "$dir"
fi
done
# Check images path
if [ ! -e ./images ]; then
mkdir images
mv *.* images
fi
cd ../../
fi
}
log(){
message="$1"
type="${2:-info}"
echo "$type: $message" >> oats.log
}