source: CIVL/examples/omp/dataracebench-1.0.0/scripts/test-harness.sh@ 65582ca

1.23 2.0 main test-branch
Last change on this file since 65582ca was a1acb0c5, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Add the released version of DataRaceBench v1.0.0

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@4394 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 9.6 KB
Line 
1#!/usr/bin/env bash
2
3# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
4# Produced at the Lawrence Livermore National Laboratory
5# Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund,
6# Markus Schordan, and Ian Karlin
7# (email: liao6@llnl.gov, lin32@llnl.gov, asplund1@llnl.gov,
8# schordan1@llnl.gov, karlin1@llnl.gov)
9# LLNL-CODE-732144
10# All rights reserved.
11#
12# This file is part of DataRaceBench. For details, see
13# https://github.com/LLNL/dataracebench. Please also see the LICENSE file
14# for our additional BSD notice
15#
16# Redistribution of Backstroke and use in source and binary forms, with
17# or without modification, are permitted provided that the following
18# conditions are met:
19#
20# * Redistributions of source code must retain the above copyright
21# notice, this list of conditions and the disclaimer below.
22#
23# * Redistributions in binary form must reproduce the above copyright
24# notice, this list of conditions and the disclaimer (as noted below)
25# in the documentation and/or other materials provided with the
26# distribution.
27#
28# * Neither the name of the LLNS/LLNL nor the names of its contributors
29# may be used to endorse or promote products derived from this
30# software without specific prior written permission.
31#
32# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
33# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
34# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL
37# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
38# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
44# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
45# THE POSSIBILITY OF SUCH DAMAGE.
46
47CSV_HEADER="tool,filename,haverace,threads,dataset,races,elapsed-time(seconds)"
48TESTS=($(grep -l main micro-benchmarks/*.c))
49OUTPUT_DIR="results"
50LOGFILE="$OUTPUT_DIR/drfs.log"
51
52VALGRIND=${VALGRIND:-"valgrind"}
53VALGRIND_COMPILE_FLAGS="-g -std=c99 -fopenmp"
54
55CLANG=${CLANG:-"clang"}
56TSAN_COMPILE_FLAGS="-fopenmp -fsanitize=thread -g"
57
58ARCHER=${ARCHER:-"clang-archer"}
59ARCHER_COMPILE_FLAGS="-larcher"
60
61INSPECTOR=${INSPECTOR:-"inspxe-cl"}
62ICC_COMPILE_FLAGS="-O0 -fopenmp -std=c99 -qopenmp-offload=host"
63
64POLYFLAG="micro-benchmarks/utilities/polybench.c -I micro-benchmarks -I micro-benchmarks/utilities -DPOLYBENCH_NO_FLUSH_CACHE -DPOLYBENCH_TIME -D_POSIX_C_SOURCE=200112L"
65
66VARLEN_PATTERN='[[:alnum:]]+-var-[[:alnum:]]+\.c'
67RACES_PATTERN='[[:alnum:]]+-[[:alnum:]]+-yes\.c'
68
69usage () {
70 echo
71 echo "Usage: $0 [--help] [OPTIONS]"
72 echo " --help : Show usage and options"
73 echo
74 echo "OPTIONS:"
75 echo " -x tool : Add the specified tool to test set."
76 echo " Value can be one of: helgrind, tsan, archer, inspector, inspector-max-resources."
77 echo " -n iterations : Run each setting the specified number of iterations."
78 echo " -t threads : Add the specified number of threads as a testcase."
79 echo " -d size : Add a specific dataset size to the varlen test suite."
80 echo
81}
82
83valid_tool_name () {
84 case "$1" in
85 helgrind) return 0 ;;
86 archer) return 0 ;;
87 tsan) return 0 ;;
88 inspector) return 0 ;;
89 inspector-max-resources) return 0 ;;
90 *) return 1 ;;
91 esac
92}
93
94if [[ "$1" == "--help" ]]; then
95 usage && exit 0;
96fi
97
98mkdir -p "$OUTPUT_DIR"
99
100TOOLS=()
101DATASET_SIZES=()
102THREADLIST=()
103ITERATIONS=0
104# Parse options
105while getopts "n:t:x:d:" opt; do
106 case $opt in
107 x) if valid_tool_name "${OPTARG}"; then TOOLS+=(${OPTARG});
108 else echo "Invalid tool name ${OPTARG}" && usage && exit 1
109 fi ;;
110 n) if [[ ${OPTARG} -gt 0 ]]; then ITERATIONS=${OPTARG};
111 else echo "Number of iterations must be greater than 0"
112 fi ;;
113 t) if [[ ${OPTARG} -gt 1 ]]; then THREADLIST+=(${OPTARG})
114 else echo "Number of threads must be greater than 1" && usage && exit 1;
115 fi ;;
116 d) if [[ ${OPTARG} -gt 1 ]]; then DATASET_SIZES+=(${OPTARG})
117 else echo "Dataset size must be greater than 1" && usage && exit 1;
118 fi ;;
119 esac
120done
121
122# Set default values
123if [[ ! ${#TOOLS[@]} -gt 0 ]]; then
124 echo "Default tool set will be used: helgrind, tsan, archer, inspector-max-resources."
125 TOOLS=( 'helgrind' 'tsan' 'archer' 'inspector-max-resources' )
126else
127 echo "Tools: ${TOOLS[*]}";
128fi
129
130if [[ ! ${#DATASET_SIZES[@]} -gt 0 ]]; then
131 echo "Default dataset sizes will be used: 32, 64, 128, 256, 512, 1024."
132 DATASET_SIZES=('32' '64' '128' '256' '512' '1024')
133else
134 echo "Dataset sizes: ${DATASET_SIZES[*]}";
135fi
136
137if [[ ! ${#THREADLIST[@]} -gt 0 ]]; then
138 echo "Default thread counts will be used: 3, 36, 45, 72, 90, 180, 256."
139 THREADLIST=('3' '36' '45' '72' '90' '180' '256')
140else
141 echo "Thread counts: ${THREADLIST[*]}";
142fi
143
144if [[ ! $ITERATIONS -gt 0 ]]; then
145 echo "Default number of iterations will be used: 5"
146 ITERATIONS=5
147else
148 echo "Iterations: ${ITERATIONS}";
149fi
150
151if [[ ! -e "$LOGFILE" ]]; then touch "$LOGFILE"; fi
152
153# Increase stack size - Fixes crashes in some analyses
154ULIMITS=$(ulimit -s)
155ulimit -s unlimited
156
157TOOL_INDEX=0
158TEST_INDEX=0
159THREAD_INDEX=0
160SIZE_INDEX=0
161ITER=1
162
163cleanup () {
164 ulimit -s "$ULIMITS"
165 if [[ -z ${exname+x} && -e $exname ]]; then rm "$exname"; fi
166 echo "EXITING"
167 echo "--------------------------" >> "$LOGFILE"
168 echo "Unfinished tests:" >> "$LOGFILE"
169 for tool in "${TOOLS[@]:$TOOL_INDEX}"; do
170 if [[ $TEST_INDEX -eq 0 && $THREAD_INDEX -eq 0 && $SIZE_INDEX -eq 0 && $ITER -eq 1 ]]; then
171 echo "$tool,all,all,all,$ITERATIONS" >> "$LOGFILE"
172 else
173 for test in "${TESTS[@]:$TEST_INDEX}"; do
174 if [[ $THREAD_INDEX -eq 0 && $SIZE_INDEX -eq 0 && $ITER -eq 1 ]]; then
175 echo "$tool,\"$test\",all,all,$ITERATIONS" >> "$LOGFILE"
176 else
177 for thread in "${THREADLIST[@]:$THREAD_INDEX}"; do
178 if [[ $SIZE_INDEX -eq 0 && $ITER -eq 1 ]]; then
179 echo "$tool,\"$test\",$thread,all,$ITERATIONS" >> "$LOGFILE"
180 else
181 for size in "${SIZES[@]:$SIZE_INDEX}"; do
182 if [[ $ITER -eq 1 ]]; then echo "$tool,\"$test\",$thread,${size:-"N/A"},$ITERATIONS" >> "$LOGFILE"
183 else echo "$tool,\"$test\",$thread,all,$((ITERATIONS - ITER + 1))" >> "$LOGFILE"; ITER=1; fi
184 done
185 SIZE_INDEX=0
186 fi
187 done
188 THREAD_INDEX=0
189 fi
190 done
191 TEST_INDEX=0
192 fi
193 done
194 exit 1
195}
196
197trap cleanup SIGINT SIGTERM
198
199for tool in "${TOOLS[@]}"; do
200
201 file="$OUTPUT_DIR/$tool.csv"
202 echo "Saving to: $file"
203 [ -e "$file" ] && rm "$file"
204 echo "$CSV_HEADER" >> "$file"
205
206 runtime_flags=''
207 case "$tool" in
208 'inspector-max-resources')
209 runtime_flags+=" -collect ti3 -knob scope=extreme -knob stack-depth=16 -knob use-maximum-resources=true"
210 tool='inspector'
211 ;;
212 'inspector')
213 runtime_flags+=" -collect ti2"
214 ;;
215 esac
216
217 TEST_INDEX=0
218 for test in "${TESTS[@]}"; do
219 additional_compile_flags=''
220 if [[ "$test" =~ $RACES_PATTERN ]]; then haverace=true; else haverace=false; fi
221 if [[ "$test" =~ $VARLEN_PATTERN ]]; then SIZES=("${DATASET_SIZES[@]}"); else SIZES=(''); fi
222
223 # Compile
224 exname="a.out"
225 if grep -q 'PolyBench' "$test"; then additional_compile_flags+=" $POLYFLAG"; fi
226
227 case "$tool" in
228 helgrind) gcc $VALGRIND_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
229 archer) clang-archer $ARCHER_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
230 tsan) clang $TSAN_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
231 inspector) icc $ICC_COMPILE_FLAGS $additional_compile_flags $test -o $exname -lm ;;
232 esac
233
234 THREAD_INDEX=0
235 for thread in "${THREADLIST[@]}"; do
236 export OMP_NUM_THREADS=$thread
237 SIZE_INDEX=0
238 for size in "${SIZES[@]}"; do
239 # Sanity check
240 if [[ ! -e "$exname" ]]; then
241 echo "$tool,\"$test\",$haverace,$thread,${size:-"N/A"},Error,N/A" >> "$file";
242 echo "Executable for $test with $thread threads and input size $size is not available" >> "$LOGFILE";
243 elif { "./$exname $size"; } 2>&1 | grep -Eq 'Segmentation fault'; then
244 echo "$tool,\"$test\",$haverace,$thread,${size:-"N/A"},Error,N/A" >> "$file";
245 echo "Seg fault found in $test with $thread threads and input size $size" >> "$LOGFILE";
246 else
247 for ITER in $(seq 1 "$ITERATIONS"); do
248 start=$(date +%s)
249 case "$tool" in
250 helgrind)
251 races=$($VALGRIND --tool=helgrind "./$exname" $size 2>&1 | grep -ce 'Possible data race') ;;
252 archer)
253 races=$("./$exname" $size 2>&1 | grep -ce 'WARNING: ThreadSanitizer: data race') ;;
254 tsan)
255 races=$("./$exname" $size 2>&1 | grep -ce 'WARNING: ThreadSanitizer: data race') ;;
256 inspector)
257 races=$($INSPECTOR $runtime_flags -- "./$exname" $size 2>&1 | grep 'Data race' | sed -E 's/[[:space:]]*([[:digit:]]+).*/\1/') ;;
258 esac
259 end=$(date +%s)
260 echo "$tool,\"$test\",$haverace,$thread,${size:-"N/A"},${races:-0},$(( end - start ))" >> "$file"
261 done
262 fi
263 SIZE_INDEX=$((SIZE_INDEX+1))
264 done
265 THREAD_INDEX=$((THREAD_INDEX+1))
266 done
267 TEST_INDEX=$((TEST_INDEX+1))
268 if [[ -z ${exname+x} && -e $exname ]]; then rm "$exname"; fi
269 done
270 TOOL_INDEX=$((TOOL_INDEX+1))
271done
272
273ulimit -s "$ULIMITS"
Note: See TracBrowser for help on using the repository browser.