Skip to contentSkip to conversation

symlink01 split

PATCH Superseded Andrea Cervesato 4 participants 12 messages Jul 10, 2024

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover symlink01 split

This is a developement series (requested by Petr Vorel) that handle symlink01 split, which has been already merged in the master branch.

In this series we face the next part of symlink01 split that includes stat04, lstat03, open15 and chmod08.

---
Changes in v3:
- stat04: smarter cleanup
- lstat03: smarter cleanup
- open15: fix algorithm, read/write from/to symlink
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- update TST_EXP_EXTR to support stringification
- call stat() inside the test run() routine
- call lstat() inside the test run() routine
- simplify chmod08
- simplify open15
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (4):
Add stat04 test
Add lstat03 test
Add chmod08 test
Add open15 test

 runtest/smoketest                          |   4 +-
 runtest/syscalls                           |  11 +--
 testcases/kernel/syscalls/chmod/.gitignore |   1 +
 testcases/kernel/syscalls/chmod/chmod08.c  |  45 +++++++++++
 testcases/kernel/syscalls/lstat/.gitignore |   2 +
 testcases/kernel/syscalls/lstat/lstat03.c  | 102 ++++++++++++++++++++++++
 testcases/kernel/syscalls/open/.gitignore  |   1 +
 testcases/kernel/syscalls/open/open15.c    |  75 ++++++++++++++++++
 testcases/kernel/syscalls/stat/.gitignore  |   2 +
 testcases/kernel/syscalls/stat/stat04.c    | 121 +++++++++++++++++++++++++++++
 10 files changed, 356 insertions(+), 8 deletions(-)

---
base-commit: 62d00fe990187c3f95b84e43c8cd06eae0e639dc
change-id: 20240702-stat04-ceeb58b80910

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v3 1/4 Add stat04 test

From: Andrea Cervesato <[email protected]>

This test has been extracted from symlink01 test and it checks that stat() executed on file provide the same information of symlink linking to it.

---
 runtest/smoketest                         |   4 +-
 runtest/syscalls                          |   4 +-
 testcases/kernel/syscalls/stat/.gitignore |   2 +
 testcases/kernel/syscalls/stat/stat04.c   | 121 ++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+), 5 deletions(-)
runtest/smoketest +1 -3
index f6f14fd2b..aeb74c9ee 100644
@@ -8,9 +8,7 @@ time01 time01
 wait02 wait02
 write01 write01
 symlink01 symlink01
-stat04 symlink01 -T stat04
-utime07 utime07
-rename01A symlink01 -T rename01
+stat04 stat04
 splice02 splice02 -s 20
 df01_sh df01.sh
 shell_test01 echo "SUCCESS" | shell_pipe01.sh
runtest/syscalls +2 -2
index b6cadb2df..1e1203503 100644
@@ -1535,8 +1535,8 @@ stat02 stat02
 stat02_64 stat02_64
 stat03 stat03
 stat03_64 stat03_64
-stat04 symlink01 -T stat04
-stat04_64 symlink01 -T stat04_64
+stat04 stat04
+stat04_64 stat04_64
 
 statfs01 statfs01
 statfs01_64 statfs01_64
testcases/kernel/syscalls/stat/.gitignore +2 -0
index fa0a4ce9f..0a62dc6ee 100644
@@ -4,3 +4,5 @@
 /stat02_64
 /stat03
 /stat03_64
+/stat04
+/stat04_64
testcases/kernel/syscalls/stat/stat04.c new file +121 -0

121 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 1/4
#2 lore raw

Re: [LTP] [PATCH v3 1/4] Add stat04 test

Hi!

Quoted 31 lines
testcases/kernel/syscalls/stat/stat04.c new file +31 -0
+static char symb_path[PATH_MAX];
+static char file_path[PATH_MAX];
+static struct stat *file_stat;
+static struct stat *symb_stat;
+static char *tmpdir;
+
+static void run(void)
+{
+	SAFE_STAT(file_path, file_stat);
+	SAFE_STAT(symb_path, symb_stat);
+
+	TST_EXP_EQ_LI(file_stat->st_dev, symb_stat->st_dev);
+	TST_EXP_EQ_LI(file_stat->st_mode, symb_stat->st_mode);
+	TST_EXP_EQ_LI(file_stat->st_nlink, symb_stat->st_nlink);
+	TST_EXP_EQ_LI(file_stat->st_uid, symb_stat->st_uid);
+	TST_EXP_EQ_LI(file_stat->st_gid, symb_stat->st_gid);
+	TST_EXP_EQ_LI(file_stat->st_size, symb_stat->st_size);
+	TST_EXP_EQ_LI(file_stat->st_atime, symb_stat->st_atime);
+	TST_EXP_EQ_LI(file_stat->st_mtime, symb_stat->st_mtime);
+	TST_EXP_EQ_LI(file_stat->st_ctime, symb_stat->st_ctime);
+}
+
+static void setup(void)
+{
+	char opt_bsize[32];
+	const char *const fs_opts[] = {opt_bsize, NULL};
+	struct stat sb;
+	int pagesize;
+	int fd;
+
+	tmpdir = tst_get_tmpdir();

testcases/kernel/syscalls/stat/stat04.c line 62

Quoted 10 lines
testcases/kernel/syscalls/stat/stat04.c new file +10 -0
+
+	if (strlen(tmpdir) >= (PATH_MAX - strlen(FILENAME))) {
+		tst_brk(TCONF, "Temporary folder name is too long. "
+			"Can't create file");
+	}
+
+	if (strlen(tmpdir) >= (PATH_MAX - strlen(SYMBNAME))) {
+		tst_brk(TCONF, "Temporary folder name is too long. "
+			"Can't create symbolic link");
+	}

Uff, this is so 1990. Can we please use asprintf() instead?

Other than that this looks good to me:

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v3 1/4] Add stat04 test

In reply to Andrea Cervesato

Hi Andrea,

testcases/kernel/syscalls/stat/stat04.c line 103

Quoted 7 lines
testcases/kernel/syscalls/stat/stat04.c new file +7 -0
+static void cleanup(void)
+{
+	if (tmpdir)
+		free(tmpdir);
+
+	if (access(SYMBNAME, F_OK) != -1)
+		SAFE_UNLINK(SYMBNAME);

nit: I would remove this (not needed).

+ Cyril's note about using asprintf(), hopefully v4 will be merged. Thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v3 1/4] Add stat04 test

In reply to Andrea Cervesato

Hi Andrea,

...

runtest/smoketest time01 time01 · line 12

Quoted 7 lines

+++ b/runtest/smoketest

runtest/smoketest +0 -2
@@ -8,9 +8,7 @@ time01 time01
 wait02 wait02
 write01 write01
 symlink01 symlink01
-stat04 symlink01 -T stat04
-utime07 utime07

nit: you still remove utime07. Not sure why, I'd keep it.

Kind regards,
Petr

Quoted 5 lines
runtest/smoketest +1 -1
-rename01A symlink01 -T rename01
+stat04 stat04
 splice02 splice02 -s 20
 df01_sh df01.sh
 shell_test01 echo "SUCCESS" | shell_pipe01.sh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v3 2/4 Add lstat03 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test has been extracted from symlink01 test and it checks that lstat() provides the right information, according with device, access time, block size, ownership, etc.

---
 runtest/syscalls                           |   4 +-
 testcases/kernel/syscalls/lstat/.gitignore |   2 +
 testcases/kernel/syscalls/lstat/lstat03.c  | 102 +++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 2 deletions(-)
runtest/syscalls +2 -2
index 1e1203503..160725893 100644
@@ -725,12 +725,12 @@ lseek02 lseek02
 lseek07 lseek07
 lseek11 lseek11
 
-lstat01A symlink01 -T lstat01
-lstat01A_64 symlink01 -T lstat01_64
 lstat01 lstat01
 lstat01_64 lstat01_64
 lstat02 lstat02
 lstat02_64 lstat02_64
+lstat03 lstat03
+lstat03_64 lstat03_64
 
 mallinfo02 mallinfo02
 
testcases/kernel/syscalls/lstat/.gitignore +2 -0
index a497a445f..72cba871f 100644
@@ -2,3 +2,5 @@
 /lstat01_64
 /lstat02
 /lstat02_64
+/lstat03
+/lstat03_64
testcases/kernel/syscalls/lstat/lstat03.c new file +102 -0

102 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 2/4
#6 lore raw

Re: [LTP] [PATCH v3 2/4] Add lstat03 test

Hi Andrea,

the same note as for stat04 - this could be using all_filesystems, but let's do it as a separate effort.

...

testcases/kernel/syscalls/lstat/lstat03.c line 83

Quoted 4 lines
testcases/kernel/syscalls/lstat/lstat03.c new file +4 -0
+static void cleanup(void)
+{
+	if (access(SYMBNAME, F_OK) != -1)
+		SAFE_UNLINK(SYMBNAME);

nit: This is not needed (file created at setup).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 3/4 Add chmod08 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test has been extracted from symlink01 and it verifies that chmod() is working correctly on symlink() generated files.

---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/chmod/.gitignore |  1 +
 testcases/kernel/syscalls/chmod/chmod08.c  | 45 ++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
runtest/syscalls +1 -0
index 160725893..40c0dd070 100644
@@ -72,6 +72,7 @@ chmod03 chmod03
 chmod05 chmod05
 chmod06 chmod06
 chmod07 chmod07
+chmod08 chmod08
 
 chown01 chown01
 chown01_16 chown01_16
testcases/kernel/syscalls/chmod/.gitignore +1 -0
index 27ddfce16..f295f4dcb 100644
@@ -3,3 +3,4 @@
 /chmod05
 /chmod06
 /chmod07
+/chmod08
testcases/kernel/syscalls/chmod/chmod08.c new file +45 -0

45 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 3/4
#8 lore raw

Re: [LTP] [PATCH v3 3/4] Add chmod08 test

Hi Andrea,

thanks a lot, merged with tiny changes.

testcases/kernel/syscalls/chmod/chmod08.c line 6

Quoted 8 lines

+++ b/testcases/kernel/syscalls/chmod/chmod08.c

testcases/kernel/syscalls/chmod/chmod08.c new file +6 -0
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *    Author: David Fenner
+ *    Copilot: Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato [email protected]

very nit: <[email protected]> (missing < >). Added.

Quoted 4 lines
testcases/kernel/syscalls/chmod/chmod08.c new file +4 -0
+ */
+
+/*\
+ * [Description]

testcases/kernel/syscalls/chmod/chmod08.c line 20

Quoted 10 lines
testcases/kernel/syscalls/chmod/chmod08.c new file +10 -0
+ *
+ * This test verifies that chmod() is working correctly on symlink()
+ * generated files.
+ */
+
+#include "tst_test.h"
+
+#define PERMS 01777
+#define TESTFILE "myobject"
+#define	SYMBNAME "my_symlink0"

Very nit: you mix tabs and spaces as a separator after define. Fixed.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

PATCH v3 4/4 Add open15 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test has been extracted from symlink01 and it verifies that open() is working correctly on symlink() generated files.

---
 runtest/syscalls                          |  2 +-
 testcases/kernel/syscalls/open/.gitignore |  1 +
 testcases/kernel/syscalls/open/open15.c   | 75 +++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)
runtest/syscalls +1 -1
index 40c0dd070..4dfdf3782 100644
@@ -923,7 +923,6 @@ nice04 nice04
 nice05 nice05
 
 open01 open01
-open01A symlink01 -T open01
 open02 open02
 open03 open03
 open04 open04
@@ -936,6 +935,7 @@ open11 open11
 open12 open12
 open13 open13
 open14 open14
+open15 open15
 
 openat01 openat01
 openat02 openat02
testcases/kernel/syscalls/open/.gitignore +1 -0
index 001d874d6..af5997572 100644
@@ -12,3 +12,4 @@
 /open12_child
 /open13
 /open14
+/open15
testcases/kernel/syscalls/open/open15.c new file +75 -0

75 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 4/4
#10 lore raw

Re: [LTP] [PATCH v3 4/4] Add open15 test

Quoted 7 lines · Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test has been extracted from symlink01 and it verifies that open() is working correctly on symlink() generated files.

It is a bit different from something in my imagination, but anyway this also looks good.

---

Quoted 129 lines
 runtest/syscalls                          |  2 +-
 testcases/kernel/syscalls/open/.gitignore |  1 +
 testcases/kernel/syscalls/open/open15.c   | 75
+++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)
runtest/syscalls +1 -1
index 40c0dd070..4dfdf3782 100644
@@ -923,7 +923,6 @@ nice04 nice04
 nice05 nice05
 
 open01 open01
-open01A symlink01 -T open01
 open02 open02
 open03 open03
 open04 open04
@@ -936,6 +935,7 @@ open11 open11
 open12 open12
 open13 open13
 open14 open14
+open15 open15
 
 openat01 openat01
 openat02 openat02
testcases/kernel/syscalls/open/.gitignore +1 -0
index 001d874d6..af5997572 100644
@@ -12,3 +12,4 @@
 /open12_child
 /open13
 /open14
+/open15
testcases/kernel/syscalls/open/open15.c new file +13 -0
new file mode 100644
index 000000000..09d7a1f3b
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *    Author: David Fenner
+ *    Copilot: Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato [email protected]
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that open() is working correctly on symlink()
+ * generated files. We generate a file via symlink, then we read both

from file
+ * and symlink, comparing that data has been correctly written.
+ */

testcases/kernel/syscalls/open/open15.c new file +42 -0
+
+#include "tst_test.h"
+
+#define FILENAME "myfile.txt"
+#define SYMBNAME "myfile_symlink"
+#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+
+static char buff_file[128];
+static char buff_symb[128];
+static int str_size;
+
+static void run(void)
+{
+       int fd_file, fd_symb;
+
+       memset(buff_file, 0, sizeof(buff_file));
+       memset(buff_symb, 0, sizeof(buff_symb));
+
+       tst_res(TINFO, "Create symlink");
+       SAFE_TOUCH(FILENAME, 0777, NULL);
+       SAFE_SYMLINK(FILENAME, SYMBNAME);
+
+       fd_file = SAFE_OPEN(FILENAME, O_RDONLY, 0777);
+       fd_symb = SAFE_OPEN(SYMBNAME, O_RDWR, 0777);
+
+       tst_res(TINFO, "Write data via symlink");
+       SAFE_WRITE(SAFE_WRITE_ALL, fd_symb, BIG_STRING, str_size);
+       SAFE_LSEEK(fd_symb, 0, 0);
+
+       tst_res(TINFO, "Read data via file");
+       SAFE_READ(1, fd_file, buff_file, str_size);
+       SAFE_LSEEK(fd_file, 0, 0);
+
+       tst_res(TINFO, "Read data via symlink");
+       SAFE_READ(1, fd_symb, buff_symb, str_size);
+       SAFE_LSEEK(fd_symb, 0, 0);
+
+       TST_EXP_EXPR(!strncmp(buff_file, BIG_STRING, str_size),
+               "file data has been correctly written");
+
+       TST_EXP_EXPR(!strncmp(buff_file, buff_symb, str_size),
+               "file data is the equivalent to symlink generated file

data");

testcases/kernel/syscalls/open/open15.c new file +18 -1
+
+       SAFE_CLOSE(fd_file);
+       SAFE_CLOSE(fd_symb);
+
+       SAFE_UNLINK(SYMBNAME);
+       SAFE_UNLINK(FILENAME);
+}
+
+static void setup(void)
+{
+       str_size = strlen(BIG_STRING);
+}
+
+static struct tst_test test = {
+       .test_all = run,
+       .setup = setup,
+       .needs_tmpdir = 1,
+};
 
--

2.43.0

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 4/4
#11 lore raw

Re: [LTP] [PATCH v3 4/4] Add open15 test

In reply to Andrea Cervesato

Hi Andrea,

again, I would prefer this to be run on all_filesystems (symlink to be on different filesystems), but this can be done later.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp