Skip to content

Commit d4b9c96

Browse files
author
Amir Cohen
committed
Add unrebased changes
1 parent 72ba702 commit d4b9c96

File tree

1 file changed

+30
-10
lines changed
  • features/storage/TESTS/blockdevice/general_block_device

1 file changed

+30
-10
lines changed

features/storage/TESTS/blockdevice/general_block_device/main.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ using namespace utest::v1;
6464
#define TEST_BLOCK_COUNT 10
6565
#define TEST_ERROR_MASK 16
6666
#define TEST_NUM_OF_THREADS 5
67+
#define TEST_THREAD_STACK_SIZE 1024
6768

6869
uint8_t num_of_sectors = TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT;
6970
uint32_t sectors_addr[TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT] = {0};
@@ -350,10 +351,6 @@ void test_multi_threads()
350351

351352
TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found.");
352353

353-
char *dummy = new (std::nothrow) char[TEST_NUM_OF_THREADS * OS_STACK_SIZE];
354-
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test.\n");
355-
delete[] dummy;
356-
357354
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
358355
static const char *prefixes[] = {"", "k", "M", "G"};
359356
for (int i_ind = 3; i_ind >= 0; i_ind--) {
@@ -366,21 +363,44 @@ void test_multi_threads()
366363
}
367364
}
368365

369-
rtos::Thread bd_thread[TEST_NUM_OF_THREADS];
370-
371366
osStatus threadStatus;
372-
int i_ind;
367+
int i_ind, j_ind;
368+
char *dummy;
369+
370+
rtos::Thread **bd_thread = new (std::nothrow) rtos::Thread*[TEST_NUM_OF_THREADS];
371+
TEST_SKIP_UNLESS_MESSAGE((*bd_thread) != NULL, "not enough heap to run test.");
372+
memset(bd_thread, 0, TEST_NUM_OF_THREADS * sizeof(rtos::Thread *));
373373

374374
for (i_ind = 0; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
375-
threadStatus = bd_thread[i_ind].start(callback(test_thread_job));
375+
376+
bd_thread[i_ind] = new (std::nothrow) rtos::Thread((osPriority_t)((int)osPriorityNormal), TEST_THREAD_STACK_SIZE);
377+
dummy = new (std::nothrow) char[TEST_THREAD_STACK_SIZE];
378+
379+
if (!bd_thread[i_ind] || !dummy) {
380+
utest_printf("Not enough heap to run Thread %d !\n", i_ind + 1);
381+
break;
382+
}
383+
delete[] dummy;
384+
385+
threadStatus = bd_thread[i_ind]->start(callback(test_thread_job));
376386
if (threadStatus != 0) {
377387
utest_printf("Thread %d Start Failed!\n", i_ind + 1);
388+
break;
378389
}
379390
}
380391

381-
for (i_ind = 0; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
382-
bd_thread[i_ind].join();
392+
for (j_ind = 0; j_ind < i_ind; j_ind++) {
393+
bd_thread[j_ind]->join();
394+
}
395+
396+
if (bd_thread) {
397+
for (j_ind = 0; j_ind < i_ind; j_ind++) {
398+
delete bd_thread[j_ind];
399+
}
400+
401+
delete[] bd_thread;
383402
}
403+
384404
}
385405

386406
void test_erase_functionality()

0 commit comments

Comments
 (0)