mirror of
https://github.com/containers/podman.git
synced 2025-10-15 18:23:30 +08:00
test: fix race conditions in /dev/kmsg tests
The e2e tests for device access involving /dev/kmsg could fail intermittently. This was due to a race condition where concurrent writes to the kernel log buffer by other processes, while the test was reading from /dev/kmsg, could cause the read to fail with ESPIPE. Fixes: https://github.com/containers/podman/issues/23882 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -50,7 +50,10 @@ var _ = Describe("Podman run device", func() {
|
||||
Expect(session).Should(ExitCleanly())
|
||||
if !isRootless() {
|
||||
// Kernel 6.9.0 (2024-03) requires SYSLOG
|
||||
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", "--cap-add", "SYS_ADMIN,SYSLOG", ALPINE, "head", "-n", "1", "/dev/kmsg"})
|
||||
// Do not read any data from the device (thus the -n 0), because there is a rare race condition that happens
|
||||
// when another writes to the ring buffer when the device is already opened and that causes the following test
|
||||
// to fail: https://github.com/containers/podman/issues/23882.
|
||||
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", "--cap-add", "SYS_ADMIN,SYSLOG", ALPINE, "head", "-n", "0", "/dev/kmsg"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
}
|
||||
@ -152,9 +155,12 @@ var _ = Describe("Podman run device", func() {
|
||||
})
|
||||
|
||||
It("podman run cannot access non default devices", func() {
|
||||
session := podmanTest.Podman([]string{"run", "-v /dev:/dev-host", ALPINE, "head", "-1", "/dev-host/kmsg"})
|
||||
// Unlikely to happen but do not read any data from the device (thus the -n 0), because there is a rare
|
||||
// race condition that happens so the test would fail for the rare race condition instead of a failure
|
||||
// reported by open(). More details: https://github.com/containers/podman/issues/23882.
|
||||
session := podmanTest.Podman([]string{"run", "-v", "/dev:/dev-host", ALPINE, "head", "-n0", "/dev-host/kmsg"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Not(ExitCleanly()))
|
||||
Expect(session).To(ExitWithErrorRegex(1, "head: /dev-host/kmsg: (Operation not permitted|Permission denied)"))
|
||||
})
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user