From 445b2bd6c3a820e632eae1c7c5d2697735137671 Mon Sep 17 00:00:00 2001 From: Krzysztof Miesowicz Date: Wed, 26 Sep 2012 13:42:11 +0200 Subject: New fstest to cover RFS bitmaps - fsrfsbitmap01 --- testsuites/fstests/Makefile.am | 1 + testsuites/fstests/configure.ac | 1 + testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.doc | 29 ++ testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn | 142 ++++++ testsuites/fstests/fsrfsbitmap01/test.c | 537 +++++++++++++++++++++ testsuites/fstests/mrfs_fsrfsbitmap01/Makefile.am | 33 ++ 6 files changed, 743 insertions(+) create mode 100644 testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.doc create mode 100644 testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn create mode 100644 testsuites/fstests/fsrfsbitmap01/test.c create mode 100644 testsuites/fstests/mrfs_fsrfsbitmap01/Makefile.am diff --git a/testsuites/fstests/Makefile.am b/testsuites/fstests/Makefile.am index 1b421152a1..78c5fff30d 100644 --- a/testsuites/fstests/Makefile.am +++ b/testsuites/fstests/Makefile.am @@ -29,6 +29,7 @@ SUBDIRS += mrfs_fsrdwr SUBDIRS += mrfs_fssymlink SUBDIRS += mrfs_fstime SUBDIRS += mrfs_fsfpathconf +SUBDIRS += mrfs_fsrfsbitmap01 SUBDIRS += fsnofs01 SUBDIRS += fsimfsgeneric01 SUBDIRS += fsbdpart01 diff --git a/testsuites/fstests/configure.ac b/testsuites/fstests/configure.ac index 9b4c9f9903..8473c15df9 100644 --- a/testsuites/fstests/configure.ac +++ b/testsuites/fstests/configure.ac @@ -105,6 +105,7 @@ mrfs_fsrdwr/Makefile mrfs_fssymlink/Makefile mrfs_fstime/Makefile mrfs_fsfpathconf/Makefile +mrfs_fsrfsbitmap01/Makefile fsnofs01/Makefile fsimfsgeneric01/Makefile fsbdpart01/Makefile diff --git a/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.doc b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.doc new file mode 100644 index 0000000000..57dcbcb437 --- /dev/null +++ b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.doc @@ -0,0 +1,29 @@ +# COPYRIGHT (c) 2012-. +# Krzysztof Miesowicz krzysztof.miesowicz@gmail.com +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: fsrfsbitmap01 + +directives: + + + rtems_rfs_bitmap_open + + rtems_rfs_bitmap_close + + rtems_rfs_bitmap_load_map + + rtems_rfs_bitmap_map_alloc + + rtems_rfs_bitmap_map_clear + + rtems_rfs_bitmap_map_clear_all + + rtems_rfs_bitmap_map_set + + rtems_rfs_bitmap_map_set_all + + rtems_rfs_bitmap_map_test + + +concepts: + + + exercise all rfs bitmap directives + diff --git a/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn new file mode 100644 index 0000000000..d76fa1e2f8 --- /dev/null +++ b/testsuites/fstests/fsrfsbitmap01/fsrfsbitmap01.scn @@ -0,0 +1,142 @@ +*** FILE SYSTEM TEST ( MOUNTED RFS ) *** +Initializing filesystem MOUNTED RFS + + START of RFS Bitmap Unit Test + Bit set value : 0 + Bit clear value : 1 + Num bit per element : 32 + +RFS Bitmap Test : size = 4096 (128) + 1. Find bit with seed > size: pass (Success) + 2. Find bit with seed = size: pass (Success) + 3. Find bit 0 with seed = 0: pass (Success): bit = 0 + 4. Find bit (size - 1) with seed = (size - 1) (4095): pass (Success): bit = 4095 + 5. Test bit 0: pass (Success) + 6. Test bit (size - 1) (4095): pass (Success) + 7. Test bit range (1,4094] all clear: pass + 8. Set all bits: PASS (Success) + 9. Clear bit 3232: PASS (Success) + 10. Find bit with seed = 0: pass (Success): bit = 3232 + 11. Fail to find bit with seed = 0: pass (Success): bit = 2048 + 12. Clear bit 0: pass (Success) + 13. Find bit with seed = (size - 1): pass (Success): bit = 0 + 14. Clear bit (size - 1) (4095): pass (Success) + 15. Find bit with seed = 0: pass (Success): bit = 4095 + 16. Clear bit 0: pass (Success) + 17. Find bit with seed = (size / 2) (2048): pass (Success): bit = 0 + 18. Clear bit (size - 1) (4095): pass, (Success) + 19. Find bit with seed = (size / 2) (2048): pass (Success): bit = 4095 + 20. Clear bit 0: pass (Success) + 21. Find bit with seed = ((size / 2) - 1) (2047): pass (Success): bit = 0 + 22. Clear bit (size - 1) (4095): pass (Success) + 23. Find bit with seed = ((size / 2) - 1) (2047): pass (Success): bit = 4095 + 23. Set all bits + 23. Cleared bits (1432, 1463] (32) + 23. Alloc'ed all bits (1463, 1494] (32) + 24. Set all bits + 24. Cleared bits (660, 716] (57) + 24. Alloc'ed all bits (716, 772] (57) + 25. Set all bits: PASS (Success) + 26. Clear bit (1321, 2070]: PASS (Success) + 27. Check free count is 749: 749: pass (Success) + 28. Create search check free count is 749: 749: pass (Success) + 29. Map set check with bit (4098) larger than size (4096) + 30. Map clear check with bit (4098) larger than size (4096) + 31. Map test check with bit (4098) larger than size (4096) + 32. Set all bits in the map, then clear bit (2048) and set this bit once again: PASSED + 33. Attempt to find bit when all bits are set (expected FAILED): FAILED + 34. Clear all bits in the map. + +RFS Bitmap Test : size = 2048 (64) + 1. Find bit with seed > size: pass (Success) + 2. Find bit with seed = size: pass (Success) + 3. Find bit 0 with seed = 0: pass (Success): bit = 0 + 4. Find bit (size - 1) with seed = (size - 1) (2047): pass (Success): bit = 2047 + 5. Test bit 0: pass (Success) + 6. Test bit (size - 1) (2047): pass (Success) + 7. Test bit range (1,2046] all clear: pass + 8. Set all bits: PASS (Success) + 9. Clear bit 449: PASS (Success) + 10. Find bit with seed = 0: pass (Success): bit = 449 + 11. Fail to find bit with seed = 0: pass (Success): bit = 0 + 12. Clear bit 0: pass (Success) + 13. Find bit with seed = (size - 1): pass (Success): bit = 0 + 14. Clear bit (size - 1) (2047): pass (Success) + 15. Find bit with seed = 0: pass (Success): bit = 2047 + 16. Clear bit 0: pass (Success) + 17. Find bit with seed = (size / 2) (1024): pass (Success): bit = 0 + 18. Clear bit (size - 1) (2047): pass, (Success) + 19. Find bit with seed = (size / 2) (1024): pass (Success): bit = 2047 + 20. Clear bit 0: pass (Success) + 21. Find bit with seed = ((size / 2) - 1) (1023): pass (Success): bit = 0 + 22. Clear bit (size - 1) (2047): pass (Success) + 23. Find bit with seed = ((size / 2) - 1) (1023): pass (Success): bit = 2047 + 23. Set all bits + 23. Cleared bits (960, 991] (32) + 23. Alloc'ed all bits (991, 1022] (32) + 24. Set all bits + 24. Cleared bits (166, 222] (57) + 24. Alloc'ed all bits (222, 278] (57) + 25. Set all bits: PASS (Success) + 26. Clear bit (177, 770]: PASS (Success) + 27. Check free count is 593: 593: pass (Success) + 28. Create search check free count is 593: 593: pass (Success) + 29. Map set check with bit (2050) larger than size (2048) + 30. Map clear check with bit (2050) larger than size (2048) + 31. Map test check with bit (2050) larger than size (2048) + 32. Set all bits in the map, then clear bit (1024) and set this bit once again: PASSED + 33. Attempt to find bit when all bits are set (expected FAILED): FAILED + 34. Clear all bits in the map. + +RFS Bitmap Test : size = 420 (14) + 1. Find bit with seed > size: pass (Success) + 2. Find bit with seed = size: pass (Success) + 3. Find bit 0 with seed = 0: pass (Success): bit = 0 + 4. Find bit (size - 1) with seed = (size - 1) (419): pass (Success): bit = 419 + 5. Test bit 0: pass (Success) + 6. Test bit (size - 1) (419): pass (Success) + 7. Test bit range (1,418] all clear: pass + 8. Set all bits: PASS (Success) + 9. Clear bit 215: PASS (Success) + 10. Find bit with seed = 0: pass (Success): bit = 215 + 11. Fail to find bit with seed = 0: pass (Success): bit = 0 + 12. Clear bit 0: pass (Success) + 13. Find bit with seed = (size - 1): pass (Success): bit = 0 + 14. Clear bit (size - 1) (419): pass (Success) + 15. Find bit with seed = 0: pass (Success): bit = 419 + 16. Clear bit 0: pass (Success) + 17. Find bit with seed = (size / 2) (210): pass (Success): bit = 0 + 18. Clear bit (size - 1) (419): pass, (Success) + 19. Find bit with seed = (size / 2) (210): pass (Success): bit = 419 + 20. Clear bit 0: pass (Success) + 21. Find bit with seed = ((size / 2) - 1) (209): pass (Success): bit = 0 + 22. Clear bit (size - 1) (419): pass (Success) + 23. Find bit with seed = ((size / 2) - 1) (209): pass (Success): bit = 419 + 23. Set all bits + 23. Cleared bits (127, 158] (32) + 23. Alloc'ed all bits (158, 189] (32) + 24. Set all bits + 24. Cleared bits (83, 139] (57) + 24. Alloc'ed all bits (139, 195] (57) + 25. Set all bits: PASS (Success) + 26. Clear bit (94, 174]: PASS (Success) + 27. Check free count is 80: 80: pass (Success) + 28. Create search check free count is 80: 80: pass (Success) + 29. Map set check with bit (422) larger than size (420) + 30. Map clear check with bit (422) larger than size (420) + 31. Map test check with bit (422) larger than size (420) + 32. Set all bits in the map, then clear bit (210) and set this bit once again: PASSED + 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 + + Allocate most of memory - attempt to fail while open bitmap - expect ENOMEM + Attempt to open bitmap returned: Not enough space + Freeing the allocated memory + + END of RFS Bitmap Unit Test + + +Shutting down filesystem MOUNTED RFS +*** END OF FILE SYSTEM TEST ( MOUNTED RFS ) *** diff --git a/testsuites/fstests/fsrfsbitmap01/test.c b/testsuites/fstests/fsrfsbitmap01/test.c new file mode 100644 index 0000000000..f02c8df277 --- /dev/null +++ b/testsuites/fstests/fsrfsbitmap01/test.c @@ -0,0 +1,537 @@ +/* + * Copyright (c) 2012-. + * Krzysztof Miesowicz krzysztof.miesowicz@gmail.com + * + * This test is extended version of rtems-rfs-bimaps-ut.c . Most of this code + * was written by Chris Johns in rtems-rfs-bitmaps-ut.c and is copied + * and pasted here. Rest of this test was written by Krzysztof Miesowicz to + * completely cover rtems_rfs_bitmap_* symbols. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include +#include + +#include "fstest.h" +#include "tmacros.h" +#include + +#define rtems_rfs_exit_on_error(_rc, _r, _c, _b) \ + if ((_rc > 0) || _r) { free (_b); rtems_rfs_bitmap_close (_c); return; } + +bool +rtems_rfs_bitmap_ut_test_range (rtems_rfs_bitmap_control* control, + int test, + bool set, + rtems_rfs_bitmap_bit bit, + size_t size) +{ + unsigned int count; + bool result; + for (count = 0; count < size; count++) + { + int rc = rtems_rfs_bitmap_map_test (control, bit + count, &result); + if (rc > 0) + { + printf (" %2d. Test bit %" PRId32 " in range (%" PRId32 ",%ld] is %s: ", + test, bit + count, bit, bit + size - 1, !set ? "set" : "clear"); + printf ("FAIL (%s)\n", strerror (rc)); + return false; + } + if (!set) + result = !result; + if (!result) + { + printf (" %2d. Test bit %" PRId32 " in range (%" PRId32 ",%ld] is %s: ", + test, bit + count, bit, bit + size - 1, !set ? "set" : "clear"); + printf (" %s\n", !result ? "pass" : "FAIL"); + return false; + } + } + + printf (" %2d. Test bit range (%" PRId32 ",%ld] all %s: pass\n", + test, bit, bit + size - 1, set ? "set" : "clear"); + + return true; +} + +bool +rtems_rfs_bitmap_ut_alloc_seq_test (rtems_rfs_bitmap_control* control, + int test, + rtems_rfs_bitmap_bit bit, + size_t size) +{ + bool state; + int i; + int rc; + + printf (" %2d. Set all bits\n", test); + rc = rtems_rfs_bitmap_map_set_all (control); + if (rc > 0) + { + printf (" %2d. set all bits: FAIL (%s)\n", test, strerror (rc)); + return false; + } + + for (i = 0; i < size; i++) + rtems_rfs_bitmap_map_clear (control, bit + i); + + printf (" %2d. Cleared bits (%" PRId32 ", %ld] (%zd)\n", + test, bit, bit + size - 1, size); + + for (i = 0; i < rtems_rfs_bitmap_element_bits (); i++) + { + rc = rtems_rfs_bitmap_map_test (control, bit + i, &state); + if (rc > 0) + { + printf (" %2d. test bit: FAIL (%s)\n", test, strerror (rc)); + return false; + } + if (state) + { + printf (" %2d. Cleared bit still set: bit = %" PRId32 "\n", test, bit + i); + return false; + } + } + + for (i = 0, bit = 0; i < size; i++) + { + rtems_rfs_bitmap_bit seed = bit; + bool result; + int rc; + rc = rtems_rfs_bitmap_map_alloc (control, seed, &result, &bit); + if (rc > 0) + { + printf (" %2d. map all: FAIL (%s)\n", test, strerror (rc)); + return false; + } + if (!result) + { + printf (" %2d. Find bit with seed = %" PRId32 ": %s: bit = %" PRId32 "\n", + test, seed, result ? "pass" : "FAIL", bit); + return false; + } + } + + printf (" %2d. Alloc'ed all bits (%" PRId32 ", %ld] (%zd)\n", + test, bit, bit + size - 1, size); + + return true; +} + +void +rtems_rfs_bitmap_ut_test_bitmap (size_t size) +{ + rtems_rfs_file_system fs; + rtems_rfs_bitmap_control control; + rtems_rfs_buffer_handle handle; + rtems_rfs_buffer buffer; + rtems_rfs_bitmap_bit bit = 0; + rtems_rfs_bitmap_bit first_bit; + rtems_rfs_bitmap_bit last_bit; + bool result; + size_t bytes; + size_t clear; + int rc; + + bytes = (rtems_rfs_bitmap_elements (size) * + sizeof (rtems_rfs_bitmap_element)); + + memset (&fs, 0, sizeof (fs)); + memset (&buffer, 0, sizeof (buffer)); + + buffer.buffer = malloc (bytes); + buffer.block = 1; + + if (!buffer.buffer) + { + printf (" Cannot allocate bitmap memory\n"); + return; + } + +#if RTEMS_RFS_BITMAP_CLEAR_ZERO + memset (buffer.buffer, 0, bytes); +#else + memset (buffer.buffer, 0xff, bytes); +#endif + + /* + * Do not close the handle so no writes need occur. + */ + rc = rtems_rfs_buffer_handle_open (&fs, &handle); + if (rc > 0) + { + printf (" Cannot open the handle: %d: %s\n", rc, strerror (rc)); + free (buffer.buffer); + return; + } + + handle.buffer = &buffer; + handle.bnum = 1; + + printf ("\nRFS Bitmap Test : size = %zd (%zd)\n", + size, rtems_rfs_bitmap_elements (size)); + + rc = rtems_rfs_bitmap_open (&control, &fs, &handle, size, 1); + if (rc > 0) + { + printf (" Cannot open the bitmap: %s\n", strerror (rc)); + free (buffer.buffer); + return; + } + + /* + * This is a new bitmap with no bits set. Try and find a bit with a few + * seeds. + */ + rc = rtems_rfs_bitmap_map_alloc (&control, size * 2, &result, &bit); + printf (" 1. Find bit with seed > size: %s (%s)\n", + result ? "FAIL" : "pass", strerror (rc)); + rtems_rfs_exit_on_error (rc, result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, size, &result, &bit); + printf (" 2. Find bit with seed = size: %s (%s)\n", + result ? "FAIL" : "pass", strerror (rc)); + rtems_rfs_exit_on_error (rc, result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit); + result = result && (bit == 0); + printf (" 3. Find bit 0 with seed = 0: %s (%s): bit = %" PRId32 "\n", + result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, size - 1, &result, &bit); + result = result && (bit == (size - 1)); + printf (" 4. Find bit (size - 1) with seed = (size - 1) (%zd): %s (%s): bit = %" PRId32 "\n", + size - 1, result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + /* + * Test the bits allocated to make sure they are set. + */ + rc = rtems_rfs_bitmap_map_test (&control, 0, &result); + printf (" 5. Test bit 0: %s (%s)\n", + result ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_test (&control, size - 1, &result); + printf (" 6. Test bit (size - 1) (%zd): %s (%s)\n", + size - 1, result ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + if (!rtems_rfs_bitmap_ut_test_range (&control, 7, false, 1, size - 2)) + rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer); + + /* + * Set all bits then clear one and find it. + */ + rc = rtems_rfs_bitmap_map_set_all (&control); + printf (" 8. Set all bits: %s (%s)\n", + rc == 0 ? "PASS" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + bit = rand () % size; + + rc = rtems_rfs_bitmap_map_clear (&control, bit); + printf (" 9. Clear bit %" PRId32 ": %s (%s)\n", + bit, rc == 0 ? "PASS" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + last_bit = bit; + rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit); + result = result && (bit == last_bit); + printf (" 10. Find bit with seed = 0: %s (%s): bit = %" PRId32 "\n", + result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit); + result = !result || (bit != last_bit); + printf (" 11. Fail to find bit with seed = 0: %s (%s): bit = %" PRId32 "\n", + result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, 0); + printf (" 12. Clear bit 0: %s (%s)\n", + rc == 0 ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, size - 1, &result, &bit); + result = result && (bit == 0); + printf (" 13. Find bit with seed = (size - 1): %s (%s): bit = %" PRId32 "\n", + result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, size - 1); + printf (" 14. Clear bit (size - 1) (%zd): %s (%s)\n", + size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit); + result = result && (bit == (size - 1)); + printf (" 15. Find bit with seed = 0: %s (%s): bit = %" PRId32 "\n", + result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, 0); + printf (" 16. Clear bit 0: %s (%s)\n", + rc == 0 ? "pass" : "FAIL", strerror (rc)); + + rc = rtems_rfs_bitmap_map_alloc (&control, size / 2, &result, &bit); + result = result && (bit == 0); + printf (" 17. Find bit with seed = (size / 2) (%zd): %s (%s): bit = %" PRId32 "\n", + size / 2, result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, size - 1); + printf (" 18. Clear bit (size - 1) (%zd): %s, (%s)\n", + size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_alloc (&control, size / 2, &result, &bit); + result = result && (bit == (size - 1)); + printf (" 19. Find bit with seed = (size / 2) (%zd): %s (%s): bit = %" PRId32 "\n", + size / 2, result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, 0); + printf (" 20. Clear bit 0: %s (%s)\n", + rc == 0 ? "pass" : "FAIL", strerror (rc)); + + rc = rtems_rfs_bitmap_map_alloc (&control, (size / 2) - 1, &result, &bit); + result = result && (bit == 0); + printf (" 21. Find bit with seed = ((size / 2) - 1) (%zd): %s (%s): bit = %" PRId32 "\n", + (size / 2) - 1, result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rc = rtems_rfs_bitmap_map_clear (&control, size - 1); + printf (" 22. Clear bit (size - 1) (%zd): %s (%s)\n", + size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc)); + + rc = rtems_rfs_bitmap_map_alloc (&control, (size / 2) - 1, &result, &bit); + result = result && (bit == (size - 1)); + printf (" 23. Find bit with seed = ((size / 2) - 1) (%zd): %s (%s): bit = %" PRId32 "\n", + (size / 2) - 1, result ? "pass" : "FAIL", strerror (rc), bit); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits (); + result = rtems_rfs_bitmap_ut_alloc_seq_test (&control, 23, bit, + rtems_rfs_bitmap_element_bits ()); + rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer); + + bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits (); + result = rtems_rfs_bitmap_ut_alloc_seq_test (&control, 24, bit, 57); + rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer); + + /* + * Set all bits, clear a random numberone then create a search map and make + * sure the clear count is correct. + */ + rc = rtems_rfs_bitmap_map_set_all (&control); + printf (" 25. Set all bits: %s (%s)\n", + rc == 0 ? "PASS" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + + first_bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits (); + last_bit = first_bit + rand () % (size / 2) + rtems_rfs_bitmap_element_bits(); + + for (bit = first_bit; bit < last_bit; bit++) + { + rc = rtems_rfs_bitmap_map_clear (&control, bit); + if (rc > 0) + { + printf (" 26. Clear bit %" PRId32 ": %s (%s)\n", + bit, rc == 0 ? "PASS" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer); + } + } + + printf (" 26. Clear bit (%" PRId32 ", %" PRId32 "]: %s (%s)\n", + first_bit, last_bit, rc == 0 ? "PASS" : "FAIL", strerror (rc)); + + clear = rtems_rfs_bitmap_map_free (&control); + result = clear == (last_bit - first_bit); + printf (" 27. Check free count is %zd: %" PRId32 ": %s (%s)\n", + clear, last_bit - first_bit, + result ? "pass" : "FAIL", strerror (rc)); + + rc = rtems_rfs_bitmap_create_search (&control); + result = clear == rtems_rfs_bitmap_map_free (&control); + printf (" 28. Create search check free count is %zd: %zd: %s (%s)\n", + clear, rtems_rfs_bitmap_map_free (&control), + result ? "pass" : "FAIL", strerror (rc)); + rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer); + + rtems_rfs_bitmap_bit mybit = control.size +2; + + printf (" 29. Map set check with bit (%d) larger than size (%d)\n", + (int)mybit, (int)control.size); + rc = rtems_rfs_bitmap_map_set(&control, mybit); + rtems_test_assert( rc == EINVAL ); + + printf (" 30. Map clear check with bit (%d) larger than size (%d)\n", + (int)mybit, (int)control.size); + rc = rtems_rfs_bitmap_map_clear(&control, mybit); + rtems_test_assert( rc == EINVAL ); + + printf (" 31. Map test check with bit (%d) larger than size (%d)\n", + (int)mybit, (int)control.size); + rc = rtems_rfs_bitmap_map_test(&control, mybit ,&result); + rtems_test_assert( rc == EINVAL ); + + /* Set all bits, clear one and then set this cleared bit once again */ + printf (" 32. Set all bits in the map, then clear bit (%lu) and set this bit once again:",control.size/2); + rc = rtems_rfs_bitmap_map_set_all(&control); + rtems_test_assert( rc == 0 ); + rc = rtems_rfs_bitmap_map_clear(&control, control.size/2); + rtems_test_assert (rc == 0 ); + rc = rtems_rfs_bitmap_map_set(&control, control.size/2); + rtems_test_assert (rc == 0 ); + printf (" PASSED\n"); + + /* Attempt to find free bit (with different seeds) when all bits are set */ + printf (" 33. Attempt to find bit when all bits are set (expected FAILED):"); + rc = rtems_rfs_bitmap_map_alloc(&control, 0, &result, &bit); + rtems_test_assert(rc == 0 ); + rtems_test_assert ( result == false ); + rc = rtems_rfs_bitmap_map_alloc(&control, size-1, &result, &bit); + rtems_test_assert(rc == 0 ); + rtems_test_assert ( result == false ); + rc = rtems_rfs_bitmap_map_alloc(&control, size/2, &result, &bit); + rtems_test_assert(rc == 0 ); + rtems_test_assert ( result == false ); + rc = rtems_rfs_bitmap_map_alloc(&control, 1, &result, &bit); + rtems_test_assert(rc == 0 ); + rtems_test_assert ( result == false ); + rc = rtems_rfs_bitmap_map_alloc(&control, -2, &result, &bit); + rtems_test_assert(rc == 0 ); + rtems_test_assert ( result == false ); + printf(" FAILED\n"); + + /* Simply clear all bits */ + printf (" 34. Clear all bits in the map.\n"); + rc = rtems_rfs_bitmap_map_clear_all(&control); + rtems_test_assert( rc == 0 ); + + rtems_rfs_bitmap_close (&control); + free (buffer.buffer); +} + +void rtems_rfs_bitmap_unit_test (void) +{ + printf (" Bit set value : %d\n", RTEMS_RFS_BITMAP_BIT_SET); + printf (" Bit clear value : %d\n", RTEMS_RFS_BITMAP_BIT_CLEAR); + printf (" Num bit per element : %zd\n", rtems_rfs_bitmap_element_bits ()); + +#if INT_MAX >= 0x23984237 + srand (0x23984237); +#else + srand (0x2398); +#endif + rtems_rfs_bitmap_ut_test_bitmap (4096); + rtems_rfs_bitmap_ut_test_bitmap (2048); + rtems_rfs_bitmap_ut_test_bitmap (420); +} + +void nullpointer_test(void){ + + rtems_rfs_bitmap_control* control=NULL; + rtems_rfs_bitmap_control notnullcontrol; + 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); + 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); +} + +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; + + /* 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 ); + + 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; + + rc = rtems_rfs_bitmap_open (&control, &fs, &handle, size, 1); + rtems_test_assert( rc == ENOMEM ); + printf( " Attempt to open bitmap returned: %s\n", strerror(rc)); + puts( " Freeing the allocated memory" ); + rtems_heap_greedy_free( opaque ); +} + +void test(void){ + puts("\n START of RFS Bitmap Unit Test"); + + rtems_rfs_bitmap_unit_test(); + nullpointer_test(); + open_failure(); + + puts("\n END of RFS Bitmap Unit Test"); +} + + diff --git a/testsuites/fstests/mrfs_fsrfsbitmap01/Makefile.am b/testsuites/fstests/mrfs_fsrfsbitmap01/Makefile.am new file mode 100644 index 0000000000..c4063c1b3f --- /dev/null +++ b/testsuites/fstests/mrfs_fsrfsbitmap01/Makefile.am @@ -0,0 +1,33 @@ + +rtems_tests_PROGRAMS = mrfs_fsrfsbitmap01 +mrfs_fsrfsbitmap01_SOURCES = ../fsrfsbitmap01/test.c +mrfs_fsrfsbitmap01_SOURCES += ../support/ramdisk_support.c +mrfs_fsrfsbitmap01_SOURCES += ../support/fstest_support.c +mrfs_fsrfsbitmap01_SOURCES += ../support/fstest_support.h +mrfs_fsrfsbitmap01_SOURCES += ../support/ramdisk_support.h +mrfs_fsrfsbitmap01_SOURCES += ../support/fstest.h +mrfs_fsrfsbitmap01_SOURCES += ../../psxtests/include/pmacros.h +mrfs_fsrfsbitmap01_SOURCES += ../mrfs_support/fs_support.c +mrfs_fsrfsbitmap01_SOURCES += ../mrfs_support/fs_config.h + +#dist_rtems_tests_DATA = mrfs_fsrfsbitmap01.scn +#dist_rtems_tests_DATA += mrfs_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 = $(mrfs_fsrfsbitmap01_OBJECTS) +LINK_LIBS = $(mrfs_fsrfsbitmap01_LDLIBS) + +mrfs_fsrfsbitmap01$(EXEEXT): $(mrfs_fsrfsbitmap01_OBJECTS) $(mrfs_fsrfsbitmap01_DEPENDENCIES) + @rm -f mrfs_fsrfsbitmap01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am -- cgit v1.2.3