diff --git a/README.md b/README.md index 434e2ca..f54f965 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ All workers are built on top of [alpine linux](https://alpinelinux.org/) 3.6 Currently we have following images - + - [bash](containers/bash) - [c](containers/c) - [cpp](containers/cpp) - [c#](containers/csharp) diff --git a/containers/bash/Dockerfile b/containers/bash/Dockerfile new file mode 100644 index 0000000..550a0a8 --- /dev/null +++ b/containers/bash/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache musl-dev bash="4.3.48-r1" bash + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/bash/compile.sh b/containers/bash/compile.sh new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/containers/bash/compile.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/containers/bash/run.sh b/containers/bash/run.sh new file mode 100644 index 0000000..c12cdff --- /dev/null +++ b/containers/bash/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +sh script.sh < run.stdin 1> run.stdout 2> run.stderr diff --git a/test.sh b/test.sh index 32ff951..335499d 100755 --- a/test.sh +++ b/test.sh @@ -1,12 +1,15 @@ #!/usr/bin/env bats +@test "test bash" { + bash tests/bash/test_worker.sh +} @test "test c" { bash tests/c/test_worker.sh } -#@test "test cpp" { -# bash tests/cpp/test_worker.sh -#} +@test "test cpp" { + bash tests/cpp/test_worker.sh +} @test "test csharp" { bash tests/csharp/test_worker.sh diff --git a/tests/bash/run.stdin b/tests/bash/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/bash/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/bash/script.sh b/tests/bash/script.sh new file mode 100644 index 0000000..ef10ce8 --- /dev/null +++ b/tests/bash/script.sh @@ -0,0 +1,2 @@ +read input +echo Hello $input diff --git a/tests/bash/test_worker.sh b/tests/bash/test_worker.sh new file mode 100644 index 0000000..6cb4082 --- /dev/null +++ b/tests/bash/test_worker.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Remove RUNBOX +rm -rf $RUNBOX + +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp -fv $DIR/script.sh $RUNBOX/script.sh +cp -fv $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="1" \ + --memory="100m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox codingblocks/judge-worker-bash \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +rm -rf $RUNBOX