1 //===-- HostTest.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Host/Host.h"
10 #include "lldb/Host/FileSystem.h"
11 #include "lldb/Host/HostInfo.h"
12 #include "lldb/Target/Process.h"
13 #include "gtest/gtest.h"
14
15 using namespace lldb_private;
16
17 namespace {
18 class HostTest : public testing::Test {
19 public:
SetUpTestCase()20 static void SetUpTestCase() {
21 FileSystem::Initialize();
22 HostInfo::Initialize();
23 }
TearDownTestCase()24 static void TearDownTestCase() {
25 HostInfo::Terminate();
26 FileSystem::Terminate();
27 }
28 };
29 } // namespace
30
TEST_F(HostTest,GetProcessInfo)31 TEST_F(HostTest, GetProcessInfo) {
32 ProcessInstanceInfo Info;
33 ASSERT_FALSE(Host::GetProcessInfo(0, Info));
34
35 ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info));
36
37 ASSERT_TRUE(Info.ProcessIDIsValid());
38 EXPECT_EQ(lldb::pid_t(getpid()), Info.GetProcessID());
39
40 ASSERT_TRUE(Info.ParentProcessIDIsValid());
41 EXPECT_EQ(lldb::pid_t(getppid()), Info.GetParentProcessID());
42
43 ASSERT_TRUE(Info.EffectiveUserIDIsValid());
44 EXPECT_EQ(geteuid(), Info.GetEffectiveUserID());
45
46 ASSERT_TRUE(Info.EffectiveGroupIDIsValid());
47 EXPECT_EQ(getegid(), Info.GetEffectiveGroupID());
48
49 ASSERT_TRUE(Info.UserIDIsValid());
50 EXPECT_EQ(geteuid(), Info.GetUserID());
51
52 ASSERT_TRUE(Info.GroupIDIsValid());
53 EXPECT_EQ(getegid(), Info.GetGroupID());
54
55 EXPECT_TRUE(Info.GetArchitecture().IsValid());
56 EXPECT_EQ(HostInfo::GetArchitecture(HostInfo::eArchKindDefault),
57 Info.GetArchitecture());
58 }
59