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/Utility/ProcessInfo.h"
11 #include "gtest/gtest.h"
13 using namespace lldb_private
;
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());
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"));
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());
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());