libtests/termios01: Use greedy allocation API

This commit is contained in:
Sebastian Huber
2012-07-17 10:45:17 +02:00
parent 317ee8d7ff
commit c8615dcf26
2 changed files with 22 additions and 36 deletions

View File

@@ -473,7 +473,7 @@ static rtems_task Init(
test_termios_baud2number(); test_termios_baud2number();
test_termios_number_to_baud(); 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" ); directive_failed( sc, "rtems_termios_bufsize" );
/* /*

View File

@@ -23,6 +23,7 @@
#include <termios.h> #include <termios.h>
#include <rtems/termiostypes.h> #include <rtems/termiostypes.h>
#include <rtems/libcsupport.h> #include <rtems/libcsupport.h>
#include <rtems/malloc.h>
#include "termios_testdriver.h" #include "termios_testdriver.h"
/* forward declarations to avoid warnings */ /* forward declarations to avoid warnings */
@@ -162,9 +163,7 @@ rtems_device_driver termios_test_driver_open(
rtems_status_code sc; rtems_status_code sc;
int rc; int rc;
rtems_libio_open_close_args_t *args = arg; rtems_libio_open_close_args_t *args = arg;
void *alloc_ptr = (void *)0; static bool firstCall = true;
static int test = 0;
size_t freeMemory;
static const rtems_termios_callbacks Callbacks = { static const rtems_termios_callbacks Callbacks = {
NULL, /* firstOpen */ NULL, /* firstOpen */
@@ -182,39 +181,26 @@ rtems_device_driver termios_test_driver_open(
rtems_test_exit(0); rtems_test_exit(0);
} }
freeMemory = malloc_free_space(); if( firstCall ) {
if( test == 0 ) { static const uintptr_t allocSizes [] = {
alloc_ptr = malloc( freeMemory - 4 ); sizeof( struct rtems_termios_tty ),
128,
64,
256
};
size_t i;
firstCall = false;
sc = rtems_termios_open (major, minor, arg, &Callbacks); for (i = 0; i < sizeof( allocSizes ) / sizeof( allocSizes [0] ); ++i) {
rtems_test_assert( sc == RTEMS_NO_MEMORY ); void *opaque = rtems_heap_greedy_allocate( allocSizes, i );
free( alloc_ptr ); sc = rtems_termios_open( major, minor, arg, &Callbacks );
alloc_ptr = malloc( freeMemory - 4 - 10 - rtems_test_assert( sc == RTEMS_NO_MEMORY );
sizeof( struct rtems_termios_tty ) );
rtems_heap_greedy_free( opaque );
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 );
free( alloc_ptr );
test = 1;
} }
sc = rtems_termios_open (major, minor, arg, &Callbacks); sc = rtems_termios_open (major, minor, arg, &Callbacks);