mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Remove side effect from shm tests
Individual test cases must not rely on being executed in a clean environment. PiperOrigin-RevId: 353684155
This commit is contained in:
committed by
gVisor bot
parent
a358de583b
commit
0592dac851
+11
-17
@@ -256,32 +256,26 @@ TEST(ShmTest, IpcInfo) {
|
||||
}
|
||||
|
||||
TEST(ShmTest, ShmInfo) {
|
||||
struct shm_info info;
|
||||
|
||||
// We generally can't know what other processes on a linux machine
|
||||
// does with shared memory segments, so we can't test specific
|
||||
// numbers on Linux. When running under gvisor, we're guaranteed to
|
||||
// be the only ones using shm, so we can easily verify machine-wide
|
||||
// numbers.
|
||||
if (IsRunningOnGvisor()) {
|
||||
ASSERT_NO_ERRNO(Shmctl(0, SHM_INFO, &info));
|
||||
EXPECT_EQ(info.used_ids, 0);
|
||||
EXPECT_EQ(info.shm_tot, 0);
|
||||
EXPECT_EQ(info.shm_rss, 0);
|
||||
EXPECT_EQ(info.shm_swp, 0);
|
||||
}
|
||||
// Take a snapshot of the system before the test runs.
|
||||
struct shm_info snap;
|
||||
ASSERT_NO_ERRNO(Shmctl(0, SHM_INFO, &snap));
|
||||
|
||||
const ShmSegment shm = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
Shmget(IPC_PRIVATE, kAllocSize, IPC_CREAT | 0777));
|
||||
const char* addr = ASSERT_NO_ERRNO_AND_VALUE(Shmat(shm.id(), nullptr, 0));
|
||||
|
||||
struct shm_info info;
|
||||
ASSERT_NO_ERRNO(Shmctl(1, SHM_INFO, &info));
|
||||
|
||||
// We generally can't know what other processes on a linux machine do with
|
||||
// shared memory segments, so we can't test specific numbers on Linux. When
|
||||
// running under gvisor, we're guaranteed to be the only ones using shm, so
|
||||
// we can easily verify machine-wide numbers.
|
||||
if (IsRunningOnGvisor()) {
|
||||
ASSERT_NO_ERRNO(Shmctl(shm.id(), SHM_INFO, &info));
|
||||
EXPECT_EQ(info.used_ids, 1);
|
||||
EXPECT_EQ(info.shm_tot, kAllocSize / kPageSize);
|
||||
EXPECT_EQ(info.shm_rss, kAllocSize / kPageSize);
|
||||
EXPECT_EQ(info.used_ids, snap.used_ids + 1);
|
||||
EXPECT_EQ(info.shm_tot, snap.shm_tot + (kAllocSize / kPageSize));
|
||||
EXPECT_EQ(info.shm_rss, snap.shm_rss + (kAllocSize / kPageSize));
|
||||
EXPECT_EQ(info.shm_swp, 0); // Gvisor currently never swaps.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user