From 8ecce14dad97097f2fbaca11d3f519e8cc10b424 Mon Sep 17 00:00:00 2001 From: RAJKUMAR KANAGARAJ Date: Wed, 6 Nov 2019 04:49:19 -0800 Subject: [PATCH 1/2] Skip Bare metal green tea test for storage related components or the components test cases which is based on RTOS --- .../blockdevice/COMPONENT_SD/SDBlockDevice.cpp | 2 ++ .../TESTS/filesystem/parallel/main.cpp | 4 ++++ .../TESTS/device_key/functionality/main.cpp | 8 ++++---- .../blockdevice/general_block_device/main.cpp | 7 ++++++- .../kvstore/filesystemstore_tests/main.cpp | 4 ++++ .../kvstore/general_tests_phase_1/main.cpp | 4 ++++ .../kvstore/general_tests_phase_2/main.cpp | 4 ++++ .../storage/TESTS/kvstore/static_tests/main.cpp | 17 ++++++++++++++--- .../TESTS/nvstore/functionality/main.cpp | 8 ++++---- 9 files changed, 46 insertions(+), 12 deletions(-) diff --git a/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp b/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp index 769fcfbbe36..a0082b3ce15 100644 --- a/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp +++ b/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp @@ -872,7 +872,9 @@ uint32_t SDBlockDevice::_go_idle_state() if (R1_IDLE_STATE == response) { break; } +#if defined(MBED_CONF_RTOS_PRESENT) rtos::ThisThread::sleep_for(1); +#endif } return response; } diff --git a/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp b/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp index 39e1aa44768..b51d7d1fe35 100644 --- a/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp +++ b/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if !defined(MBED_CONF_RTOS_PRESENT) +#error [NOT_SUPPORTED] filesystem test cases requires RTOS to run +#else #include "mbed.h" #include "greentea-client/test_env.h" @@ -207,3 +210,4 @@ int main() { return !Harness::run(specification); } +#endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/features/device_key/TESTS/device_key/functionality/main.cpp b/features/device_key/TESTS/device_key/functionality/main.cpp index 22bd47d41d3..959fdea7544 100644 --- a/features/device_key/TESTS/device_key/functionality/main.cpp +++ b/features/device_key/TESTS/device_key/functionality/main.cpp @@ -14,6 +14,10 @@ * limitations under the License. */ +#if !DEVICEKEY_ENABLED +#error [NOT_SUPPORTED] DeviceKey needs to be enabled for this test +#else + #include "DeviceKey.h" #include "mbedtls/config.h" #include "utest/utest.h" @@ -28,10 +32,6 @@ using namespace utest::v1; using namespace mbed; -#if !DEVICEKEY_ENABLED -#error [NOT_SUPPORTED] DeviceKey needs to be enabled for this test -#else - #define MSG_VALUE_DUMMY "0" #define MSG_VALUE_LEN 32 #define MSG_KEY_LEN 32 diff --git a/features/storage/TESTS/blockdevice/general_block_device/main.cpp b/features/storage/TESTS/blockdevice/general_block_device/main.cpp index cfe324780b7..a114126159e 100644 --- a/features/storage/TESTS/blockdevice/general_block_device/main.cpp +++ b/features/storage/TESTS/blockdevice/general_block_device/main.cpp @@ -310,6 +310,7 @@ void test_random_program_read_erase() static void test_thread_job() { +#if defined(MBED_CONF_RTOS_PRESENT) static int thread_num = 0; _mutex->lock(); int block_num = thread_num++ % TEST_NUM_OF_THREADS; @@ -335,10 +336,12 @@ static void test_thread_job() end: delete[] read_block; delete[] write_block; +#endif } void test_multi_threads() { +#if defined(MBED_CONF_RTOS_PRESENT) utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); @@ -392,7 +395,7 @@ void test_multi_threads() delete[] bd_thread; } - +#endif } void test_erase_functionality() @@ -727,7 +730,9 @@ typedef struct { template_case_t template_cases[] = { {"Testing Init block device", test_init_bd, greentea_failure_handler}, {"Testing read write random blocks", test_random_program_read_erase, greentea_failure_handler}, +#if defined(MBED_CONF_RTOS_PRESENT) {"Testing multi threads erase program read", test_multi_threads, greentea_failure_handler}, +#endif {"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}, diff --git a/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp b/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp index da9e6e51485..cd16d5791aa 100644 --- a/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp +++ b/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp @@ -15,6 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if !defined(MBED_CONF_RTOS_PRESENT) +#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#else #include "rtos/Thread.h" #include "mbed_trace.h" @@ -522,3 +525,4 @@ int main() } #endif // !defined(TARGET_K64F) && !defined(TARGET_ARM_FM) +#endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp b/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp index 1568693d3e2..58a40d10471 100644 --- a/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp +++ b/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp @@ -14,6 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if !defined(MBED_CONF_RTOS_PRESENT) +#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#else #include "SecureStore.h" #include "TDBStore.h" @@ -857,3 +860,4 @@ int main() } #endif // !defined(TARGET_K64F) && !defined(TARGET_ARM_FM) +#endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp b/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp index aa8105e8aac..5cb5cea3b15 100644 --- a/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp +++ b/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp @@ -14,6 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if !defined(MBED_CONF_RTOS_PRESENT) +#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#else #include "SecureStore.h" #include "TDBStore.h" @@ -860,3 +863,4 @@ int main() } #endif // !defined(TARGET_K64F) && !defined(TARGET_ARM_FM) +#endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/features/storage/TESTS/kvstore/static_tests/main.cpp b/features/storage/TESTS/kvstore/static_tests/main.cpp index b6f60cd1b74..f6011735420 100644 --- a/features/storage/TESTS/kvstore/static_tests/main.cpp +++ b/features/storage/TESTS/kvstore/static_tests/main.cpp @@ -15,7 +15,9 @@ * limitations under the License. */ +#if defined(MBED_CONF_RTOS_PRESENT) #include "Thread.h" +#endif #include "mbed_error.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -33,10 +35,10 @@ static size_t actual_size = 0; static const size_t buffer_size = 20; static const int num_of_threads = 3; static const char num_of_keys = 3; - +#if defined(MBED_CONF_RTOS_PRESENT) /* Forked 3 threads plus misc, so minimum (4 * OS_STACK_SIZE) heap are required. */ static const int heap_alloc_threshold_size = 4 * OS_STACK_SIZE; - +#endif static const char *keys[] = {"key1", "key2", "key3"}; static int init_res = MBED_ERROR_NOT_READY; @@ -67,6 +69,7 @@ static void parse_default_kv() //init the blockdevice static void kvstore_init() { +#if defined(MBED_CONF_RTOS_PRESENT) uint8_t *dummy = new (std::nothrow) uint8_t[heap_alloc_threshold_size]; TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough heap to run test"); delete[] dummy; @@ -76,6 +79,7 @@ static void kvstore_init() init_res = kv_reset(def_kv); TEST_SKIP_UNLESS_MESSAGE(init_res != MBED_ERROR_UNSUPPORTED, "Unsupported configuration. Test skipped."); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, init_res); +#endif } /*----------------set()------------------*/ @@ -144,6 +148,7 @@ static void test_thread_set(char *th_key) //get several keys multithreaded static void set_several_keys_multithreaded() { +#if defined(MBED_CONF_RTOS_PRESENT) TEST_SKIP_UNLESS(!init_res); rtos::Thread kvstore_thread[num_of_threads]; osStatus threadStatus; @@ -169,6 +174,7 @@ static void set_several_keys_multithreaded() res = kv_remove(keys[i]); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); } +#endif } //set key "write once" and try to set it again @@ -464,6 +470,7 @@ static void test_thread_get(const void *th_key) //get several keys multithreaded static void get_several_keys_multithreaded() { +#if defined(MBED_CONF_RTOS_PRESENT) TEST_SKIP_UNLESS(!init_res); int i = 0, res = 0; rtos::Thread kvstore_thread[num_of_threads]; @@ -489,6 +496,7 @@ static void get_several_keys_multithreaded() res = kv_remove(keys[i]); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); } +#endif } /*----------------remove()------------------*/ @@ -924,7 +932,9 @@ Case cases[] = { Case("set_buffer_null_size_not_zero", set_buffer_null_size_not_zero, greentea_failure_handler), Case("set_buffer_size_is_zero", set_buffer_size_is_zero, greentea_failure_handler), Case("set_same_key_several_time", set_same_key_several_time, greentea_failure_handler), +#if defined(MBED_CONF_RTOS_PRESENT) Case("set_several_keys_multithreaded", set_several_keys_multithreaded, greentea_failure_handler), +#endif Case("set_write_once_flag_try_set_twice", set_write_once_flag_try_set_twice, greentea_failure_handler), Case("set_write_once_flag_try_remove", set_write_once_flag_try_remove, greentea_failure_handler), Case("set_key_value_one_byte_size", set_key_value_one_byte_size, greentea_failure_handler), @@ -944,8 +954,9 @@ Case cases[] = { Case("get_non_existing_key", get_non_existing_key, greentea_failure_handler), Case("get_removed_key", get_removed_key, greentea_failure_handler), Case("get_key_that_was_set_twice", get_key_that_was_set_twice, greentea_failure_handler), +#if defined(MBED_CONF_RTOS_PRESENT) Case("get_several_keys_multithreaded", get_several_keys_multithreaded, greentea_failure_handler), - +#endif Case("remove_key_null", remove_key_null, greentea_failure_handler), Case("remove_key_length_exceeds_max", remove_key_length_exceeds_max, greentea_failure_handler), Case("remove_non_existing_key", remove_non_existing_key, greentea_failure_handler), diff --git a/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp b/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp index 5bd263bd877..8ac5eeff819 100644 --- a/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp +++ b/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp @@ -14,6 +14,10 @@ * limitations under the License. */ +#if !NVSTORE_ENABLED +#error [NOT_SUPPORTED] NVSTORE needs to be enabled for this test +#else + #include "nvstore.h" #ifdef MBED_CONF_RTOS_PRESENT #include "Thread.h" @@ -27,10 +31,6 @@ #include #include -#if !NVSTORE_ENABLED -#error [NOT_SUPPORTED] NVSTORE needs to be enabled for this test -#else - using namespace utest::v1; static const uint16_t max_test_keys = 20; From d8e2dd5b4715ccaf3b1f4341183f3feeb4068ca5 Mon Sep 17 00:00:00 2001 From: RAJKUMAR KANAGARAJ Date: Fri, 8 Nov 2019 09:04:32 -0800 Subject: [PATCH 2/2] Incorporated the review comments --- .../blockdevice/COMPONENT_SD/SDBlockDevice.cpp | 2 -- .../TESTS/filesystem/parallel/main.cpp | 2 +- .../TESTS/device_key/functionality/main.cpp | 8 ++++---- .../blockdevice/general_block_device/main.cpp | 6 ++---- .../kvstore/filesystemstore_tests/main.cpp | 2 +- .../kvstore/general_tests_phase_1/main.cpp | 2 +- .../kvstore/general_tests_phase_2/main.cpp | 2 +- .../TESTS/kvstore/static_tests/main.cpp | 5 +++-- .../TESTS/nvstore/functionality/main.cpp | 18 ++++++++---------- 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp b/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp index a0082b3ce15..769fcfbbe36 100644 --- a/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp +++ b/components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp @@ -872,9 +872,7 @@ uint32_t SDBlockDevice::_go_idle_state() if (R1_IDLE_STATE == response) { break; } -#if defined(MBED_CONF_RTOS_PRESENT) rtos::ThisThread::sleep_for(1); -#endif } return response; } diff --git a/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp b/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp index b51d7d1fe35..10b1e94c35a 100644 --- a/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp +++ b/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/parallel/main.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ #if !defined(MBED_CONF_RTOS_PRESENT) -#error [NOT_SUPPORTED] filesystem test cases requires RTOS to run +#error [NOT_SUPPORTED] filesystem test cases require a RTOS to run #else #include "mbed.h" diff --git a/features/device_key/TESTS/device_key/functionality/main.cpp b/features/device_key/TESTS/device_key/functionality/main.cpp index 959fdea7544..22bd47d41d3 100644 --- a/features/device_key/TESTS/device_key/functionality/main.cpp +++ b/features/device_key/TESTS/device_key/functionality/main.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -#if !DEVICEKEY_ENABLED -#error [NOT_SUPPORTED] DeviceKey needs to be enabled for this test -#else - #include "DeviceKey.h" #include "mbedtls/config.h" #include "utest/utest.h" @@ -32,6 +28,10 @@ using namespace utest::v1; using namespace mbed; +#if !DEVICEKEY_ENABLED +#error [NOT_SUPPORTED] DeviceKey needs to be enabled for this test +#else + #define MSG_VALUE_DUMMY "0" #define MSG_VALUE_LEN 32 #define MSG_KEY_LEN 32 diff --git a/features/storage/TESTS/blockdevice/general_block_device/main.cpp b/features/storage/TESTS/blockdevice/general_block_device/main.cpp index a114126159e..00bdf90a81a 100644 --- a/features/storage/TESTS/blockdevice/general_block_device/main.cpp +++ b/features/storage/TESTS/blockdevice/general_block_device/main.cpp @@ -308,9 +308,9 @@ void test_random_program_read_erase() delete[] write_block; } +#if defined(MBED_CONF_RTOS_PRESENT) static void test_thread_job() { -#if defined(MBED_CONF_RTOS_PRESENT) static int thread_num = 0; _mutex->lock(); int block_num = thread_num++ % TEST_NUM_OF_THREADS; @@ -336,12 +336,10 @@ static void test_thread_job() end: delete[] read_block; delete[] write_block; -#endif } void test_multi_threads() { -#if defined(MBED_CONF_RTOS_PRESENT) utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); @@ -395,8 +393,8 @@ void test_multi_threads() delete[] bd_thread; } -#endif } +#endif void test_erase_functionality() { diff --git a/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp b/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp index cd16d5791aa..d8a75286cd3 100644 --- a/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp +++ b/features/storage/TESTS/kvstore/filesystemstore_tests/main.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ #if !defined(MBED_CONF_RTOS_PRESENT) -#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#error [NOT_SUPPORTED] Kvstore API test cases require a RTOS to run #else #include "rtos/Thread.h" diff --git a/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp b/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp index 58a40d10471..7bbbfb6130b 100644 --- a/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp +++ b/features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ #if !defined(MBED_CONF_RTOS_PRESENT) -#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#error [NOT_SUPPORTED] Kvstore API test cases require a RTOS to run #else #include "SecureStore.h" diff --git a/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp b/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp index 5cb5cea3b15..33aa6c5849f 100644 --- a/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp +++ b/features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ #if !defined(MBED_CONF_RTOS_PRESENT) -#error [NOT_SUPPORTED] Kvstore API test cases requires RTOS to run +#error [NOT_SUPPORTED] Kvstore API test cases require a RTOS to run #else #include "SecureStore.h" diff --git a/features/storage/TESTS/kvstore/static_tests/main.cpp b/features/storage/TESTS/kvstore/static_tests/main.cpp index f6011735420..b3bfce83460 100644 --- a/features/storage/TESTS/kvstore/static_tests/main.cpp +++ b/features/storage/TESTS/kvstore/static_tests/main.cpp @@ -38,6 +38,9 @@ static const char num_of_keys = 3; #if defined(MBED_CONF_RTOS_PRESENT) /* Forked 3 threads plus misc, so minimum (4 * OS_STACK_SIZE) heap are required. */ static const int heap_alloc_threshold_size = 4 * OS_STACK_SIZE; +#else +/* Bare metal does not require memory for threads, so use just minimum for test */ +static const int heap_alloc_threshold_size = MBED_CONF_TARGET_BOOT_STACK_SIZE; #endif static const char *keys[] = {"key1", "key2", "key3"}; @@ -69,7 +72,6 @@ static void parse_default_kv() //init the blockdevice static void kvstore_init() { -#if defined(MBED_CONF_RTOS_PRESENT) uint8_t *dummy = new (std::nothrow) uint8_t[heap_alloc_threshold_size]; TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough heap to run test"); delete[] dummy; @@ -79,7 +81,6 @@ static void kvstore_init() init_res = kv_reset(def_kv); TEST_SKIP_UNLESS_MESSAGE(init_res != MBED_ERROR_UNSUPPORTED, "Unsupported configuration. Test skipped."); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, init_res); -#endif } /*----------------set()------------------*/ diff --git a/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp b/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp index 8ac5eeff819..6d9ba4b5303 100644 --- a/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp +++ b/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp @@ -14,9 +14,6 @@ * limitations under the License. */ -#if !NVSTORE_ENABLED -#error [NOT_SUPPORTED] NVSTORE needs to be enabled for this test -#else #include "nvstore.h" #ifdef MBED_CONF_RTOS_PRESENT @@ -31,6 +28,10 @@ #include #include +#if !NVSTORE_ENABLED +#error [NOT_SUPPORTED] NVSTORE needs to be enabled for this test +#else + using namespace utest::v1; static const uint16_t max_test_keys = 20; @@ -396,6 +397,7 @@ static void nvstore_basic_functionality_test() delete[] nvstore_testing_buf_get; } +#ifdef MBED_CONF_RTOS_PRESENT static void thread_test_check_key(uint16_t key) { uint8_t get_buff[thr_test_max_data_size]; @@ -422,7 +424,6 @@ static void thread_test_check_key(uint16_t key) } -#ifdef MBED_CONF_RTOS_PRESENT static void thread_test_worker() { int ret; @@ -444,11 +445,9 @@ static void thread_test_worker() wait_ms(1); } } -#endif static void nvstore_multi_thread_test() { -#ifdef MBED_CONF_RTOS_PRESENT int i, result; uint16_t size; uint16_t key; @@ -562,8 +561,6 @@ static void nvstore_multi_thread_test() } nvstore.reset(); - -#endif } @@ -578,7 +575,6 @@ static void race_test_worker(void *buf) static void nvstore_race_test() { -#ifdef MBED_CONF_RTOS_PRESENT int i; uint16_t initial_buf_size; int ret; @@ -668,8 +664,8 @@ static void nvstore_race_test() delete[] buffs[i]; } delete[] get_buff; -#endif } +#endif @@ -681,8 +677,10 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai Case cases[] = { Case("NVStore: Basic functionality", nvstore_basic_functionality_test, greentea_failure_handler), +#if defined(MBED_CONF_RTOS_PRESENT) Case("NVStore: Race test", nvstore_race_test, greentea_failure_handler), Case("NVStore: Multiple thread test", nvstore_multi_thread_test, greentea_failure_handler), +#endif }; utest::v1::status_t greentea_test_setup(const size_t number_of_cases)