Skip to content

Commit

Permalink
Parallelize bootstrap tests in Github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenthuberdeau committed Aug 9, 2024
1 parent 180815d commit 8aba8f5
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 85 deletions.
97 changes: 47 additions & 50 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,102 @@ on:
- '**' # Matches all branches

jobs:
tests-linux:
tests-exe: # Run tests for pnut-exe on all supported platforms and architectures
strategy:
matrix:
target: ["i386", "x86_64"] # Test on both i386 and x86_64
runs-on: ubuntu-latest
include:
- target: i386
host: ubuntu-latest
- target: x86_64
host: ubuntu-latest
- target: mac_os
host: macos-latest
runs-on: ${{ matrix.host }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run ${{ matrix.target }} Linux tests
- name: Run ${{ matrix.target }} tests on ${{ matrix.host }}
run: |
set -e
./run-tests.sh ${{ matrix.target }}
tests-mac:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run MacOS x86_64 tests
run: |
set -e
./run-tests.sh mac_os
tests-shell:
tests-shell: # Run tests for pnut-sh on all supported shells
strategy:
matrix:
shell: ["bash", "dash", "ksh", "zsh"]
shell: ["bash", "dash", "ksh", "mksh", "yash", "zsh"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install shells
- name: Install ${{ matrix.shell }} shell
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.shell }}
sudo apt-get install -y bash ${{ matrix.shell }}
- name: Run tests with ${{ matrix.shell }}
run: |
set -e
./run-tests.sh sh --shell ${{ matrix.shell }}
bash ./run-tests.sh sh --shell ${{ matrix.shell }}
bootstrap-shell:
bootstrap-pnut-sh:
strategy:
matrix:
shell: ["bash", "dash", "ksh", "mksh", "yash", "zsh"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install shells
- name: Install ${{ matrix.shell }} shell
run: |
sudo apt-get update
sudo apt-get install -y bash ksh dash zsh yash mksh
sudo apt-get install -y bash ${{ matrix.shell }}
- name: Run bootstrap shell with all shells
- name: Bootstrap pnut.sh on ${{ matrix.shell }}
run: |
set -e
chmod +x bootstrap-pnut.sh
./bootstrap-pnut.sh TEST_ALL_SHELLS
if [ $? -ne 0 ]; then
echo "Bootstrap with all shells failed"
exit 1
fi
bash ./bootstrap-pnut.sh --shell ${{ matrix.shell }}
bootstrap-x86:
runs-on: ubuntu-latest
bootstrap-pnut-exe:
strategy:
matrix:
shell: ["dash", "ksh"] # Not testing on other shells to save time
include:
- target: i386
host: ubuntu-latest
- target: x86_64
host: ubuntu-latest
- target: mac_os
host: macos-latest
runs-on: ${{ matrix.host }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install shells
- name: Install ${{ matrix.shell }} shell
run: |
sudo apt-get update
sudo apt-get install -y bash ksh dash zsh yash mksh
if [ ${{ matrix.host }} = "macos-latest" ]; then
brew install ${{ matrix.shell }}
else
sudo apt-get update
sudo apt-get install -y ${{ matrix.shell }}
fi
- name: Run bootstrap x86
- name: Bootstrap pnut-exe with ${{ matrix.target }} backend
run: |
set -e
chmod +x bootstrap-pnut-x86.sh
./bootstrap-pnut-x86.sh
if [ $? -ne 0 ]; then
echo "Bootstrap x86 failed"
exit 1
fi
./bootstrap-pnut-exe.sh --backend ${{ matrix.target }}
- name: Run bootstrap x86 with shell
- name: Bootstrap pnut-exe with ${{ matrix.target }} backend on ${{ matrix.shell }}
run: |
set -e
chmod +x bootstrap-pnut-x86.sh
./bootstrap-pnut-x86.sh WITH_SHELL
if [ $? -ne 0 ]; then
echo "Bootstrap x86 with shell failed"
exit 1
fi
./bootstrap-pnut-exe.sh --backend ${{ matrix.target }} --shell ${{ matrix.shell }}
success-message:
runs-on: ubuntu-latest
needs: [tests-linux, tests-mac, tests-shell, bootstrap-shell, bootstrap-x86]
needs: [tests-exe, tests-shell, bootstrap-pnut-sh, bootstrap-pnut-exe]
steps:
- name: Tests finished
run: |
Expand Down
74 changes: 46 additions & 28 deletions bootstrap-pnut-x86.sh → bootstrap-pnut-exe.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#! /bin/sh

set -e -u

TEMP_DIR="bootstrap-results"

# PNUT_x86_OPTIONS="-Dmac_os"
# PNUT_x86_OPTIONS="-Dx86_64"
PNUT_x86_OPTIONS="-Di386"
# PNUT_EXE_OPTIONS="-Dmac_os"
# PNUT_EXE_OPTIONS="-Dx86_64"
PNUT_EXE_OPTIONS="-Di386"
PNUT_SH_OPTIONS="-DRT_NO_INIT_GLOBALS -Dsh"

if [ ! -d "$TEMP_DIR" ]; then mkdir "$TEMP_DIR"; fi
Expand All @@ -22,13 +24,13 @@ bootstrap_with_gcc() {

# Compile pnut x86 using GCC, then compile pnut x86 using pnut x86

gcc -o $TEMP_DIR/pnut-x86-by-gcc.exe $PNUT_x86_OPTIONS pnut.c
# gcc -E -P -DPNUT_CC $PNUT_x86_OPTIONS pnut.c > "$TEMP_DIR/pnut-after-cpp.c"
./$TEMP_DIR/pnut-x86-by-gcc.exe $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe
gcc -o $TEMP_DIR/pnut-x86-by-gcc.exe $PNUT_EXE_OPTIONS pnut.c
# gcc -E -P -DPNUT_CC $PNUT_EXE_OPTIONS pnut.c > "$TEMP_DIR/pnut-after-cpp.c"
./$TEMP_DIR/pnut-x86-by-gcc.exe $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe

chmod +x $TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe

./$TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-x86-by-pnut-x86-by-pnut-x86-by-gcc.exe
./$TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-x86-by-pnut-x86-by-pnut-x86-by-gcc.exe

if [ -s $TEMP_DIR/pnut-x86-by-pnut-x86-by-pnut-x86-by-gcc.exe ] ; then
if diff $TEMP_DIR/pnut-x86-by-pnut-x86-by-gcc.exe $TEMP_DIR/pnut-x86-by-pnut-x86-by-pnut-x86-by-gcc.exe 2>&1 > /dev/null ; then
Expand All @@ -53,7 +55,7 @@ bootstrap_with_shell() {
./$TEMP_DIR/pnut-sh-compiled-by-gcc.exe $PNUT_SH_OPTIONS pnut.c > $TEMP_DIR/pnut-sh.sh

# create pnut-i386.sh, the C to i386 machine code compiler as a shell script
# gcc -E -P -DPNUT_CC $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-after-cpp.c
# gcc -E -P -DPNUT_CC $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-after-cpp.c
printf_timing "pnut-sh.sh compiling pnut.c -> pnut-sh-compiled-by-pnut-sh-sh.sh" \
"$1 $TEMP_DIR/pnut-sh.sh $PNUT_SH_OPTIONS pnut.c > $TEMP_DIR/pnut-sh-compiled-by-pnut-sh-sh.sh"
if diff $TEMP_DIR/pnut-sh.sh $TEMP_DIR/pnut-sh-compiled-by-pnut-sh-sh.sh 2>&1 > /dev/null ; then
Expand All @@ -63,14 +65,14 @@ bootstrap_with_shell() {
exit 1
fi
printf_timing "pnut-sh.sh compiling pnut.c -> pnut-i386-compiled-by-pnut-sh-sh.sh" \
"$1 $TEMP_DIR/pnut-sh.sh $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-sh-sh.sh"
"$1 $TEMP_DIR/pnut-sh.sh $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-sh-sh.sh"
printf_timing "pnut-i386-compiled-by-pnut-sh-sh.sh compiling pnut.c -> pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe" \
"$1 $TEMP_DIR/pnut-i386-compiled-by-pnut-sh-sh.sh $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe"
"$1 $TEMP_DIR/pnut-i386-compiled-by-pnut-sh-sh.sh $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe"

chmod +x $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe

printf_timing "pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe compiling pnut.c -> pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe" \
"./$TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe $PNUT_x86_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe"
"./$TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe $PNUT_EXE_OPTIONS pnut.c > $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe"

chmod +x $TEMP_DIR/pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-i386-compiled-by-pnut-sh-sh.exe

Expand Down Expand Up @@ -116,23 +118,39 @@ bootstrap_with_shell() {
fi
}

# Handle runtime options
WITH_SHELL=0
TEST_ALL_SHELLS=0

if [ $# -gt 0 ] && [ $1 = "WITH_SHELL" ] ; then WITH_SHELL=1; shift; fi
if [ $# -gt 0 ] && [ $1 = "TEST_ALL_SHELLS" ] ; then TEST_ALL_SHELLS=1; shift; fi
# Parse the arguments
backend="x86_64" # Default to x86_64 Linux
shell= # Defined if doing the full bootstrap using pnut.sh on Posix shell. "all" to test with all shells (slow).

while [ $# -gt 0 ]; do
case $1 in
--backend) backend="$2"; shift 2 ;;
--shell) shell="$2"; shift 2 ;;
*) echo "Unknown option: $1"; exit 1;;
esac
done

case $backend in
i386 | x86_64 | mac_os)
PNUT_EXE_OPTIONS="-D$backend" ;;
*)
echo "Unknown backend: $backend"
exit 1
;;
esac

if [ $WITH_SHELL -ne 0 ]; then
bootstrap_with_shell "ksh"
if [ -z "$shell" ]; then
bootstrap_with_gcc
else
bootstrap_with_gcc # Much faster than bootstrapping on the Shell
fi

if [ $TEST_ALL_SHELLS -ne 0 ]; then
bootstrap_with_shell "dash"
bootstrap_with_shell "bash"
bootstrap_with_shell "zsh"
bootstrap_with_shell "yash"
bootstrap_with_shell "mksh"
if [ "$shell" = "all" ]; then
set +e # Don't exit on error because we want to test all shells.
bootstrap_with_shell "dash"
bootstrap_with_shell "ksh"
bootstrap_with_shell "bash"
bootstrap_with_shell "yash"
bootstrap_with_shell "mksh"
bootstrap_with_shell "zsh"
else
bootstrap_with_shell "$shell"
fi
fi
23 changes: 16 additions & 7 deletions bootstrap-pnut.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /bin/sh

set -e

TEMP_DIR="bootstrap-results"
PNUT_SH_OPTIONS="-DRT_NO_INIT_GLOBALS -Dsh"

Expand All @@ -22,17 +24,24 @@ bootstrap_with_shell() {
wc pnut.c "$TEMP_DIR/pnut.sh" "$TEMP_DIR/pnut-twice-bootstrapped.sh"
}

# Handle runtime options
TEST_ALL_SHELLS=0

if [ $# -gt 0 ] && [ $1 = "TEST_ALL_SHELLS" ] ; then TEST_ALL_SHELLS=1; shift; fi
# Parse the arguments
shell="$SHELL" # Use current shell as the default. "all" to test all shells.

bootstrap_with_shell "ksh"
while [ $# -gt 0 ]; do
case $1 in
--shell) shell="$2"; shift 2 ;;
*) echo "Unknown option: $1"; exit 1;;
esac
done

if [ $TEST_ALL_SHELLS -ne 0 ]; then
if [ "$shell" = "all" ]; then
set +e # Don't exit on error because we want to test all shells.
bootstrap_with_shell "dash"
bootstrap_with_shell "ksh"
bootstrap_with_shell "bash"
bootstrap_with_shell "zsh"
bootstrap_with_shell "yash"
bootstrap_with_shell "mksh"
bootstrap_with_shell "zsh"
else
bootstrap_with_shell "$shell"
fi

0 comments on commit 8aba8f5

Please sign in to comment.