57c8c59d06abf8dcd23827514d5ddc406d1c6ad3
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_fuzzer / examples / build_and_run_toy_fuzzer.sh
1 #! /bin/bash
2
3 # Copyright 2020 The Pigweed Authors
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 # use this file except in compliance with the License. You may obtain a copy of
7 # the License at
8 #
9 #     https://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations under
15 # the License.
16
17 # TODO(pwbug/177): Pythonize this, or otherwise replace it.
18
19 set -e
20
21 OUT_DIR="out/host"
22
23 confirm() {
24   echo
25   while [ -n "$1" ] ; do
26     echo "$1"
27     shift
28   done
29   echo
30   read -p "Do you wish to continue? [yN]" confirm
31   case $confirm in
32       [Yy]* ) ;;
33       * ) exit;;
34   esac
35   echo
36 }
37
38 confirm "This script builds and runs a example fuzzer." \
39         "This script is about to delete $OUT_DIR."
40 set -x
41 rm -rf $OUT_DIR
42
43 mkdir -p $OUT_DIR
44 echo 'pw_target_toolchain="//pw_toolchain:host_clang_og"' > $OUT_DIR/args.gn
45 echo 'pw_sanitizer="address"' >> $OUT_DIR/args.gn
46 gn gen $OUT_DIR
47 ninja -C $OUT_DIR pw_module_fuzzers
48
49 set +x
50 confirm "The toy_fuzzer was built successfully!" \
51         "This script is about to start fuzzing."
52 set -x
53 $OUT_DIR/obj/pw_fuzzer/toy_fuzzer