Skip to content

Commit

Permalink
Add bash scripts to run instrumentation tests concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
IslamSalah committed Sep 16, 2018
1 parent 9229584 commit e80e5af
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions firebase-run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Takes 2 argument:
# $1: the test(s) name.
# $2: the output file where the result code will be written.

# ================= Simulating testing code =================
echo "testing $1 ..."
sleep 5

echo "$?" >> "$2" # The return code of the `sleep` cmd (simulating test cmd).`
# ============================================================

# ================= Actual testing code =================
#echo "y" | gcloud beta firebase test android run \
#--app app/build/outputs/apk/mock/debug/app-mock-debug.apk \ # To be filled with actual path
#--test app/build/outputs/apk/androidTest/mock/debug/app-mock-debug-androidTest.apk \ # To be filled with actual path
#--device model=Nexus5,version=19,locale=en,orientation=portrait \
#--device model=Nexus6,version=21,locale=en,orientation=portrait \
#--device model=Nexus6P,version=23,locale=en,orientation=portrait \
#--use-orchestrator \
#--timeout 30m \
#--results-bucket "my-bucket" \ # To be filled with actual argument
#--test-targets="$1";

#echo "$?" >> "$2" # The return code of Firebase cmd `gcloud beta firebase test...`
# ============================================================
22 changes: 22 additions & 0 deletions firebase-run-tests-concurrently.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Takes 1 argument:
# $1: file containing tests, one test case per line.

CORES_COUNT=`cat /proc/cpuinfo | grep processor | wc -l`
PARALLEL_JOBS=$((CORES_COUNT > 16 ? CORES_COUNT : 16)) # at least 16 parallel jobs
TESTS_COUNT=`wc -l < $1`
TESTS_PER_JOB=$(( (TESTS_COUNT + PARALLEL_JOBS - 1) / PARALLEL_JOBS )) # round up division

# Pre-process input test file
# Prepend "class " to each line, then concat each "$TESTS_PER_JOB" lines to be comma separated to be executed in 1 run.
cat "$1" | while read line; do echo "class $line"; done | paste -d, $(for i in `seq 1 $TESTS_PER_JOB`; do printf "%b" "- "; done) > intermediate-test-file
sed 's/,*$//' intermediate-test-file > batch-test-file # Remove trailing commas, if any, at the end of each line

# Run tests simultaneously
echo y | apt-get install parallel # Install GNU parallel tool
TESTS_RESULT_FILE="result-file"
cat batch-test-file | parallel -j0 "bash firebase-run-test.sh {} $TESTS_RESULT_FILE" # "-j0" run as many jobs as needed

# Check overall result of all tests
OVERALL_TESTS_RESULT=`awk '{s+=$1} END {print s}' $TESTS_RESULT_FILE` # Sum result codes all test cmds
echo "The result of running all tests is $OVERALL_TESTS_RESULT"

0 comments on commit e80e5af

Please sign in to comment.