xref: /aosp_15_r20/external/jazzer-api/examples/check_for_finding.sh (revision 33edd6723662ea34453766bfdca85dbfdd5342b8)
1#!/usr/bin/env bash
2# Copyright 2021 Code Intelligence GmbH
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# --- begin runfiles.bash initialization v2 ---
17# Copy-pasted from the Bazel Bash runfiles library v2.
18set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
19source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
20  source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
21  source "$0.runfiles/$f" 2>/dev/null || \
22  source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
23  source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
24  { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
25# --- end runfiles.bash initialization v2 ---
26
27# Temporarily disable exit on error since we expect the command below to fail.
28set +e
29"$(rlocation "$1")" "$2" "$(rlocation "$3")" "${@:4}"
30declare -i exit_code=$?
31set -e
32
33# Assert that we either found a crash in java (exit code 77) or an ASan crash
34# (exit code 76).
35if [ $exit_code -eq 77 ] || [ $exit_code -eq 76 ]
36then
37  exit 0
38else
39  echo "Unexpected exit code: $exit_code"
40  exit 1
41fi
42