• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 "src/profiling/memory/client.h"
18 
19 #include "gtest/gtest.h"
20 #include "perfetto/base/thread_utils.h"
21 #include "perfetto/base/unix_socket.h"
22 
23 #include <thread>
24 
25 namespace perfetto {
26 namespace profiling {
27 namespace {
28 
TEST(ClientTest,GetThreadStackBase)29 TEST(ClientTest, GetThreadStackBase) {
30   std::thread th([] {
31     const char* stackbase = GetThreadStackBase();
32     ASSERT_NE(stackbase, nullptr);
33     // The implementation assumes the stack grows from higher addresses to
34     // lower. We will need to rework once we encounter architectures where the
35     // stack grows the other way.
36     EXPECT_GT(stackbase, __builtin_frame_address(0));
37   });
38   th.join();
39 }
40 
TEST(ClientTest,IsMainThread)41 TEST(ClientTest, IsMainThread) {
42   // Our code relies on the fact that getpid() == GetThreadId() if this
43   // process/thread is the main thread of the process. This test ensures that is
44   // true.
45   auto pid = getpid();
46   auto main_thread_id = base::GetThreadId();
47   EXPECT_EQ(pid, main_thread_id);
48   std::thread th(
49       [main_thread_id] { EXPECT_NE(main_thread_id, base::GetThreadId()); });
50   th.join();
51 }
52 
53 }  // namespace
54 }  // namespace profiling
55 }  // namespace perfetto
56