1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <tuple>
18
19 #include <gtest/gtest.h>
20
21 #if defined(__BIONIC__)
22 #include <android-base/test_utils.h>
23 #include "gtest_globals.h"
24 #include "platform/bionic/mte.h"
25 #include "utils.h"
26 #endif
27
28 class MemtagStackTest : public testing::TestWithParam<std::tuple<const char*, bool>> {};
29
TEST_P(MemtagStackTest,test)30 TEST_P(MemtagStackTest, test) {
31 #if defined(__BIONIC__) && defined(__aarch64__)
32 if (!mte_supported()) {
33 GTEST_SKIP() << "MTE unsupported";
34 }
35 bool is_static = std::get<1>(GetParam());
36 if (running_with_hwasan() && !is_static) {
37 GTEST_SKIP() << "Can't run with HWASanified libc.so";
38 }
39 std::string helper =
40 GetTestLibRoot() + (is_static ? "/stack_tagging_static_helper" : "/stack_tagging_helper");
41 const char* arg = std::get<0>(GetParam());
42 ExecTestHelper eth;
43 eth.SetArgs({helper.c_str(), arg, nullptr});
44 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, "");
45 #else
46 GTEST_SKIP() << "bionic/arm64 only";
47 #endif
48 }
49
50 INSTANTIATE_TEST_SUITE_P(
51 , MemtagStackTest,
52 testing::Combine(testing::Values("vfork_execve", "vfork_execl", "vfork_exit", "longjmp",
53 "longjmp_sigaltstack", "android_mallopt", "exception_cleanup"),
54 testing::Bool()),
__anoncff3b81a0202(const ::testing::TestParamInfo<MemtagStackTest::ParamType>& info) 55 [](const ::testing::TestParamInfo<MemtagStackTest::ParamType>& info) {
56 std::string s = std::get<0>(info.param);
57 if (std::get<1>(info.param)) s += "_static";
58 return s;
59 });
60