From 8f1b6cdef5e06caedf9615f70180606394f928bb Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 12 Nov 2012 14:58:13 +0100 Subject: fstests/fsrfsbitmap01: Fix NULL pointer access Move test files into one directory. --- testsuites/fstests/fsrfsbitmap01/Makefile.am | 33 +++++++++ testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn | 2 +- testsuites/fstests/fsrfsbitmap01/test.c | 85 ++++++++-------------- 3 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 testsuites/fstests/fsrfsbitmap01/Makefile.am (limited to 'testsuites/fstests/fsrfsbitmap01') diff --git a/testsuites/fstests/fsrfsbitmap01/Makefile.am b/testsuites/fstests/fsrfsbitmap01/Makefile.am new file mode 100644 index 0000000000..b52fa9903b --- /dev/null +++ b/testsuites/fstests/fsrfsbitmap01/Makefile.am @@ -0,0 +1,33 @@ + +rtems_tests_PROGRAMS = fsrfsbitmap01 +fsrfsbitmap01_SOURCES = test.c +fsrfsbitmap01_SOURCES += ../support/ramdisk_support.c +fsrfsbitmap01_SOURCES += ../support/fstest_support.c +fsrfsbitmap01_SOURCES += ../support/fstest_support.h +fsrfsbitmap01_SOURCES += ../support/ramdisk_support.h +fsrfsbitmap01_SOURCES += ../support/fstest.h +fsrfsbitmap01_SOURCES += ../../psxtests/include/pmacros.h +fsrfsbitmap01_SOURCES += ../mrfs_support/fs_support.c +fsrfsbitmap01_SOURCES += ../mrfs_support/fs_config.h + +dist_rtems_tests_DATA = fsrfsbitmap01.scn +dist_rtems_tests_DATA += fsrfsbitmap01.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + + +AM_CPPFLAGS += -I$(top_srcdir)/support +AM_CPPFLAGS += -I$(top_srcdir)/mrfs_support +AM_CPPFLAGS += -I$(top_srcdir)/../support/include +AM_CPPFLAGS += -I$(top_srcdir)/../psxtests/include + +LINK_OBJS = $(fsrfsbitmap01_OBJECTS) +LINK_LIBS = $(fsrfsbitmap01_LDLIBS) + +fsrfsbitmap01$(EXEEXT): $(fsrfsbitmap01_OBJECTS) $(fsrfsbitmap01_DEPENDENCIES) + @rm -f fsrfsbitmap01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn index d76fa1e2f8..ec944c527d 100644 --- a/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn +++ b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn @@ -129,7 +129,7 @@ RFS Bitmap Test : size = 420 (14) 33. Attempt to find bit when all bits are set (expected FAILED): FAILED 34. Clear all bits in the map. - Testing bitmap_map functions with NULL bitmap control pointer + Testing bitmap_map functions with zero initialized bitmap control pointer Allocate most of memory - attempt to fail while open bitmap - expect ENOMEM Attempt to open bitmap returned: Not enough space diff --git a/testsuites/fstests/fsrfsbitmap01/test.c b/testsuites/fstests/fsrfsbitmap01/test.c index dcd96df7a5..df6e47882d 100644 --- a/testsuites/fstests/fsrfsbitmap01/test.c +++ b/testsuites/fstests/fsrfsbitmap01/test.c @@ -446,79 +446,56 @@ static void rtems_rfs_bitmap_unit_test (void) static void nullpointer_test(void){ - rtems_rfs_bitmap_control* control=NULL; - rtems_rfs_bitmap_control notnullcontrol; + rtems_rfs_bitmap_control control; rtems_rfs_bitmap_bit bit = 0; rtems_rfs_bitmap_bit seed_bit = 0; int rc; bool result; - printf("\n Testing bitmap_map functions with NULL bitmap control " - "pointer\n"); - /* Invoke all functions with NULL control */ - rc = rtems_rfs_bitmap_map_set(control, bit); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_map_clear(control, bit); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_map_test(control, bit, &result); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_map_set_all(control); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_map_clear_all(control); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_create_search(control); - rtems_test_assert(rc>0); - rc = rtems_rfs_bitmap_map_alloc(control, seed_bit, &result, &bit); + memset(&control, 0, sizeof(control)); + + printf ("\n Testing bitmap_map functions with zero " + "initialized bitmap control pointer\n"); + + /* Invoke all functions with control initialized to zero */ + rc = rtems_rfs_bitmap_map_set(&control, bit); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_map_clear(&control, bit); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_map_test(&control, bit, &result); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_map_set_all(&control); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_map_clear_all(&control); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_create_search(&control); + rtems_test_assert(rc == ENXIO); + rc = rtems_rfs_bitmap_map_alloc(&control, seed_bit, &result, &bit); + rtems_test_assert(rc == 0); rtems_test_assert(!result); - /* - * Invoke map_alloc with not-null pointer to control, but with - * control uninitialized. It is to cover check in rtems_rfs_bitmap_load_map. - * We can't check directly if it goes this path, but we will see this in - * coverage - */ - rc = rtems_rfs_bitmap_map_set(¬nullcontrol, bit); - rtems_test_assert(rc > 0); + rc = rtems_rfs_bitmap_map_set(&control, bit); + rtems_test_assert(rc == ENXIO); } static void open_failure(void){ - rtems_rfs_file_system fs; - rtems_rfs_bitmap_control control; - rtems_rfs_buffer_handle handle; - rtems_rfs_buffer buffer; - size_t bytes; - int rc; + rtems_rfs_file_system fs; + rtems_rfs_bitmap_control control; + rtems_rfs_buffer_handle handle; + int rc; + void *opaque; /* Attempt to get ENOMEM while open bitmap */ printf("\n Allocate most of memory - attempt to fail while open bitmap - expect ENOMEM\n" ); - void *opaque; - static const uintptr_t location_size [] = { - sizeof(rtems_filesystem_global_location_t) - }; - - size_t size = location_size[0]*rtems_rfs_bitmap_search_element_bits(); - bytes = (rtems_rfs_bitmap_elements (size) * - sizeof (rtems_rfs_bitmap_element)); - opaque = rtems_heap_greedy_allocate( location_size, 1 ); + opaque = rtems_heap_greedy_allocate( NULL, 0 ); memset (&fs, 0, sizeof (fs)); - memset (&buffer, 0, sizeof (buffer)); - - buffer.buffer = malloc (bytes); - buffer.block = 1; - -#if RTEMS_RFS_BITMAP_CLEAR_ZERO - memset (buffer.buffer, 0, bytes); -#else - memset (buffer.buffer, 0xff, bytes); -#endif rc = rtems_rfs_buffer_handle_open (&fs, &handle); - handle.buffer = &buffer; - handle.bnum = 1; + rtems_test_assert( rc == 0 ); - rc = rtems_rfs_bitmap_open (&control, &fs, &handle, size, 1); + rc = rtems_rfs_bitmap_open (&control, &fs, &handle, 0, 0); rtems_test_assert( rc == ENOMEM ); printf( " Attempt to open bitmap returned: %s\n", strerror(rc)); puts( " Freeing the allocated memory" ); -- cgit v1.2.3