xref: /llvm-project/lldb/unittests/Host/HostTest.cpp (revision 266a9274dd14d06d559ca8a37e2d1b5f985a5398)
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/Utility/ProcessInfo.h"
11 #include "gtest/gtest.h"
12 
13 using namespace lldb_private;
14 using namespace llvm;
15 
TEST(Host,WaitStatusFormat)16 TEST(Host, WaitStatusFormat) {
17   EXPECT_EQ("W01", formatv("{0:g}", WaitStatus{WaitStatus::Exit, 1}).str());
18   EXPECT_EQ("X02", formatv("{0:g}", WaitStatus{WaitStatus::Signal, 2}).str());
19   EXPECT_EQ("S03", formatv("{0:g}", WaitStatus{WaitStatus::Stop, 3}).str());
20   EXPECT_EQ("Exited with status 4",
21             formatv("{0}", WaitStatus{WaitStatus::Exit, 4}).str());
22 }
23 
TEST(Host,GetEnvironment)24 TEST(Host, GetEnvironment) {
25   putenv(const_cast<char *>("LLDB_TEST_ENVIRONMENT_VAR=Host::GetEnvironment"));
26   ASSERT_EQ("Host::GetEnvironment",
27             Host::GetEnvironment().lookup("LLDB_TEST_ENVIRONMENT_VAR"));
28 }
29 
TEST(Host,ProcessInstanceInfoCumulativeUserTimeIsValid)30 TEST(Host, ProcessInstanceInfoCumulativeUserTimeIsValid) {
31   ProcessInstanceInfo info;
32   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{0, 0});
33   EXPECT_FALSE(info.CumulativeUserTimeIsValid());
34   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{0, 1});
35   EXPECT_TRUE(info.CumulativeUserTimeIsValid());
36   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{1, 0});
37   EXPECT_TRUE(info.CumulativeUserTimeIsValid());
38 }
39 
TEST(Host,ProcessInstanceInfoCumulativeSystemTimeIsValid)40 TEST(Host, ProcessInstanceInfoCumulativeSystemTimeIsValid) {
41   ProcessInstanceInfo info;
42   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{0, 0});
43   EXPECT_FALSE(info.CumulativeSystemTimeIsValid());
44   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{0, 1});
45   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
46   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{1, 0});
47   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
48 }