[LTP] [PATCH 2/2] open12: Fix O_APPEND test case
Martin Doucha
mdoucha@suse.cz
Mon Jun 2 17:57:06 CEST 2025
The original O_APPEND test case is guaranteed to succeed even if
O_APPEND doesn't work. Check the cursor position correctly.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
testcases/kernel/syscalls/open/open12.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open12.c b/testcases/kernel/syscalls/open/open12.c
index c8147bc9f..0dff26c7c 100644
--- a/testcases/kernel/syscalls/open/open12.c
+++ b/testcases/kernel/syscalls/open/open12.c
@@ -45,6 +45,7 @@ static void setup(void)
static void test_append(void)
{
off_t len1, len2;
+ struct stat statbuf;
tst_res(TINFO, "Testing O_APPEND");
@@ -54,14 +55,24 @@ static void test_append(void)
return;
len1 = SAFE_LSEEK(fd, 0, SEEK_CUR);
- SAFE_WRITE(1, fd, TEST_FILE, strlen(TEST_FILE));
+
+ if (len1)
+ tst_res(TFAIL, "Initial cursor position is not zero");
+
+ SAFE_FSTAT(fd, &statbuf);
+ len1 = strlen(TEST_FILE);
+ SAFE_WRITE(1, fd, TEST_FILE, len1);
len2 = SAFE_LSEEK(fd, 0, SEEK_CUR);
SAFE_CLOSE(fd);
+ len1 += statbuf.st_size;
- if (len2 > len1)
- tst_res(TPASS, "O_APPEND works as expected");
- else
- tst_res(TFAIL, "O_APPEND did not move write cursor");
+ if (len2 != len1) {
+ tst_res(TFAIL, "Wrong cursor position after write: %ld != %ld",
+ (long)len2, (long)len1);
+ return;
+ }
+
+ tst_res(TPASS, "O_APPEND works as expected");
}
static void test_noatime(void)
--
2.49.0
More information about the ltp
mailing list