@@ -64,6 +64,7 @@ using namespace utest::v1;
64
64
#define TEST_BLOCK_COUNT 10
65
65
#define TEST_ERROR_MASK 16
66
66
#define TEST_NUM_OF_THREADS 5
67
+ #define TEST_THREAD_STACK_SIZE 1024
67
68
68
69
uint8_t num_of_sectors = TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT;
69
70
uint32_t sectors_addr[TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT] = {0 };
@@ -350,10 +351,6 @@ void test_multi_threads()
350
351
351
352
TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
352
353
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
-
357
354
for (unsigned atr = 0 ; atr < sizeof (ATTRS) / sizeof (ATTRS[0 ]); atr++) {
358
355
static const char *prefixes[] = {" " , " k" , " M" , " G" };
359
356
for (int i_ind = 3 ; i_ind >= 0 ; i_ind--) {
@@ -366,21 +363,44 @@ void test_multi_threads()
366
363
}
367
364
}
368
365
369
- rtos::Thread bd_thread[TEST_NUM_OF_THREADS];
370
-
371
366
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 *));
373
373
374
374
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));
376
386
if (threadStatus != 0 ) {
377
387
utest_printf (" Thread %d Start Failed!\n " , i_ind + 1 );
388
+ break ;
378
389
}
379
390
}
380
391
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;
383
402
}
403
+
384
404
}
385
405
386
406
void test_erase_functionality ()
0 commit comments