|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# ------------------------------------------------------------------------------ |
| 4 | +# Copyright (c) 2020, Arm Limited, All Rights Reserved |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | +# not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http:#www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# ------------------------------------------------------------------------------ |
| 19 | + |
| 20 | +FUZZ_CONTAINER_NAME=parsec_fuzzer |
| 21 | +CLEANUP_CONTAINER_NAME=parsec_fuzzer_cleanup |
| 22 | + |
| 23 | +set -e |
| 24 | + |
| 25 | +if [[ "$1" == "run" ]] |
| 26 | +then |
| 27 | + # Set up fuzz folder |
| 28 | + docker run --rm -v $(pwd):/parsec -w /parsec/fuzz --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh |
| 29 | + # A copy of the config file is used because the file is modified during the run |
| 30 | + cp fuzz/config.toml fuzz/run_config.toml |
| 31 | + |
| 32 | + # Build Docker image |
| 33 | + docker build fuzz/docker -t parsec/fuzz |
| 34 | + |
| 35 | + # Stop previous container and run fuzzer |
| 36 | + docker kill $FUZZ_CONTAINER_NAME || true |
| 37 | + sleep 5s |
| 38 | + docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz --name $FUZZ_CONTAINER_NAME parsec/fuzz ./run_fuzz.sh |
| 39 | +elif [[ "$1" == "stop" ]] |
| 40 | +then |
| 41 | + docker kill $FUZZ_CONTAINER_NAME |
| 42 | +elif [[ "$1" == "follow" ]] |
| 43 | +then |
| 44 | + docker logs -f --tail 100 $FUZZ_CONTAINER_NAME |
| 45 | +elif [[ "$1" == "clean" ]] |
| 46 | +then |
| 47 | + # Cleanup is done via Docker because on some systems ACL settings prevent the user who |
| 48 | + # created a container from removing the files created by said container. Another one |
| 49 | + # is needed to do the cleanup. |
| 50 | + docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh |
| 51 | +elif [[ "$1" == "erase" ]] |
| 52 | +then |
| 53 | + docker run -d --rm -v $(pwd):/parsec -w /parsec/fuzz -e "ERASE=true" --name $CLEANUP_CONTAINER_NAME parsec/fuzz ./cleanup.sh |
| 54 | +else |
| 55 | + echo "usage: ./fuzz.sh [COMMAND] |
| 56 | +
|
| 57 | +Commands: |
| 58 | +'run' - builds the fuzzing container and runs the fuzzer |
| 59 | +'stop' - stops the fuzzing container |
| 60 | +'follow' - prints and follows the log output of the fuzzing container |
| 61 | +'clean' - clean up the fuzzing environment (does not remove artifacts or the fuzz corpus) |
| 62 | +'erase' - fully clean the fuzzing environment - WARNING: this will remove all the results of previous runs" |
| 63 | +fi |
0 commit comments