@@ -51,7 +51,8 @@ using namespace utest::v1;
5151
5252#define TEST_BLOCK_COUNT 10
5353#define TEST_ERROR_MASK 16
54- #define TEST_NUM_OF_THREADS 5
54+ #define TEST_NUM_OF_THREADS 4
55+ #define TEST_THREAD_STACK_SIZE 1024
5556
5657const struct {
5758 const char *name;
@@ -331,10 +332,6 @@ void test_multi_threads()
331332
332333 TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
333334
334- char *dummy = new (std::nothrow) char [TEST_NUM_OF_THREADS * OS_STACK_SIZE];
335- TEST_SKIP_UNLESS_MESSAGE (dummy, " Not enough memory for test.\n " );
336- delete[] dummy;
337-
338335 for (unsigned atr = 0 ; atr < sizeof (ATTRS) / sizeof (ATTRS[0 ]); atr++) {
339336 static const char *prefixes[] = {" " , " k" , " M" , " G" };
340337 for (int i_ind = 3 ; i_ind >= 0 ; i_ind--) {
@@ -347,21 +344,44 @@ void test_multi_threads()
347344 }
348345 }
349346
350- rtos::Thread bd_thread[TEST_NUM_OF_THREADS];
351-
352347 osStatus threadStatus;
353- int i_ind;
348+ int i_ind, j_ind;
349+ char *dummy;
350+
351+ rtos::Thread **bd_thread = new (std::nothrow) rtos::Thread*[TEST_NUM_OF_THREADS];
352+ TEST_SKIP_UNLESS_MESSAGE ((*bd_thread) != NULL , " not enough heap to run test." );
353+ memset (bd_thread, 0 , TEST_NUM_OF_THREADS * sizeof (rtos::Thread *));
354354
355355 for (i_ind = 0 ; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
356- threadStatus = bd_thread[i_ind].start (callback (test_thread_job, (void *)block_device));
356+
357+ bd_thread[i_ind] = new (std::nothrow) rtos::Thread ((osPriority_t)((int )osPriorityNormal), TEST_THREAD_STACK_SIZE);
358+ dummy = new (std::nothrow) char [TEST_THREAD_STACK_SIZE];
359+
360+ if (!bd_thread[i_ind] || !dummy) {
361+ utest_printf (" Not enough heap to run Thread %d !\n " , i_ind + 1 );
362+ break ;
363+ }
364+ delete[] dummy;
365+
366+ threadStatus = bd_thread[i_ind]->start (callback (test_thread_job, (void *)block_device));
357367 if (threadStatus != 0 ) {
358368 utest_printf (" Thread %d Start Failed!\n " , i_ind + 1 );
369+ break ;
359370 }
360371 }
361372
362- for (i_ind = 0 ; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
363- bd_thread[i_ind].join ();
373+ for (j_ind = 0 ; j_ind < i_ind; j_ind++) {
374+ bd_thread[j_ind]->join ();
375+ }
376+
377+ if (bd_thread) {
378+ for (j_ind = 0 ; j_ind < i_ind; j_ind++) {
379+ delete bd_thread[j_ind];
380+ }
381+
382+ delete[] bd_thread;
364383 }
384+
365385}
366386
367387void test_erase_functionality ()
0 commit comments