From 0ab91dbf4e865d4d48a375b880f1bbeb64b04686 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Fri, 14 Jan 2022 15:44:37 -0800 Subject: [PATCH] Do not check the stability of certain /proc/cpuinfo fields. PiperOrigin-RevId: 421928736 --- test/syscalls/linux/proc.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc index f2a0a10d9..cd973ff9f 100644 --- a/test/syscalls/linux/proc.cc +++ b/test/syscalls/linux/proc.cc @@ -395,6 +395,25 @@ int ReadlinkWhileExited(std::string const& basename, char* buf, size_t count) { return ret; } +void RemoveUnstableCPUInfoFields(std::vector& cpu_info_fields) { + const std::vector unstable_fields{"cpu MHz", "bogomips"}; + auto it = cpu_info_fields.begin(); + while (it != cpu_info_fields.end()) { + bool found = false; + for (const std::string& unstable_field : unstable_fields) { + if (it->find(unstable_field) != std::string::npos) { + found = true; + break; + } + } + if (found) { + it = cpu_info_fields.erase(it); + } else { + ++it; + } + } +} + TEST(ProcTest, NotFoundInRoot) { struct stat s; EXPECT_THAT(stat("/proc/foobar", &s), SyscallFailsWithErrno(ENOENT)); @@ -1217,7 +1236,6 @@ TEST(ProcCpuinfo, RequiredFieldsArePresent) { std::string proc_cpuinfo = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/cpuinfo")); ASSERT_FALSE(proc_cpuinfo.empty()); - std::vector cpuinfo_fields = absl::StrSplit(proc_cpuinfo, '\n'); // Check that the usual fields are there. We don't really care about the // contents. @@ -1271,7 +1289,14 @@ TEST(ProcCpuinfo, Stable) { MaybeSave(); std::string output_after; ASSERT_NO_ERRNO(GetContents("/proc/cpuinfo", &output_after)); - EXPECT_THAT(output_before, Eq(output_after)); + + std::vector before_fields = absl::StrSplit(output_before, '\n'); + std::vector after_fields = absl::StrSplit(output_before, '\n'); + RemoveUnstableCPUInfoFields(before_fields); + RemoveUnstableCPUInfoFields(after_fields); + + EXPECT_THAT(absl::StrJoin(before_fields, "\n"), + Eq(absl::StrJoin(after_fields, "\n"))); } // Sanity checks that uptime is present.