My 1billion row challenge solutions in various languages
1#!/bin/bash
2#
3# Copyright 2023 The original authors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18set -euo pipefail
19
20INPUT=${1:-""}
21
22if [ "$INPUT" = "-h" ] || [ "$#" -gt 1 ]; then
23 echo "Usage: ./test_all.sh [input file pattern]"
24 echo
25 echo "For each available fork run ./test.sh <fork name> [input file pattern]."
26 echo "Note that optional <input file pattern> should be quoted if contains wild cards."
27 echo
28 echo "Examples:"
29 echo "./test_all.sh"
30 echo "./test_all.sh 2>/dev/null"
31 echo "./test_all.sh src/test/resources/samples/measurements-1.txt"
32 echo "./test_all.sh 'src/test/resources/samples/measurements-*.txt'"
33 exit 1
34fi
35
36if [ -t 1 ]; then
37 GREEN='\033[0;32m'
38 RED='\033[0;31m'
39 RESET='\033[0m'
40else
41 GREEN=""
42 RED=""
43 RESET=""
44fi
45
46WITH_TIMEOUT=""
47if [ -x "$(command -v timeout)" ]; then
48 WITH_TIMEOUT="timeout -s KILL 5s"
49elif [ -x "$(command -v gtimeout)" ]; then # MacOS from `brew install coreutils`
50 WITH_TIMEOUT="gtimeout -s KILL 5s"
51else
52 echo "$0: timeout command not available, tests may run indefinitely long." 1>&2
53fi
54
55for impl in $(ls calculate_average_*.sh | sort); do
56 noext="${impl%%.sh}"
57 fork=${noext##calculate_average_}
58
59 # ./test.sh calls ./prepare_$fork.sh e.g. to build native image
60 # which may take some time.
61 # Here we run it upfront, assuming that prepare result is cached
62 # to avoid timeout due to long preparation.
63 if [ -f "./prepare_$fork.sh" ]; then
64 if ! output=$("./prepare_$fork.sh" 2>&1); then
65 echo "$output" 1>&2
66 echo "FAIL $fork"
67 continue
68 fi
69 fi
70
71 if output=$($WITH_TIMEOUT ./test.sh "$fork" "$INPUT" 2>&1); then
72 echo -e "${GREEN}PASS${RESET} $fork"
73 elif [ $? -eq 137 ]; then
74 echo -e "${RED}TIME${RESET} $fork"
75 else
76 echo "$output" 1>&2
77 echo -e "${RED}FAIL${RESET} $fork"
78 fi
79done