Skip to content

Commit

Permalink
Add convenience scripts for running tests and fuzzing using Docker co…
Browse files Browse the repository at this point in the history
…ntainers
  • Loading branch information
alexforster committed Mar 23, 2021
1 parent 75f29f0 commit 17a10d9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions fuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

DOCKER="docker"

${DOCKER} build -t pdu-fuzz - <<'EOF'
FROM ubuntu:bionic
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8
VOLUME /usr/local/src/pdu
WORKDIR /usr/local/src/pdu
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]
RUN \
export DEBIAN_FRONTEND=noninteractive; \
apt-get -q update; \
apt-get -q install -y curl build-essential linux-headers-generic pkg-config binutils-dev libunwind-dev libpcap-dev tshark; \
apt-get -q clean autoclean;
RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable; \
source $HOME/.cargo/env; \
cargo install honggfuzz;
ENTRYPOINT \
source $HOME/.cargo/env; \
cd ./fuzz; \
RUSTFLAGS="-C link-dead-code" cargo hfuzz run $FUZZ_TARGET
EOF

if [ -z "$1" ]; then
echo "Usage: fuzz.sh [ ethernet | arp | ipv4 | ipv6 | tcp | udp | icmp | gre ]"
fi

${DOCKER} run --init --rm -v "$(pwd):/usr/local/src/pdu" -e FUZZ_TARGET=$1 pdu-fuzz
2 changes: 2 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
hfuzz_target/
hfuzz_workspace/**/*.cov
!hfuzz_workspace/**/
!.gitignore
.*
26 changes: 26 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

DOCKER="docker"

${DOCKER} build -t pdu-test - <<'EOF'
FROM ubuntu:bionic
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8
VOLUME /usr/local/src/pdu
WORKDIR /usr/local/src/pdu
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]
RUN \
export DEBIAN_FRONTEND=noninteractive; \
apt-get -q update; \
apt-get -q install -y curl build-essential linux-headers-generic pkg-config binutils-dev libunwind-dev libpcap-dev tshark; \
apt-get -q clean autoclean;
RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable; \
source $HOME/.cargo/env; \
cargo install honggfuzz;
ENTRYPOINT \
source $HOME/.cargo/env; \
cargo test --verbose
EOF

${DOCKER} run --init --rm -v "$(pwd):/usr/local/src/pdu" pdu-test

0 comments on commit 17a10d9

Please sign in to comment.