[compiler-rt] aeb13a4 - [test][hwasan] Use perror and abort in test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 14 15:22:27 PDT 2023


Author: Vitaly Buka
Date: 2023-06-14T15:22:12-07:00
New Revision: aeb13a44595d0ff4befd319a7c9a4ea59b9fad3e

URL: https://github.com/llvm/llvm-project/commit/aeb13a44595d0ff4befd319a7c9a4ea59b9fad3e
DIFF: https://github.com/llvm/llvm-project/commit/aeb13a44595d0ff4befd319a7c9a4ea59b9fad3e.diff

LOG: [test][hwasan] Use perror and abort in test

Added: 
    

Modified: 
    compiler-rt/test/hwasan/TestCases/munmap.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/hwasan/TestCases/munmap.c b/compiler-rt/test/hwasan/TestCases/munmap.c
index 4b18e8f456bde..6f8f97b675566 100644
--- a/compiler-rt/test/hwasan/TestCases/munmap.c
+++ b/compiler-rt/test/hwasan/TestCases/munmap.c
@@ -16,14 +16,14 @@ int main(int argc, char **argv) {
   void *r =
       mmap(0, kSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (r == MAP_FAILED) {
-    fprintf(stderr, "Failed to mmap.\n");
+    perror("Failed to mmap: ");
     abort();
   }
 
   // Check that the pointer is untagged.
   if (r != __hwasan_tag_pointer(r, 0)) {
     fprintf(stderr, "Pointer returned by mmap should be untagged.\n");
-    return 1;
+    abort();
   }
 
   // Manually tag the pointer and the memory.
@@ -33,14 +33,18 @@ int main(int argc, char **argv) {
   // Check that the pointer and the tag match.
   if (__hwasan_test_shadow(p1, kSize) != -1) {
     fprintf(stderr, "Failed to tag.\n");
-    return 1;
+    abort();
   }
 
   // First munmmap and then mmap the same pointer using MAP_FIXED.
-  munmap(r, kSize);
+  if (munmap((char *)r, kSize) != 0) {
+    perror("Failed to unmap: ");
+    abort();
+  }
+
   if (__hwasan_test_shadow(r, kSize) != -1) {
     fprintf(stderr, "Shadow memory was not cleaned by munmap.\n");
-    return 1;
+    abort();
   }
   __hwasan_tag_memory(r, kTag, kSize);
   int *p2 = (int *)mmap(r, kSize, PROT_READ | PROT_WRITE,
@@ -49,13 +53,13 @@ int main(int argc, char **argv) {
   // Check that the pointer has no tag in it.
   if (p2 != r) {
     fprintf(stderr, "The mmap pointer has a non-zero tag in it.\n");
-    return 1;
+    abort();
   }
 
   // Make sure we can access the shadow with an untagged pointer.
   if (__hwasan_test_shadow(p2, kSize) != -1) {
     fprintf(stderr, "Shadow memory was not cleaned by mmap.\n");
-    return 1;
+    abort();
   }
   return 0;
 }


        


More information about the llvm-commits mailing list