Skip to contentSkip to conversation

syscalls/shmat01: Fix test on 32bit

PATCH New Cyril Hrubis 2 participants 3 messages Sep 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 syscalls/shmat01: Fix test on 32bit

The problem there is that the address casted to intptr_t yields negative number which when divided then multiplied by SHMLBA aligns the value up instead of down.

The fix is simple, we cast the pointer to uintptr_t instead of intptr_t and also include stdint.h explicitly.

---
 testcases/kernel/syscalls/ipc/shmat/shmat01.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmat/shmat01.c +2 -1
index 4f5c4e725..4c6ce58d3 100644
@@ -35,12 +35,13 @@
 #include <sys/shm.h>
 #include <sys/wait.h>
 #include <stdlib.h>
+#include <stdint.h>
 
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
 
-#define ALIGN_DOWN(in_addr) ((void *)(((intptr_t)in_addr / SHMLBA) * SHMLBA))
+#define ALIGN_DOWN(in_addr) ((void *)(((uintptr_t)in_addr / SHMLBA) * SHMLBA))
 
 static int shm_id = -1;
 static key_t shm_key;
Signature · 1 line
2.13.0
#1 lore raw

PATCH 2/2 syscalls/shmat: Print expected and actual address on failure

---
 testcases/kernel/syscalls/ipc/shmat/shmat01.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmat/shmat01.c +3 -1
index 4c6ce58d3..b46ba6831 100644
@@ -129,7 +129,9 @@ static void verify_shmat(unsigned int n)
 	}
 
 	if (expected_addr(*tc->shmaddr, addr) != addr) {
-		tst_res(TFAIL, "shared memory address was not correct");
+		tst_res(TFAIL,
+			"shared memory address %p is not correct, expected %p",
+			addr, expected_addr(*tc->shmaddr, addr));
 		goto end;
 	}
 
Signature · 1 line
2.13.0
#2 lore raw

PATCH 1/2 syscalls/shmat01: Fix test on 32bit

In reply to Cyril Hrubis

----- Original Message -----

Quoted 8 lines

The problem there is that the address casted to intptr_t yields negative number which when divided then multiplied by SHMLBA aligns the value up instead of down.

The fix is simple, we cast the pointer to uintptr_t instead of intptr_t and also include stdint.h explicitly.

You have beat me by ~3 minutes. I was just going to push, did final 'git pull --rebase' and my commit disappeared :-).

Regards,
Jan