#include "perfetto/base/build_config.h"
#if PERFETTO_BUILDFLAG(PERFETTO_WATCHDOG)
#include "perfetto/ext/base/watchdog_posix.h"
#include <stdio.h>
#include "perfetto/ext/base/file_utils.h"
#include "perfetto/ext/base/temp_file.h"
#include "test/gtest_and_gmock.h"
namespace perfetto {
namespace base {
namespace {
TEST(WatchdogPosixTest, ParseProcStat) {
constexpr const char stat[] =
"2965981 (zsh) S 2965977 2965981 2965981 34822 2966607 4194304 6632 6697 "
"0 0 11 6 4 1 20 0 1 0 227163466 15839232 2311 18446744073709551615 "
"94823961161728 94823961762781 140722993535472 0 0 0 2 3686400 134295555 "
"0 0 0 17 2 0 0 0 0 0 94823961905904 94823961935208 94823993954304 "
"140722993543678 140722993543691 140722993543691 140722993545195 0";
TempFile f = TempFile::CreateUnlinked();
WriteAll(f.fd(), stat, sizeof(stat));
ASSERT_NE(lseek(f.fd(), 0, SEEK_SET), -1);
ProcStat ps;
ASSERT_TRUE(ReadProcStat(f.fd(), &ps));
EXPECT_EQ(ps.utime, 11u);
EXPECT_EQ(ps.stime, 6u);
EXPECT_EQ(ps.rss_pages, 2311);
}
}
}
}
#endif