Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows/macOS/Linux and x86/arm64 fuzzing CI #255

Merged
merged 4 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .azure-pipelines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash
DISTRO=${DISTRO:-alpine}
OCAML_VERSIONS=${OCAML_VERSIONS:-4.06 4.07}
TEST_DISTRIB=${TEST_DISTRIB:-no}
export OPAMYES=1
export OPAMJOBS=3
set -ex
case $AGENT_OS in
Linux)
sudo add-apt-repository ppa:avsm/ppa
sudo apt-get update
sudo apt-get -y install opam
opam init --auto-setup https://github.com/ocaml/opam-repository.git
opam install depext
git config --global user.name "Azure Pipelines CI"
git config --global user.email "bactrian@ocaml.org"
TEST_CURRENT_SWITCH_ONLY=yes
eval $(opam env)
;;
LinuxDocker)
sudo chown -R opam /home/opam/src
cd /home/opam/src
git -C /home/opam/opam-repository pull origin master
opam update
opam install depext
eval $(opam env)
;;
Windows_NT)
echo Preparing Cygwin environment
SWITCH=${OPAM_SWITCH:-'4.07.1+mingw64c'}
OPAM_DL_SUB_LINK=0.0.0.2
case $AGENT_OSARCHITECTURE in
"X64")
OPAM_URL="https://github.com/fdopen/opam-repository-mingw/releases/download/${OPAM_DL_SUB_LINK}/opam64.tar.xz"
OPAM_ARCH=opam64 ;;
"X86")
OPAM_URL="https://github.com/fdopen/opam-repository-mingw/releases/download/${OPAM_DL_SUB_LINK}/opam32.tar.xz"
OPAM_ARCH=opam32 ;;
*)
echo "Unsupported architecture $AGENT_OSARCHITECTURE"
exit 1 ;;
esac
if [ $# -gt 0 ] && [ -n "$1" ]; then
SWITCH=$1
fi
export OPAM_LINT="false"
export CYGWIN='winsymlinks:native'
export OPAMYES=1
set -eu
curl -fsSL -o "${OPAM_ARCH}.tar.xz" "${OPAM_URL}"
tar -xf "${OPAM_ARCH}.tar.xz"
"${OPAM_ARCH}/install.sh" --quiet
# if a msvc compiler must be compiled from source, we have to modify the
# environment first
case "$SWITCH" in
*msvc32)
eval $(ocaml-env cygwin --ms=vs2015 --no-opam --32) ;;
*msvc64)
eval $(ocaml-env cygwin --ms=vs2015 --no-opam --64) ;;
esac
opam init -c "ocaml-variants.${SWITCH}" --disable-sandboxing --enable-completion --enable-shell-hook --auto-setup default "https://github.com/fdopen/opam-repository-mingw.git#opam2"
opam config set jobs "$OPAMJOBS"
opam update
is_msvc=0
case "$SWITCH" in
*msvc*)
is_msvc=1
eval $(ocaml-env cygwin --ms=vs2015)
;;
*mingw*)
eval $(ocaml-env cygwin)
;;
*)
echo "ocamlc reports a dubious system: ${ocaml_system}. Good luck!" >&2
eval $(opam env)
esac
if [ $is_msvc -eq 0 ]; then
opam install depext-cygwinports depext
else
opam install depext
fi
cd ${BUILD_SOURCES_DIR}
git config --global user.name "Azure Pipelines CI"
git config --global user.email "bactrian@ocaml.org"
TEST_CURRENT_SWITCH_ONLY=yes
SKIP_ASYNC_ON_WIN32=yes
;;
Darwin)
brew install opam ocaml
opam init --auto-setup https://github.com/ocaml/opam-repository.git
opam install depext
git config --global user.name "Azure Pipelines CI"
git config --global user.email "bactrian@ocaml.org"
TEST_CURRENT_SWITCH_ONLY=yes
TEST_DISTRIB=yes
eval $(opam env)
;;
*)
echo Unknown OS $AGENT_OS
exit 1
esac

PACKAGES=`ls -1 *.opam|xargs -I% -n 1 basename % .opam`

if [ "$SKIP_ASYNC_ON_WIN32" != "" ]; then
echo Skipping Async on Windows
PACKAGES=`echo $PACKAGES | sed -e 's/cstruct-async//g'`
fi

echo Processing $PACKAGES
# git pins fails under cygwin, need to debug
opam pin add -n -k path .
opam --yes depext -y $PACKAGES
opam install --with-test --with-doc --deps-only $PACKAGES
case $TEST_CURRENT_SWITCH_ONLY in
yes)
echo Testing current switch only
opam switch
# hack until async builds on windows in a few weeks
rm -rf async cstruct-async.opam
dune build
dune runtest
;;
*)
echo "(lang dune 1.0)" > dune-workspace.dev
for v in $OCAML_VERSIONS; do
echo "(context (opam (switch $v)))" >> dune-workspace.dev
opam install --deps-only -t --switch $v .
done

dune build --workspace dune-workspace.dev
dune runtest --workspace dune-workspace.dev
;;
esac

if [ "$TEST_DISTRIB" = "yes" ]; then
opam install -y dune-release odoc
dune build @doc
dune-release distrib
dune runtest --force
fi
21 changes: 21 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
kind: pipeline
name: amd

platform:
os: linux
arch: amd64

steps:
- name: build
image: ocaml/opam2:4.07
commands:
- sudo apt-get update && sudo apt-get -y install afl
- sudo chown -R opam .
- git -C /home/opam/opam-repository pull origin && opam update
- opam switch 4.07+afl
- opam pin add -n .
- opam depext cstruct-async cstruct-lwt cstruct-unix cstruct ppx_cstruct
- opam install -y .
- opam pin add -n bun https://github.com/yomimono/ocaml-bun.git
- opam install -y crowbar fmt bun
- opam exec -- dune build @fuzz --no-buffer
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default behaviour, for if core.autocrlf isn't set
* text=auto

.azure-pipelines.sh text eol=lf
ppx_test/errors/* text eol=lf
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ structures, and they are accessed via the `Bigarray` module.
## Installation

This repository provides several packages that can be installed via the
[OPAM](https://opam.ocaml.org) package manager:
[opam](https://opam.ocaml.org) package manager:

- `cstruct`: the core Cstruct library
- `cstruct-sexp`: serialisers into s-expression format of Cstructs
Expand All @@ -18,7 +18,7 @@ This repository provides several packages that can be installed via the
- `cstruct-lwt`: provide [Lwt](https://ocsigen.org/lwt) variants of read/write functions
- `ppx_cstruct`: a [PPX](https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec248) syntax extension (see below)

The libraries depend on OCaml version 4.02.3 and later, since it provides a
The libraries depend on OCaml version 4.03.0 and later, since it provides a
[ppx](http://whitequark.org/blog/2014/04/16/a-guide-to-extension-points-in-ocaml/)
extension point. The old
[camlp4](http://caml.inria.fr/pub/docs/manual-camlp4/manual002.html)
Expand Down
17 changes: 0 additions & 17 deletions appveyor.yml

This file was deleted.

64 changes: 64 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
jobs:
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: env AGENT_OS=Linux TEST_DISTRIB=yes ./.azure-pipelines.sh
displayName: Build
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'docs'
targetPath: '_build/default/_doc/_html/'
- job: LinuxDistros
pool:
vmImage: 'ubuntu-16.04'
strategy:
matrix:
alpine:
DISTRO: 'alpine'
debian-stable:
DISTRO: 'debian-stable'
ubuntu-lts:
DISTRO: 'ubuntu-lts'
opensuse:
DISTRO: 'opensuse'
fedora:
DISTRO: 'fedora'
steps:
- script: docker run -e AGENT_OS=LinuxDocker -e DISTRO=${DISTRO} -v `pwd`:/home/opam/src ocaml/opam2:${DISTRO} /home/opam/src/.azure-pipelines.sh
displayName: Build
- job: macOS
pool:
vmImage: 'macOS-10.13'
steps:
- script: ./.azure-pipelines.sh
displayName: Build
- job: Windows
variables:
CYGWIN_ROOT: $(System.Workfolder)\cygwin
CYGWIN_MIRROR: http://cygwin.mirror.constant.com
pool:
vmImage: 'vs2017-win2016'
steps:
- script: |
choco install cygwin --params="/InstallDir:%CYGWIN_ROOT%"
displayName: Install Cygwin
- script: |
%CYGWIN_ROOT%\cygwinsetup.exe -qnNdO -R "%CYGWIN_ROOT%" -s "%CYGWIN_MIRROR%" -g -P ^
curl,^
diff,^
diffutils,^
git,^
m4,^
make,^
patch,^
perl,^
rsync,^
mingw64-x86_64-gcc-core,^
unzip
displayName: Install Dependencies
- script: |
set PATH=%CYGWIN_ROOT%\bin;%SYSTEMROOT%\system32
set BUILD_SOURCES_DIR=$(Build.SourcesDirectory)
env.exe -- bash.exe -l $(Build.SourcesDirectory)/.azure-pipelines.sh
displayName: Build
8 changes: 8 additions & 0 deletions fuzz/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
(executable
(name fuzz)
(libraries cstruct bigarray cstruct-sexp crowbar fmt))

(alias
(name fuzz)
(deps fuzz.exe (source_tree input))
(action (run
timeout --preserve-status 50m
bun -v --input=input --output=output
-- ./fuzz.exe)))
2 changes: 2 additions & 0 deletions fuzz/fuzz.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
open Crowbar

[@@@warning "-3"]

let create x =
match Cstruct.create x with
| c -> assert (x >= 0); c
Expand Down
1 change: 1 addition & 0 deletions fuzz/input/start
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bactrian
2 changes: 2 additions & 0 deletions lib_test/bounds.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

[@@@warning "-3"]

let to_string { Cstruct.buffer; off; len } =
Printf.sprintf "buffer length = %d; off=%d; len=%d" (Bigarray.Array1.dim buffer) off len

Expand Down
Loading