1 //===-- HostTest.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/Host.h"
10 #include "lldb/Host/FileSystem.h"
11 #include "lldb/Host/HostInfo.h"
12 #include "lldb/Utility/ProcessInfo.h"
13 #include "gtest/gtest.h"
15 using namespace lldb_private
;
18 class HostTest
: public testing::Test
{
20 static void SetUpTestCase() {
21 FileSystem::Initialize();
22 HostInfo::Initialize();
24 static void TearDownTestCase() {
25 HostInfo::Terminate();
26 FileSystem::Terminate();
31 TEST_F(HostTest
, GetProcessInfo
) {
32 ProcessInstanceInfo Info
;
33 ASSERT_FALSE(Host::GetProcessInfo(0, Info
));
35 ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info
));
37 ASSERT_TRUE(Info
.ProcessIDIsValid());
38 EXPECT_EQ(lldb::pid_t(getpid()), Info
.GetProcessID());
40 ASSERT_TRUE(Info
.ParentProcessIDIsValid());
41 EXPECT_EQ(lldb::pid_t(getppid()), Info
.GetParentProcessID());
43 ASSERT_TRUE(Info
.EffectiveUserIDIsValid());
44 EXPECT_EQ(geteuid(), Info
.GetEffectiveUserID());
46 ASSERT_TRUE(Info
.EffectiveGroupIDIsValid());
47 EXPECT_EQ(getegid(), Info
.GetEffectiveGroupID());
49 ASSERT_TRUE(Info
.UserIDIsValid());
50 EXPECT_EQ(geteuid(), Info
.GetUserID());
52 ASSERT_TRUE(Info
.GroupIDIsValid());
53 EXPECT_EQ(getegid(), Info
.GetGroupID());
55 EXPECT_TRUE(Info
.GetArchitecture().IsValid());
56 EXPECT_EQ(HostInfo::GetArchitecture(HostInfo::eArchKindDefault
),
57 Info
.GetArchitecture());