@@ -328,6 +328,9 @@ void test_mem_domain_migration(void)
328
328
printk ("migrate to new domain\n" );
329
329
k_mem_domain_add_thread (& test_domain , & child_thread );
330
330
331
+ /**TESTPOINT: add to existing domain will do nothing */
332
+ k_mem_domain_add_thread (& test_domain , & child_thread );
333
+
331
334
/* set spin_done so the child thread completes */
332
335
printk ("set test completion\n" );
333
336
spin_done = true;
@@ -346,7 +349,7 @@ void test_mem_domain_migration(void)
346
349
* - System testing
347
350
*
348
351
* Prerequisite Conditions:
349
- * - N/A
352
+ * - N/A
350
353
*
351
354
* Input Specifications:
352
355
* - N/A
@@ -379,3 +382,77 @@ void test_mem_part_overlap(void)
379
382
380
383
k_mem_domain_add_partition (& test_domain , & overlap_part );
381
384
}
385
+
386
+
387
+ extern struct k_spinlock z_mem_domain_lock ;
388
+
389
+ static ZTEST_BMEM bool need_recover_spinlock ;
390
+
391
+ static struct k_mem_domain test_domain_fail ;
392
+
393
+ void post_fatal_error_handler (unsigned int reason , const z_arch_esf_t * pEsf )
394
+ {
395
+ if (need_recover_spinlock ) {
396
+ k_spin_release (& z_mem_domain_lock );
397
+
398
+ need_recover_spinlock = false;
399
+ }
400
+ }
401
+
402
+ #if defined(CONFIG_ASSERT )
403
+ static volatile uint8_t __aligned (MEM_REGION_ALLOC ) misc_buf [MEM_REGION_ALLOC ];
404
+ K_MEM_PARTITION_DEFINE (find_no_part , misc_buf , sizeof (misc_buf ),
405
+ K_MEM_PARTITION_P_RO_U_RO );
406
+
407
+ /**
408
+ * @brief Test error case of removing memory partition fail
409
+ *
410
+ * @details Try to remove a partition not in the domain will cause
411
+ * assertion, then triggher an expected fatal error.
412
+ * And while the fatal error happened, the memory domain spinlock
413
+ * is held, we need to release them to make other follow test case.
414
+ *
415
+ * @ingroup kernel_memprotect_tests
416
+ */
417
+ void test_mem_domain_remove_part_fail (void )
418
+ {
419
+ struct k_mem_partition * no_parts = & find_no_part ;
420
+
421
+ need_recover_spinlock = true;
422
+ set_fault_valid (true);
423
+ k_mem_domain_remove_partition (& test_domain , no_parts );
424
+ }
425
+ #else
426
+ void test_mem_domain_remove_part_fail (void )
427
+ {
428
+ ztest_test_skip ();
429
+ }
430
+ #endif
431
+
432
+ /**
433
+ * @brief Test error case of initializing memory domain fail
434
+ *
435
+ * @details Try to initialize a domain with invalid partition, then see
436
+ * if an expected fatal error happens.
437
+ * And while the fatal error happened, the memory domain spinlock
438
+ * is held, we need to release them to make other follow test case.
439
+ *
440
+ * @ingroup kernel_memprotect_tests
441
+ */
442
+ void test_mem_domain_init_fail (void )
443
+ {
444
+ struct k_mem_partition * no_parts [] = {& ro_part , 0 };
445
+
446
+ /* init another domain fail, expected fault happened */
447
+ need_recover_spinlock = true;
448
+ set_fault_valid (true);
449
+ k_mem_domain_init (& test_domain_fail , ARRAY_SIZE (no_parts ),
450
+ no_parts );
451
+
452
+ /* For acrh which not CONFIG_ARCH_MEM_DOMAIN_DATA, if assert is off,
453
+ * it will reach here.
454
+ */
455
+ #if !defined(CONFIG_ASSERT ) && defined(CONFIG_ARCH_MEM_DOMAIN_DATA )
456
+ zassert_unreachable ("should not be here" );
457
+ #endif
458
+ }
0 commit comments