summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2021-01-31 15:00:14 -0500
committerGravatar Benjamin Barenblat <bbaren@google.com>2021-01-31 15:04:48 -0500
commit9229f2a0b73adb577b85e30b3060862c1c583d1a (patch)
treeb8178b1646687e1cbb8af29bdde48fb0f1c5a4c8
parent811a85b5d78807d1280e79151a915eb44577421b (diff)
Ignore missing CPU frequency when testing on certain platforms
Skip unit tests requiring a CPU frequency on MIPS, PA-RISC, POWER, RISC-V, and s390x; those platforms do not reliably expose CPU frequency through /sys.
-rw-r--r--debian/patches/cpu-frequency.diff54
-rw-r--r--debian/patches/series1
2 files changed, 55 insertions, 0 deletions
diff --git a/debian/patches/cpu-frequency.diff b/debian/patches/cpu-frequency.diff
new file mode 100644
index 00000000..adfba7e0
--- /dev/null
+++ b/debian/patches/cpu-frequency.diff
@@ -0,0 +1,54 @@
+From: Benjamin Barenblat <bbaren@google.com>
+Subject: Ignore missing CPU frequency on more architectures
+Forwarded: yes
+Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/1918ad2ae38aa32c74b558b322479a8efdd76363
+
+Linux on MIPS, PA-RISC, RISC-V, and SystemZ doesn’t expose the nominal CPU
+frequency via /sys, so don’t worry if `NominalCPUFrequency` returns 1.0 on those
+platforms.
+
+Some POWER machines expose the CPU frequency; others do not. Since we can’t
+predict which type of machine the tests will run on, simply disable testing for
+`NominalCPUFrequency` on POWER.
+
+The author works at Google. Upstream applied this patch as Piper revision
+347079873 and exported it to GitHub; the Applied-Upstream URL above points to
+the exported commit.
+
+--- a/absl/base/internal/sysinfo_test.cc
++++ b/absl/base/internal/sysinfo_test.cc
+@@ -37,17 +37,28 @@ TEST(SysinfoTest, NumCPUs) {
+ << "NumCPUs() should not have the default value of 0";
+ }
+
++// Ensure that NominalCPUFrequency returns a reasonable value, or 1.00 on
++// platforms where the CPU frequency is not available through sysfs.
++//
++// POWER is particularly problematic here; some Linux kernels expose the CPU
++// frequency, while others do not. Since we can't predict a priori what a given
++// machine is going to do, just disable this test on POWER on Linux.
++#if !(defined(__linux) && (defined(__ppc64__) || defined(__PPC64__)))
+ TEST(SysinfoTest, NominalCPUFrequency) {
+-#if !(defined(__aarch64__) && defined(__linux__)) && !defined(__EMSCRIPTEN__)
+- EXPECT_GE(NominalCPUFrequency(), 1000.0)
+- << "NominalCPUFrequency() did not return a reasonable value";
+-#else
+- // Aarch64 cannot read the CPU frequency from sysfs, so we get back 1.0.
+- // Emscripten does not have a sysfs to read from at all.
++ // Linux only exposes the CPU frequency on certain architectures, and
++ // Emscripten doesn't expose it at all.
++#if defined(__linux__) && \
++ (defined(__aarch64__) || defined(__hppa__) || defined(__mips__) || \
++ defined(__riscv) || defined(__s390x__)) || \
++ defined(__EMSCRIPTEN__)
+ EXPECT_EQ(NominalCPUFrequency(), 1.0)
+ << "CPU frequency detection was fixed! Please update unittest.";
++#else
++ EXPECT_GE(NominalCPUFrequency(), 1000.0)
++ << "NominalCPUFrequency() did not return a reasonable value";
+ #endif
+ }
++#endif
+
+ TEST(SysinfoTest, GetTID) {
+ EXPECT_EQ(GetTID(), GetTID()); // Basic compile and equality test.
diff --git a/debian/patches/series b/debian/patches/series
index 8dd1d3d3..cf05a43f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@ configure.diff
fix-hppa.diff
std-hash.diff
latomic.diff
+cpu-frequency.diff