forked from minio/mint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.sh
executable file
·166 lines (139 loc) · 4.25 KB
/
tests.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
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
#!/bin/bash
#
# Mint (C) 2017 Minio, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
root_dir="$PWD"
log_dir="log"
error_file_name="error.log"
log_file_name="output.log"
# Prints message after an error
printMsg() {
echo ""
echo "Use 'docker ps -a' to find container-id"
echo "Export run logs from the container using 'docker cp ${container_id:0:12}:/mint/log /tmp/mint-logs'"
}
# Setup environment variables for the run.
_init() {
set -e
# If SERVER_ENDPOINT is not set the tests are run on play.minio.io by default.
# SERVER_ENDPOINT is passed on as env variables while starting the docker container.
if [ -z "$SERVER_ENDPOINT" ]; then
export SERVER_ENDPOINT="play.minio.io:9000"
export ACCESS_KEY="Q3AM3UQ867SPQQA43P2F"
export SECRET_KEY="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
export ENABLE_HTTPS=1
fi
if [ -z "$SERVER_REGION" ]; then
export SERVER_REGION="us-east-1"
fi
if [ -z "$ENABLE_HTTPS" ]; then
export ENABLE_HTTPS=0
fi
# mode is set via env vars
if [ -z "$MINT_MODE" ]; then
export MINT_MODE=core
fi
# init log directory
if [ ! -d $log_dir ]; then
mkdir -p "$log_dir"
fi
if [ -z "$MINT_DATA_DIR" ]; then
export MINT_DATA_DIR="/mint/data"
fi
# check if any tests are ignored
if [ -n "$SKIP_TESTS" ]; then
IFS=',' read -ra sdks_to_ignore <<< "${SKIP_TESTS}"
fi
# Set Docker Container ID
container_id=$(basename "$(cat /proc/1/cpuset)")
}
# Run the current SDK Test
runCoreTest() {
# Clear log directories before run.
local sdk_log_dir
sdk_log_dir="$root_dir/$log_dir/$(basename "$1")"
# make and clean SDK specific log directories.
if [ ! -d "$sdk_log_dir" ]
then
mkdir -p "$sdk_log_dir"
else
rm -rf "$sdk_log_dir"
fi
# move to SDK directory
cd "$1"
# run the test
./run.sh "$sdk_log_dir/$log_file_name" "$sdk_log_dir/$error_file_name"
# move back to top level directory
cd "${root_dir}"
}
# checks if an element is not present in an array
doesntContainElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 1; done
return 0
}
# Cycle through the sdk directories and run sdk/cli tests
coreMain() {
local test_dir
test_dir="run/core"
# read the SDKs to run
for i in ${root_dir}/${test_dir}/*;
do
sdk="$(basename "$i")"
# if "i" is a directory
if [[ -d "${i}" ]] && doesntContainElement "$sdk" "${sdks_to_ignore[@]}"; then
echo -n "Running $sdk tests ... "
# log start time
start=$(date +%s)
runCoreTest "$i" || { printMsg; exit 2; }
# log end time
end=$(date +%s)
# get diif
diff=$(( end - start ))
echo "Finished in $(humantime ${diff})"
fi
done
echo "Mint ran all core tests successfully. To view logs, use 'docker cp ${container_id:0:12}:/mint/log /tmp/mint-logs'"
}
function humantime {
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( D > 0 )) && printf '%d days ' $D
(( H > 0 )) && printf '%d hours ' $H
(( M > 0 )) && printf '%d minutes ' $M
(( D > 0 || H > 0 || M > 0 )) && printf 'and '
printf '%d seconds\n' $S
}
# calls subsequent test methods based on the mode.
# core is run in all modes
main() {
# set the directories to run
if [ "$MINT_MODE" == "core" ]; then
coreMain
elif [ "$MINT_MODE" == "stress" ]; then
coreMain
# Add stressMain here
elif [ "$MINT_MODE" == "bench" ]; then
coreMain
# Add benchMain here
else
coreMain
# Add other modes here
fi
}
_init && main