1#!/bin/bash
2# Copyright (C) 2023 The Android Open Source Project
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
16color_success=$'\E'"[0;32m"
17color_failed=$'\E'"[0;31m"
18color_reset=$'\E'"[00m"
19
20FUZZER_NAME=test_service_fuzzer_should_crash
21FUZZER_OUT=fuzzer-output
22
23if [ ! -f "$FUZZER_NAME" ]
24then
25    echo -e "${color_failed}Binary $FUZZER_NAME does not exist"
26    echo "${color_reset}"
27    exit 1
28fi
29
30for CRASH_TYPE in PLAIN KNOWN_UID AID_SYSTEM AID_ROOT BINDER DUMP SHELL_CMD; do
31    echo "INFO: Running fuzzer : test_service_fuzzer_should_crash $CRASH_TYPE"
32
33    ./test_service_fuzzer_should_crash "$CRASH_TYPE" -max_total_time=60 &>"$FUZZER_OUT"
34
35    echo "INFO: Searching fuzzer output for expected crashes"
36    if grep -q "Expected crash, $CRASH_TYPE." "$FUZZER_OUT"
37    then
38        echo -e "${color_success}Success: Found expected crash. fuzzService test successful!"
39    else
40        echo -e "${color_failed}Failed: Unable to find successful fuzzing output from test_service_fuzzer_should_crash"
41        echo "${color_reset}"
42        exit 1
43    fi
44done
45