Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip a few tests if not enough memory can be allocated for them #7465

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions TESTS/mbed_platform/error_handling/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void test_error_logging()
}

#define NUM_TEST_THREADS 5
#define THREAD_STACK_SIZE 512

//Error logger threads
void err_thread_func(mbed_error_status_t *error_status)
Expand All @@ -211,16 +212,20 @@ void err_thread_func(mbed_error_status_t *error_status)
*/
void test_error_logging_multithread()
{
uint8_t *dummy = new (std::nothrow) uint8_t[NUM_TEST_THREADS * THREAD_STACK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

mbed_error_ctx error_ctx = {0};
int i=0;
int i;
Thread *errThread[NUM_TEST_THREADS];
mbed_error_status_t error_status[NUM_TEST_THREADS] = {
MBED_ERROR_INVALID_ARGUMENT, MBED_ERROR_INVALID_DATA_DETECTED, MBED_ERROR_INVALID_FORMAT, MBED_ERROR_INVALID_SIZE, MBED_ERROR_INVALID_OPERATION
};


for(; i<NUM_TEST_THREADS; i++) {
errThread[i] = new Thread(osPriorityNormal1, 512, NULL, NULL);
for(i=0; i<NUM_TEST_THREADS; i++) {
errThread[i] = new Thread(osPriorityNormal1, THREAD_STACK_SIZE, NULL, NULL);
errThread[i]->start(callback(err_thread_func, &error_status[i]));
}
wait(2.0);
Expand Down
10 changes: 8 additions & 2 deletions features/TESTS/filesystem/buffered_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ static const bd_size_t num_blocks = 4;

void functionality_test()
{
uint8_t *dummy = new (std::nothrow) uint8_t[num_blocks * heap_erase_size + heap_prog_size];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

HeapBlockDevice heap_bd(num_blocks * heap_erase_size, heap_read_size, heap_prog_size, heap_erase_size);
BufferedBlockDevice bd(&heap_bd);

int err = bd.init();
TEST_ASSERT_EQUAL(0, err);

uint8_t *read_buf, *write_buf;
read_buf = new uint8_t[heap_prog_size];
write_buf = new uint8_t[heap_prog_size];
read_buf = new (std::nothrow) uint8_t[heap_prog_size];
TEST_SKIP_UNLESS_MESSAGE(read_buf, "Not enough memory for test");
write_buf = new (std::nothrow) uint8_t[heap_prog_size];
TEST_SKIP_UNLESS_MESSAGE(write_buf, "Not enough memory for test");

TEST_ASSERT_EQUAL(1, bd.get_read_size());
TEST_ASSERT_EQUAL(1, bd.get_program_size());
Expand Down
24 changes: 20 additions & 4 deletions features/TESTS/filesystem/heap_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const struct {

// Simple test that read/writes random set of blocks
void test_read_write() {
uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

HeapBlockDevice bd(TEST_BLOCK_DEVICE_SIZE, TEST_BLOCK_SIZE);

int err = bd.init();
Expand All @@ -63,12 +67,18 @@ void test_read_write() {
}
}

bd_size_t block_size = bd.get_erase_size();
uint8_t *write_block = new uint8_t[block_size];
uint8_t *read_block = new uint8_t[block_size];
uint8_t *error_mask = new uint8_t[TEST_ERROR_MASK];
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;

bd_size_t block_size = bd.get_erase_size();
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
uint8_t *error_mask = new (std::nothrow) uint8_t[TEST_ERROR_MASK];
if (!write_block || !read_block || !error_mask) {
printf("Not enough memory for test");
goto end;
}


for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
// Find a random block
bd_addr_t block = (rand()*block_size) % bd.size();
Expand Down Expand Up @@ -135,6 +145,12 @@ void test_read_write() {

err = bd.deinit();
TEST_ASSERT_EQUAL(0, err);

end:
delete[] write_block;
delete[] read_block;
delete[] error_mask;

}


Expand Down
33 changes: 26 additions & 7 deletions features/TESTS/filesystem/mbr_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
// Testing formatting of master boot record
void test_mbr_format()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

// Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
Expand Down Expand Up @@ -68,6 +72,10 @@ void test_mbr_format()
// Testing mbr attributes
void test_mbr_attr()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

// Load partitions
MBRBlockDevice part1(&bd, 1);
int err = part1.init();
Expand Down Expand Up @@ -123,18 +131,28 @@ void test_mbr_attr()
// Testing mbr read write
void test_mbr_read_write()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

int err;

// Load partitions
MBRBlockDevice part1(&bd, 1);
int err = part1.init();
err = part1.init();
TEST_ASSERT_EQUAL(0, err);

MBRBlockDevice part2(&bd, 2);
err = part2.init();
TEST_ASSERT_EQUAL(0, err);

// Test reading/writing the partitions
uint8_t *write_block = new uint8_t[BLOCK_SIZE];
uint8_t *read_block = new uint8_t[BLOCK_SIZE];
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) {
printf("Not enough memory for test");
goto end;
}

// Fill with random sequence
srand(1);
Expand Down Expand Up @@ -200,15 +218,16 @@ void test_mbr_read_write()
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

// Clean up
delete[] write_block;
delete[] read_block;

err = part1.deinit();
TEST_ASSERT_EQUAL(0, err);

err = part2.deinit();
TEST_ASSERT_EQUAL(0, err);

end:
// Clean up
delete[] write_block;
delete[] read_block;
}


Expand Down
84 changes: 62 additions & 22 deletions features/TESTS/filesystem/util_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,32 @@ using namespace utest::v1;

// Simple test which read/writes blocks on a sliced block device
void test_slicing() {
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

int err;

HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
uint8_t *write_block = new uint8_t[BLOCK_SIZE];
uint8_t *read_block = new uint8_t[BLOCK_SIZE];

// Test with first slice of block device
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);

int err = slice1.init();
// Test with first slice of block device
err = slice1.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_SIZE));
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());

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) {
printf("Not enough memory for test");
goto end;
}

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
Expand Down Expand Up @@ -85,8 +97,6 @@ void test_slicing() {


// Test with second slice of block device
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);

err = slice2.init();
TEST_ASSERT_EQUAL(0, err);

Expand Down Expand Up @@ -122,24 +132,38 @@ void test_slicing() {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

delete[] write_block;
delete[] read_block;
err = slice2.deinit();
TEST_ASSERT_EQUAL(0, err);

end:
delete[] write_block;
delete[] read_block;
}

// Simple test which read/writes blocks on a chain of block devices
void test_chaining() {
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

int err;

HeapBlockDevice bd1((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
uint8_t *write_block = new uint8_t[BLOCK_SIZE];
uint8_t *read_block = new uint8_t[BLOCK_SIZE];

// Test with chain of block device
BlockDevice *bds[] = {&bd1, &bd2};
ChainingBlockDevice chain(bds);

int err = chain.init();
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) {
printf("Not enough memory for test");
goto end;
}

err = chain.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
Expand Down Expand Up @@ -178,27 +202,41 @@ void test_chaining() {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

delete[] write_block;
delete[] read_block;
err = chain.deinit();
TEST_ASSERT_EQUAL(0, err);

end:
delete[] write_block;
delete[] read_block;
}

// Simple test which read/writes blocks on a chain of block devices
void test_profiling() {
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
uint8_t *write_block = new uint8_t[BLOCK_SIZE];
uint8_t *read_block = new uint8_t[BLOCK_SIZE];
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;

int err;
bd_size_t read_count, program_count, erase_count;

HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
// Test under profiling
ProfilingBlockDevice profiler(&bd);

int err = profiler.init();
err = profiler.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, profiler.get_erase_size());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, profiler.size());

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) {
printf("Not enough memory for test");
goto end;
}

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
Expand Down Expand Up @@ -231,18 +269,20 @@ void test_profiling() {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

delete[] write_block;
delete[] read_block;
err = profiler.deinit();
TEST_ASSERT_EQUAL(0, err);

// Check that profiled operations match expectations
bd_size_t read_count = profiler.get_read_count();
read_count = profiler.get_read_count();
TEST_ASSERT_EQUAL(BLOCK_SIZE, read_count);
bd_size_t program_count = profiler.get_program_count();
program_count = profiler.get_program_count();
TEST_ASSERT_EQUAL(BLOCK_SIZE, program_count);
bd_size_t erase_count = profiler.get_erase_count();
erase_count = profiler.get_erase_count();
TEST_ASSERT_EQUAL(BLOCK_SIZE, erase_count);

end:
delete[] write_block;
delete[] read_block;
}


Expand Down