diff options
author | Andrei Vagin <avagin@google.com> | 2021-08-16 23:12:12 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-08-16 23:14:40 -0700 |
commit | 6294a7a6ec6d0e4666f5413df6e59738d02fc12e (patch) | |
tree | e39a9b41823f3e43fafbfe9a7989afd0eafcae9a /test | |
parent | bb13d015a4ffcedac42cce05ec9f1ff4728d12d7 (diff) |
test/syscalls/proc_net: /proc/net/snmp can contain system-wide statistics
This is a new kernel feature that are controlled by the net.core.mibs_allocation
sysctl.
PiperOrigin-RevId: 391215784
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/proc_net.cc | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/test/syscalls/linux/proc_net.cc b/test/syscalls/linux/proc_net.cc index 4cbe30fc1..162c0b665 100644 --- a/test/syscalls/linux/proc_net.cc +++ b/test/syscalls/linux/proc_net.cc @@ -152,6 +152,22 @@ TEST(ProcNetDev, Format) { EXPECT_GT(entries.size(), 0); } +// GetMibsAllocationSysctl retuns a value of the net.core.mibs_allocation +// sysctl./proc/sys/net/core/mibs_allocation +// +// When mibs_allocation is unset, a netns creation inherits MIB from init +// network namespace. Otherwise, MIBS is allocated for each namespace. +int GetMibsAllocationSysctl() { + auto ret = GetContents("/proc/sys/net/core/mibs_allocation"); + if (!ret.ok()) { + // The current kernel doesn't support mibs_allocation. + return 1; + } + int32_t val; + EXPECT_TRUE(absl::SimpleAtoi(ret.ValueOrDie(), &val)); + return val; +} + PosixErrorOr<uint64_t> GetSNMPMetricFromProc(const std::string snmp, const std::string& type, const std::string& item) { @@ -226,12 +242,21 @@ TEST(ProcNetSnmp, TcpReset) { newAttemptFails = ASSERT_NO_ERRNO_AND_VALUE( GetSNMPMetricFromProc(snmp, "Tcp", "AttemptFails")); - EXPECT_EQ(oldActiveOpens, newActiveOpens - 1); - EXPECT_EQ(oldOutRsts, newOutRsts - 1); - EXPECT_EQ(oldAttemptFails, newAttemptFails - 1); + if (GetMibsAllocationSysctl()) { + EXPECT_EQ(oldActiveOpens, newActiveOpens - 1); + EXPECT_EQ(oldOutRsts, newOutRsts - 1); + EXPECT_EQ(oldAttemptFails, newAttemptFails - 1); + } else { + // System-wide statistics can have some noise. + EXPECT_LE(oldOutRsts, newOutRsts - 1); + EXPECT_LE(oldAttemptFails, newAttemptFails - 1); + } } TEST(ProcNetSnmp, TcpEstab) { + // System-wide statistics can have some noise. + SKIP_IF(GetMibsAllocationSysctl() == 0); + // TODO(gvisor.dev/issue/866): epsocket metrics are not savable. DisableSave ds; @@ -355,8 +380,14 @@ TEST(ProcNetSnmp, UdpNoPorts) { newNoPorts = ASSERT_NO_ERRNO_AND_VALUE(GetSNMPMetricFromProc(snmp, "Udp", "NoPorts")); - EXPECT_EQ(oldOutDatagrams, newOutDatagrams - 1); - EXPECT_EQ(oldNoPorts, newNoPorts - 1); + if (GetMibsAllocationSysctl()) { + EXPECT_EQ(oldOutDatagrams, newOutDatagrams - 1); + EXPECT_EQ(oldNoPorts, newNoPorts - 1); + } else { + // System-wide statistics can have some noise. + EXPECT_LE(oldOutDatagrams, newOutDatagrams - 1); + EXPECT_LE(oldNoPorts, newNoPorts - 1); + } } TEST(ProcNetSnmp, UdpIn) { @@ -405,8 +436,14 @@ TEST(ProcNetSnmp, UdpIn) { newInDatagrams = ASSERT_NO_ERRNO_AND_VALUE( GetSNMPMetricFromProc(snmp, "Udp", "InDatagrams")); - EXPECT_EQ(oldOutDatagrams, newOutDatagrams - 1); - EXPECT_EQ(oldInDatagrams, newInDatagrams - 1); + if (GetMibsAllocationSysctl()) { + EXPECT_EQ(oldOutDatagrams, newOutDatagrams - 1); + EXPECT_EQ(oldInDatagrams, newInDatagrams - 1); + } else { + // System-wide statistics can have some noise. + EXPECT_LE(oldOutDatagrams, newOutDatagrams - 1); + EXPECT_LE(oldInDatagrams, newInDatagrams - 1); + } } TEST(ProcNetSnmp, CheckNetStat) { |