tests: kernel/userspace: skip other thread tests if needed

With memory domain enabled, all threads within the same domain
have access to each other threads' stacks, especially with
CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API enabled (as it is
expected behavior). So update the conditions to skip both
tests to read and write to other threads' stacks.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c
index 81a039d..edf5e8c 100644
--- a/tests/kernel/mem_protect/userspace/src/main.c
+++ b/tests/kernel/mem_protect/userspace/src/main.c
@@ -553,9 +553,17 @@
 	/* Try to read from another thread's stack. */
 	unsigned int val;
 
-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) || defined(CONFIG_MPU)
+#if defined(CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API)
+	/* With memory domain enabled, all threads within the same domain
+	 * have access to each other threads' stacks, especially with
+	 * CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API=y (as it is expected
+	 * behavior). The access would not fault which the test expects.
+	 * So skip this test.
+	 */
 	ztest_test_skip();
 #endif
+#endif
 	k_thread_create(&test_thread, test_stack, STACKSIZE,
 			uthread_read_body, &val, NULL, NULL,
 			-1, K_USER | K_INHERIT_PERMS,
@@ -575,9 +583,17 @@
 	/* Try to write to another thread's stack. */
 	unsigned int val;
 
-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) || defined(CONFIG_MPU)
+#if defined(CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API)
+	/* With memory domain enabled, all threads within the same domain
+	 * have access to each other threads' stacks, especially with
+	 * CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API=y (as it is expected
+	 * behavior). The access would not fault which the test expects.
+	 * So skip this test.
+	 */
 	ztest_test_skip();
 #endif
+#endif
 	k_thread_create(&test_thread, test_stack, STACKSIZE,
 			uthread_write_body, &val, NULL, NULL,
 			-1, K_USER | K_INHERIT_PERMS,