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 "gtest_globals.h"
23 #include "platform/bionic/mte.h"
24 #include "utils.h"
25 #endif
26 
27 class MemtagStackTest : public testing::TestWithParam<std::tuple<const char*, bool>> {};
28 
TEST_P(MemtagStackTest,test)29 TEST_P(MemtagStackTest, test) {
30 #if defined(__BIONIC__) && defined(__aarch64__)
31   if (!mte_supported()) {
32     GTEST_SKIP() << "MTE unsupported";
33   }
34   bool is_static = std::get<1>(GetParam());
35   std::string helper =
36       GetTestLibRoot() + (is_static ? "/stack_tagging_static_helper" : "/stack_tagging_helper");
37   const char* arg = std::get<0>(GetParam());
38   ExecTestHelper eth;
39   eth.SetArgs({helper.c_str(), arg, nullptr});
40   eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, "");
41 #else
42   GTEST_SKIP() << "bionic/arm64 only";
43 #endif
44 }
45 
46 INSTANTIATE_TEST_SUITE_P(
47     , MemtagStackTest,
48     testing::Combine(testing::Values("vfork_execve", "vfork_execl", "vfork_exit", "longjmp",
49                                      "longjmp_sigaltstack", "android_mallopt", "exception_cleanup"),
50                      testing::Bool()),
__anon289024e40202(const ::testing::TestParamInfo<MemtagStackTest::ParamType>& info) 51     [](const ::testing::TestParamInfo<MemtagStackTest::ParamType>& info) {
52       std::string s = std::get<0>(info.param);
53       if (std::get<1>(info.param)) s += "_static";
54       return s;
55     });
56