Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Last active August 7, 2022 23:30
Show Gist options
  • Save DonaldKellett/cb949687f04f057c1dca33767b8639c1 to your computer and use it in GitHub Desktop.
Save DonaldKellett/cb949687f04f057c1dca33767b8639c1 to your computer and use it in GitHub Desktop.
docker.io/donaldsebleung/criterion

docker.io/donaldsebleung/criterion

Criterion testing framework in C packaged by donaldsebleung

This is an unofficial build not endorsed or supported by upstream in any way.

Usage

Pull the image:

$ docker pull docker.io/donaldsebleung/criterion

Place the following files in your working directory:

  • preloaded.h: interface
  • solution.c: implementation
  • tests.c: Criterion unit tests

Then, to compile and execute the code:

$ ./run.sh

By default, the script assumes you have Docker installed. If you have another container engine such as Podman installed, specify it through CONTAINER_ENGINE:

$ CONTAINER_ENGINE=podman ./run.sh
FROM docker.io/library/ubuntu:jammy
RUN set -ex; \
buildDeps='git ca-certificates build-essential cmake'; \
apt-get update; \
apt-get install -y --no-install-recommends gcc $buildDeps; \
cd /tmp; \
git clone --recurse-submodules --branch v2.3.3 \
https://github.com/Snaipe/Criterion; \
cd Criterion; \
mkdir build; \
cd build; \
cmake ..; \
cmake --build .; \
make install; \
cd /tmp; \
apt-get purge -y --auto-remove $buildDeps; \
apt-get clean; \
rm -rvf /var/lib/apt/lists/* /tmp/*;
RUN useradd -m student
USER student
WORKDIR /home/student
#!/bin/bash
set -eu
if [ -z "${CONTAINER_ENGINE:+x}" ]; then
CONTAINER_ENGINE=docker
fi
if [ -z "${IMAGE_TAG:+x}" ]; then
IMAGE_TAG=docker.io/donaldsebleung/criterion:latest
fi
W=/home/student
# Create container
C=$($CONTAINER_ENGINE container create --rm -w $W $IMAGE_TAG sh -c "gcc -O2 preloaded.h solution.c tests.c -lcriterion -o tests && ./tests")
# Copy files from the current directory
$CONTAINER_ENGINE container cp ./. $C:$W
# Run tests
$CONTAINER_ENGINE container start --attach $C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment