1 //===-- ProcessInstanceInfoTest.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/Target/Process.h"
10 #include "gtest/gtest.h"
13 using namespace lldb_private
;
16 /// A very simple resolver which fails for even ids and returns a simple string
18 class DummyUserIDResolver
: public UserIDResolver
{
20 std::optional
<std::string
> DoGetUserName(id_t uid
) override
{
22 return ("user" + llvm::Twine(uid
)).str();
26 std::optional
<std::string
> DoGetGroupName(id_t gid
) override
{
28 return ("group" + llvm::Twine(gid
)).str();
34 TEST(ProcessInstanceInfo
, Dump
) {
35 ProcessInstanceInfo
info("a.out", ArchSpec("x86_64-pc-linux"), 47);
37 info
.SetEffectiveUserID(2);
39 info
.SetEffectiveGroupID(4);
41 DummyUserIDResolver resolver
;
43 info
.Dump(s
, resolver
);
44 EXPECT_STREQ(R
"( pid = 47
47 arch = x86_64-pc-linux
56 TEST(ProcessInstanceInfo
, DumpTable
) {
57 ProcessInstanceInfo
info("a.out", ArchSpec("x86_64-pc-linux"), 47);
59 info
.SetEffectiveUserID(2);
61 info
.SetEffectiveGroupID(4);
63 DummyUserIDResolver resolver
;
66 const bool show_args
= false;
67 const bool verbose
= true;
68 ProcessInstanceInfo::DumpTableHeader(s
, show_args
, verbose
);
69 info
.DumpAsTableRow(s
, resolver
, show_args
, verbose
);
71 R
"(PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS
72 ====== ====== ========== ========== ========== ========== ============================== ============================
73 47 0 user1 group3 2 4 x86_64-pc-linux
78 TEST(ProcessInstanceInfo
, DumpTable_invalidUID
) {
79 ProcessInstanceInfo
info("a.out", ArchSpec("aarch64-unknown-linux-android"), 47);
81 DummyUserIDResolver resolver
;
84 const bool show_args
= false;
85 const bool verbose
= false;
86 ProcessInstanceInfo::DumpTableHeader(s
, show_args
, verbose
);
87 info
.DumpAsTableRow(s
, resolver
, show_args
, verbose
);
89 R
"(PID PARENT USER TRIPLE NAME
90 ====== ====== ========== ============================== ============================
91 47 0 aarch64-unknown-linux-android a.out
96 TEST(ProcessInstanceInfoMatch
, Name
) {
97 ProcessInstanceInfo info_bar
, info_empty
;
98 info_bar
.GetExecutableFile().SetFile("/foo/bar", FileSpec::Style::posix
);
100 ProcessInstanceInfoMatch match
;
101 match
.SetNameMatchType(NameMatch::Equals
);
102 match
.GetProcessInfo().GetExecutableFile().SetFile("bar",
103 FileSpec::Style::posix
);
105 EXPECT_TRUE(match
.Matches(info_bar
));
106 EXPECT_FALSE(match
.Matches(info_empty
));
108 match
.GetProcessInfo().GetExecutableFile() = FileSpec();
109 EXPECT_TRUE(match
.Matches(info_bar
));
110 EXPECT_TRUE(match
.Matches(info_empty
));