18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciset -e
58c2ecf20Sopenharmony_ciset -o pipefail
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci# To debug, uncomment the following line
88c2ecf20Sopenharmony_ci# set -x
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci# -mprofile-kernel is only supported on 64le, so this should not be invoked
118c2ecf20Sopenharmony_ci# for other targets. Therefore we can pass in -m64 and -mlittle-endian
128c2ecf20Sopenharmony_ci# explicitly, to take care of toolchains defaulting to other targets.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci# Test whether the compile option -mprofile-kernel exists and generates
158c2ecf20Sopenharmony_ci# profiling code (ie. a call to _mcount()).
168c2ecf20Sopenharmony_ciecho "int func() { return 0; }" | \
178c2ecf20Sopenharmony_ci    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
188c2ecf20Sopenharmony_ci    2> /dev/null | grep -q "_mcount"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci# Test whether the notrace attribute correctly suppresses calls to _mcount().
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciecho -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
238c2ecf20Sopenharmony_ci    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
248c2ecf20Sopenharmony_ci    2> /dev/null | grep -q "_mcount" && \
258c2ecf20Sopenharmony_ci    exit 1
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciexit 0
28