xref: /llvm-project/lldb/unittests/Host/HostTest.cpp (revision 266a9274dd14d06d559ca8a37e2d1b5f985a5398)
180814287SRaphael Isemann //===-- HostTest.cpp ------------------------------------------------------===//
23508fc8cSPavel Labath //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63508fc8cSPavel Labath //
73508fc8cSPavel Labath //===----------------------------------------------------------------------===//
83508fc8cSPavel Labath 
93508fc8cSPavel Labath #include "lldb/Host/Host.h"
10*266a9274SMarc Auberer #include "lldb/Utility/ProcessInfo.h"
113508fc8cSPavel Labath #include "gtest/gtest.h"
123508fc8cSPavel Labath 
133508fc8cSPavel Labath using namespace lldb_private;
143508fc8cSPavel Labath using namespace llvm;
153508fc8cSPavel Labath 
TEST(Host,WaitStatusFormat)163508fc8cSPavel Labath TEST(Host, WaitStatusFormat) {
173508fc8cSPavel Labath   EXPECT_EQ("W01", formatv("{0:g}", WaitStatus{WaitStatus::Exit, 1}).str());
183508fc8cSPavel Labath   EXPECT_EQ("X02", formatv("{0:g}", WaitStatus{WaitStatus::Signal, 2}).str());
193508fc8cSPavel Labath   EXPECT_EQ("S03", formatv("{0:g}", WaitStatus{WaitStatus::Stop, 3}).str());
203508fc8cSPavel Labath   EXPECT_EQ("Exited with status 4",
213508fc8cSPavel Labath             formatv("{0}", WaitStatus{WaitStatus::Exit, 4}).str());
223508fc8cSPavel Labath }
2362930e57SPavel Labath 
TEST(Host,GetEnvironment)2462930e57SPavel Labath TEST(Host, GetEnvironment) {
2562930e57SPavel Labath   putenv(const_cast<char *>("LLDB_TEST_ENVIRONMENT_VAR=Host::GetEnvironment"));
2662930e57SPavel Labath   ASSERT_EQ("Host::GetEnvironment",
2762930e57SPavel Labath             Host::GetEnvironment().lookup("LLDB_TEST_ENVIRONMENT_VAR"));
2862930e57SPavel Labath }
29*266a9274SMarc Auberer 
TEST(Host,ProcessInstanceInfoCumulativeUserTimeIsValid)30*266a9274SMarc Auberer TEST(Host, ProcessInstanceInfoCumulativeUserTimeIsValid) {
31*266a9274SMarc Auberer   ProcessInstanceInfo info;
32*266a9274SMarc Auberer   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{0, 0});
33*266a9274SMarc Auberer   EXPECT_FALSE(info.CumulativeUserTimeIsValid());
34*266a9274SMarc Auberer   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{0, 1});
35*266a9274SMarc Auberer   EXPECT_TRUE(info.CumulativeUserTimeIsValid());
36*266a9274SMarc Auberer   info.SetCumulativeUserTime(ProcessInstanceInfo::timespec{1, 0});
37*266a9274SMarc Auberer   EXPECT_TRUE(info.CumulativeUserTimeIsValid());
38*266a9274SMarc Auberer }
39*266a9274SMarc Auberer 
TEST(Host,ProcessInstanceInfoCumulativeSystemTimeIsValid)40*266a9274SMarc Auberer TEST(Host, ProcessInstanceInfoCumulativeSystemTimeIsValid) {
41*266a9274SMarc Auberer   ProcessInstanceInfo info;
42*266a9274SMarc Auberer   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{0, 0});
43*266a9274SMarc Auberer   EXPECT_FALSE(info.CumulativeSystemTimeIsValid());
44*266a9274SMarc Auberer   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{0, 1});
45*266a9274SMarc Auberer   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
46*266a9274SMarc Auberer   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{1, 0});
47*266a9274SMarc Auberer   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
48*266a9274SMarc Auberer }