Skip to contentSkip to conversation

syscalls/mmap08: Use macro TST_EXP_FAIL_PTR_VOID()

PATCH Superseded Avinesh Kumar 2 participants 4 messages Apr 29, 2024 – May 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/mmap08: Use macro TST_EXP_FAIL_PTR_VOID()

---
 testcases/kernel/syscalls/mmap/mmap08.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
testcases/kernel/syscalls/mmap/mmap08.c +1 -10
index 5c9fd782c..befd73e14 100644
@@ -27,16 +27,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));
-
-	if (TST_RET_PTR != MAP_FAILED) {
-		tst_res(TFAIL, "mmap() passed unexpectedly");
-		SAFE_MUNMAP(TST_RET_PTR, page_sz);
-	} else if (TST_ERR == EBADF) {
-		tst_res(TPASS, "mmap() failed with EBADF");
-	} else {
-		tst_res(TFAIL | TERRNO, "mmap() failed with an invalid errno");
-	}
+	TST_EXP_FAIL_PTR_VOID(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0), EBADF);
 }
 
 static void cleanup(void)
Signature · 5 lines
2.44.0


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

Hi Avinesh,

Quoted 14 lines
---
 testcases/kernel/syscalls/mmap/mmap08.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
testcases/kernel/syscalls/mmap/mmap08.c +0 -1
index 5c9fd782c..befd73e14 100644
@@ -27,16 +27,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));

testcases/kernel/syscalls/mmap/mmap08.c static void setup(void) · line 30

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap08.c +1 -9
-
-	if (TST_RET_PTR != MAP_FAILED) {
-		tst_res(TFAIL, "mmap() passed unexpectedly");
-		SAFE_MUNMAP(TST_RET_PTR, page_sz);
-	} else if (TST_ERR == EBADF) {
-		tst_res(TPASS, "mmap() failed with EBADF");
-	} else {
-		tst_res(TFAIL | TERRNO, "mmap() failed with an invalid errno");
-	}
+	TST_EXP_FAIL_PTR_VOID(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0), EBADF);

Don't we need to add:

	if (TST_RET_PTR != MAP_FAILED) {
		SAFE_MUNMAP(TST_RET_PTR, page_sz);

Also, while at it, could you please change docs: "verify that" => "Verify that" ?

Kind regards,
Petr

Quoted 3 lines
testcases/kernel/syscalls/mmap/mmap08.c +0 -0
 }
 
 static void cleanup(void)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 syscalls/mmap08: Use macro TST_EXP_FAIL_PTR_VOID()

---
 testcases/kernel/syscalls/mmap/mmap08.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/mmap/mmap08.c +3 -8
index 5c9fd782c..f023446f5 100644
@@ -8,7 +8,7 @@
 /*\
  * [Description]
  *
- * verify that, mmap() calls fails with errno EBADF when a file mapping
+ * Verify that, mmap() calls fails with errno EBADF when a file mapping
  * is requested but the fd is not a valid file descriptor.
  */
 
@@ -27,15 +27,10 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));
+	TST_EXP_FAIL_PTR_VOID(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0), EBADF);
 
-	if (TST_RET_PTR != MAP_FAILED) {
-		tst_res(TFAIL, "mmap() passed unexpectedly");
+	if(TST_RET_PTR != MAP_FAILED) {
 		SAFE_MUNMAP(TST_RET_PTR, page_sz);
-	} else if (TST_ERR == EBADF) {
-		tst_res(TPASS, "mmap() failed with EBADF");
-	} else {
-		tst_res(TFAIL | TERRNO, "mmap() failed with an invalid errno");
 	}
 }
 
Signature · 5 lines
2.44.0


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

Hi Avinesh,

...

testcases/kernel/syscalls/mmap/mmap08.c static void setup(void) · line 32

Quoted 8 lines

static void run(void)
{

testcases/kernel/syscalls/mmap/mmap08.c +2 -3
-	TESTPTR(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));
+	TST_EXP_FAIL_PTR_VOID(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0), EBADF);
 
-	if (TST_RET_PTR != MAP_FAILED) {
-		tst_res(TFAIL, "mmap() passed unexpectedly");
+	if(TST_RET_PTR != MAP_FAILED) {

Whitespace was broken (missing space after "if") + brackets were not needed any more. I fixed it and merged together with mmap06 patch.

Thank you!

Kind regards,
Petr

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