Skip to contentSkip to conversation

unlink07: use TST_EXP_FAIL() and turn comment into docparse, reword

PATCH In review Avinesh Kumar 2 participants 3 messages Jul 15, 2022 – Sep 2, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unlink07: use TST_EXP_FAIL() and turn comment into docparse, reword

---
 testcases/kernel/syscalls/unlink/unlink07.c | 38 ++++++++-------------
 1 file changed, 14 insertions(+), 24 deletions(-)
testcases/kernel/syscalls/unlink/unlink07.c +14 -24
index 869bd5f51..8848c1283 100644
@@ -3,15 +3,17 @@
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  */
 
-/*
- * Description:
- * The testcase checks the various errnos of the unlink(2).
- * 1) unlink() returns ENOENT if file doesn't exist.
- * 2) unlink() returns ENOENT if path is empty.
- * 3) unlink() returns ENOENT if path contains a non-existent file.
- * 4) unlink() returns EFAULT if address is invalid.
- * 5) unlink() returns ENOTDIR if path contains a regular file.
- * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+/*\
+ * [Description]
+ *
+ * Verify that unlink() fails with
+ * - ENOENT when file does not exist.
+ * - ENOENT when pathname is empty.
+ * - ENOENT when a component in pathname does not exist.
+ * - EFAULT when pathname points outside the accessible address space.
+ * - ENOTDIR when a component used as a directory in pathname is not,
+ * in fact, a directory.
+ * - ENAMETOOLONG when pathname is too long.
  */
 
 #include <errno.h>
@@ -39,21 +41,9 @@ static void verify_unlink(unsigned int n)
 {
 	struct test_case_t *tc = &tcases[n];
 
-	TEST(unlink(tc->name));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
-			tc->desc);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {
-		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
-			tc->desc);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"unlink(<%s>) failed, expected errno: %s",
-			tc->desc, tst_strerrno(tc->exp_errno));
-	}
+	TST_EXP_FAIL(unlink(tc->name),
+				tc->exp_errno,
+				"%s", tc->desc);
 }
 
 static void setup(void)
Signature · 5 lines
2.36.1


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

Hi Avinesh,

testcases/kernel/syscalls/unlink/unlink07.c line 3

Quoted 3 lines

+++ b/testcases/kernel/syscalls/unlink/unlink07.c

testcases/kernel/syscalls/unlink/unlink07.c +0 -0
@@ -3,15 +3,17 @@
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.

Maybe adding copyright?

testcases/kernel/syscalls/unlink/unlink07.c line 16

Quoted 13 lines
testcases/kernel/syscalls/unlink/unlink07.c +11 -0
  */
 
+/*\
+ * [Description]
+ *
+ * Verify that unlink() fails with
+ * - ENOENT when file does not exist.
+ * - ENOENT when pathname is empty.
+ * - ENOENT when a component in pathname does not exist.
+ * - EFAULT when pathname points outside the accessible address space.
+ * - ENOTDIR when a component used as a directory in pathname is not,
+ * in fact, a directory.
+ * - ENAMETOOLONG when pathname is too long.

I'd remove dot in the end.
I don't like 'when', but I don't know anything better.

Quoted 15 lines
testcases/kernel/syscalls/unlink/unlink07.c +0 -8
  */
 
 #include <errno.h>
@@ -39,21 +41,9 @@ static void verify_unlink(unsigned int n)
 {
 	struct test_case_t *tc = &tcases[n];
 
-	TEST(unlink(tc->name));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
-			tc->desc);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {

testcases/kernel/syscalls/unlink/unlink07.c static void verify_unlink(unsigned int n) · line 46

Quoted 10 lines
testcases/kernel/syscalls/unlink/unlink07.c +3 -7
-		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
-			tc->desc);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"unlink(<%s>) failed, expected errno: %s",
-			tc->desc, tst_strerrno(tc->exp_errno));
-	}
+	TST_EXP_FAIL(unlink(tc->name),
+				tc->exp_errno,
+				"%s", tc->desc);

This should be on single line.

testcases/kernel/syscalls/unlink/unlink07.c static void verify_unlink(unsigned int n) · line 49

Quoted 3 lines
testcases/kernel/syscalls/unlink/unlink07.c +0 -0
 }
 
 static void setup(void)

Other proposed changes:

* PATH_MAX is in limits.h + we usually don't put comments why it's included:
-#include <sys/param.h> /* for PATH_MAX */
+#include <limits.h>

* use size_t in setup
static void setup(void)
{
- unsigned int n;
+ size_t n;

BTW it'd build just with #include "tst_test.h", because all 4 headers are included by headers which tst_test.h includes.

I guess most of that it applies to your patch unlink08.c as well, could you please send v2?

Kind regards,
Petr

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

Hi Petr,

Quoted 63 lines · IST Petr Vorel

Hi Avinesh,

testcases/kernel/syscalls/unlink/unlink07.c line 3

Quoted 3 lines

+++ b/testcases/kernel/syscalls/unlink/unlink07.c

testcases/kernel/syscalls/unlink/unlink07.c +0 -0
@@ -3,15 +3,17 @@
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.

Maybe adding copyright?

testcases/kernel/syscalls/unlink/unlink07.c line 16

Quoted 13 lines
testcases/kernel/syscalls/unlink/unlink07.c +11 -0
  */
 
+/*\
+ * [Description]
+ *
+ * Verify that unlink() fails with
+ * - ENOENT when file does not exist.
+ * - ENOENT when pathname is empty.
+ * - ENOENT when a component in pathname does not exist.
+ * - EFAULT when pathname points outside the accessible address space.
+ * - ENOTDIR when a component used as a directory in pathname is not,
+ * in fact, a directory.
+ * - ENAMETOOLONG when pathname is too long.

I'd remove dot in the end.
I don't like 'when', but I don't know anything better.

Quoted 15 lines
testcases/kernel/syscalls/unlink/unlink07.c +0 -8
  */
 
 #include <errno.h>
@@ -39,21 +41,9 @@ static void verify_unlink(unsigned int n)
 {
 	struct test_case_t *tc = &tcases[n];
 
-	TEST(unlink(tc->name));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
-			tc->desc);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {

testcases/kernel/syscalls/unlink/unlink07.c static void verify_unlink(unsigned int n) · line 46

Quoted 10 lines
testcases/kernel/syscalls/unlink/unlink07.c +3 -7
-		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
-			tc->desc);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"unlink(<%s>) failed, expected errno: %s",
-			tc->desc, tst_strerrno(tc->exp_errno));
-	}
+	TST_EXP_FAIL(unlink(tc->name),
+				tc->exp_errno,
+				"%s", tc->desc);

This should be on single line.

testcases/kernel/syscalls/unlink/unlink07.c static void verify_unlink(unsigned int n) · line 49

Quoted 3 lines
testcases/kernel/syscalls/unlink/unlink07.c +0 -0
 }
 
 static void setup(void)

Other proposed changes:

* PATH_MAX is in limits.h + we usually don't put comments why it's included:

(quoted diff) +1 -1
-#include <sys/param.h>	/* for PATH_MAX */
+#include <limits.h>

* use size_t in setup
static void setup(void)
{

(quoted diff) +1 -1
-	unsigned int n;
+	size_t n;
Quoted 5 lines

BTW it'd build just with #include "tst_test.h", because all 4 headers are included by headers which tst_test.h includes.

I guess most of that it applies to your patch unlink08.c as well, could you please send v2?

Thank you for the review, I have incorporated your suggestions and sent v2.

Quoted 4 lines

Kind regards,
Petr

Regards,
Avinesh

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