Skip to contentSkip to conversation

Add stat04 test

PATCH Superseded Andrea Cervesato 4 participants 6 messages Feb 22, 2024 – Feb 24, 2024

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 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.

---
free() tmpdir
rename link_stat into link
rename path_stat into path

 runtest/smoketest                         |  2 +-
 runtest/syscalls                          |  4 +-
 testcases/kernel/syscalls/stat/.gitignore |  2 +
 testcases/kernel/syscalls/stat/stat04.c   | 50 +++++++++++++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/stat/stat04.c
runtest/smoketest +1 -1
index 83eebfe7b..5608417f9 100644
@@ -8,7 +8,7 @@ time01 time01
 wait02 wait02
 write01 write01
 symlink01 symlink01
-stat04 symlink01 -T stat04
+stat04 stat04
 utime01A symlink01 -T utime01
 rename01A symlink01 -T rename01
 splice02 splice02 -s 20
runtest/syscalls +2 -2
index 7794f1465..ef90076e4 100644
@@ -1529,8 +1529,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 +50 -0

50 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v4 1/1
#1 lore raw
Quoted 63 lines

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.

---
free() tmpdir
rename link_stat into link
rename path_stat into path

 runtest/smoketest                         |  2 +-
 runtest/syscalls                          |  4 +-
 testcases/kernel/syscalls/stat/.gitignore |  2 +
 testcases/kernel/syscalls/stat/stat04.c   | 50 +++++++++++++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/stat/stat04.c
runtest/smoketest +1 -1
index 83eebfe7b..5608417f9 100644
@@ -8,7 +8,7 @@ time01 time01
 wait02 wait02
 write01 write01
 symlink01 symlink01
-stat04 symlink01 -T stat04
+stat04 stat04
 utime01A symlink01 -T utime01
 rename01A symlink01 -T rename01
 splice02 splice02 -s 20
runtest/syscalls +2 -2
index 7794f1465..ef90076e4 100644
@@ -1529,8 +1529,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 +0 -0
new file mode 100644
index 000000000..aebfacf5a

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

Quoted 5 lines
testcases/kernel/syscalls/stat/stat04.c new file +5 -0
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *    Author: David Fenner
+ *    Copilot: Jon Hendrickson

very nit:
* Author: David Fenner, Jon Hendrickson

Quoted 12 lines
testcases/kernel/syscalls/stat/stat04.c new file +12 -0
+ * Copyright (C) 2024 Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test checks that stat() executed on file provide the same information
+ * of symlink linking to it.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"

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

Quoted 10 lines
testcases/kernel/syscalls/stat/stat04.c new file +10 -0
+
+static void run(void)
+{
+	char *symname = "my_symlink0";
+	char *tmpdir = tst_get_tmpdir();
+
+	SAFE_SYMLINK(tmpdir, symname);
+
+	struct stat path;
+	struct stat link;

nit: maybe define struct at the top of the function?

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

Quoted 3 lines
testcases/kernel/syscalls/stat/stat04.c new file +3 -0
+
+	TST_EXP_PASS(stat(tmpdir, &path));
+	free(tmpdir);

If SAFE_SYMLINK() fails, free() will not happen. I wonder if we should bother (we'd have to set it NULL and add a cleanup function).

Kind regards,
Petr

Quoted 20 lines
testcases/kernel/syscalls/stat/stat04.c new file +20 -0
+
+	TST_EXP_PASS(stat(symname, &link));
+
+	TST_EXP_EQ_LI(path.st_dev, link.st_dev);
+	TST_EXP_EQ_LI(path.st_mode, link.st_mode);
+	TST_EXP_EQ_LI(path.st_nlink, link.st_nlink);
+	TST_EXP_EQ_LI(path.st_uid, link.st_uid);
+	TST_EXP_EQ_LI(path.st_gid, link.st_gid);
+	TST_EXP_EQ_LI(path.st_size, link.st_size);
+	TST_EXP_EQ_LI(path.st_atime, link.st_atime);
+	TST_EXP_EQ_LI(path.st_mtime, link.st_mtime);
+	TST_EXP_EQ_LI(path.st_ctime, link.st_ctime);
+
+	SAFE_UNLINK(symname);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_tmpdir = 1,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!

Quoted 2 lines

If SAFE_SYMLINK() fails, free() will not happen. I wonder if we should bother (we'd have to set it NULL and add a cleanup function).

There is no point in bothering to deallocate memory if the process is going to call exit() soon anyways.

My main complaint was that we allocated memory in run() function, which is obviously a problem for large enough -i...

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Petr Vorel

Hi!

Quoted 81 lines · Petr Vorel
Quoted 58 lines

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.

---
free() tmpdir
rename link_stat into link
rename path_stat into path

  runtest/smoketest                         |  2 +-
  runtest/syscalls                          |  4 +-
  testcases/kernel/syscalls/stat/.gitignore |  2 +
  testcases/kernel/syscalls/stat/stat04.c   | 50 +++++++++++++++++++++++
  4 files changed, 55 insertions(+), 3 deletions(-)

create mode 100644 testcases/kernel/syscalls/stat/stat04.c

runtest/smoketest +1 -1
index 83eebfe7b..5608417f9 100644
@@ -8,7 +8,7 @@ time01 time01
  wait02 wait02
  write01 write01
  symlink01 symlink01
-stat04 symlink01 -T stat04
+stat04 stat04
  utime01A symlink01 -T utime01
  rename01A symlink01 -T rename01
  splice02 splice02 -s 20
runtest/syscalls +2 -2
index 7794f1465..ef90076e4 100644
@@ -1529,8 +1529,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 +0 -0
new file mode 100644
index 000000000..aebfacf5a

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

Quoted 5 lines
testcases/kernel/syscalls/stat/stat04.c new file +5 -0
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *    Author: David Fenner
+ *    Copilot: Jon Hendrickson

very nit:
* Author: David Fenner, Jon Hendrickson

Quoted 15 lines
testcases/kernel/syscalls/stat/stat04.c new file +15 -0
+ * Copyright (C) 2024 Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test checks that stat() executed on file provide the same information
+ * of symlink linking to it.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+static void run(void)
+{
Quoted 8 lines

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

Quoted 7 lines
testcases/kernel/syscalls/stat/stat04.c new file +7 -0
+	char *symname = "my_symlink0";
+	char *tmpdir = tst_get_tmpdir();
+
+	SAFE_SYMLINK(tmpdir, symname);
+
+	struct stat path;
+	struct stat link;

nit: maybe define struct at the top of the function?

This is common in the first versions of C, but a good practice is to define variables as close as possible where they are used in order to improve readability.

Quoted 23 lines

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

Quoted 3 lines
testcases/kernel/syscalls/stat/stat04.c new file +3 -0
+
+	TST_EXP_PASS(stat(tmpdir, &path));
+	free(tmpdir);

If SAFE_SYMLINK() fails, free() will not happen. I wonder if we should bother (we'd have to set it NULL and add a cleanup function).

Kind regards,
Petr

Quoted 12 lines
testcases/kernel/syscalls/stat/stat04.c new file +12 -0
+
+	TST_EXP_PASS(stat(symname, &link));
+
+	TST_EXP_EQ_LI(path.st_dev, link.st_dev);
+	TST_EXP_EQ_LI(path.st_mode, link.st_mode);
+	TST_EXP_EQ_LI(path.st_nlink, link.st_nlink);
+	TST_EXP_EQ_LI(path.st_uid, link.st_uid);
+	TST_EXP_EQ_LI(path.st_gid, link.st_gid);
+	TST_EXP_EQ_LI(path.st_size, link.st_size);
+	TST_EXP_EQ_LI(path.st_atime, link.st_atime);
+	TST_EXP_EQ_LI(path.st_mtime, link.st_mtime);
+	TST_EXP_EQ_LI(path.st_ctime, link.st_ctime);
Quoted 8 lines

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

Quoted 8 lines
testcases/kernel/syscalls/stat/stat04.c new file +8 -0
+
+	SAFE_UNLINK(symname);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_tmpdir = 1,
+};

According to Cyril suggestions we are probably done with this patch so it can be merged. Isn't it?

Thanks,
Andrea

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

Hi Andrea,

Quoted 11 lines
Quoted 8 lines

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

Quoted 7 lines
testcases/kernel/syscalls/stat/stat04.c new file +7 -0
+	char *symname = "my_symlink0";
+	char *tmpdir = tst_get_tmpdir();
+
+	SAFE_SYMLINK(tmpdir, symname);
+
+	struct stat path;
+	struct stat link;

nit: maybe define struct at the top of the function?

This is common in the first versions of C, but a good practice is to define variables as close as possible where they are used in order to improve readability.

Fair enough.

Quoted 10 lines
Quoted 10 lines

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

Quoted 3 lines
testcases/kernel/syscalls/stat/stat04.c new file +3 -0
+
+	TST_EXP_PASS(stat(tmpdir, &path));
+	free(tmpdir);

If SAFE_SYMLINK() fails, free() will not happen. I wonder if we should bother (we'd have to set it NULL and add a cleanup function).

Kind regards,
Petr

...

Quoted 2 lines

According to Cyril suggestions we are probably done with this patch so it can be merged. Isn't it?

Well you free() later in the function. But Cyril's note sounds reasonable for me:
"call it once in the test setup() or use "." instead."

Could you please do it?

Also most of the tests really run tst_get_tmpdir() in the setup() (or cleanup(), there are exceptions (new API: testcases/kernel/syscalls/pathconf/pathconf01.c, old API: testcases/kernel/syscalls/symlink/symlink01.c, testcases/kernel/syscalls/clone/clone02.c), which should be fixed. IMHO tests which call tst_get_tmpdir() in the run()

Kind regards,
Petr

Quoted 2 lines

Thanks,
Andrea

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

Hi,

Quoted 31 lines · Petr Vorel

Hi Andrea,

Quoted 11 lines
Quoted 8 lines

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

Quoted 7 lines
testcases/kernel/syscalls/stat/stat04.c new file +7 -0
+    char *symname = "my_symlink0";
+    char *tmpdir = tst_get_tmpdir();
+
+    SAFE_SYMLINK(tmpdir, symname);
+
+    struct stat path;
+    struct stat link;

nit: maybe define struct at the top of the function?

This is common in the first versions of C, but a good practice is to define variables as close as possible where they are used in order to improve readability.

Fair enough.

Quoted 10 lines
Quoted 10 lines

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

Quoted 3 lines
testcases/kernel/syscalls/stat/stat04.c new file +3 -0
+
+    TST_EXP_PASS(stat(tmpdir, &path));
+    free(tmpdir);

If SAFE_SYMLINK() fails, free() will not happen. I wonder if we should bother (we'd have to set it NULL and add a cleanup function).

Kind regards,
Petr

...

Quoted 9 lines
Quoted 2 lines

According to Cyril suggestions we are probably done with this patch so it can be merged. Isn't it?

Well you free() later in the function. But Cyril's note sounds reasonable for me:
"call it once in the test setup() or use "." instead."

Could you please do it?

Makes sense. I think we should adapt all other tests as well because it’s full of memory leakage when it comes to get temporary directory.

Quoted 6 lines

Also most of the tests really run tst_get_tmpdir() in the setup() (or cleanup(), there are exceptions (new API: testcases/kernel/syscalls/pathconf/pathconf01.c, old API: testcases/kernel/syscalls/symlink/symlink01.c, testcases/kernel/syscalls/clone/clone02.c), which should be fixed. IMHO tests which call tst_get_tmpdir() in the run()

Quoted 6 lines

Kind regards,
Petr

Quoted 2 lines

Thanks,
Andrea

Regards,
Andrea

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