diff libcxxabi/test/test_fallback_malloc.pass.cpp @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children c4bab56944e8
line wrap: on
line diff
--- a/libcxxabi/test/test_fallback_malloc.pass.cpp	Tue Jun 15 19:13:43 2021 +0900
+++ b/libcxxabi/test/test_fallback_malloc.pass.cpp	Tue Jun 15 19:15:29 2021 +0900
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <iostream>
+#include <cstdio>
 #include <deque>
 
 #include <__threading_support>
@@ -20,169 +20,172 @@
 container alloc_series ( size_t sz ) {
     container ptrs;
     void *p;
-    
+
     while ( NULL != ( p = fallback_malloc ( sz )))
         ptrs.push_back ( p );
     return ptrs;
-    }
+}
 
 container alloc_series ( size_t sz, float growth ) {
     container ptrs;
     void *p;
-    
+
     while ( NULL != ( p = fallback_malloc ( sz ))) {
         ptrs.push_back ( p );
         sz *= growth;
-        }
+    }
 
     return ptrs;
-    }
+}
 
 container alloc_series ( const size_t *first, size_t len ) {
     container ptrs;
     const size_t *last = first + len;
     void * p;
-    
+
     for ( const size_t *iter = first; iter != last; ++iter ) {
         if ( NULL == (p = fallback_malloc ( *iter )))
             break;
         ptrs.push_back ( p );
-        }
+    }
 
     return ptrs;
-    }
+}
 
 void *pop ( container &c, bool from_end ) {
     void *ptr;
     if ( from_end ) {
         ptr = c.back ();
         c.pop_back ();
-        }
+    }
     else {
         ptr = c.front ();
         c.pop_front ();
-        }
+    }
     return ptr;
-    }
+}
 
 void exhaustion_test1 () {
     container ptrs;
-    
+
     init_heap ();
-    std::cout << "Constant exhaustion tests" << std::endl;
-    
+    std::printf("Constant exhaustion tests\n");
+
 //  Delete in allocation order
     ptrs = alloc_series ( 32 );
-    std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+    std::printf("Allocated %zu 32 byte chunks\n", ptrs.size());
     print_free_list ();
     for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
+    std::printf("----\n");
 
 //  Delete in reverse order
     ptrs = alloc_series ( 32 );
-    std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+    std::printf("Allocated %zu 32 byte chunks\n", ptrs.size());
     for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
+    std::printf("----\n");
 
 //  Alternate deletions
     ptrs = alloc_series ( 32 );
-    std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
+    std::printf("Allocated %zu 32 byte chunks\n", ptrs.size());
     while ( ptrs.size () > 0 )
         fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
     print_free_list ();
-    }
-            
+}
+
 void exhaustion_test2 () {
     container ptrs;
     init_heap ();
-    
-    std::cout << "Growing exhaustion tests" << std::endl;
+
+    std::printf("Growing exhaustion tests\n");
 
 //  Delete in allocation order
     ptrs = alloc_series ( 32, 1.5 );
-    std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... }  byte chunks" << std::endl;
+
+    std::printf("Allocated %zu { 32, 48, 72, 108, 162 ... } byte chunks\n",
+                ptrs.size());
     print_free_list ();
     for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
-    
+    std::printf("----\n");
+
 //  Delete in reverse order
     print_free_list ();
     ptrs = alloc_series ( 32, 1.5 );
-    std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... }  byte chunks" << std::endl;
+    std::printf("Allocated %zu { 32, 48, 72, 108, 162 ... } byte chunks\n",
+                ptrs.size());
     for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
+    std::printf("----\n");
 
 //  Alternate deletions
     ptrs = alloc_series ( 32, 1.5 );
-    std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... }  byte chunks" << std::endl;
+    std::printf("Allocated %zu { 32, 48, 72, 108, 162 ... } byte chunks\n",
+                ptrs.size());
     while ( ptrs.size () > 0 )
         fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
-    print_free_list (); 
-    
-    }
+    print_free_list ();
+
+}
 
 void exhaustion_test3 () {
     const size_t allocs [] = { 124, 60, 252, 60, 4 };
     container ptrs;
     init_heap ();
-    
-    std::cout << "Complete exhaustion tests" << std::endl;
+
+    std::printf("Complete exhaustion tests\n");
 
 //  Delete in allocation order
     ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
-    std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+    std::printf("Allocated %zu chunks\n", ptrs.size());
     print_free_list ();
     for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
-    
+    std::printf("----\n");
+
 //  Delete in reverse order
     print_free_list ();
     ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
-    std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+    std::printf("Allocated %zu chunks\n", ptrs.size());
     for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
         fallback_free ( *iter );
     print_free_list ();
-    std::cout << "----" << std::endl;
+    std::printf("----\n");
 
 //  Alternate deletions
     ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
-    std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
+    std::printf("Allocated %zu chunks\n", ptrs.size());
     while ( ptrs.size () > 0 )
         fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
-    print_free_list (); 
-    
-    }
+    print_free_list ();
 
-    
+}
+
+
 int main () {
     print_free_list ();
 
     char *p = (char *) fallback_malloc ( 1024 );    // too big!
-    std::cout << "fallback_malloc ( 1024 ) --> " << (unsigned long ) p << std::endl;
+    std::printf("fallback_malloc ( 1024 ) --> %lu\n", (unsigned long ) p);
     print_free_list ();
-    
+
     p = (char *) fallback_malloc ( 32 );
-    std::cout << "fallback_malloc ( 32 ) --> " << (unsigned long) (p - heap) << std::endl;
+    std::printf("fallback_malloc ( 32 ) --> %lu\n", (unsigned long) (p - heap));
     if ( !is_fallback_ptr ( p ))
-        std::cout << "### p is not a fallback pointer!!" << std::endl;
-    
+        std::printf("### p is not a fallback pointer!!\n");
+
     print_free_list ();
     fallback_free ( p );
     print_free_list ();
-    
-    std::cout << std::endl;
-    exhaustion_test1 (); std::cout << std::endl;
-    exhaustion_test2 (); std::cout << std::endl;
-    exhaustion_test3 (); std::cout << std::endl;
+
+    exhaustion_test1();
+    exhaustion_test2();
+    exhaustion_test3();
     return 0;
-    }
+}