My 1billion row challenge solutions in various languages
at main 3.7 kB view raw
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 -eo pipefail 19 20if [ -z "$1" ] 21 then 22 echo "Usage: test_ci.sh <fork name> (<fork name 2> ...)" 23 echo " for each fork, there must be a 'calculate_average_<fork name>.sh' script and an optional 'prepare_<fork name>.sh'." 24 exit 1 25fi 26 27BOLD_WHITE='\033[1;37m' 28CYAN='\033[0;36m' 29GREEN='\033[0;32m' 30PURPLE='\033[0;35m' 31BOLD_RED='\033[1;31m' 32RED='\033[0;31m' 33BOLD_YELLOW='\033[1;33m' 34RESET='\033[0m' # No Color 35 36MEASUREMENTS_FILE="measurements_10M.txt" 37RUNS=5 38DEFAULT_JAVA_VERSION="21.0.1-open" 39RUN_TIME_LIMIT=300 # seconds 40 41TIMEOUT="" 42if [ "$(uname -s)" == "Linux" ]; then 43 TIMEOUT="timeout -v $RUN_TIME_LIMIT" 44else # MacOs 45 if [ -x "$(command -v gtimeout)" ]; then 46 TIMEOUT="gtimeout -v $RUN_TIME_LIMIT" # from `brew install coreutils` 47 else 48 echo -e "${BOLD_YELLOW}WARNING${RESET} gtimeout not available, benchmark runs may take indefinitely long." 49 fi 50fi 51 52function check_command_installed { 53 if ! [ -x "$(command -v $1)" ]; then 54 echo "Error: $1 is not installed." >&2 55 exit 1 56 fi 57} 58 59function print_and_execute() { 60 echo "+ $@" >&2 61 "$@" 62} 63 64check_command_installed java 65 66# Validate that ./calculate_average_<fork>.sh exists for each fork 67for fork in "$@"; do 68 if [ ! -f "./calculate_average_$fork.sh" ]; then 69 echo -e "${BOLD_RED}ERROR${RESET}: ./calculate_average_$fork.sh does not exist." >&2 70 exit 1 71 fi 72done 73 74## SDKMAN Setup 75# 1. Custom check for sdkman installed; not sure why check_command_installed doesn't detect it properly 76if [ ! -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then 77 echo -e "${BOLD_RED}ERROR${RESET}: sdkman is not installed." >&2 78 exit 1 79fi 80 81# 2. Init sdkman in this script 82source "$HOME/.sdkman/bin/sdkman-init.sh" 83 84# 3. make sure the default java version is installed 85if [ ! -d "$HOME/.sdkman/candidates/java/$DEFAULT_JAVA_VERSION" ]; then 86 print_and_execute sdk install java $DEFAULT_JAVA_VERSION 87fi 88 89# 4. Install missing SDK java versions in any of the prepare_*.sh scripts for the provided forks 90for fork in "$@"; do 91 if [ -f "./prepare_$fork.sh" ]; then 92 grep -h "^sdk use" "./prepare_$fork.sh" | cut -d' ' -f4 | while read -r version; do 93 if [ ! -d "$HOME/.sdkman/candidates/java/$version" ]; then 94 print_and_execute sdk install java $version 95 fi 96 done || true # grep returns exit code 1 when no match, `|| true` prevents the script from exiting early 97 fi 98done 99## END - SDKMAN Setup 100 101# Run tests and benchmark for each fork 102filetimestamp=$(date +"%Y%m%d%H%M%S") # same for all fork.out files from this run 103failed=() 104for fork in "$@"; do 105 set +e # we don't want prepare.sh, test.sh or hyperfine failing on 1 fork to exit the script early 106 107 # Run prepare script 108 if [ -f "./prepare_$fork.sh" ]; then 109 print_and_execute source "./prepare_$fork.sh" 110 else 111 print_and_execute sdk use java $DEFAULT_JAVA_VERSION 112 fi 113 114 # Run the test suite 115 print_and_execute $TIMEOUT ./test.sh $fork 116 if [ $? -ne 0 ]; then 117 failed+=("$fork") 118 echo "" 119 echo -e "${BOLD_RED}FAILURE${RESET}: ./test.sh $fork failed" 120 121 exit 1 122 fi 123 echo "" 124done