xref: /aosp_15_r20/external/jazzer-api/tests/src/test/shell/junit_agent_configuration_test.sh (revision 33edd6723662ea34453766bfdca85dbfdd5342b8)
1#!/bin/bash
2# Copyright 2022 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# Verify that instrumentation filter defaults set by @FuzzTest work.
17
18# --- begin runfiles.bash initialization v2 ---
19# Copy-pasted from the Bazel Bash runfiles library v2.
20set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
21source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
22  source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
23  source "$0.runfiles/$f" 2>/dev/null || \
24  source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
25  source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
26  { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
27# --- end runfiles.bash initialization v2 ---
28
29function fail() {
30  echo "FAILED: $1"
31  exit 1
32}
33
34stderr="$TEST_TMPDIR/stderr"
35
36"$(rlocation "$1")" --target_class=com.example.JUnitAgentConfigurationFuzzTest 2>&1 -runs=1 | tee "$stderr" || fail "Jazzer did not exit with exit code 0"
37
38[[ $(grep -c "INFO: Instrumented " "$stderr") == 1 ]] || fail "Expected exactly one instrumented class"
39[[ $(grep "INFO: Instrumented " "$stderr" | grep -c -v "INFO: Instrumented com.example.") == 0 ]] || fail "Expected all instrumented classes to be in com.example"
40