[rtems commit] libtests/termios01: Use greedy allocation API

Sebastian Huber sebh at rtems.org
Tue Jul 17 09:17:46 UTC 2012


Module:    rtems
Branch:    master
Commit:    c8615dcf262da168b44c478a76d0b831cdf4286a
Changeset: http://git.rtems.org/rtems/commit/?id=c8615dcf262da168b44c478a76d0b831cdf4286a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jul 17 10:45:17 2012 +0200

libtests/termios01: Use greedy allocation API

---

 testsuites/libtests/termios01/init.c               |    2 +-
 testsuites/libtests/termios01/termios_testdriver.c |   56 +++++++------------
 2 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/testsuites/libtests/termios01/init.c b/testsuites/libtests/termios01/init.c
index 0b5d01a..9649ffa 100644
--- a/testsuites/libtests/termios01/init.c
+++ b/testsuites/libtests/termios01/init.c
@@ -473,7 +473,7 @@ static rtems_task Init(
   test_termios_baud2number();
   test_termios_number_to_baud();
 
-  sc = rtems_termios_bufsize( 256, 138, 64 );
+  sc = rtems_termios_bufsize( 256, 128, 64 );
   directive_failed( sc, "rtems_termios_bufsize" );
 
   /*
diff --git a/testsuites/libtests/termios01/termios_testdriver.c b/testsuites/libtests/termios01/termios_testdriver.c
index 70e0d49..c53b5b4 100644
--- a/testsuites/libtests/termios01/termios_testdriver.c
+++ b/testsuites/libtests/termios01/termios_testdriver.c
@@ -23,6 +23,7 @@
 #include <termios.h>
 #include <rtems/termiostypes.h>
 #include <rtems/libcsupport.h>
+#include <rtems/malloc.h>
 #include "termios_testdriver.h"
 
 /* forward declarations to avoid warnings */
@@ -162,9 +163,7 @@ rtems_device_driver termios_test_driver_open(
   rtems_status_code sc;
   int               rc;
   rtems_libio_open_close_args_t *args = arg;
-  void *alloc_ptr = (void *)0;
-  static int test = 0;
-  size_t freeMemory;
+  static bool firstCall = true;
   
   static const rtems_termios_callbacks Callbacks = {
     NULL,                                    /* firstOpen */
@@ -182,39 +181,26 @@ rtems_device_driver termios_test_driver_open(
     rtems_test_exit(0);
   }
 
-  freeMemory = malloc_free_space();
-  if( test == 0 ) {
-    alloc_ptr = malloc( freeMemory - 4 );
-    
-    sc = rtems_termios_open (major, minor, arg, &Callbacks);
-    rtems_test_assert( sc == RTEMS_NO_MEMORY );
-    
-    free( alloc_ptr );
-    alloc_ptr = malloc( freeMemory - 4 - 10 -
-			sizeof( struct rtems_termios_tty ) );
-    
-    sc = rtems_termios_open (major, minor, arg, &Callbacks);
-    rtems_test_assert( sc == RTEMS_NO_MEMORY );
-    
-    free( alloc_ptr );
-    alloc_ptr = malloc( freeMemory - 4 - 20 -
-			sizeof( struct rtems_termios_tty ) -
-			128 );
-    
-    sc = rtems_termios_open (major, minor, arg, &Callbacks);
-    rtems_test_assert( sc == RTEMS_NO_MEMORY );
-    
-    free( alloc_ptr );
-    alloc_ptr = malloc( freeMemory - 4 - 20 -
-			sizeof( struct rtems_termios_tty ) -
-			128 -
-			80 );
-    
-    sc = rtems_termios_open (major, minor, arg, &Callbacks);
-    rtems_test_assert( sc == RTEMS_NO_MEMORY );
+  if( firstCall ) {
+    static const uintptr_t allocSizes [] = {
+      sizeof( struct rtems_termios_tty ),
+      128,
+      64,
+      256
+    };
+
+    size_t i;
+
+    firstCall = false;
     
-    free( alloc_ptr );
-    test = 1;
+    for (i = 0; i < sizeof( allocSizes ) / sizeof( allocSizes [0] ); ++i) {
+      void *opaque = rtems_heap_greedy_allocate( allocSizes, i );
+
+      sc = rtems_termios_open( major, minor, arg, &Callbacks );
+      rtems_test_assert( sc == RTEMS_NO_MEMORY );
+
+      rtems_heap_greedy_free( opaque );
+    }
   }
   
   sc = rtems_termios_open (major, minor, arg, &Callbacks);




More information about the vc mailing list