diff --git a/bundle.json b/bundle.json index 08130f903894bfd2807c38e01307385adf759a25..4b87b9b890b1ee67eabe8b85afa14e2c4331a1ea 100644 --- a/bundle.json +++ b/bundle.json @@ -30,9 +30,11 @@ "build": { "sub_component": [ "//kernel/linux/build:linux_kernel" - ], + ], "inner_kits": [], - "test": [] + "test": [ + "//kernel/linux/build/test:linuxkerneltest" + ] } } } diff --git a/test/BUILD.gn b/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5964ac0f69b2352fab2d3e36d58ed0a863109b8b --- /dev/null +++ b/test/BUILD.gn @@ -0,0 +1,51 @@ +# 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") +import("//build/ohos_var.gni") +if (is_standard_system) { + import("//build/test.gni") +} + +if (is_standard_system) { + module_output_path = "linuxkerneltest/" + linuxkerneltest_public_deps = [ "//third_party/googletest:gtest_main" ] + + ohos_unittest("accesstokenid_test") { + module_out_path = module_output_path + sources = [ "unittest/accesstokenid/accesstokenid_test.cpp" ] + deps = linuxkerneltest_public_deps + part_name = "linux" + subsystem_name = "kernel" + } + + script_dir = "kernel/linux/build/test/moduletest/runtest" + action("init_runtest") { + script = "init_runtest.sh" + outputs = [ "$root_build_dir/tests/moduletest/runtest.timestamp" ] + args = [ + rebase_path("$root_build_dir/../../$script_dir"), + rebase_path("$root_build_dir/tests/moduletest"), + ] + } +} + +group("linuxkerneltest") { + testonly = true + if (is_standard_system) { + deps = [ + ":accesstokenid_test", + ":init_runtest", + ] + } +} diff --git a/test/init_runtest.sh b/test/init_runtest.sh new file mode 100755 index 0000000000000000000000000000000000000000..e1eb7b583bb2e07b1f189703269d0587547a7680 --- /dev/null +++ b/test/init_runtest.sh @@ -0,0 +1,34 @@ +#!/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: init_runtest.sh +# +# Description: init for linuxkerneltest runtest +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +cp -r $1/ $2 + +cd $2 + +tar -zcvf runtest.tar.gz runtest + +cd - diff --git a/test/moduletest/Test.json b/test/moduletest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..8adbbd167f8471fd3fec5b5b8cbfcda71fa74a23 --- /dev/null +++ b/test/moduletest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for runtest", + "kits": [ + { + "push": [ + "runtest.tar.gz->/data/local/tmp" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "ShellTest", + "module-name": "runtest.tar.gz", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + } +} + diff --git a/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpuhotplug_do_spin_loop b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpuhotplug_do_spin_loop new file mode 100644 index 0000000000000000000000000000000000000000..371f9301a07d99a9861b6c319d8cc7e1e189643b --- /dev/null +++ b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpuhotplug_do_spin_loop @@ -0,0 +1,33 @@ +#!/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: cpuhotplug_do_spin_loop +# +# Description: no operation for loop +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +echo $$ + +while : +do + NOOP=1 +done diff --git a/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug01.sh b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug01.sh new file mode 100644 index 0000000000000000000000000000000000000000..e1debc37c39ae75e75291c024fa8cf1dac8b2e7f --- /dev/null +++ b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug01.sh @@ -0,0 +1,85 @@ +#!/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: cpusetdecouple_cpuhotplug01.sh +# +# Description: Check whether CPU hot-plug and CPUSET decoupling are implemented +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +ret=0 + +source tst_oh.sh + +do_setup() +{ + if [ ! -d "/dev/cpuset" ]; then + mkdir /dev/cupset + fi + + if mountpoint -q /dev/cpuset; then + tst_res TINFO "mountpoint -q /dev/cpuset" + else + mount -t cpuset none /dev/cupset + tst_res TINFO "mount -t cpuset none /dev/cupset" + fi +} + +do_test() +{ + tst_res TINFO "Start test cupsetdecouple_cpuhotplug01" + mkdir /dev/cpuset/hotplug01 + echo "0-3" > /dev/cpuset/hotplug01/cpuset.cpus + cat /dev/cpuset/hotplug01/cpuset.cpus + + cpu_total=$(cat /proc/cpuinfo | grep "processor" | wc -l) + cpu_total=$(( $cpu_total -1 )) + + for i in $(seq 1 $cpu_total); do + echo $i + echo 0 > /sys/devices/system/cpu/cpu$i/online + cat /dev/cpuset/hotplug01/cpuset.cpus + cpu_set=$(cat /dev/cpuset/hotplug01/cpuset.cpus) + if [ $cpu_set == '0-3' ]; then + tst_res TINFO "hotplug01 cpu$i offline cpuset decouple success" + else + tst_res TINFO "hotplug01 cpu$i offline cpuset decouple fail" + ret=$(( $ret + 1 )) + fi + echo 1 > /sys/devices/system/cpu/cpu$i/online + done + + if [ $ret -eq 0 ];then + tst_res TPASS "cpusetdecouple_cpuhotplug01 CPU hot-plug and CPUSET decoupling are implemented." + else + tst_res TFAIL "cpusetdecouple_cpuhotplug01 CPU hot-plug and CPUSET decoupling are implemented." + fi +} + +do_clean() +{ + rmdir /dev/cpuset/hotplug01 +} + +do_setup +do_test +do_clean +tst_exit diff --git a/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug02.sh b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug02.sh new file mode 100644 index 0000000000000000000000000000000000000000..d48737138a71104a14737a75d407df96e83a57b0 --- /dev/null +++ b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug02.sh @@ -0,0 +1,88 @@ +#!/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: cpusetdecouple_cpuhotplug02.sh +# +# Description: Check whether process are migrated when the CPU is offline +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +ret=0 + +source tst_oh.sh + +do_setup() +{ + if [ ! -d "/dev/cpuset" ]; then + mkdir /dev/cupset + fi + + if mountpoint -q /dev/cpuset; then + tst_res TINFO "mountpoint -q /dev/cpuset" + else + mount -t cpuset none /dev/cupset + tst_res TINFO "mount -t cpuset none /dev/cupset" + fi +} + +do_test() +{ + tst_res TINFO "Start test cupset_decouple_cpuhotplug02" + mkdir /dev/cpuset/hotplug02 + echo "1" > /dev/cpuset/hotplug02/cpuset.cpus + cat /dev/cpuset/hotplug02/cpuset.cpus + + sh cpuhotplug_do_spin_loop > /dev/null 2>&1 & + pid=$! + + echo $pid > /dev/cpuset/hotplug02/cgroup.procs + echo 0 > /sys/devices/system/cpu/cpu1/online + + cat /dev/cpuset/hotplug02/cpuset.cpus + cpu_set=$(cat /dev/cpuset/hotplug02/cpuset.cpus) + + if [ $cpu_set == '1' ]; then + tst_res TINFO "hotplug02 cpu1 offline cpuset decouple success" + else + tst_res TINFO "hotplug02 cpu1 offline cpuset decouple fail" + ret=$(( $ret + 1 )) + fi + + if [ $ret -eq 0 ];then + tst_res TPASS "cpusetdecouple_cpuhotplug02 CPU hot-plug and CPUSET decoupling are implemented." + else + tst_res TFAIL "cpusetdecouple_cpuhotplug02 CPU hot-plug and CPUSET decoupling are implemented." + fi + + echo 1 > /sys/devices/system/cpu/cpu1/online #offline cpu$i + +} + +do_clean() +{ + rmdir /dev/cpuset/hotplug02 + killall cpuhotplug_do_spin_loop +} + +do_setup +do_test +do_clean +tst_exit diff --git a/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug03.sh b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug03.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7bdbfe5c324f1a3d871554d2c18905e5c90de9a --- /dev/null +++ b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug03.sh @@ -0,0 +1,89 @@ +#!/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: cpusetdecouple_cpuhotplug03.sh +# +# Description: Check whether processes will be migrated to new online CPU +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +ret=0 + +source tst_oh.sh + +do_setup() +{ + if [ ! -d "/dev/cpuset" ]; then + mkdir /dev/cupset + fi + + if mountpoint -q /dev/cpuset; then + tst_res TINFO "mountpoint -q /dev/cpuset" + else + mount -t cpuset none /dev/cupset + tst_res TINFO "mount -t cpuset none /dev/cupset" + fi +} + +do_test() +{ + tst_res TINFO "Start test cupset_decouple_cpuhotplug03" + mkdir /dev/cpuset/hotplug03 + echo 0 > /sys/devices/system/cpu/cpu2/online #offline cpu2 + echo 0 > /sys/devices/system/cpu/cpu3/online #offline cpu3 + + echo "0-3" > /dev/cpuset/hotplug03/cpuset.cpus + cat /dev/cpuset/hotplug03/cpuset.cpus + cpu_set=$(cat /dev/cpuset/hotplug03/cpuset.cpus) + if [ $cpu_set == '0-3' ]; then + tst_res TINFO "hotplug03 cpu2 cpu3 offline cpuset decouple success" + else + tst_res TINFO "hotplug03 cpu2 cpu3 offline cpuset decouple fail" + ret=$(( $ret + 1 )) + fi + + if [ $ret -eq 0 ]; then + tst_res TPASS "cpusetdecouple_cpuhotplug03 CPU hot-plug and CPUSET decoupling are implemented." + else + tst_res TFAIL "cpusetdecouple_cpuhotplug03 CPU hot-plug and CPUSET decoupling are implemented." + fi + + for i in $(seq 1 100); do + sh cpuhotplug_do_spin_loop > /dev/null 2>&1 & + pid=$! + echo $pid > /dev/cpuset/hotplug03/cgroup.procs + done + + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + +} + +do_clean() +{ + rmdir /dev/cpuset/hotplug03 + killall cpuhotplug_do_spin_loop +} + +do_setup +do_test +do_clean +tst_exit diff --git a/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug04.sh b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug04.sh new file mode 100644 index 0000000000000000000000000000000000000000..270f5b2cf63bd9c0bacf164d90f60cda717ba845 --- /dev/null +++ b/test/moduletest/runtest/bin/cpusetdecouple_cpuhotplug_t/testcases/bin/cpusetdecouple_cpuhotplug04.sh @@ -0,0 +1,88 @@ +#!/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: cpusetdecouple_cpuhotplug04.sh +# +# Description: Test CPU online and offline function +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################# + +ret=0 + +source tst_oh.sh + +do_setup() +{ + if [ ! -d "/dev/cpuset" ]; then + mkdir /dev/cupset + fi + + if mountpoint -q /dev/cpuset; then + tst_res TINFO "mountpoint -q /dev/cpuset" + else + mount -t cpuset none /dev/cupset + tst_res TINFO "mount -t cpuset none /dev/cupset" + fi +} + +do_test() +{ + tst_res TINFO "Start test cupset_decouple_cpuhotplug04" + mkdir /dev/cpuset/hotplug04 + echo "0-3" > /dev/cpuset/hotplug04/cpuset.cpus + cat /dev/cpuset/hotplug04/cpuset.cpus + + cpu_total=$(cat /proc/cpuinfo | grep "processor" | wc -l) + cpu_total=$(( $cpu_total -1 )) + + for i in $(seq 0 $cpu_total); do + echo $i + echo 0 > /sys/devices/system/cpu/cpu$i/online #offline cpu$i + cat /dev/cpuset/hotplug04/cpuset.cpus + cpu_set=$(cat /dev/cpuset/hotplug04/cpuset.cpus) + if [ $cpu_set == '0-3' ]; then + tst_res TINFO "hotplug04 cpu$i offline cpuset decouple success" + else + tst_res TINFO "hotplug04 cpu$i offline cpuset decouple fail" + ret=$(( $ret + 1 )) + fi + done + + if [ $ret -eq 0 ]; then + tst_res TPASS "cpusetdecouple_cpuhotplug04 CPU hot-plug and CPUSET decoupling are implemented." + else + tst_res TFAIL "cpusetdecouple_cpuhotplug04 CPU hot-plug and CPUSET decoupling are implemented." + fi + + for i in $(seq 0 $cpu_total); do + echo 1 > /sys/devices/system/cpu/cpu$i/online #offline cpu$i + done +} + +do_clean() +{ + rmdir /dev/cpuset/hotplug04 +} + +do_setup +do_test +do_clean +tst_exit diff --git a/test/moduletest/runtest/conf/OH_RK3568_config b/test/moduletest/runtest/conf/OH_RK3568_config new file mode 100644 index 0000000000000000000000000000000000000000..088861d6ef75d2e2a33d9027021b05f1eb001cf6 --- /dev/null +++ b/test/moduletest/runtest/conf/OH_RK3568_config @@ -0,0 +1,26 @@ +################################################################################ +# +# 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: OH_RK3568_config +# +# Description: OpenHarmony linuxkerneltest testsuite list for RK3568 +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ +cpusetdecouple_cpuhotplug_t diff --git a/test/moduletest/runtest/lib/libapi.sh b/test/moduletest/runtest/lib/libapi.sh new file mode 100644 index 0000000000000000000000000000000000000000..f86c05a901b0823367637dc2278aaa0390078586 --- /dev/null +++ b/test/moduletest/runtest/lib/libapi.sh @@ -0,0 +1,53 @@ +#!/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: libapi.sh +# +# Description: shell library api for linuxkerneltest +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +print_error() +{ + echo -e "\033[41m$1\033[0m" +} + +print_warn() +{ + echo -e "\033[43m$1\033[0m" +} + +print_pass() +{ + echo -e "\033[42m$1\033[0m" +} + +print_info() +{ + echo -e "\033[37m$1\033[0m" +} + +print_deg() +{ + if [ $DEBUG -eq 1 ]; then + echo -e "\033[1;33m$1\033[0m" + fi +} diff --git a/test/moduletest/runtest/lib/tst_oh.sh b/test/moduletest/runtest/lib/tst_oh.sh new file mode 100644 index 0000000000000000000000000000000000000000..adc93e37c684f850fbdb3a4cc13024697e81621a --- /dev/null +++ b/test/moduletest/runtest/lib/tst_oh.sh @@ -0,0 +1,188 @@ +#!/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: tst_oh.sh +# +# Description: OpenHarmony linuxkerneltest test library for shell +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +[ -n "$TST_LTB_LOADED" ] && return 0 + +export TST_PASS=0 +export TST_FAIL=0 +export TST_BROK=0 +export TST_WARN=0 +export TST_CONF=0 +export TST_COUNT=0 +export TST_COLOR_ENABLED=1 +export TST_LTB_LOADED=1 + +trap "tst_brk TBROK 'test interrupted'" INT + +tst_flag2color() +{ + local ansi_color_blue='\033[1;34m' + local ansi_color_green='\033[1;32m' + local ansi_color_magenta='\033[1;35m' + local ansi_color_red='\033[1;31m' + local ansi_color_yellow='\033[1;33m' + + case "$1" in + TPASS) printf $ansi_color_green;; + TFAIL) printf $ansi_color_red;; + TBROK) printf $ansi_color_red;; + TWARN) printf $ansi_color_magenta;; + TINFO) printf $ansi_color_blue;; + TCONF) printf $ansi_color_yellow;; + esac +} + +tst_color_enabled() +{ + [[ $TST_COLOR_ENABLED -eq 1 ]] && return 1 || return 0 +} + +tst_print_colored() +{ + tst_color_enabled + local color=$? + + + [ "$color" = "1" ] && tst_flag2color "$1" + printf "$2" + [ "$color" = "1" ] && printf '\033[0m' +} + +tst_exit() +{ + local ret=0 + + if [ $TST_FAIL -gt 0 ]; then + ret=$((ret|1)) + fi + + if [ $TST_BROK -gt 0 ]; then + ret=$((ret|2)) + fi + + if [ $TST_WARN -gt 0 ]; then + ret=$((ret|4)) + fi + + if [ $TST_CONF -gt 0 ]; then + ret=$((ret|32)) + fi + + echo + echo "Summary:" + echo "passed $TST_PASS" + echo "failed $TST_FAIL" + echo "broken $TST_BROK" + echo "skipped $TST_CONF" + echo "warnings $TST_WARN" + + exit $ret +} + +_tst_inc_ret() +{ + case "$1" in + TPASS) TST_PASS=$((TST_PASS+1));; + TFAIL) TST_FAIL=$((TST_FAIL+1));; + TBROK) TST_BROK=$((TST_BROK+1));; + TWARN) TST_WARN=$((TST_WARN+1));; + TCONF) TST_CONF=$((TST_CONF+1));; + TINFO) ;; + *) tst_brk TBROK "Invalid res type '$1'";; + esac +} + +tst_res() +{ + local res=$1 + shift + + tst_color_enabled + local color=$? + + TST_COUNT=$(($TST_COUNT+1)) + + _tst_inc_ret "$res" + printf "$TST_ID $TST_COUNT `date` " + tst_print_colored $res "$res: " + echo "$@" +} + +tst_brk() +{ + local res=$1 + shift + + if [ "$TST_DO_EXIT" = 1 ]; then + tst_res TWARN "$@" + return + fi + + tst_res "$res" "$@" + tst_exit +} + +tst_judged() +{ + actual_res=$1 + shift + expect_res=$1 + shift + + comment="$@" + if [ "$actual_res" == "$expect_res" ]; then + tst_res TPASS "$comment test pass, expect $expect_res return $actual_res" + else + tst_res TFAIL "$comment test fail, expect $expect_res return $actual_res" + fi +} + +tst_judged_fail() +{ + actual_res=$1 + shift + expect_res=$1 + shift + comment="$@" + if [ "$actual_res" != "$expect_res" ]; then + tst_res TPASS "$comment test pass, expect $expect_res return $actual_res" + else + tst_res TFAIL "$comment test fail, expect $expect_res return $actual_res" + fi +} + +get_product() +{ + echo `uname -a | awk '{printf $NF}'` +} + +if [ -z "$TST_TD" ]; then + _tst_filename=$(basename $0) || \ + tst_brk TCONF "Failed to set TST_TD from \$0 ('$0'), fix it with setting TST_ID before sourcing tst_test.sh" + TST_ID=${_tst_filename%%.*} +fi +export TST_ID="$TST_ID" diff --git a/test/moduletest/runtest/runtest b/test/moduletest/runtest/runtest new file mode 100644 index 0000000000000000000000000000000000000000..24758c33a9a9fcea5082bfe7f25c54e5b2022754 --- /dev/null +++ b/test/moduletest/runtest/runtest @@ -0,0 +1,523 @@ +#!/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: runtest +# +# Description: shell scripts entry for linuxkerneltest +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +export DEBUG=1 + +export LC_ALL=c + +source lib/libapi.sh + +export test_lists +export test_scenario +export cur_test +export cur_testcase +export cross_compile_flag +export no_need_run_checkflg=0 +export testcase_timeout_flg=0 +export no_need_run_testlist +export testcase_timelimit=120 +export testcase_exit_code=0 + +export testcase_total=0 +export testcase_fail=0 +export testcase_timeout=0 +export testsuite_total=0 + +export TEST_ROOT=`pwd` +export KERNEL_TEST_SUITE=${TEST_ROOT}/../ +export LOG_DIR=${TEST_ROOT}/log +export BIN_LOCATE_DIR=${TEST_ROOT}/bin +export INSTALL_BIN_DIR=/data/local/tmp/OH_kernel_test +export COMPILE_LOG_DIR=${LOG_DIR}/compile_log +export COMPILE_LOG=${COMPILE_LOG_DIR}/compile.log +export RESULT_LOG_DIR +export RESULT_SUM_LOG +export RESULT_FAIL_LOG +export TOOL_BIN_DIR + +export ARCH +export CROSS_COMPILE +export KERNEL_DIR +export CROSS_COMPILER_DIR +export HOST_TARGET +export CROSS_COMPILE_NAME + +print_usage() +{ + " + usage: + + COMPILE: + sh runtest compile [ -t test_lists ] [ -d sdk_dir ] [ -a arch ] [ -c cross_compile ] [ -k kernel_dir ] [ -o install_dir ] + -t testsuite name or a file of testsuites list + eg. -t ltp: compile single testsuite of ltp + eg. -t a.file: compile all testsuites in a.file + (missing -t means compile all testsuites) + -d sdk directory + -a arch for cross_compile, eg: arm or arm64 + -c cross_compile name, eg: arm-linux-gnueabi- or aarch64-linux-gnu- + -k kernel dir for module compile, eg: /usr/src/module_obj + -o install directory, eg: /data/, default to /data/local/tmp + + TEST: + sh runtest test [ -t test_lists ] [ -n skip_cases ] [ -l testcase timeout limit ] + -t testsuite name or a file of testsuites list + eg. -t ltp: test single testsuite of ltp + eg. -t a.file: test all testsuites in a.file + (missing -t means test all testsuites) + + -n conf file of testcases no needed to run, default located at test/skip_test/XXX + + -l testcase timeout limit, testcase will be killed in 120s(by default) if it hasn't finished run itself + + eg1: sh runtest test -t OH_RK3568_config -n OH_RK3568_skiptest -l 60 + + eg2: sh runtest test -t ltp -n OH_RK3568_skiptest -l 60 + + eg2: sh runtest test -t cpusetdecouple_cpuhotplug_t -n OH_RK3568_skiptest -l 60 + " + + exit 0 +} + +check_cross_compiler() +{ + if [ ! -z ${CROSS_COMPILER_DIR} ] && [ ! -d ${CROSS_COMPILER_DIR} ]; then + print_error "${CROSS_COMPILER_DIR} not found, check params!!!" + exit 1 + fi + + export PATH=${CROSS_COMPILER_DIR}:$PATH + CROSS_COMPILE_NAME=${CROSS_COMPILE_NAME}gcc + which ${CROSS_COMPILE_NAME} + if [ $? -ne 0 ]; then + print_error "${CROSS_COMPILE_NAME} not found, check SDK!!!" + exit 1 + fi + + if [ -z ${KERNEL_DIR} ] && [ ! -d ${KERNEL_DIR} ]; then + print_error "${KERNEL_DIR} not found, check params!!!" + exit 1 + fi + + if [ cross_compile_flag == 1 ]; then + HOST_TARGET=${CROSS_COMPILE%-*} + fi +} + +do_install() +{ + print_info "Install OH_kernel_test to ${INSTALL_BIN_DIR}..." + if [ ! -d ${INSTALL_BIN_DIR} ];then + mkdir -p ${INSTALL_BIN_DIR} + fi + + cp -r ${TEST_ROOT}/lib ${INSTALL_BIN_DIR} + cp ${TEST_ROOT}/runtest ${INSTALL_BIN_DIR} + cp -r ${TEST_ROOT}/test ${INSTALL_BIN_DIR} + cp -r ${TEST_ROOT}/conf ${INSTALL_BIN_DIR} + cp -r ${BIN_LOCATE_DIR} ${INSTALL_BIN_DIR} +} + +do_compile() +{ + check_cross_compiler + + if [ -z "${test_lists}" ]; then + test_lists=`cat ${TEST_ROOT}/conf/testsuites.list` + fi + + if [ ! -d ${BIN_LOCATE_DIR} ]; then + mkdir -p ${BIN_LOCATE_DIR} + fi + + if [ -d ${COMPILE_LOG_DIR} ]; then + rm -rf ${COMPILE_LOG_DIR} + fi + mkdir -p ${COMPILE_LOG_DIR} + + echo "Start to compile testsuites..." >> ${COMPILE_LOG} + echo "Testsuites list:" >> ${COMPILE_LOG} + echo "${test_lists}" >> ${COMPILE_LOG} + + for testsuite in ${test_lists}; do + cd ${KERNEL_TEST_SUITE} + if [ ! -d ${testsuite} ]; then + print_error "${testsuite} not found!!!" + continue + fi + print_info "Start to compile ${testsuite}..." + mkdir -p ${COMPILE_LOG_DIR}/${testsuite} + cd ${testsuite}/${testsuite}_src + if [ -f "pre_compile.sh" ]; then + sh pre_compile.sh + fi + + TOOL_BIN_DIR=${BIN_LOCATE_DIR}/${testsuite}/testcases/bin + if [ ! -d ${TOOL_BIN_DIR} ]; then + mkdir -p ${TOOL_BIN_DIR} + fi + + if [ -e "configure" ]; then + if [ cross_compile_flag == 1 ]; then + ./configure cross_compile=$CROSS_COMPILE_NAME --host=$HOST_TARGET --target=$HOST_TARGET --prefix=${BIN_LOCATE_DIR}/${testsuite} --with-realtime-testsuite >> ${COMPILE_LOG_DIR}/${testsuite}/configure.log 2>&1 + else + ./configure --prefix=$BIN_LOCATE_DIR/${testsuite} --with-realtime-testsuite >> ${COMPILE_LOG_DIR}/${testsuite}/configure.log 2>&1 + fi + fi + + make clean >> ${COMPILE_LOG_DIR}/${testsuite}/make.log 2>&1 + if [ ${testsuite} == "ltp" ]; then + ./configure CFLAGS="-static" LDFLAGS="-static" --prefix=$BIN_LOCATE_DIR/${testsuite} >> ${COMPILE_LOG_DIR}/${testsuite}/configure.log 2>&1 + fi + + make -j $(nproc) >> ${COMPILE_LOG_DIR}/${testsuite}/make.log 2>&1 + if [ $? -ne 0 ]; then + print_warn "${testsuite} make error, skip!" + continue + fi + + make install >> ${COMPILE_LOG_DIR}/${testsuite}/make.log 2>&1 + if [ $? -ne 0 ]; then + print_warn "${testsuite} make install error, skip!" + continue + fi + + if [ -f ../init.sh ]; then + cp ../init.sh ${BIN_LOCATE_DIR}/${testsuite}_init.sh + fi + + if [ -f ../uninit.sh ]; then + cp ../uninit.sh ${BIN_LOCATE_DIR}/${testsuite}_uninit.sh + fi + + print_info "Finished compile ${testsuite}." + done + + cd ${TEST_ROOT} + do_install +} + +skip_run() +{ + local test_cmd=$1 + + if [ -z "$test_cmd" ]; then + return 1 + else + local m_flag=`echo $test_cmd | awk '{print substr($1, 1, 1)}'` + if [ -z "$m_flag" ]||[ "$m_flag" = "#" ]; then + return 1 + fi + + if [ "${no_need_run_checkflg}" = "1" ]; then + local testcase_name=`echo $test_cmd | awk '{print $1}'` + cat ${TEST_ROOT}/tests/skip_test/${no_need_run_testlist} | grep "${testcase_name}" | sed 's/^[\t]*//g' | grep -e "^${testcase_name} " -e "^${testcase_name}"$'\t' -e "^${testcase_name}$" > /dev/null + if [ $? -eq 0 ]; then + return 1 + fi + fi + + return 0 + fi +} + +run_test() +{ + local test_cmd=$1 + + local testcase_name=`echo $test_cmd | awk '{print $1}'` + local testcase_cmdline=`echo $test_cmd | awk '{for(i=2;i<=NF;i++) printf $i OFS}'` + + setsid sh -c "eval ${testcase_cmdline}" > ${RESULT_LOG_DIR}/${cur_test}/${testcase_name}.log 2>&1 & + local pgid=$! + + timeout=${testcase_timelimit} + while [ $timeout -gt 0 ]; do + kill -s 0 $pgid 2>/dev/null + if [ $? -ne 0 ]; then + break + fi + timeout=$((timeout - 1)) + sleep 1 + done + + if [ $timeout -le 0 ]; then + kill -KILL -- -$pgid + fi + + wait $pgid + testcase_exit_code=$? +} + +do_test_by_feature() +{ + if [ -z "${test_lists}" ]; then + test_lists=`cat ${TEST_ROOT}/conf/testsuites.list` + fi + + RESULT_LOG_DIR=${LOG_DIR}/${test_scenario}_`date +"%Y_%m_%d-%Hh_%Mm_%Ss"`_result_log + RESULT_SUM_LOG=${RESULT_LOG_DIR}/result_sum.log + RESULT_FAIL_LOG=${RESULT_LOG_DIR}/result_fail.log + + mkdir -p ${RESULT_LOG_DIR} + + echo "Start to test" >> ${RESULT_SUM_LOG} + echo "Testsuites list:" >> ${RESULT_SUM_LOG} + echo "${test_lists}" >> ${RESULT_SUM_LOG} + print_info "Start to test ${test_lists}" + + while read testcase + do + skip_run "${testcase}" + if [ $? -ne 0 ]; then + continue + fi + + cd ${BIN_LOCATE_DIR}/testcases/bin + run_test "${testcase}" + + if [ $? -ne 0 ]; then + echo "${testcase}" >> ${RESULT_LOG_DIR}/fail.list + echo "[${testsuite}] ${testcase}" >> ${RESULT_FAIL_LOG} + testcase_fail=$(($testcase_fail + 1)) + fi + + testcase_total=$(($testcase_total + 1)) + done < ${TEST_ROOT}/tests/${test_lists} + + cd ${TEST_ROOT} + echo "" | tee ${RESULT_SUM_LOG} + echo "******************************************************" | tee ${RESULT_SUM_LOG} + echo "Test result summary:" | tee ${RESULT_SUM_LOG} + echo "Total testcases: ${testcase_total}" | tee ${RESULT_SUM_LOG} + echo "Fail testcases: ${testcase_fail}" | tee ${RESULT_SUM_LOG} +} + +do_test_by_conf() +{ + if [ -z "${test_lists}" ]; then + test_lists=`cat ${TEST_ROOT}/conf/testsuites.list` + fi + + RESULT_LOG_DIR=${LOG_DIR}/${test_scenario}_`date +"%Y_%m_%d-%Hh_%Mm_%Ss"`_result_log + RESULT_SUM_LOG=${RESULT_LOG_DIR}/result_sum.log + RESULT_FAIL_LOG=${RESULT_LOG_DIR}/result_fail.log + + mkdir -p ${RESULT_LOG_DIR} + + echo "Start to test" >> ${RESULT_SUM_LOG} + echo "Testsuites list:" >> ${RESULT_SUM_LOG} + echo "${test_lists}" >> ${RESULT_SUM_LOG} + + local curtest_total=0 + local curtest_fail=0 + local curtest_timeout=0 + + original_path=$PATH + + for testsuite in ${test_lists}; do + curtest_fail=0 + curtest_total=0 + curtest_timeout=0 + + if [ ! -f ${TEST_ROOT}/tests/${testsuite} ]; then + print_error "${testsuite} file not found in ${TEST_ROOT}/tests!" + continue + fi + + cur_test=${testsuite} + mkdir -p ${RESULT_LOG_DIR}/${testsuite} + echo "Start time: `date '+%Y-%m-%d %H:%M:%S'`" >> ${RESULT_LOG_DIR}/${testsuite}/summary.log + print_info "`date '+%Y-%m-%d %H:%M:%S'` Start to test ${testsuite}" + print_info "******************************************************" + + if [ -f ${BIN_LOCATE_DIR}/${testsuite}_init.sh ]; then + cd ${BIN_LOCATE_DIR} + source ./${testsuite}_init.sh &> ${RESULT_LOG_DIR}/${testsuite}/init.log + fi + + PATH=${BIN_LOCATE_DIR}/${testsuite}/testcases/bin:${TEST_ROOT}/lib:$PATH + while read testcase; do + local testcase_name=`echo ${testcase} | awk '{print $1}'` + skip_run "${testcase}" + if [ $? -ne 0 ]; then + continue + fi + + cur_testcase=${testcase} + echo "Testsuite:${cur_test} Testcase:${cur_testcase}" > ${RESULT_LOG_DIR}/current_test + cd ${BIN_LOCATE_DIR}/${testsuite}/testcases/bin + run_test "${testcase}" + + if [ $testcase_exit_code -eq 137 ]; then + echo "${testcase} (Timeout)" >> ${RESULT_LOG_DIR}/${testsuite}/timeout.list + echo "${testsuite} ${testcase} (Timeout)" >> ${RESULT_FAIL_LOG} + testcase_timeout=$(($testcase_timeout + 1)) + curtest_timeout=$(($testcase_timeout + 1)) + print_warn "`date '+%Y-%m-%d %H:%M:%S'` ${testcase_name} TIMEOUT!" + elif [ $testcase_exit_code -ne 0 ]; then + echo "${testcase}" >> ${RESULT_LOG_DIR}/${testsuite}/fail.list + echo "${testsuite} ${testcase}" >> ${RESULT_FAIL_LOG} + testcase_fail=$(($testcase_fail + 1)) + curtest_fail=$(($curtest_fail + 1)) + print_error "`date '+%Y-%m-%d %H:%M:%S'` ${testcase_name} ERROR!!!" + else + print_pass "`date '+%Y-%m-%d %H:%M:%S'` ${testcase_name} PASS." + fi + + testcase_total=$(($testcase_total + 1)) + curtest_total=$(($curtest_total + 1)) + + cd ${TEST_ROOT} > /dev/null + done < ${TEST_ROOT}/tests/${testsuite} + + if [ -f ${BIN_LOCATE_DIR}/${testsuite}_uninit.sh ]; then + cd ${BIN_LOCATE_DIR} + source ./${testsuite}_uninit.sh &> ${RESULT_LOG_DIR}/${testsuite}/uninit.log + fi + + testsuite_total=$((${testsuite_totaol} + 1)) + echo "Test total: ${curtest_total}" >> ${RESULT_LOG_DIR}/${testsuite}/summary.log + echo "Test failed: ${curtest_fail}" >> ${RESULT_LOG_DIR}/${testsuite}/summary.log + echo "Test timeout: ${curtest_timeout}" >> ${RESULT_LOG_DIR}/${testsuite}/summary.log + echo "End time: `date '+%Y-%m-%d %H:%M:%S'`" >> ${RESULT_LOG_DIR}/${testsuite}/summary.log + print_info "${testsuite} test total: ${curtest_total}" + print_info "${testsuite} test failed: ${curtest_fail}" + print_info "${testsuite} test timeout: ${curtest_timeout}" + print_info "`date '+%Y-%m-%d %H:%M:%S'` Finished to test ${testsuite}" + print_info "******************************************************" + + PATH=${original_path} + done + + cd ${TEST_ROOT} + + echo "" >> ${RESULT_SUM_LOG} + echo "******************************************************" >> ${RESULT_SUM_LOG} + echo "Test result summary:" >> ${RESULT_SUM_LOG} + echo "Total testsuites: ${testsuite_total}" >> ${RESULT_SUM_LOG} + echo "Total testcases: ${testcase_total}" >> ${RESULT_SUM_LOG} + echo "Fail testcases: ${testcase_fail}" >> ${RESULT_SUM_LOG} + echo "Timeout testcases: ${testcase_timeout}" >> ${RESULT_SUM_LOG} + + print_info "Test result summary:" + print_info "Total testsuites: ${testsuite_total}" + print_info "Total testcases: ${testcase_total}" + print_info "Fail testcases: ${testcase_fail}" + print_info "Timeout testcases: ${testcase_timeout}" +} + +do_stop() +{ + print_info "Test aborted..." + echo "" >> ${RESULT_SUM_LOG} + echo "******************************************************" >> ${RESULT_SUM_LOG} + echo "Test result summary:" >> ${RESULT_SUM_LOG} + echo "Total testsuites: ${testsuite_total}" >> ${RESULT_SUM_LOG} + echo "Total testcases: ${testcase_total}" >> ${RESULT_SUM_LOG} + echo "Fail testcases: ${testcase_fail}" >> ${RESULT_SUM_LOG} + echo "Timeout testcases: ${testcase_timeout}" >> ${RESULT_SUM_LOG} + + echo "Testsuite:${cur_test}" > ${RESULT_LOG_DIR}/current_test + echo "Testcase:${cur_testcase}" >> ${RESULT_LOG_DIR}/current_test + + exit 10 +} + +main() +{ + if [ "$1" == "compile" ]; then + shift + while getopts t:d:a:c:k:o arg + do case $arg in + t) + test_scenario=$OPTARG + if [ ! -d ${KERNEL_TEST_SUITE}/${OPTARG} ] && [ ! -f ${KERNEL_TEST_SUITE}/conf/${OPTARG} ]; then + print_usage + exit 1 + elif [ -d ${KERNEL_TEST_SUITE}/${OPTARG} ]; then + test_lists=$OPTARG + else + test_lists=`cat ${TEST_ROOT}/conf/${OPTARG}` + fi + ;; + d) CROSS_COMPILER_DIR=$OPTARG;; + a) ARCH=$OPTARG;; + c) + CROSS_COMPILE=$OPTARG + cross_compile_flag=1 + ;; + k) KERNEL_DIR=$OPTARG;; + o) INSTALL_BIN_DIR=$OPTARG;; + *) print_usage;; + esac + done + fi + + if [ "$1" == "test" ]; then + shift + while getopts t:n:l: arg + do case $arg in + t) + test_scenario=$OPTARG + if [ ! -d ${BIN_LOCATE_DIR}/${OPTARG} ] && [ ! -f ${TEST_ROOT}/conf/${OPTARG} ]; then + print_error "$OPTARG not exits, please check!" + elif [ -d ${BIN_LOCATE_DIR}/${OPTARG} ]; then + test_lists=$OPTARG + else + test_lists=`cat ${TEST_ROOT}/conf/${OPTARG}` + fi + ;; + n) + no_need_run_checkflg=1 + no_need_run_testlist=$OPTARG + if [ ! -f ${TEST_ROOT}/tests/skip_test/${no_need_run_testlist} ]; then + print_error "${no_need_run_testlist} not found located at ${TEST_ROOT}/tests/skip_test, please check!" + exit 1 + fi + ;; + l) + testcase_timeout_flg=1 + testcase_timelimit=$OPTARG + ;; + *) print_usage;; + esac + done + do_test_by_conf + else + print_usage + exit 1 + fi +} + +trap do_stop TERM INT HUP ABRT QUIT + +chmod +x -R bin/ +mount -o rw,remount / + +main "$@" diff --git a/test/moduletest/runtest/tests/cpusetdecouple_cpuhotplug_t b/test/moduletest/runtest/tests/cpusetdecouple_cpuhotplug_t new file mode 100644 index 0000000000000000000000000000000000000000..d388d7914ecf89ad907edbfce375c9cfa47e0281 --- /dev/null +++ b/test/moduletest/runtest/tests/cpusetdecouple_cpuhotplug_t @@ -0,0 +1,29 @@ +################################################################################ +# +# 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: cpusetdecouple_cpuhotplug_t +# +# Description: cpusetdecouple and cpuhotplug testcase list +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ +cpusetdecouple_cpuhotplug01 cpusetdecouple_cpuhotplug01.sh +cpusetdecouple_cpuhotplug02 cpusetdecouple_cpuhotplug02.sh +cpusetdecouple_cpuhotplug03 cpusetdecouple_cpuhotplug03.sh +cpusetdecouple_cpuhotplug04 cpusetdecouple_cpuhotplug04.sh diff --git a/test/moduletest/runtest/tests/skip_test/OH_Hi3516DV300_skiptest b/test/moduletest/runtest/tests/skip_test/OH_Hi3516DV300_skiptest new file mode 100644 index 0000000000000000000000000000000000000000..fb8dd7b0eec489fd660e5df9f586096b8abd7a21 --- /dev/null +++ b/test/moduletest/runtest/tests/skip_test/OH_Hi3516DV300_skiptest @@ -0,0 +1,33 @@ +#!/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: OH_Hi3516DV300_skipfile +# +# Description: skip test file for OpenHarmony Hi3516DV300 runtest +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + +# Hi3516DV not supported cpusetdecouple_cpuhotplug +cpusetdecouple_cpuhotplug01 cpusetdecouple_cpuhotplug01.sh +cpusetdecouple_cpuhotplug02 cpusetdecouple_cpuhotplug02.sh +cpusetdecouple_cpuhotplug03 cpusetdecouple_cpuhotplug03.sh +cpusetdecouple_cpuhotplug04 cpusetdecouple_cpuhotplug04.sh + diff --git a/test/moduletest/runtest/tests/skip_test/OH_RK3568_skiptest b/test/moduletest/runtest/tests/skip_test/OH_RK3568_skiptest new file mode 100644 index 0000000000000000000000000000000000000000..61665827f1b81076781204fd05cf4e08261bbb38 --- /dev/null +++ b/test/moduletest/runtest/tests/skip_test/OH_RK3568_skiptest @@ -0,0 +1,26 @@ +################################################################################ +# +# 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: OH_RK3568_skiptest +# +# Description: skip test file for OpenHarmony RK3568 runtest +# +# Authors: Ma Feng - mafeng.ma@huawei.com +# +# History: Mar 15 2022 - init scripts +# +################################################################################ + diff --git a/test/unittest/accesstokenid/Test.json b/test/unittest/accesstokenid/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..30800a1f6b021b34b7bd7dbd0fa88d6642fc8e46 --- /dev/null +++ b/test/unittest/accesstokenid/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for accesstokenid_test", + "kits": [ + { + "push": [ + "accesstokenid_test->/data/local/tmp/accesstokenid_test" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "accesstokenid_test", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + } +} + diff --git a/test/unittest/accesstokenid/accesstokenid_test.cpp b/test/unittest/accesstokenid/accesstokenid_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae75dec5f3e28532b4ad80be56dc3b0573c7f527 --- /dev/null +++ b/test/unittest/accesstokenid/accesstokenid_test.cpp @@ -0,0 +1,643 @@ +/* + * 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 "accesstokenid_test.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int GET_TOKEN_ID = 1; +constexpr unsigned int SET_TOKEN_ID = 2; +constexpr unsigned int GET_FTOKEN_ID = 3; +constexpr unsigned int SET_FTOKEN_ID = 4; +constexpr unsigned int ACCESS_TOKENID_MAX_NR = 5; +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_GET_FTOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_FTOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_ILLEGAL1 \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, 0, unsigned long long) +#define ACCESS_TOKENID_ILLEGAL2 \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, ACCESS_TOKENID_MAX_NR, unsigned long long) + +constexpr unsigned long long INVAL_TOKEN = 0xffffffffffffffff; + +#define CHILDREN_NUM 3 +#define WAIT_FOR_SHELL_OP_TIME 1 +#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1)) + +constexpr unsigned int ACCESS_TOKEN_GRPID = 3020; +constexpr unsigned int ACCESS_TOKEN_OTHER_UID = 1234; +constexpr unsigned int ACCESS_TOKEN_OTHER_GRPID = 1234; + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +struct tokeninfo { + pid_t pid; + pid_t tid; + unsigned long long tokenid; + unsigned long long ftokenid; +}; + +namespace { +static unsigned long long GenRand64(void) +{ + struct timespec time = {0, 0}; + unsigned long long randvalue = 0; + int fd; + + fd = open("/dev/random", O_RDONLY); + if (fd > 0) { + read(fd, &randvalue, sizeof(unsigned long long)); + } + close(fd); + + sleep(1); + clock_gettime(CLOCK_REALTIME, &time); + + return randvalue + time.tv_nsec; +} + +static int GetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_GET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static int SetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_SET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static int GetfTokenid(unsigned long long *ftoken) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); + if (ret) { + printf("ioctl ACCESS_TOKENID_GET_FTOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static int SetfTokenid(unsigned long long *ftoken) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); + if (ret) { + printf("ioctl ACCESS_TOKENID_SET_FTOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static void GetCurToken(unsigned long long *token, unsigned long long *ftoken) +{ + GetTokenid(token); + GetfTokenid(ftoken); + + return; +} + +static void *CheckChildThreadInheritance(void *args) +{ + struct tokeninfo *tinfo = (struct tokeninfo *) args; + + tinfo->pid = getpid(); + tinfo->tid = gettid(); + GetTokenid(&(tinfo->tokenid)); + GetfTokenid(&(tinfo->ftokenid)); + + pthread_exit(nullptr); + return nullptr; +} + +static void *CheckChildThreadSetIndepent(void *args) +{ + struct tokeninfo *tinfo = (struct tokeninfo *) args; + unsigned long long tokenSet = GenRand64(); + unsigned long long ftokenSet = GenRand64(); + unsigned long long tokenidGet = INVAL_TOKEN; + unsigned long long ftokenidGet = INVAL_TOKEN; + + tinfo->pid = getpid(); + tinfo->tid = gettid(); + + GetTokenid(&tokenidGet); + GetfTokenid(&ftokenidGet); + SetTokenid(&tokenSet); + SetfTokenid(&ftokenSet); + GetTokenid(&(tinfo->tokenid)); + GetfTokenid(&(tinfo->ftokenid)); + + /* Indicate that the tokenid setting of each child thread does not met requirements. */ + if (ftokenidGet == 0 && tinfo->tokenid == tokenSet && tinfo->ftokenid == ftokenSet && tinfo->ftokenid != 0) { + tinfo->ftokenid = INVAL_TOKEN; + } + + pthread_exit(nullptr); + return nullptr; +} +} + +using namespace testing::ext; +using namespace std; + +void AccesstokenidTest::SetUp() {} + +void AccesstokenidTest::TearDown() {} + +void AccesstokenidTest::SetUpTestCase() {} + +void AccesstokenidTest::TearDownTestCase() {} + +/** + * @tc.name: CheckInitToken + * @tc.desc: Test init value of tokenid and ftokenid + * @tc.desc: tokenid equals to the father(hdcd) and ftokenid equals to 0 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, CheckInitToken, Function | MediumTest | Level1) +{ + unsigned long long token = INVAL_TOKEN; + unsigned long long ftoken = INVAL_TOKEN; + + GetCurToken(&token, &ftoken); + + /* /data/service/el0/access_token/nativetoken.json + {"processName":"hdcd","APL":3,"version":1,"tokenId":680034571,"tokenAttr":0,"dcaps":[]} + */ + ASSERT_NE(0, token); + ASSERT_EQ(0, ftoken); +} + +/** + * @tc.name: CheckSetTokenid + * @tc.desc: Test setting of tokenid + * @tc.desc: tokenid equals to the setting value + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, CheckSetTokenid, Function | MediumTest | Level1) +{ + unsigned long long token = INVAL_TOKEN; + unsigned long long tokenSet = GenRand64(); + + SetTokenid(&tokenSet); + GetTokenid(&token); + + ASSERT_EQ(tokenSet, token); +} + +/** + * @tc.name: CheckSetfTokenid + * @tc.desc: Test setting of ftokenid + * @tc.desc: ftokenid equals to the setting value + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, CheckSetfTokenid, Function | MediumTest | Level1) +{ + unsigned long long ftoken = INVAL_TOKEN; + unsigned long long ftokenSet = GenRand64(); + + SetfTokenid(&ftokenSet); + GetfTokenid(&ftoken); + + ASSERT_EQ(ftokenSet, ftoken); +} + +/** + * @tc.name: CheckChildThreadInheritance + * @tc.desc: Test each child thread tokenid equals to father process while ftokenid not equals + * @tc.desc: The ftokenid of each child thread equals to 0 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, CheckChildThreadInheritance, Function | MediumTest | Level1) +{ + pthread_t cid[10]; + + unsigned long long token = INVAL_TOKEN; + unsigned long long ftoken = INVAL_TOKEN; + unsigned long long tokenSet = GenRand64(); + unsigned long long ftokenSet = GenRand64(); + + struct tokeninfo tinfo; + tinfo.pid = getpid(); + tinfo.tid = gettid(); + tinfo.tokenid = INVAL_TOKEN; + tinfo.ftokenid = INVAL_TOKEN; + + GetTokenid(&token); + GetfTokenid(&ftoken); + + SetTokenid(&tokenSet); + SetfTokenid(&ftokenSet); + + for (int i = 0; i < 10; i++) { + if (pthread_create(&cid[i], nullptr, CheckChildThreadInheritance, &tinfo) != 0) { + printf("thread %d (ID %ld) pthread_create error\n", i, cid[i]); + } + + if (pthread_join(cid[i], nullptr) != 0) { + printf("thread %d (ID %ld) pthread_join error\n", i, cid[i]); + } + + ASSERT_EQ(tinfo.tokenid, tokenSet); + ASSERT_NE(tinfo.ftokenid, ftokenSet); + ASSERT_EQ(0, tinfo.ftokenid); + } +} + +/** + * @tc.name: CheckChildThreadSetIndepent + * @tc.desc: Test each child thread tokenid and ftokenid is indepent + * @tc.desc: The tokenid and ftokenid of each child thread not equal to father process + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, CheckChildThreadSetIndepent, Function | MediumTest | Level1) +{ + pthread_t cid[10]; + + unsigned long long token = INVAL_TOKEN; + unsigned long long ftoken = INVAL_TOKEN; + unsigned long long tokenSet = GenRand64(); + unsigned long long ftokenSet = GenRand64(); + + struct tokeninfo tinfo; + tinfo.pid = getpid(); + tinfo.tid = gettid(); + tinfo.tokenid = INVAL_TOKEN; + tinfo.ftokenid = INVAL_TOKEN; + + GetTokenid(&token); + GetfTokenid(&ftoken); + + SetTokenid(&tokenSet); + SetfTokenid(&ftokenSet); + + for (int i = 0; i < 10; i++) { + if (pthread_create(&cid[i], nullptr, CheckChildThreadSetIndepent, &tinfo) != 0) { + printf("thread %d (ID %ld) pthread_create error\n", i, cid[i]); + } + + if (pthread_join(cid[i], nullptr) != 0) { + printf("thread %d (ID %ld) pthread_join error\n", i, cid[i]); + } + + ASSERT_NE(tinfo.tokenid, tokenSet); + ASSERT_NE(tinfo.ftokenid, ftokenSet); + ASSERT_NE(0, tinfo.ftokenid); + } +} + +/** + * @tc.name: AbnormalGetTokenid + * @tc.desc: Test abnormal ioctl cmd of ACCESS_TOKENID_GET_TOKENID + * @tc.desc: using nullptr instead of the address of tokenid to ioctl + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, AbnormalGetTokenid, Function | MediumTest | Level1) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, nullptr); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: AbnormalSetTokenid + * @tc.desc: Test abnormal ioctl cmd of ACCESS_TOKENID_SET_TOKENID + * @tc.desc: using nullptr instead of the address of tokenid to ioctl + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, AbnormalSetTokenid, Function | MediumTest | Level1) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, nullptr); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: AbnormalGetfTokenid + * @tc.desc: Test abnormal ioctl cmd of ACCESS_TOKENID_GET_FTOKENID + * @tc.desc: using nullptr instead of the address of ftokenid to ioctl + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, AbnormalGetfTokenid, Function | MediumTest | Level1) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, nullptr); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: AbnormalSetfTokenid + * @tc.desc: Test abnormal ioctl cmd of ACCESS_TOKENID_SET_FTOKENID + * @tc.desc: using nullptr instead of the address of ftokenid to ioctl + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, AbnormalSetfTokenid, Function | MediumTest | Level1) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, nullptr); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: AbnormalIoctlCmd + * @tc.desc: Test abnormal ioctl cmd of ACCESS_TOKENID_ILLEGAL1 and ACCESS_TOKENID_ILLEGAL1 + * @tc.desc: using illegal cmd instead of accesstokenid to ioctl + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, AbnormalIoctlCmd, Function | MediumTest | Level1) +{ + unsigned long long token; + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + int ret1 = ioctl(fd, ACCESS_TOKENID_ILLEGAL1, &token); + int ret2 = ioctl(fd, ACCESS_TOKENID_ILLEGAL2, &token); + close(fd); + + ASSERT_NE(0, ret1); + ASSERT_NE(0, ret2); +} + +/** + * @tc.name: OtherUidSetTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_UID can not set tokenid + * @tc.desc: tokenid can be only set by uid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, OtherUidSetTokenid, Function | MediumTest | Level1) +{ + unsigned long long tokenSet = GenRand64(); + int ret; + + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("setuid error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, &tokenSet); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: OtherUidGetTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_UID can get tokenid + * @tc.desc: tokenid can get not only by uid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, OtherUidGetTokenid, Function | MediumTest | Level1) +{ + unsigned long long token = INVAL_TOKEN; + int ret; + + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("setuid error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, &token); + close(fd); + + ASSERT_EQ(0, ret); +} + +/** + * @tc.name: WithoutGrpSetfTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_GRPID can not set ftokenid + * @tc.desc: ftokenid can not set by groups without grpid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, WithoutGrpSetfTokenid, Function | MediumTest | Level1) +{ + int ret; + size_t size = 1; + gid_t list[1] = {ACCESS_TOKEN_OTHER_GRPID}; + unsigned long long ftokenSet = GenRand64(); + + ret = setgroups(size, list); + if (ret != 0) { + printf("setgroups error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, &ftokenSet); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: WithoutGrpGetfTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_GRPID can not get ftokenid + * @tc.desc: ftokenid can not get by groups without grpid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, WithoutGrpGetfTokenid, Function | MediumTest | Level1) +{ + int ret; + size_t size = 1; + gid_t list[1] = {ACCESS_TOKEN_OTHER_GRPID}; + unsigned long long ftoken = INVAL_TOKEN; + + ret = setgroups(size, list); + if (ret != 0) { + printf("setgroups error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, &ftoken); + close(fd); + + ASSERT_NE(0, ret); +} + +/** + * @tc.name: WithGrpSetfTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_GRPID and ACCESS_TOKEN_GRPID can set ftokenid + * @tc.desc: ftokenid can set by groups with grpid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, WithGrpSetfTokenid, Function | MediumTest | Level1) +{ + int ret; + size_t size = 2; + gid_t list[2] = {ACCESS_TOKEN_OTHER_GRPID, ACCESS_TOKEN_GRPID}; + unsigned long long ftokenSet = GenRand64(); + + ret = setgroups(size, list); + if (ret != 0) { + printf("setgroups error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, &ftokenSet); + close(fd); + + ASSERT_EQ(0, ret); +} + +/** + * @tc.name: WithGrpGetfTokenid + * @tc.desc: Test ACCESS_TOKEN_OTHER_GRPID and ACCESS_TOKEN_GRPID can set ftokenid + * @tc.desc: ftokenid can set by groups with grpid 3020 + * @tc.type: FUNC + */ +HWTEST_F(AccesstokenidTest, WithGrpGetfTokenid, Function | MediumTest | Level1) +{ + int ret; + size_t size = 2; + gid_t list[2] = {ACCESS_TOKEN_OTHER_GRPID, ACCESS_TOKEN_GRPID}; + unsigned long long ftoken = INVAL_TOKEN; + + ret = setgroups(size, list); + if (ret != 0) { + printf("setgroups error %d \r\n", ret); + } + + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return; + } + + ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, &ftoken); + close(fd); + + ASSERT_EQ(0, ret); +} + diff --git a/test/unittest/accesstokenid/accesstokenid_test.h b/test/unittest/accesstokenid/accesstokenid_test.h new file mode 100644 index 0000000000000000000000000000000000000000..1c00aefc98916a5682ad56fc00e399ac97643493 --- /dev/null +++ b/test/unittest/accesstokenid/accesstokenid_test.h @@ -0,0 +1,27 @@ +/* + * 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. + */ +#ifndef ACCESSTOKENID_TEST_H +#define ACCESSTOKENID_TEST_H + +#include + +class AccesstokenidTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +#endif // ACCESSTOKENID_TEST_H \ No newline at end of file