@@ -51,7 +51,8 @@ using namespace utest::v1;
51
51
52
52
#define TEST_BLOCK_COUNT 10
53
53
#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
55
56
56
57
const struct {
57
58
const char *name;
@@ -331,10 +332,6 @@ void test_multi_threads()
331
332
332
333
TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
333
334
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
-
338
335
for (unsigned atr = 0 ; atr < sizeof (ATTRS) / sizeof (ATTRS[0 ]); atr++) {
339
336
static const char *prefixes[] = {" " , " k" , " M" , " G" };
340
337
for (int i_ind = 3 ; i_ind >= 0 ; i_ind--) {
@@ -347,21 +344,44 @@ void test_multi_threads()
347
344
}
348
345
}
349
346
350
- rtos::Thread bd_thread[TEST_NUM_OF_THREADS];
351
-
352
347
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 *));
354
354
355
355
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));
357
367
if (threadStatus != 0 ) {
358
368
utest_printf (" Thread %d Start Failed!\n " , i_ind + 1 );
369
+ break ;
359
370
}
360
371
}
361
372
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;
364
383
}
384
+
365
385
}
366
386
367
387
void test_erase_functionality ()
0 commit comments