From 6e92692c44227f62a5deccbc54613894354ba5a5 Mon Sep 17 00:00:00 2001 From: 13359001024 Date: Fri, 5 Aug 2022 15:12:42 +0800 Subject: [PATCH] add tracepoint test. Signed-off-by: 13359001024 --- test/BUILD.gn | 3 + test/tracepointtest/BUILD.gn | 21 +++ test/tracepointtest/Kconfig | 18 ++ test/tracepointtest/Makefile | 10 + test/tracepointtest/emmc.h | 40 ++++ test/tracepointtest/rockchip_linux_defconfig | 11 ++ test/tracepointtest/tracepoint.sh | 176 ++++++++++++++++++ test/tracepointtest/tracepoint_test/Kconfig | 9 + test/tracepointtest/tracepoint_test/Makefile | 6 + .../tracepoint_test/tracepoint_test.c | 40 ++++ test/tracepointtest/tracepointtestko.sh | 67 +++++++ .../vendoramlemmcpartition_test/Kconfig | 10 + .../vendoramlemmcpartition_test/Makefile | 6 + .../vendoramlemmcpartition_test.c | 39 ++++ test/tracepointtest/vendordommap_test/Kconfig | 10 + .../tracepointtest/vendordommap_test/Makefile | 6 + .../vendordommap_test/vendordommap_test.c | 39 ++++ .../vendordomprotectpkey_test/Kconfig | 10 + .../vendordomprotectpkey_test/Makefile | 6 + .../vendordomprotectpkey_test.c | 39 ++++ .../vendorfakebootpartition_test/Kconfig | 10 + .../vendorfakebootpartition_test/Makefile | 6 + .../vendorfakebootpartition_test.c | 39 ++++ 23 files changed, 621 insertions(+) create mode 100644 test/tracepointtest/BUILD.gn create mode 100644 test/tracepointtest/Kconfig create mode 100644 test/tracepointtest/Makefile create mode 100644 test/tracepointtest/emmc.h create mode 100644 test/tracepointtest/rockchip_linux_defconfig create mode 100644 test/tracepointtest/tracepoint.sh create mode 100644 test/tracepointtest/tracepoint_test/Kconfig create mode 100644 test/tracepointtest/tracepoint_test/Makefile create mode 100644 test/tracepointtest/tracepoint_test/tracepoint_test.c create mode 100644 test/tracepointtest/tracepointtestko.sh create mode 100644 test/tracepointtest/vendoramlemmcpartition_test/Kconfig create mode 100644 test/tracepointtest/vendoramlemmcpartition_test/Makefile create mode 100644 test/tracepointtest/vendoramlemmcpartition_test/vendoramlemmcpartition_test.c create mode 100644 test/tracepointtest/vendordommap_test/Kconfig create mode 100644 test/tracepointtest/vendordommap_test/Makefile create mode 100644 test/tracepointtest/vendordommap_test/vendordommap_test.c create mode 100644 test/tracepointtest/vendordomprotectpkey_test/Kconfig create mode 100644 test/tracepointtest/vendordomprotectpkey_test/Makefile create mode 100644 test/tracepointtest/vendordomprotectpkey_test/vendordomprotectpkey_test.c create mode 100644 test/tracepointtest/vendorfakebootpartition_test/Kconfig create mode 100644 test/tracepointtest/vendorfakebootpartition_test/Makefile create mode 100644 test/tracepointtest/vendorfakebootpartition_test/vendorfakebootpartition_test.c diff --git a/test/BUILD.gn b/test/BUILD.gn index 89103af..b3051e2 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -48,5 +48,8 @@ group("linuxkerneltest") { ":init_runtest", "fuzztest:fuzztest", ] + if ("$device_name" == "rk3568") { + deps += [ "tracepointtest:tracepointtest" ] + } } } diff --git a/test/tracepointtest/BUILD.gn b/test/tracepointtest/BUILD.gn new file mode 100644 index 0000000..9bbfd4d --- /dev/null +++ b/test/tracepointtest/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +action("tracepointtest") { + script = "tracepoint.sh" + outputs = + [ "$root_build_dir/tests/kernel_shelltest/tracepointtest.timestamp" ] + deps = [ "//device/board/hihope/rk3568/kernel:kernel" ] +} diff --git a/test/tracepointtest/Kconfig b/test/tracepointtest/Kconfig new file mode 100644 index 0000000..81e5e04 --- /dev/null +++ b/test/tracepointtest/Kconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Kconfig for tracepoint test +# + +menu "tracepoint test" + +source "drivers/tracepointtest/vendordommap_test/Kconfig" + +source "drivers/tracepointtest/vendordomprotectpkey_test/Kconfig" + +source "drivers/tracepointtest/tracepoint_test/Kconfig" + +source "drivers/tracepointtest/vendoramlemmcpartition_test/Kconfig" + +source "drivers/tracepointtest/vendorfakebootpartition_test/Kconfig" + +endmenu diff --git a/test/tracepointtest/Makefile b/test/tracepointtest/Makefile new file mode 100644 index 0000000..47a3e4b --- /dev/null +++ b/test/tracepointtest/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for tracepoint test +# + +obj-$(CONFIG_TRACEPOINT_MMAP) += vendordommap_test/ +obj-$(CONFIG_TRACEPOINT_MPROTECT_PKEY) += vendordomprotectpkey_test/ +obj-$(CONFIG_TRACEPOINT_TEST) += tracepoint_test/ +obj-$(CONFIG_TRACEPOINT_AML_EMMC_PARTITION) += vendoramlemmcpartition_test/ +obj-$(CONFIG_TRACEPOINT_FAKE_BOOT_PARTITION) += vendorfakebootpartition_test/ diff --git a/test/tracepointtest/emmc.h b/test/tracepointtest/emmc.h new file mode 100644 index 0000000..bb238ff --- /dev/null +++ b/test/tracepointtest/emmc.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* SPDX-License-Identifier: GPL-2.0 */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM emmc + +#define TRACE_INCLUDE_PATH trace/hooks +#if !defined(_TRACE_HOOKS_EMMC_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOKS_EMMC_H + +#include +#include + +DECLARE_HOOK(vendor_aml_emmc_partition, + TP_PROTO(unsigned long prot, int *err), + TP_ARGS(prot, err) +); + +DECLARE_HOOK(vendor_fake_boot_partition, + TP_PROTO(unsigned long prot, int *err), + TP_ARGS(prot, err) +); + +#endif + +/* This part must be outside protection */ +#include diff --git a/test/tracepointtest/rockchip_linux_defconfig b/test/tracepointtest/rockchip_linux_defconfig new file mode 100644 index 0000000..8a1d874 --- /dev/null +++ b/test/tracepointtest/rockchip_linux_defconfig @@ -0,0 +1,11 @@ +# +# Automatically generated file; DO NOT EDIT. +# Linux/arm64 5.10.79 Kernel Configuration +# + +CONFIG_VENDOR_HOOKS=y +CONFIG_TRACEPOINT_MMAP=m +CONFIG_TRACEPOINT_MPROTECT_PKEY=m +CONFIG_TRACEPOINT_TEST=m +CONFIG_TRACEPOINT_AML_EMMC_PARTITION=m +CONFIG_TRACEPOINT_FAKE_BOOT_PARTITION=m \ No newline at end of file diff --git a/test/tracepointtest/tracepoint.sh b/test/tracepointtest/tracepoint.sh new file mode 100644 index 0000000..93bbda8 --- /dev/null +++ b/test/tracepointtest/tracepoint.sh @@ -0,0 +1,176 @@ +#!/bin/sh +################################################################################ +# +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# File: tracepoint.sh +# +# Description: test tracepoint +# +# Authors: yang ming di +# +# History: August 4 2022 - test tracepoint +# +################################################################################ + +CURRENT_DIR=$(pwd) +ROOT_DIR=$(cd $CURRENT_DIR/../../ && pwd) +ROOT_FILE_DIR=$ROOT_DIR/kernel/linux/build/test/tracepointtest +#ROOT_TEST_DIR=$(cd $CURRENT_DIR/../../../../../ && pwd) +COMPILE_DIR=$ROOT_DIR/out/kernel/src_tmp/linux-5.10 +OBJ_DIR=$ROOT_DIR/out/kernel/OBJ +DRIVERS_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/drivers +TRACEPOINT_INCLUDE_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/include/trace/hooks +DRIVERS_TRACEPOINT_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/drivers/tracepointtest +CONFIG_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/arch/arm64/configs + +copy() { + echo "copy $1 to $2" + cp -rf $1 $2 +} + +modify_config() { + if [ -e $CONFIG_DIR/tmp ]; then + rm -f $CONFIG_DIR/tmp + fi + + cp -f $CONFIG_DIR/$2 $CONFIG_DIR/$2_tmpfile + + while read line; do + echo "$line" >>$CONFIG_DIR/tmp + done <$CONFIG_DIR/$2 + + while read line; do + if [[ "$line" != "#"* ]]; then + echo "$line" >>$CONFIG_DIR/tmp + fi + done <$1 + + mv $CONFIG_DIR/tmp $CONFIG_DIR/$2 +} + +modify_files() { + KCONFIG=$DRIVERS_DIR/Kconfig + MAKEFILE=$DRIVERS_DIR/Makefile + VENDOR_HOOKS=$DRIVERS_DIR/hooks/vendor_hooks.c + TMPFILE=$DRIVERS_DIR/tmp + + cp -f $KCONFIG ${KCONFIG}_tmpfile + cp -f $MAKEFILE ${MAKEFILE}_tmpfile + cp -f $VENDOR_HOOKS ${VENDOR_HOOKS}_tmpfile + + if [ -e $TMPFILE ]; then + rm -f $TMPFILE + fi + + while read line; do + if [[ "$line" != "endmenu" ]]; then + echo "$line" >>$TMPFILE + fi + done <$KCONFIG + echo "source \"drivers/tracepointtest/Kconfig\"" >>$TMPFILE + echo "endmenu" >>$TMPFILE + mv $TMPFILE $KCONFIG + + while read line; do + echo "$line" >>$TMPFILE + done <$MAKEFILE + echo "obj-y += tracepointtest/" >>$TMPFILE + mv $TMPFILE $MAKEFILE + + while read line; do + echo "$line" >>$TMPFILE + done <$VENDOR_HOOKS + echo "#include " >>$TMPFILE + echo "EXPORT_TRACEPOINT_SYMBOL_GPL(vendor_aml_emmc_partition);" >>$TMPFILE + echo "EXPORT_TRACEPOINT_SYMBOL_GPL(vendor_fake_boot_partition);" >>$TMPFILE + mv $TMPFILE $VENDOR_HOOKS +} + +compile() { + cd $COMPILE_DIR || exit + export PRODUCT_COMPANY=hihope + export DEVICE_NAME=rk3568 + export DEVICE_COMPANY=rockchip + export PRODUCT_PATH=~/OpenHarmony/master/out/kernel/vendor/hihope/rk3568 + ./make-ohos.sh TB-RK3568X0 >null + if [ $? -ne 0 ]; then + echo "compile failed" + exit 1 + else + echo "compile success" + fi +} + +collectKO() { + if [ -e $OBJ_DIR/kofiles ]; then + rm -f $OBJ_DIR/kofiles + mkdir -p $OBJ_DIR/kofiles + else + mkdir -p $OBJ_DIR/kofiles + fi + + find $DRIVERS_TRACEPOINT_DIR -name '*.ko' | xargs cp -t $OBJ_DIR/kofiles +} + +restore() { + CONFIGNAME=rockchip_linux_defconfig + KCONFIG=$DRIVERS_DIR/Kconfig + MAKEFILE=$DRIVERS_DIR/Makefile + VENDOR_HOOKS=$DRIVERS_DIR/hooks/vendor_hooks.c + + rm -rf $DRIVERS_TRACEPOINT_DIR + mv -f $CONFIG_DIR/${CONFIGNAME}_tmpfile $CONFIG_DIR/$CONFIGNAME + mv -f ${KCONFIG}_tmpfile $KCONFIG + mv -f ${MAKEFILE}_tmpfile $MAKEFILE + mv -f ${VENDOR_HOOKS}_tmpfile $VENDOR_HOOKS + rm -rf $COMPILE_DIR/.lock +} + +main() { + if [ -e $COMPILE_DIR/.lock ]; then + restore + fi + + echo "" >$COMPILE_DIR/.lock + + if [ -d $DRIVERS_DIR/tracepointtest ]; then + rm -rf $DRIVERS_DIR/tracepointtest + mkdir -p $DRIVERS_DIR/tracepointtest + else + mkdir -p $DRIVERS_DIR/tracepointtest + fi + + for dir in $(ls $ROOT_FILE_DIR); do + if [ -d $ROOT_FILE_DIR/$dir ]; then + copy $ROOT_FILE_DIR/$dir $DRIVERS_TRACEPOINT_DIR/$dir + elif [[ "$dir" == "Makefile" ]]; then + copy $ROOT_FILE_DIR/$dir $DRIVERS_TRACEPOINT_DIR/$dir + elif [[ "$dir" == "Kconfig" ]]; then + copy $ROOT_FILE_DIR/$dir $DRIVERS_TRACEPOINT_DIR/$dir + elif [[ $dir == *.h ]]; then + copy $ROOT_FILE_DIR/$dir $TRACEPOINT_INCLUDE_DIR/$dir + elif [[ "$dir" == "rockchip_linux_defconfig" ]]; then + modify_config $ROOT_FILE_DIR/$dir $dir + fi + done + + modify_files + compile + collectKO + restore +} + +main diff --git a/test/tracepointtest/tracepoint_test/Kconfig b/test/tracepointtest/tracepoint_test/Kconfig new file mode 100644 index 0000000..764d713 --- /dev/null +++ b/test/tracepointtest/tracepoint_test/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +config TRACEPOINT_TEST + tristate "Test Tracepoint For Vendor Hooks" + default m + help + Enable test tracepoint for vendor hooks + Allow vendor modules to attach driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK diff --git a/test/tracepointtest/tracepoint_test/Makefile b/test/tracepointtest/tracepoint_test/Makefile new file mode 100644 index 0000000..ea3a6de --- /dev/null +++ b/test/tracepointtest/tracepoint_test/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for test tracepoint +# + +obj-$(CONFIG_TRACEPOINT_TEST) += tracepoint_test.o diff --git a/test/tracepointtest/tracepoint_test/tracepoint_test.c b/test/tracepointtest/tracepoint_test/tracepoint_test.c new file mode 100644 index 0000000..99343d6 --- /dev/null +++ b/test/tracepointtest/tracepoint_test/tracepoint_test.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +static int tracepoint_test_init_module(void) +{ + pr_info("tracepoint test module init\n"); + trace_vendor_do_mmap(NULL, NULL); + trace_vendor_do_mprotect_pkey(NULL, NULL); + trace_vendor_aml_emmc_partition(NULL, NULL); + trace_vendor_fake_boot_partition(NULL, NULL); + return 0; +} + +static void tracepoint_test_exit_module(void) +{ + pr_info("tracepoint test module exit\n"); +} + +/* module entry points */ +module_init(tracepoint_test_init_module); +module_exit(tracepoint_test_exit_module); +MODULE_LICENSE ("GPL v2"); diff --git a/test/tracepointtest/tracepointtestko.sh b/test/tracepointtest/tracepointtestko.sh new file mode 100644 index 0000000..e9c9749 --- /dev/null +++ b/test/tracepointtest/tracepointtestko.sh @@ -0,0 +1,67 @@ +#!/bin/sh +################################################################################ +# +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# File: tracepointtestko.sh +# +# Description: tracepoint ko test +# +# Authors: yang ming di +# +# History: August 4 2022 - tracepoint ko test +# +################################################################################ + +CURRENT_DIR=$(pwd) +KO_DIR=$CURRENT_DIR/kofile + +insmod_ko() { + for dir in $(ls $KO_DIR); do + if [[ "$dir" != "tracepoint_test.ko" ]]; then + insmod $KO_DIR/$dir + echo "$KO_DIR/$dir is loaded" + fi + done + + insmod $KO_DIR/tracepoint_test.ko + + arr=(vendor_do_mmap vendor_do_mprotect_pkey vendor_aml_emmc_partition vendor_fake_boot_partition) + for i in ${arr[@]}; do + dmesg | grep $i >/dev/null + if [ $? -eq 0 ]; then + echo "tracepoint $i succeed" + else + echo "tracepoint $i failed" + fi + done +} + +rmmod_ko() { + for dir in $(ls $KO_DIR); do + rmmod $KO_DIR/$dir + echo "$KO_DIR/$dir is removed" + done +} + +main() { + if [[ $1 == "rmmod_ko" ]]; then + rmmod_ko + else + insmod_ko + fi +} + +main $1 diff --git a/test/tracepointtest/vendoramlemmcpartition_test/Kconfig b/test/tracepointtest/vendoramlemmcpartition_test/Kconfig new file mode 100644 index 0000000..4ea0483 --- /dev/null +++ b/test/tracepointtest/vendoramlemmcpartition_test/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config TRACEPOINT_AML_EMMC_PARTITION + tristate "AML_EMMC_PARTITION Tracepoint For Vendor Hooks" + depends on VENDOR_HOOKS + default m + help + Enable aml emmc partition tracepoint for vendor hooks + Allow vendor modules to attach driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK diff --git a/test/tracepointtest/vendoramlemmcpartition_test/Makefile b/test/tracepointtest/vendoramlemmcpartition_test/Makefile new file mode 100644 index 0000000..7ef4eed --- /dev/null +++ b/test/tracepointtest/vendoramlemmcpartition_test/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for aml emmc partition tracepoint +# + +obj-$(CONFIG_TRACEPOINT_AML_EMMC_PARTITION) += vendoramlemmcpartition_test.o diff --git a/test/tracepointtest/vendoramlemmcpartition_test/vendoramlemmcpartition_test.c b/test/tracepointtest/vendoramlemmcpartition_test/vendoramlemmcpartition_test.c new file mode 100644 index 0000000..d3042a4 --- /dev/null +++ b/test/tracepointtest/vendoramlemmcpartition_test/vendoramlemmcpartition_test.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +static void vendor_aml_emmc_partition(void *data, unsigned long prot, int *err) +{ + pr_info("%s\n", __func__); +} + +static int aml_emmc_partition_test_init_module(void) +{ + return register_trace_vendor_aml_emmc_partition(&vendor_aml_emmc_partition, NULL); +} + +static void aml_emmc_partition_test_exit_module(void) +{ + unregister_trace_vendor_aml_emmc_partition(&vendor_aml_emmc_partition, NULL); +} + +/* module entry points */ +module_init(aml_emmc_partition_test_init_module); +module_exit(aml_emmc_partition_test_exit_module); +MODULE_LICENSE ("GPL v2"); diff --git a/test/tracepointtest/vendordommap_test/Kconfig b/test/tracepointtest/vendordommap_test/Kconfig new file mode 100644 index 0000000..2de4270 --- /dev/null +++ b/test/tracepointtest/vendordommap_test/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config TRACEPOINT_MMAP + tristate "MMAP Tracepoint For Vendor Hooks" + depends on VENDOR_HOOKS + default m + help + Enable mmap tracepoint for vendor hooks + Allow vendor modules to attach driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK diff --git a/test/tracepointtest/vendordommap_test/Makefile b/test/tracepointtest/vendordommap_test/Makefile new file mode 100644 index 0000000..3046e3d --- /dev/null +++ b/test/tracepointtest/vendordommap_test/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for mmap tracepoint +# + +obj-$(CONFIG_TRACEPOINT_MMAP) += vendordommap_test.o diff --git a/test/tracepointtest/vendordommap_test/vendordommap_test.c b/test/tracepointtest/vendordommap_test/vendordommap_test.c new file mode 100644 index 0000000..c0dcb99 --- /dev/null +++ b/test/tracepointtest/vendordommap_test/vendordommap_test.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +static void vendor_do_mmap(void *data, vm_flags_t *vm_flags, int *err) +{ + pr_info("%s\n", __func__); +} + +static int mmap_test_init_module(void) +{ + return register_trace_vendor_do_mmap(&vendor_do_mmap, NULL); +} + +static void mmap_test_exit_module(void) +{ + unregister_trace_vendor_do_mmap(&vendor_do_mmap, NULL); +} + +/* module entry points */ +module_init(mmap_test_init_module); +module_exit(mmap_test_exit_module); +MODULE_LICENSE ("GPL v2"); diff --git a/test/tracepointtest/vendordomprotectpkey_test/Kconfig b/test/tracepointtest/vendordomprotectpkey_test/Kconfig new file mode 100644 index 0000000..8a0a9fe --- /dev/null +++ b/test/tracepointtest/vendordomprotectpkey_test/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config TRACEPOINT_MPROTECT_PKEY + tristate "MPROTECT_PKEY Tracepoint For Vendor Hooks" + depends on VENDOR_HOOKS + default m + help + Enable mprotect pkey tracepoint for vendor hooks + Allow vendor modules to attach driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK diff --git a/test/tracepointtest/vendordomprotectpkey_test/Makefile b/test/tracepointtest/vendordomprotectpkey_test/Makefile new file mode 100644 index 0000000..4f60ffd --- /dev/null +++ b/test/tracepointtest/vendordomprotectpkey_test/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for mprotect pkey tracepoint +# + +obj-$(CONFIG_TRACEPOINT_MPROTECT_PKEY) += vendordomprotectpkey_test.o diff --git a/test/tracepointtest/vendordomprotectpkey_test/vendordomprotectpkey_test.c b/test/tracepointtest/vendordomprotectpkey_test/vendordomprotectpkey_test.c new file mode 100644 index 0000000..f4722bc --- /dev/null +++ b/test/tracepointtest/vendordomprotectpkey_test/vendordomprotectpkey_test.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +static void vendor_do_mprotect_pkey(void *data, unsigned long prot, int *err) +{ + pr_info("%s\n", __func__); +} + +static int mprotect_pkey_test_init_module(void) +{ + return register_trace_vendor_do_mprotect_pkey(&vendor_do_mprotect_pkey, NULL); +} + +static void mprotect_pkey_test_exit_module(void) +{ + unregister_trace_vendor_do_mprotect_pkey(&vendor_do_mprotect_pkey, NULL); +} + +/* module entry points */ +module_init(mprotect_pkey_test_init_module); +module_exit(mprotect_pkey_test_exit_module); +MODULE_LICENSE ("GPL v2"); diff --git a/test/tracepointtest/vendorfakebootpartition_test/Kconfig b/test/tracepointtest/vendorfakebootpartition_test/Kconfig new file mode 100644 index 0000000..394b35b --- /dev/null +++ b/test/tracepointtest/vendorfakebootpartition_test/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config TRACEPOINT_FAKE_BOOT_PARTITION + tristate "FAKE_BOOT_PARTITION Tracepoint For Vendor Hooks" + depends on VENDOR_HOOKS + default m + help + Enable fake boot partition tracepoint for vendor hooks + Allow vendor modules to attach driver hooks defined via + DECLARE_HOOK or DECLARE_RESTRICTED_HOOK diff --git a/test/tracepointtest/vendorfakebootpartition_test/Makefile b/test/tracepointtest/vendorfakebootpartition_test/Makefile new file mode 100644 index 0000000..b6882ea --- /dev/null +++ b/test/tracepointtest/vendorfakebootpartition_test/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for fake boot partition tracepoint +# + +obj-$(CONFIG_TRACEPOINT_FAKE_BOOT_PARTITION) += vendorfakebootpartition_test.o diff --git a/test/tracepointtest/vendorfakebootpartition_test/vendorfakebootpartition_test.c b/test/tracepointtest/vendorfakebootpartition_test/vendorfakebootpartition_test.c new file mode 100644 index 0000000..7b8457b --- /dev/null +++ b/test/tracepointtest/vendorfakebootpartition_test/vendorfakebootpartition_test.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +static void vendor_fake_boot_partition(void *data, unsigned long prot, int *err) +{ + pr_info("%s\n", __func__); +} + +static int fake_boot_partition_test_init_module(void) +{ + return register_trace_vendor_fake_boot_partition(&vendor_fake_boot_partition, NULL); +} + +static void fake_boot_partition_test_exit_module(void) +{ + unregister_trace_vendor_fake_boot_partition(&vendor_fake_boot_partition, NULL); +} + +/* module entry points */ +module_init(fake_boot_partition_test_init_module); +module_exit(fake_boot_partition_test_exit_module); +MODULE_LICENSE ("GPL v2"); -- Gitee