[compiler-rt] d1b7d57 - [sanitizer] Deduplicate dn_expand test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 14:47:47 PDT 2022


Author: Vitaly Buka
Date: 2022-07-07T14:47:35-07:00
New Revision: d1b7d57cab2a665e4abde956f958d524c2b9ecae

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

LOG: [sanitizer] Deduplicate dn_expand test

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D129246

Added: 
    

Modified: 
    compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp

Removed: 
    compiler-rt/test/msan/Linux/dn_expand.cpp


################################################################################
diff  --git a/compiler-rt/test/msan/Linux/dn_expand.cpp b/compiler-rt/test/msan/Linux/dn_expand.cpp
deleted file mode 100644
index 114b811865301..0000000000000
--- a/compiler-rt/test/msan/Linux/dn_expand.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-// RUN: %clangxx_msan -O0 %s -o %t && %run %t
-
-#include <assert.h>
-#include <resolv.h>
-#include <string.h>
-
-#include <sanitizer/msan_interface.h>
-
-void testWrite() {
-  char unsigned input[] = {0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00,
-                           0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
-                           0x10, 0x01, 0x05, 0x00, 0x01, 0x0a, 0x67, 0x6f, 0x6f,
-                           0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00};
-  char output[1024];
-
-  int res = dn_expand(input, input + sizeof(input), input + 23, output,
-                      sizeof(output));
-
-  assert(res >= 0);
-  assert(strlen(output) == 11);
-  __msan_check_mem_is_initialized(output, strlen(output) + 1);
-}
-
-void testWriteZeroLength() {
-  char unsigned input[] = {
-      0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x01,
-      0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x10, 0x01, 0x05, 0x00, 0x01, 0x00,
-  };
-  char output[1024];
-
-  int res = dn_expand(input, input + sizeof(input), input + 23, output,
-                      sizeof(output));
-
-  assert(res >= 0);
-  assert(strlen(output) == 0);
-  __msan_check_mem_is_initialized(output, strlen(output) + 1);
-}
-
-void testComp() {
-  char unsigned msg[1024];
-  char unsigned *mb = msg;
-  char unsigned *me = msg + sizeof(msg);
-  char unsigned **pb = (char unsigned **)mb;
-  pb[0] = msg;
-  pb[1] = nullptr;
-  mb += 64;
-  char unsigned **pe = (char unsigned **)mb;
-
-  char unsigned *n1 = mb;
-  int res = dn_comp("llvm.org", mb, me - mb, pb, pe);
-  assert(res == 10);
-  mb += res;
-
-  char unsigned *n2 = mb;
-  res = dn_comp("lab.llvm.org", mb, me - mb, pb, pe);
-  assert(res == 6);
-  mb += res;
-
-  {
-    char output[1024];
-    res = dn_expand(msg, msg + sizeof(msg), n1, output, sizeof(output));
-
-    fprintf(stderr, "%d\n", res);
-    assert(res == 10);
-    assert(strlen(output) == 8);
-    __msan_check_mem_is_initialized(output, strlen(output) + 1);
-  }
-
-  {
-    char output[1024];
-    res = dn_expand(msg, msg + sizeof(msg), n2, output, sizeof(output));
-
-    assert(res == 6);
-    assert(strlen(output) == 12);
-    __msan_check_mem_is_initialized(output, strlen(output) + 1);
-  }
-}
-
-int main(int iArgc, const char *szArgv[]) {
-  testWrite();
-  testWriteZeroLength();
-  testComp();
-
-  return 0;
-}

diff  --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
index b0120d755b01c..2b22f80bdab4d 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
@@ -4,7 +4,7 @@
 #include <resolv.h>
 #include <string.h>
 
-#include <sanitizer/msan_interface.h>
+#include "sanitizer_common/sanitizer_specific.h"
 
 void testWrite() {
   char unsigned input[] = {0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00,
@@ -18,6 +18,7 @@ void testWrite() {
 
   assert(res == 12);
   assert(strcmp(output, "google\\.com") == 0);
+  check_mem_is_good(output, strlen(output) + 1);
 }
 
 void testWriteZeroLength() {
@@ -32,6 +33,7 @@ void testWriteZeroLength() {
 
   assert(res == 1);
   assert(strcmp(output, "") == 0);
+  check_mem_is_good(output, strlen(output) + 1);
 }
 
 void testComp() {
@@ -61,6 +63,7 @@ void testComp() {
     fprintf(stderr, "%d\n", res);
     assert(res == 10);
     assert(strcmp(output, "llvm.org") == 0);
+    check_mem_is_good(output, strlen(output) + 1);
   }
 
   {
@@ -69,6 +72,7 @@ void testComp() {
 
     assert(res == 6);
     assert(strcmp(output, "lab.llvm.org") == 0);
+    check_mem_is_good(output, strlen(output) + 1);
   }
 }
 


        


More information about the llvm-commits mailing list