| 1 |
#!/bin/bash |
|---|
| 2 |
|
|---|
| 3 |
# enable debugging |
|---|
| 4 |
# set -x |
|---|
| 5 |
|
|---|
| 6 |
# cmd line args |
|---|
| 7 |
input_dir=$1 # ex: runnable |
|---|
| 8 |
test_name=$2 # ex: pi |
|---|
| 9 |
test_extension=$3 # ex: d html or sh |
|---|
| 10 |
|
|---|
| 11 |
# env vars |
|---|
| 12 |
# ARGS == default set of dmd command line args to test combinatorially |
|---|
| 13 |
# DMD == compiler path and filename |
|---|
| 14 |
# RESULTS_DIR == directory for temporary files and output |
|---|
| 15 |
|
|---|
| 16 |
# tedious env vars |
|---|
| 17 |
# DSEP == \\ or / depending on windows or not |
|---|
| 18 |
# SEP == \ or / depending on windows or not |
|---|
| 19 |
# OBJ == .obj or .o |
|---|
| 20 |
# EXE == .exe or <null> |
|---|
| 21 |
|
|---|
| 22 |
# enable support for expressions like *( ) in substitutions |
|---|
| 23 |
shopt -s extglob |
|---|
| 24 |
|
|---|
| 25 |
# NOTE: $? tests below test for greater than 125: |
|---|
| 26 |
# 126 -- command found but isn't executable |
|---|
| 27 |
# 127 -- command not found |
|---|
| 28 |
# 128+N -- N is the signal that caused the process to exit |
|---|
| 29 |
# for example, segv == 11, so $? will be 139 |
|---|
| 30 |
# abort == 6, so $? will be 134 |
|---|
| 31 |
|
|---|
| 32 |
input_file=${input_dir}/${test_name}.${test_extension} |
|---|
| 33 |
output_dir=${RESULTS_DIR}${SEP}${input_dir} |
|---|
| 34 |
output_file=${RESULTS_DIR}/${input_dir}/${test_name}.${test_extension}.out |
|---|
| 35 |
test_app_dmd=${output_dir}${SEP}${test_name} |
|---|
| 36 |
test_app_exe=${RESULTS_DIR}/${input_dir}/${test_name} |
|---|
| 37 |
|
|---|
| 38 |
rm -f ${output_file} |
|---|
| 39 |
|
|---|
| 40 |
r_args=`grep REQUIRED_ARGS ${input_file} | tr -d \\\\r\\\\n` |
|---|
| 41 |
if [ ! -z "${r_args}" ]; then |
|---|
| 42 |
r_args="${r_args/*REQUIRED_ARGS:*( )/}" |
|---|
| 43 |
if [ ! -z "${r_args}" ]; then |
|---|
| 44 |
extra_space=" " |
|---|
| 45 |
fi |
|---|
| 46 |
fi |
|---|
| 47 |
|
|---|
| 48 |
p_args=`grep PERMUTE_ARGS ${input_file} | tr -d \\\\r\\\\n` |
|---|
| 49 |
if [ -z "${p_args}" ]; then |
|---|
| 50 |
if [ "${input_dir}" != "fail_compilation" ]; then |
|---|
| 51 |
p_args="${ARGS}" |
|---|
| 52 |
fi |
|---|
| 53 |
else |
|---|
| 54 |
p_args="${p_args/*PERMUTE_ARGS:*( )/}" |
|---|
| 55 |
if [ "${OS}" == "win32" ]; then |
|---|
| 56 |
p_args="${p_args/-fPIC/}" |
|---|
| 57 |
fi |
|---|
| 58 |
fi |
|---|
| 59 |
|
|---|
| 60 |
if [ "${MODEL}" == "64" ]; then |
|---|
| 61 |
p_args="${p_args/-O/}" |
|---|
| 62 |
r_args="${r_args/-O/}" |
|---|
| 63 |
fi |
|---|
| 64 |
|
|---|
| 65 |
e_args=`grep EXECUTE_ARGS ${input_file} | tr -d \\\\r\\\\n` |
|---|
| 66 |
if [ ! -z "$e_args" ]; then |
|---|
| 67 |
e_args="${e_args/*EXECUTE_ARGS:*( )/}" |
|---|
| 68 |
fi |
|---|
| 69 |
|
|---|
| 70 |
extra_sources=`grep EXTRA_SOURCES ${input_file} | tr -d \\\\r\\\\n` |
|---|
| 71 |
if [ ! -z "${extra_sources}" ]; then |
|---|
| 72 |
# remove the field name, leaving just the list of files |
|---|
| 73 |
extra_sources=(${extra_sources/*EXTRA_SOURCES:*( )/}) |
|---|
| 74 |
# prepend the test dir (ie, runnable) to each extra file |
|---|
| 75 |
#extra_sources=(${extra_sources[*]/imports\//${input_dir}\/imports\/}) |
|---|
| 76 |
prefixed_extra_sources=() |
|---|
| 77 |
for tmp in ${extra_sources[*]}; do prefixed_extra_sources=(${prefixed_extra_sources[*]} "${input_dir}/${tmp}"); done |
|---|
| 78 |
all_sources=(${input_file} ${prefixed_extra_sources[*]}) |
|---|
| 79 |
else |
|---|
| 80 |
all_sources=(${input_file}) |
|---|
| 81 |
fi |
|---|
| 82 |
# replace / with the correct separator |
|---|
| 83 |
all_sources=(${all_sources[*]//\//${SEP}}) |
|---|
| 84 |
|
|---|
| 85 |
grep -q COMPILE_SEPARATELY ${input_file} |
|---|
| 86 |
separate=$? |
|---|
| 87 |
|
|---|
| 88 |
post_script=`grep POST_SCRIPT ${input_file} | tr -d \\\\r\\\\n` |
|---|
| 89 |
if [ ! -z "${post_script}" ]; then |
|---|
| 90 |
post_script="${post_script/*POST_SCRIPT:*( )/}" |
|---|
| 91 |
fi |
|---|
| 92 |
|
|---|
| 93 |
if [ "${input_dir}" != "runnable" ]; then |
|---|
| 94 |
extra_compile_args="-c" |
|---|
| 95 |
fi |
|---|
| 96 |
|
|---|
| 97 |
if [ "${input_dir}" != "fail_compilation" ]; then |
|---|
| 98 |
expect_compile_rc=1 |
|---|
| 99 |
else |
|---|
| 100 |
expect_compile_rc=0 |
|---|
| 101 |
fi |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
printf " ... %-25s %s%s(%s)\n" "${input_file}" "${r_args}" "${extra_space}" "${p_args}" |
|---|
| 105 |
|
|---|
| 106 |
${RESULTS_DIR}/combinations ${p_args} | while read x; do |
|---|
| 107 |
|
|---|
| 108 |
if [ ${separate} -ne 0 ]; then |
|---|
| 109 |
echo ${DMD} -m${MODEL} -I${input_dir} ${r_args} $x -od${output_dir} -of${test_app_dmd} ${extra_compile_args} ${all_sources[*]} >> ${output_file} |
|---|
| 110 |
${DMD} -m${MODEL} -I${input_dir} ${r_args} $x -od${output_dir} -of${test_app_dmd} ${extra_compile_args} ${all_sources[*]} >> ${output_file} 2>&1 |
|---|
| 111 |
if [ $? -eq ${expect_compile_rc} -o $? -gt 125 ]; then |
|---|
| 112 |
cat ${output_file} |
|---|
| 113 |
rm -f ${output_file} |
|---|
| 114 |
exit 1 |
|---|
| 115 |
fi |
|---|
| 116 |
else |
|---|
| 117 |
for file in ${all_sources[*]}; do |
|---|
| 118 |
echo ${DMD} -m${MODEL} -I${input_dir} ${r_args} $x -od${output_dir} -c $file >> ${output_file} |
|---|
| 119 |
${DMD} -m${MODEL} -I${input_dir} ${r_args} $x -od${output_dir} -c $file >> ${output_file} 2>&1 |
|---|
| 120 |
if [ $? -eq ${expect_compile_rc} -o $? -gt 125 ]; then |
|---|
| 121 |
cat ${output_file} |
|---|
| 122 |
rm -f ${output_file} |
|---|
| 123 |
exit 1 |
|---|
| 124 |
fi |
|---|
| 125 |
done |
|---|
| 126 |
|
|---|
| 127 |
all_os=(${all_sources[*]/%.d/${OBJ}}) |
|---|
| 128 |
all_os=(${all_os[*]/${DSEP}imports${DSEP}/${SEP}}) |
|---|
| 129 |
all_os=(${all_os[*]/#/${RESULTS_DIR}${SEP}}) |
|---|
| 130 |
|
|---|
| 131 |
if [ "${input_dir}" = "runnable" ]; then |
|---|
| 132 |
echo ${DMD} -m${MODEL} -od${output_dir} -of${test_app_dmd} ${all_os[*]} >> ${output_file} |
|---|
| 133 |
${DMD} -m${MODEL} -od${output_dir} -of${test_app_dmd} ${all_os[*]} >> ${output_file} 2>&1 |
|---|
| 134 |
if [ $? -eq ${expect_compile_rc} -o $? -gt 125 ]; then |
|---|
| 135 |
cat ${output_file} |
|---|
| 136 |
rm -f ${output_file} |
|---|
| 137 |
exit 1 |
|---|
| 138 |
fi |
|---|
| 139 |
fi |
|---|
| 140 |
fi |
|---|
| 141 |
|
|---|
| 142 |
if [ "${input_dir}" = "runnable" ]; then |
|---|
| 143 |
echo ${test_app_exe} ${e_args} >> ${output_file} |
|---|
| 144 |
${test_app_exe} ${e_args} >> ${output_file} 2>&1 |
|---|
| 145 |
if [ $? -ne 0 ]; then |
|---|
| 146 |
cat ${output_file} |
|---|
| 147 |
rm -f ${output_file} |
|---|
| 148 |
exit 1 |
|---|
| 149 |
fi |
|---|
| 150 |
fi |
|---|
| 151 |
|
|---|
| 152 |
if [ ! -z ${post_script} ]; then |
|---|
| 153 |
echo "Executing post-test script: ${post_script}" >> ${output_file} |
|---|
| 154 |
${post_script} >> ${output_file} 2>&1 |
|---|
| 155 |
if [ $? -ne 0 ]; then |
|---|
| 156 |
cat ${output_file} |
|---|
| 157 |
rm -f ${output_file} |
|---|
| 158 |
exit 1 |
|---|
| 159 |
fi |
|---|
| 160 |
fi |
|---|
| 161 |
|
|---|
| 162 |
rm -f ${test_app_exe} ${test_app_exe}${OBJ} ${all_os[*]} |
|---|
| 163 |
|
|---|
| 164 |
echo >> ${output_file} |
|---|
| 165 |
done |
|---|