[compiler-rt] 1bbed69 - [sanitizer] Another attempt to fix protoent test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 17:31:39 PDT 2020


Author: Vitaly Buka
Date: 2020-07-17T17:31:15-07:00
New Revision: 1bbed69059d5ac35c0775e8ed598a34628d8ba6d

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

LOG: [sanitizer] Another attempt to fix protoent test

Now we are going to pick name and index based on output of getprotoent_r.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
index a10fd114022c..003790067d1b 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
@@ -7,6 +7,10 @@
 #include <errno.h>
 #include <netdb.h>
 #include <stdio.h>
+#include <string>
+
+std::string any_name;
+int total_count;
 
 void print_protoent(protoent *curr_entry) {
   fprintf(stderr, "%s (%d)\n", curr_entry->p_name, curr_entry->p_proto);
@@ -23,6 +27,8 @@ void print_all_protoent() {
   protoent *curr_entry;
 
   while (getprotoent_r(&entry, buf, sizeof(buf), &curr_entry) != ENOENT && curr_entry) {
+    ++total_count;
+    any_name = curr_entry->p_name;
     print_protoent(curr_entry);
   }
 }
@@ -51,10 +57,13 @@ int main() {
   fprintf(stderr, "All protoent\n");
   print_all_protoent();
 
+  if (!total_count)
+    return 0;
+
   fprintf(stderr, "Protoent by name\n");
-  print_protoent_by_name("ipv6");
+  print_protoent_by_name(any_name.c_str());
 
   fprintf(stderr, "Protoent by num\n");
-  print_protoent_by_num(17);
+  print_protoent_by_num(total_count / 2);
   return 0;
 }


        


More information about the llvm-commits mailing list