Skip to contentSkip to conversation

fstat02.c: simplify using TST_EXP_*() macros

PATCH Superseded Avinesh Kumar 2 participants 4 messages Jul 8, 2022 – Aug 8, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fstat02.c: simplify using TST_EXP_*() macros

Simplifying the tests using TST_EXP_*() macros and removing the unnecessary header includes

---
 testcases/kernel/syscalls/fstat/fstat02.c | 59 ++++-------------------
 1 file changed, 9 insertions(+), 50 deletions(-)
testcases/kernel/syscalls/fstat/fstat02.c +9 -50
index 2f9632edf..2142ae3e6 100644
@@ -4,17 +4,14 @@
  *  07/2001 Ported by Wayne Boyer
  *  05/2019 Ported to new library: Christian Amann <[email protected]>
  */
-/*
+
+/*\ [Description]
+ *
  * Tests if fstat() returns correctly and reports correct file information
  * using the stat structure.
  */
 
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include "tst_test.h"
-#include "tst_safe_macros.h"
 
 #define TESTFILE        "test_file"
 #define LINK_TESTFILE   "link_test_file"
@@ -29,50 +26,12 @@ static int fildes;
 
 static void run(void)
 {
-	int fail = 0;
-
-	TEST(fstat(fildes, &stat_buf));
-
-	if (TST_RET != 0) {
-		tst_res(TFAIL | TTERRNO, "fstat() failed");
-		return;
-	}
-
-	fail = 0;
-	if (stat_buf.st_uid != user_id) {
-		tst_res(TFAIL, "stat_buf.st_uid = %i expected %i",
-			stat_buf.st_uid, user_id);
-		fail++;
-	}
-
-	if (stat_buf.st_gid != group_id) {
-		tst_res(TFAIL, "stat_buf.st_gid = %i expected %i",
-			stat_buf.st_gid, group_id);
-		fail++;
-	}
-
-	if (stat_buf.st_size != FILE_SIZE) {
-		tst_res(TFAIL, "stat_buf.st_size = %li expected %i",
-			(long)stat_buf.st_size, FILE_SIZE);
-		fail++;
-	}
-
-	if ((stat_buf.st_mode & 0777) != FILE_MODE) {
-		tst_res(TFAIL, "stat_buf.st_mode = %o expected %o",
-			(stat_buf.st_mode & 0777), FILE_MODE);
-		fail++;
-	}
-
-	if (stat_buf.st_nlink != NLINK) {
-		tst_res(TFAIL, "stat_buf.st_nlink = %li expected %i",
-			(long)stat_buf.st_nlink, NLINK);
-		fail++;
-	}
-
-	if (fail)
-		return;
-
-	tst_res(TPASS, "fstat() reported correct values.");
+	TST_EXP_PASS(fstat(fildes, &stat_buf));
+	TST_EXP_EQ_LI(stat_buf.st_uid, user_id);
+	TST_EXP_EQ_LI(stat_buf.st_gid, group_id);
+	TST_EXP_EQ_LI(stat_buf.st_size, FILE_SIZE);
+	TST_EXP_EQ_LI(stat_buf.st_mode & 0777, FILE_MODE);
+	TST_EXP_EQ_LI(stat_buf.st_nlink, NLINK);
 }
 
 static void setup(void)
Signature · 5 lines
2.36.1


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

Hi Avinesh,

LGTM, thanks!
Minor comments below.

...

Quoted 1 line

+++ b/testcases/kernel/syscalls/fstat/fstat02.c

...

testcases/kernel/syscalls/fstat/fstat02.c line 17

Quoted 6 lines
testcases/kernel/syscalls/fstat/fstat02.c +0 -5
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include "tst_test.h"
-#include "tst_safe_macros.h"

nit: obviously works without all these headers, but <sys/stat.h> is needed (fstat) but included by tst_test.h

testcases/kernel/syscalls/fstat/fstat02.c line 9

Quoted 3 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -0
+
+/*\ [Description]
+ *

This is wrong, causes docparse not being formatted. It must be:
/*\
* [Description]

(can be fixed before merge)

Quoted 3 lines

* Tests if fstat() returns correctly and reports correct file information
* using the stat structure.
*/

...

testcases/kernel/syscalls/fstat/fstat02.c static int fildes; · line 31

Quoted 4 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -1
-	tst_res(TPASS, "fstat() reported correct values.");
+	TST_EXP_PASS(fstat(fildes, &stat_buf));
+	TST_EXP_EQ_LI(stat_buf.st_uid, user_id);
+	TST_EXP_EQ_LI(stat_buf.st_gid, group_id);

nit: At least st_uid and st_gid are unsigned, thus maybe TST_EXP_EQ_LU?

testcases/kernel/syscalls/fstat/fstat02.c static int fildes; · line 35

Quoted 4 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -0
+	TST_EXP_EQ_LI(stat_buf.st_size, FILE_SIZE);
+	TST_EXP_EQ_LI(stat_buf.st_mode & 0777, FILE_MODE);
+	TST_EXP_EQ_LI(stat_buf.st_nlink, NLINK);
 }

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 5 lines · IST Petr Vorel

Hi Avinesh,

LGTM, thanks!
Minor comments below.

Hi Petr, Thank you! I agree with your comments here. Do I need to send v2 or you will merge with these changes?

Quoted 34 lines

...

Quoted 1 line

+++ b/testcases/kernel/syscalls/fstat/fstat02.c

...

testcases/kernel/syscalls/fstat/fstat02.c line 17

Quoted 6 lines
testcases/kernel/syscalls/fstat/fstat02.c +0 -5
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include "tst_test.h"
-#include "tst_safe_macros.h"

nit: obviously works without all these headers, but <sys/stat.h> is needed (fstat) but included by tst_test.h

testcases/kernel/syscalls/fstat/fstat02.c line 9

Quoted 3 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -0
+
+/*\ [Description]
+ *

This is wrong, causes docparse not being formatted. It must be:
/*\
* [Description]

(can be fixed before merge)

Quoted 3 lines

* Tests if fstat() returns correctly and reports correct file information
* using the stat structure.
*/

...

testcases/kernel/syscalls/fstat/fstat02.c static int fildes; · line 31

Quoted 4 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -1
-	tst_res(TPASS, "fstat() reported correct values.");
+	TST_EXP_PASS(fstat(fildes, &stat_buf));
+	TST_EXP_EQ_LI(stat_buf.st_uid, user_id);
+	TST_EXP_EQ_LI(stat_buf.st_gid, group_id);

nit: At least st_uid and st_gid are unsigned, thus maybe TST_EXP_EQ_LU?

Quoted 8 lines

testcases/kernel/syscalls/fstat/fstat02.c static int fildes; · line 35

Quoted 4 lines
testcases/kernel/syscalls/fstat/fstat02.c +3 -0
+	TST_EXP_EQ_LI(stat_buf.st_size, FILE_SIZE);
+	TST_EXP_EQ_LI(stat_buf.st_mode & 0777, FILE_MODE);
+	TST_EXP_EQ_LI(stat_buf.st_nlink, NLINK);
 }

Kind regards,
Petr

--
Avinesh

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 8 lines · IST Petr Vorel
Quoted 5 lines

Hi Avinesh,

LGTM, thanks!
Minor comments below.

Hi Petr, Thank you! I agree with your comments here. Do I need to send v2 or you will merge with these changes?

I'm sorry, I overlooked your question (vacation).
Going to merge v2.

Kind regards,
Petr

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