[PATCH rtems 13/14] Flashdev: Allow flash geometry beeing set from test case
berndmoessner80 at gmail.com
berndmoessner80 at gmail.com
Tue Jan 2 20:45:34 UTC 2024
From: Bernd Moessner <berndmoessner80 at gmail.com>
---
testsuites/libtests/flashdev01/init.c | 9 ++--
.../libtests/flashdev01/test_flashdev.c | 51 +++++++++++++------
.../libtests/flashdev01/test_flashdev.h | 2 +-
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c
index 368968ce10..33cbb8bad8 100644
--- a/testsuites/libtests/flashdev01/init.c
+++ b/testsuites/libtests/flashdev01/init.c
@@ -62,15 +62,18 @@ static void run_test(void) {
uint32_t jedec;
int page_count;
int type;
- size_t min_write_size_in[] = {1,8,16};
+ const size_t min_write_size_in[] = {1,8,16};
size_t min_write_size_out = 0;
size_t erase_size = 0;
const char flash_path[] = "/dev/flashdev0";
+ const int page_count_in = 16;
+ const int page_size_in = 128;
+
for ( int loop = 0; loop <= 2; loop++)
{
/* Initalize the flash device driver and flashdev */
- flash = test_flashdev_init(min_write_size_in[loop], ERASE_SIZE);
+ flash = test_flashdev_init(page_size_in, page_count_in, min_write_size_in[loop], ERASE_SIZE);
rtems_test_assert(flash != NULL);
/* Register the flashdev as a device */
@@ -185,7 +188,7 @@ static void run_test(void) {
}
/* Initalize the flash device driver and flashdev */
- flash = test_flashdev_init(min_write_size_in[1], ERASE_SIZE);
+ flash = test_flashdev_init(page_size_in, page_count_in, min_write_size_in[1], ERASE_SIZE);
rtems_test_assert(flash != NULL);
/* Register the flashdev as a device */
diff --git a/testsuites/libtests/flashdev01/test_flashdev.c b/testsuites/libtests/flashdev01/test_flashdev.c
index df21d432ad..09bd4f0c0c 100644
--- a/testsuites/libtests/flashdev01/test_flashdev.c
+++ b/testsuites/libtests/flashdev01/test_flashdev.c
@@ -31,11 +31,9 @@
#include <rtems/seterr.h>
-#define TEST_DATA_SIZE (PAGE_SIZE * PAGE_COUNT)
-#define PAGE_COUNT 16
-#define PAGE_SIZE 128
-#define MAX_NUM_PARTITIONS 16
-
+static size_t g_test_data_size = 0;
+static size_t g_page_count = 0;
+static size_t g_page_size = 0;
static size_t g_min_write_size = 0;
static size_t g_erase_size = 0;
@@ -114,8 +112,8 @@ int test_flashdev_get_page_by_off(
size_t *page_size
)
{
- *page_offset = search_offset - (search_offset%PAGE_SIZE);
- *page_size = PAGE_SIZE;
+ *page_offset = search_offset - (search_offset%g_page_size);
+ *page_size = g_page_size;
return 0;
}
@@ -127,8 +125,8 @@ int test_flashdev_get_page_by_index(
size_t *page_size
)
{
- *page_offset = search_index * PAGE_SIZE;
- *page_size = PAGE_SIZE;
+ *page_offset = search_index * g_page_size;
+ *page_size = g_page_size;
return 0;
}
@@ -138,7 +136,7 @@ int test_flashdev_get_page_count(
int *page_count
)
{
- *page_count = PAGE_COUNT;
+ *page_count = g_page_count;
return 0;
}
@@ -195,7 +193,7 @@ int test_flashdev_read(
{
test_flashdev* driver = flash->driver;
- if (offset + count > TEST_DATA_SIZE) {
+ if (offset + count > g_test_data_size) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
@@ -214,7 +212,7 @@ int test_flashdev_write(
{
test_flashdev* driver = flash->driver;
- if (offset + count > TEST_DATA_SIZE) {
+ if (offset + count > g_test_data_size) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
@@ -232,11 +230,11 @@ int test_flashdev_erase(
{
test_flashdev* driver = flash->driver;
- if (offset + count > TEST_DATA_SIZE) {
+ if (offset + count > g_test_data_size) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
- if (offset%PAGE_SIZE || count%PAGE_SIZE) {
+ if (offset%g_page_size || count%g_page_size) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
@@ -245,7 +243,7 @@ int test_flashdev_erase(
}
/* Initialize Flashdev and underlying driver. */
-rtems_flashdev* test_flashdev_init(size_t min_write_size, size_t erase_size)
+rtems_flashdev* test_flashdev_init(size_t page_size, size_t page_count, size_t min_write_size, size_t erase_size)
{
if (0 == min_write_size) {
return NULL;
@@ -255,13 +253,34 @@ rtems_flashdev* test_flashdev_init(size_t min_write_size, size_t erase_size)
return NULL;
}
+ if (0 == page_size) {
+ return NULL;
+ }
+
+ if (0 == page_count) {
+ return NULL;
+ }
+
+
if (erase_size % min_write_size) {
return NULL;
}
+ if (erase_size % page_size) {
+ return NULL;
+ }
+
+
+ g_page_count = page_count;
+ g_page_size = page_size;
+ g_test_data_size = g_page_count * g_page_size;
g_min_write_size = min_write_size;
g_erase_size = erase_size;
+ if (g_test_data_size % g_erase_size) {
+ return NULL;
+ }
+
rtems_flashdev *flash = rtems_flashdev_alloc_and_init(sizeof(rtems_flashdev));
if (flash == NULL) {
@@ -275,7 +294,7 @@ rtems_flashdev* test_flashdev_init(size_t min_write_size, size_t erase_size)
return NULL;
}
- flash_driver->data = calloc(1, TEST_DATA_SIZE);
+ flash_driver->data = calloc(1, g_test_data_size);
if (flash_driver->data == NULL) {
free(flash_driver);
rtems_flashdev_destroy_and_free(flash);
diff --git a/testsuites/libtests/flashdev01/test_flashdev.h b/testsuites/libtests/flashdev01/test_flashdev.h
index 52cb6befb1..b02a5deed1 100644
--- a/testsuites/libtests/flashdev01/test_flashdev.h
+++ b/testsuites/libtests/flashdev01/test_flashdev.h
@@ -31,7 +31,7 @@
#include <dev/flash/flashdev.h>
-rtems_flashdev* test_flashdev_init(size_t min_write_size, size_t erase_size);
+rtems_flashdev* test_flashdev_init(size_t page_size, size_t page_count, size_t min_write_size, size_t erase_size);
void test_flashdev_deinit(rtems_flashdev* flash);
--
2.34.1
More information about the devel
mailing list