From 4abe2880fae513725025d39cec81b4141a1dc593 Mon Sep 17 00:00:00 2001 From: Amir Cohen Date: Tue, 26 Feb 2019 16:26:55 +0200 Subject: [PATCH] Merge SPIF & QSPIF components test to general block device tests The SPIF and QPIF components tests are fully merged into general block device tests and were deleted --- .../{TESTS => }/COMMON/fslittle_debug.h | 0 .../{TESTS => }/COMMON/fslittle_test.c | 0 .../{TESTS => }/COMMON/fslittle_test.h | 0 .../TESTS/block_device/qspif/main.cpp | 296 ------------------ .../TESTS/block_device/spif/main.cpp | 291 ----------------- .../blockdevice/general_block_device/main.cpp | 74 ++++- 6 files changed, 60 insertions(+), 601 deletions(-) rename components/storage/blockdevice/COMPONENT_FLASHIAP/{TESTS => }/COMMON/fslittle_debug.h (100%) rename components/storage/blockdevice/COMPONENT_FLASHIAP/{TESTS => }/COMMON/fslittle_test.c (100%) rename components/storage/blockdevice/COMPONENT_FLASHIAP/{TESTS => }/COMMON/fslittle_test.h (100%) delete mode 100644 components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp delete mode 100644 components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_debug.h b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_debug.h rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.c b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.c rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.h b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.h similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.h rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.h diff --git a/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp b/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp deleted file mode 100644 index 0674fc463de..00000000000 --- a/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "QSPIFBlockDevice.h" -#include "mbed_trace.h" -#include "rtos/Thread.h" -#include - -using namespace utest::v1; - -#define TEST_BLOCK_COUNT 10 -#define TEST_ERROR_MASK 16 -#define QSPIF_TEST_NUM_OF_THREADS 5 - -const struct { - const char *name; - bd_size_t (BlockDevice::*method)() const; -} ATTRS[] = { - {"read size", &BlockDevice::get_read_size}, - {"program size", &BlockDevice::get_program_size}, - {"erase size", &BlockDevice::get_erase_size}, - {"total size", &BlockDevice::size}, -}; - -static SingletonPtr _mutex; - - -// Mutex is protecting rand() per srand for buffer writing and verification. -// Mutex is also protecting printouts for clear logs. -// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test! -void basic_erase_program_read_test(QSPIFBlockDevice &blockD, bd_size_t block_size, uint8_t *write_block, - uint8_t *read_block, unsigned addrwidth) -{ - int err = 0; - _mutex->lock(); - - static unsigned block_seed = 1; - srand(block_seed++); - - // Find a random block - bd_addr_t block = (rand() * block_size) % blockD.size(); - - // Use next random number as temporary seed to keep - // the address progressing in the pseudorandom sequence - unsigned seed = rand(); - - // Fill with random sequence - srand(seed); - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - write_block[i_ind] = 0xff & rand(); - } - // Write, sync, and read the block - utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size); - _mutex->unlock(); - - err = blockD.erase(block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = blockD.program(write_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = blockD.read(read_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - _mutex->lock(); - // Check that the data was unmodified - srand(seed); - int val_rand; - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - val_rand = rand(); - if ((0xff & val_rand) != read_block[i_ind]) { - utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size); - utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind], - write_block[i_ind]); - } - TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]); - } - _mutex->unlock(); -} - -void test_qspif_random_program_read_erase() -{ - utest_printf("\nTest Random Program Read Erase Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_size_t block_size = blockD.get_erase_size(); - unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(blockD, block_size, write_block, read_block, addrwidth); - } - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); - -end: - delete[] write_block; - delete[] read_block; -} - -void test_qspif_unaligned_erase() -{ - - utest_printf("\nTest Unaligned Erase Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_addr_t addr = 0; - bd_size_t sector_erase_size = blockD.get_erase_size(addr); - unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1; - - utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); - - //unaligned start address - addr += 1; - err = blockD.erase(addr, sector_erase_size - 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //unaligned end address - addr = 0; - - err = blockD.erase(addr, 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, sector_erase_size + 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //erase size exceeds flash device size - err = blockD.erase(addr, blockD.size() + 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - // Valid erase - err = blockD.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_OK, err); - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - - - -static void test_qspif_thread_job(void *vBlockD/*, int thread_num*/) -{ - static int thread_num = 0; - thread_num++; - QSPIFBlockDevice *blockD = (QSPIFBlockDevice *)vBlockD; - utest_printf("\n Thread %d Started \n", thread_num); - - bd_size_t block_size = blockD->get_erase_size(); - unsigned addrwidth = ceil(log(float(blockD->size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test((*blockD), block_size, write_block, read_block, addrwidth); - } - -end: - delete[] write_block; - delete[] read_block; -} - -void test_qspif_multi_threads() -{ - - utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - rtos::Thread qspif_bd_thread[QSPIF_TEST_NUM_OF_THREADS]; - - osStatus threadStatus; - int i_ind; - - for (i_ind = 0; i_ind < QSPIF_TEST_NUM_OF_THREADS; i_ind++) { - threadStatus = qspif_bd_thread[i_ind].start(test_qspif_thread_job, (void *)&blockD); - if (threadStatus != 0) { - utest_printf("\n Thread %d Start Failed!", i_ind + 1); - } - } - - for (i_ind = 0; i_ind < QSPIF_TEST_NUM_OF_THREADS; i_ind++) { - qspif_bd_thread[i_ind].join(); - } - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - - - - -// Test setup -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("Testing unaligned erase blocks", test_qspif_unaligned_erase), - Case("Testing read write random blocks", test_qspif_random_program_read_erase), - Case("Testing Multi Threads Erase Program Read", test_qspif_multi_threads) -}; - -Specification specification(test_setup, cases); - - -int main() -{ - mbed_trace_init(); - utest_printf("MAIN STARTS\n"); - return !Harness::run(specification); -} diff --git a/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp b/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp deleted file mode 100644 index ad2b2636ed7..00000000000 --- a/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "SPIFBlockDevice.h" -#include "mbed_trace.h" -#include "rtos/Thread.h" -#include - -using namespace utest::v1; - -#define TEST_BLOCK_COUNT 10 -#define TEST_ERROR_MASK 16 -#define SPIF_TEST_NUM_OF_THREADS 5 - -const struct { - const char *name; - bd_size_t (BlockDevice::*method)() const; -} ATTRS[] = { - {"read size", &BlockDevice::get_read_size}, - {"program size", &BlockDevice::get_program_size}, - {"erase size", &BlockDevice::get_erase_size}, - {"total size", &BlockDevice::size}, -}; - -static SingletonPtr _mutex; - -// Mutex is protecting rand() per srand for buffer writing and verification. -// Mutex is also protecting printouts for clear logs. -// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test! -void basic_erase_program_read_test(SPIFBlockDevice &block_device, bd_size_t block_size, uint8_t *write_block, - uint8_t *read_block, unsigned addrwidth) -{ - int err = 0; - _mutex->lock(); - - // Make sure block address per each test is unique - static unsigned block_seed = 1; - srand(block_seed++); - - // Find a random block - bd_addr_t block = (rand() * block_size) % block_device.size(); - - // Use next random number as temporary seed to keep - // the address progressing in the pseudorandom sequence - unsigned seed = rand(); - - // Fill with random sequence - srand(seed); - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - write_block[i_ind] = 0xff & rand(); - } - // Write, sync, and read the block - utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size); - _mutex->unlock(); - - err = block_device.erase(block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = block_device.program(write_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = block_device.read(read_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - _mutex->lock(); - // Check that the data was unmodified - srand(seed); - int val_rand; - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - val_rand = rand(); - if ((0xff & val_rand) != read_block[i_ind]) { - utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size); - utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind], - write_block[i_ind]); - } - TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]); - } - _mutex->unlock(); -} - -void test_spif_random_program_read_erase() -{ - utest_printf("\nTest Random Program Read Erase Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_size_t block_size = block_device.get_erase_size(); - unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth); - } - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); - -end: - delete[] write_block; - delete[] read_block; -} - -void test_spif_unaligned_erase() -{ - utest_printf("\nTest Unaligned Erase Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_addr_t addr = 0; - bd_size_t sector_erase_size = block_device.get_erase_size(addr); - unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1; - - utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); - - //unaligned start address - addr += 1; - err = block_device.erase(addr, sector_erase_size - 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //unaligned end address - addr = 0; - - err = block_device.erase(addr, 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, sector_erase_size + 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //erase size exceeds flash device size - err = block_device.erase(addr, block_device.size() + 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - // Valid erase - err = block_device.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_OK, err); - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - -static void test_spif_thread_job(void *block_device_ptr/*, int thread_num*/) -{ - static int thread_num = 0; - thread_num++; - SPIFBlockDevice *block_device = (SPIFBlockDevice *)block_device_ptr; - utest_printf("\n Thread %d Started \n", thread_num); - - bd_size_t block_size = block_device->get_erase_size(); - unsigned addrwidth = ceil(log(float(block_device->size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test((*block_device), block_size, write_block, read_block, addrwidth); - } - -end: - delete[] write_block; - delete[] read_block; -} - -void test_spif_multi_threads() -{ - utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - rtos::Thread spif_bd_thread[SPIF_TEST_NUM_OF_THREADS]; - - osStatus threadStatus; - int i_ind; - - for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) { - threadStatus = spif_bd_thread[i_ind].start(test_spif_thread_job, (void *)&block_device); - if (threadStatus != 0) { - utest_printf("\n Thread %d Start Failed!", i_ind + 1); - } - } - - for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) { - spif_bd_thread[i_ind].join(); - } - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - -// Test setup -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("Testing unaligned erase blocks", test_spif_unaligned_erase), - Case("Testing read write random blocks", test_spif_random_program_read_erase), - Case("Testing Multi Threads Erase Program Read", test_spif_multi_threads) -}; - -Specification specification(test_setup, cases); - -int main() -{ - mbed_trace_init(); - utest_printf("MAIN STARTS\n"); - return !Harness::run(specification); -} diff --git a/features/storage/TESTS/blockdevice/general_block_device/main.cpp b/features/storage/TESTS/blockdevice/general_block_device/main.cpp index fecfe1a0dbc..61edb9085e5 100644 --- a/features/storage/TESTS/blockdevice/general_block_device/main.cpp +++ b/features/storage/TESTS/blockdevice/general_block_device/main.cpp @@ -622,6 +622,65 @@ void test_program_read_small_data_sizes() delete buff_block_device; } + +void test_unaligned_erase_blocks() +{ + + utest_printf("\nTest Unaligned Erase Starts..\n"); + + TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); + + TEST_SKIP_UNLESS_MESSAGE(block_device->get_erase_value() != -1, "block device has no erase functionality."); + + bd_addr_t addr = 0; + bd_size_t sector_erase_size = block_device->get_erase_size(addr); + unsigned addrwidth = ceil(log(float(block_device->size() - 1)) / log(float(16))) + 1; + + utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); + + //unaligned start address + addr += 1; + int err = block_device->erase(addr, sector_erase_size - 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, sector_erase_size); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + //unaligned end address + addr = 0; + + err = block_device->erase(addr, 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, sector_erase_size + 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + //erase size exceeds flash device size + err = block_device->erase(addr, block_device->size() + 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + // Valid erase + err = block_device->erase(addr, sector_erase_size); + TEST_ASSERT_EQUAL(0, err); +} + +void test_deinit_bd() +{ + utest_printf("\nTest deinit block device.\n"); + + test_iteration++; + + TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); + + int err = block_device->deinit(); + TEST_ASSERT_EQUAL(0, err); + + block_device = NULL; +} + void test_get_type_functionality() { utest_printf("\nTest get blockdevice type..\n"); @@ -645,20 +704,6 @@ void test_get_type_functionality() #endif } -void test_deinit_bd() -{ - utest_printf("\nTest deinit block device.\n"); - - test_iteration++; - - TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); - - int err = block_device->deinit(); - TEST_ASSERT_EQUAL(0, err); - - block_device = NULL; -} - utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { greentea_case_failure_abort_handler(source, reason); @@ -678,6 +723,7 @@ template_case_t template_cases[] = { {"Testing contiguous erase, write and read", test_contiguous_erase_write_read, greentea_failure_handler}, {"Testing BlockDevice erase functionality", test_erase_functionality, greentea_failure_handler}, {"Testing program read small data sizes", test_program_read_small_data_sizes, greentea_failure_handler}, + {"Testing unaligned erase blocks", test_unaligned_erase_blocks, greentea_failure_handler}, {"Testing Deinit block device", test_deinit_bd, greentea_failure_handler}, };