Skip to content

Commit c10ad7f

Browse files
author
Cruz Monrreal
authored
Merge pull request #7212 from davidsaada/david_flashiap_test_small_flash
FlashIAP & NVStore tests: Skip test if overwriting code in flash
2 parents 96af5a4 + 876b5f7 commit c10ad7f

File tree

3 files changed

+24
-5
lines changed
  • TESTS/mbed_drivers/flashiap
  • features/nvstore/TESTS/nvstore/functionality
  • targets/TARGET_TOSHIBA/TARGET_TMPM46B/device/TOOLCHAIN_IAR

3 files changed

+24
-5
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
#include "utest/utest_serial.h"
2424
#include "unity/unity.h"
2525
#include "greentea-client/test_env.h"
26+
#include "FlashIAP.h"
27+
#include "unity.h"
2628
#include <algorithm>
2729

2830
#include "mbed.h"
2931

3032
using namespace utest::v1;
3133

34+
3235
void flashiap_init_test()
3336
{
3437
FlashIAP flash_device;
@@ -59,6 +62,9 @@ void flashiap_program_test()
5962
// the one before the last sector in the system
6063
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
6164
TEST_ASSERT_TRUE(address != 0UL);
65+
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_ROM_END, address);
66+
TEST_SKIP_UNLESS_MESSAGE(address >= FLASHIAP_ROM_END, "Test skipped. Test region overlaps code.");
67+
6268
ret = flash_device.erase(address, sector_size);
6369
TEST_ASSERT_EQUAL_INT32(0, ret);
6470

@@ -93,6 +99,7 @@ void flashiap_program_test()
9399
TEST_ASSERT_EQUAL_INT32(0, ret);
94100
}
95101

102+
96103
void flashiap_cross_sector_program_test()
97104
{
98105
FlashIAP flash_device;
@@ -111,6 +118,7 @@ void flashiap_cross_sector_program_test()
111118
agg_size += sector_size;
112119
address -= sector_size;
113120
}
121+
TEST_SKIP_UNLESS_MESSAGE(address >= FLASHIAP_ROM_END, "Test skipped. Test region overlaps code.");
114122
ret = flash_device.erase(address, agg_size);
115123
TEST_ASSERT_EQUAL_INT32(0, ret);
116124

@@ -166,6 +174,7 @@ void flashiap_program_error_test()
166174
TEST_ASSERT_TRUE(address != 0UL);
167175

168176
// unaligned address
177+
TEST_SKIP_UNLESS_MESSAGE(address >= FLASHIAP_ROM_END, "Test skipped. Test region overlaps code.");
169178
ret = flash_device.erase(address + 1, sector_size);
170179
TEST_ASSERT_EQUAL_INT32(-1, ret);
171180
if (flash_device.get_page_size() > 1) {
@@ -185,7 +194,7 @@ void flashiap_timing_test()
185194
uint32_t ret = flash_device.init();
186195
TEST_ASSERT_EQUAL_INT32(0, ret);
187196
mbed::Timer timer;
188-
int num_write_sizes;
197+
unsigned int num_write_sizes;
189198
unsigned int curr_time, byte_usec_ratio;
190199
unsigned int avg_erase_time = 0;
191200
unsigned int max_erase_time = 0, min_erase_time = (unsigned int) -1;
@@ -222,7 +231,7 @@ void flashiap_timing_test()
222231
uint32_t address = base_address;
223232
unsigned int avg_write_time = 0;
224233
unsigned int max_write_time = 0, min_write_time = (unsigned int) -1;
225-
int num_writes;
234+
unsigned int num_writes;
226235
for (num_writes = 0; num_writes < max_writes; num_writes++) {
227236
if ((address + write_size) > end_address) {
228237
break;

features/nvstore/TESTS/nvstore/functionality/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static const int race_test_data_size = 128;
6666
static const int race_test_min_stack_size = 768;
6767
static const int race_test_max_stack_size = 1024;
6868

69+
static bool nvstore_overlaps_code = false;
70+
6971
static void gen_random(uint8_t *s, int len)
7072
{
7173
for (int i = 0; i < len; ++i) {
@@ -91,6 +93,10 @@ static void nvstore_basic_functionality_test()
9193
size_t area_size;
9294
nvstore.get_area_params(area, area_address, area_size);
9395
printf("Area %d: address 0x%08lx, size %d (0x%x)\n", area, area_address, area_size, area_size);
96+
if (area_address < FLASHIAP_ROM_END) {
97+
nvstore_overlaps_code = true;
98+
}
99+
TEST_SKIP_UNLESS_MESSAGE(!nvstore_overlaps_code, "Test skipped. NVStore region overlaps code.");
94100
}
95101

96102
gen_random(nvstore_testing_buf_set, basic_func_max_data_size);
@@ -485,6 +491,8 @@ static void nvstore_multi_thread_test()
485491

486492
NVStore &nvstore = NVStore::get_instance();
487493

494+
TEST_SKIP_UNLESS_MESSAGE(!nvstore_overlaps_code, "Test skipped. NVStore region overlaps code.");
495+
488496
ret = nvstore.reset();
489497
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, ret);
490498

@@ -574,6 +582,8 @@ static void nvstore_race_test()
574582
int num_threads = race_test_num_threads;
575583
uint16_t actual_len_bytes;
576584

585+
TEST_SKIP_UNLESS_MESSAGE(!nvstore_overlaps_code, "Test skipped. NVStore region overlaps code.");
586+
577587
NVStore &nvstore = NVStore::get_instance();
578588

579589
ret = nvstore.reset();

targets/TARGET_TOSHIBA/TARGET_TMPM46B/device/TOOLCHAIN_IAR/tmpm46bf10fg.icf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFED
2525
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
2626
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
2727

28-
define block FLASH_CODE_ROM {section FLASH_ROM_init object flash_api.o, section .text_init object tmpm46b_fc.o};
29-
define block FLASH_CODE_RAM {section FLASH_ROM object flash_api.o, section .text object tmpm46b_fc.o};
28+
define block FLASH_CODE_ROM {section FLASH_ROM_init object flash_api.o};
29+
define block FLASH_CODE_RAM {section FLASH_ROM object flash_api.o};
3030

3131
initialize by copy { readwrite };
32-
initialize manually { section FLASH_ROM object flash_api.o, section .text object tmpm46b_fc.o};
32+
initialize manually { section FLASH_ROM object flash_api.o };
3333
do not initialize { section .noinit };
3434

3535
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

0 commit comments

Comments
 (0)