mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
kselftest/openat2: test for OPENAT2_REGULAR flag
Just a happy path test. Christian Brauner <brauner@kernel.org> says: Update OPENAT2_REGULAR fallback define to match upper-32-bit UAPI value. Port the test to the kselftest_harness TEST*/FIXTURE framework to match the migrated openat2_test.c, and add a regression test ensuring open()/openat() keep ignoring the internal __O_REGULAR carrier bit. Signed-off-by: Dorjoy Chowdhury <dorjoychy111@gmail.com> Link: https://patch.msgid.link/20260328172314.45807-3-dorjoychy111@gmail.com Reviewed-by: Aleksa Sarai <aleksa@amutable.com> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
parent
8b82cacad9
commit
6045a75399
|
|
@ -310,4 +310,53 @@ TEST_F(openat2, flag_validation)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef OPENAT2_REGULAR
|
||||
#define OPENAT2_REGULAR ((__u64)1 << 32)
|
||||
#endif
|
||||
|
||||
#ifndef EFTYPE
|
||||
#define EFTYPE 134
|
||||
#endif
|
||||
|
||||
/* Kernel-internal carrier for OPENAT2_REGULAR (see __O_REGULAR in fcntl.h). */
|
||||
#ifndef __O_REGULAR
|
||||
#define __O_REGULAR (1 << 30)
|
||||
#endif
|
||||
|
||||
/* Verify that OPENAT2_REGULAR rejects non-regular files with EFTYPE. */
|
||||
TEST_F(openat2, regular_flag)
|
||||
{
|
||||
struct open_how how = {
|
||||
.flags = OPENAT2_REGULAR | O_RDONLY,
|
||||
};
|
||||
int fd;
|
||||
|
||||
fd = sys_openat2(AT_FDCWD, "/dev/null", &how);
|
||||
if (fd == -ENOENT)
|
||||
SKIP(return, "/dev/null does not exist");
|
||||
|
||||
EXPECT_EQ(-EFTYPE, fd) {
|
||||
TH_LOG("openat2 with OPENAT2_REGULAR should fail with %d (%s), got %d (%s)",
|
||||
-EFTYPE, strerror(EFTYPE), fd, strerror(-fd));
|
||||
}
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* open()/openat() must keep ignoring the internal __O_REGULAR bit. */
|
||||
TEST(legacy_openat_ignores_o_regular)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = openat(AT_FDCWD, "/dev/null", O_RDONLY | __O_REGULAR);
|
||||
if (fd < 0 && errno == ENOENT)
|
||||
SKIP(return, "/dev/null does not exist");
|
||||
|
||||
ASSERT_GE(fd, 0) {
|
||||
TH_LOG("legacy openat() must ignore the __O_REGULAR carrier bit, got errno %d (%s)",
|
||||
errno, strerror(errno));
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
TEST_HARNESS_MAIN
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user