|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2025 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +################################################################################ |
| 17 | + |
| 18 | +# Module for validating "run_tests.sh" of a given project. Before the run_tests.sh |
| 19 | +# script is run, a cached container image is first built. We assume here that the |
| 20 | +# replay is working for the target project. |
| 21 | +# (TODO): make sure this works for both replay_build.sh and ccached rebuilds. |
| 22 | +# currently the focus is on replay_build.sh. |
| 23 | +_PROJECT=$1 |
| 24 | +_FUZZING_LANGUAGE=$2 |
| 25 | +_SANITIZER=${3:-address} |
| 26 | + |
| 27 | +BASE=$PWD |
| 28 | + |
| 29 | +# Final image is either ccache or replay script, depending on which worked. |
| 30 | +FINAL_IMAGE_NAME=us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/${_PROJECT}-ofg-cached-${_SANITIZER} |
| 31 | + |
| 32 | +# Step 1: build the base image |
| 33 | +cd projects/${_PROJECT} |
| 34 | +docker build -t gcr.io/oss-fuzz/${_PROJECT} . |
| 35 | + |
| 36 | +# Step 2: create a container where `compile` has run which enables ccaching |
| 37 | +# and also generates a replay build script. |
| 38 | +cd ${BASE} |
| 39 | +mkdir -p ccaches/${_PROJECT} |
| 40 | +mkdir -p build/out/${_PROJECT} |
| 41 | + |
| 42 | +# Clean up existing images. |
| 43 | +docker container rm -f ${_PROJECT}-origin-${_SANITIZER} |
| 44 | + |
| 45 | +docker run \ |
| 46 | + --env=SANITIZER=${_SANITIZER} \ |
| 47 | + --env=CCACHE_DIR=/workspace/ccache \ |
| 48 | + --env=FUZZING_LANGUAGE=${_FUZZING_LANGUAGE} \ |
| 49 | + --env=CAPTURE_REPLAY_SCRIPT=1 \ |
| 50 | + --name=${_PROJECT}-origin-${_SANITIZER} \ |
| 51 | + -v=$PWD/ccaches/${_PROJECT}/ccache:/workspace/ccache \ |
| 52 | + -v=$PWD/build/out/${_PROJECT}/:/out/ \ |
| 53 | + gcr.io/oss-fuzz/${_PROJECT} \ |
| 54 | + /bin/bash -c \ |
| 55 | + "export PATH=/ccache/bin:\$PATH && compile && cp -n /usr/local/bin/replay_build.sh \$SRC/" |
| 56 | + |
| 57 | + |
| 58 | +# Step 3: save (commit, locally) the cached container as an image |
| 59 | +docker container commit -c "ENV REPLAY_ENABLED=1" -c "ENV CAPTURE_REPLAY_SCRIPT=" ${_PROJECT}-origin-${_SANITIZER} $FINAL_IMAGE_NAME |
| 60 | + |
| 61 | +# Step 4: run the actual run_tests.sh script in the container. |
| 62 | +docker run \ |
| 63 | + --rm \ |
| 64 | + -ti \ |
| 65 | + us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/${_PROJECT}-ofg-cached-address /bin/bash -c 'chmod +x /src/run_tests.sh && /src/run_tests.sh' |
0 commit comments