tests: drivers: memc: Rework S(D)RAM test with ztest

* Reworked the stm32 SDRAM test to be more generic
* Added SRAM entries
* Moved to new ztest API

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
diff --git a/tests/drivers/memc/stm32_sdram/CMakeLists.txt b/tests/drivers/memc/ram/CMakeLists.txt
similarity index 100%
rename from tests/drivers/memc/stm32_sdram/CMakeLists.txt
rename to tests/drivers/memc/ram/CMakeLists.txt
diff --git a/tests/drivers/memc/ram/prj.conf b/tests/drivers/memc/ram/prj.conf
new file mode 100644
index 0000000..f4133ef
--- /dev/null
+++ b/tests/drivers/memc/ram/prj.conf
@@ -0,0 +1,3 @@
+CONFIG_ZTEST=y
+CONFIG_MEMC=y
+CONFIG_ZTEST_NEW_API=y
diff --git a/tests/drivers/memc/ram/src/main.c b/tests/drivers/memc/ram/src/main.c
new file mode 100644
index 0000000..c067df1
--- /dev/null
+++ b/tests/drivers/memc/ram/src/main.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2020, Teslabs Engineering S.L.
+ * Copyright (c) 2022, Basalte bv
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/linker/devicetree_regions.h>
+#include <zephyr/zephyr.h>
+#include <zephyr/ztest.h>
+
+/** Buffer size. */
+#define BUF_SIZE 64U
+#define BUF_DEF(label) static uint32_t buf_##label[BUF_SIZE]			\
+	Z_GENERIC_SECTION(LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(label)))
+
+/**
+ * @brief Helper function to test RAM r/w.
+ *
+ * @param mem RAM memory location to be tested.
+ */
+static void test_ram_rw(uint32_t *mem)
+{
+	/* fill memory with number range (0, BUF_SIZE - 1) */
+	for (size_t i = 0U; i < BUF_SIZE; i++) {
+		mem[i] = i;
+	}
+
+	/* check that memory contains written range */
+	for (size_t i = 0U; i < BUF_SIZE; i++) {
+		zassert_equal(mem[i], i, "Unexpected content");
+	}
+}
+
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay)
+BUF_DEF(sdram1);
+#endif
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay)
+BUF_DEF(sdram2);
+#endif
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram1), okay)
+BUF_DEF(sram1);
+#endif
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram2), okay)
+BUF_DEF(sram2);
+#endif
+
+ZTEST_SUITE(test_ram, NULL, NULL, NULL, NULL, NULL);
+
+ZTEST(test_ram, test_sdram1)
+{
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay)
+	test_ram_rw(buf_sdram1);
+#else
+	ztest_test_skip();
+#endif
+}
+
+ZTEST(test_ram, test_sdram2)
+{
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay)
+	test_ram_rw(buf_sdram2);
+#else
+	ztest_test_skip();
+#endif
+}
+
+ZTEST(test_ram, test_sram1)
+{
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram1), okay)
+	test_ram_rw(buf_sram1);
+#else
+	ztest_test_skip();
+#endif
+}
+
+ZTEST(test_ram, test_sram2)
+{
+#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram2), okay)
+	test_ram_rw(buf_sram2);
+#else
+	ztest_test_skip();
+#endif
+}
diff --git a/tests/drivers/memc/ram/testcase.yaml b/tests/drivers/memc/ram/testcase.yaml
new file mode 100644
index 0000000..4ae0d07
--- /dev/null
+++ b/tests/drivers/memc/ram/testcase.yaml
@@ -0,0 +1,12 @@
+tests:
+  drivers.memc.stm32_sdram:
+    tags: drivers memc
+    depends_on: memc
+    filter: dt_compat_enabled("st,stm32-fmc-sdram")
+  drivers.memc.smc_sram:
+    tags: drivers memc
+    depends_on: memc
+    filter: dt_compat_enabled("atmel,sam-smc")
+    platform_allow: sam4s_xplained
+    integration_platforms:
+      - sam4s_xplained
diff --git a/tests/drivers/memc/stm32_sdram/prj.conf b/tests/drivers/memc/stm32_sdram/prj.conf
deleted file mode 100644
index 4aba052..0000000
--- a/tests/drivers/memc/stm32_sdram/prj.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-CONFIG_ZTEST=y
-CONFIG_MEMC=y
diff --git a/tests/drivers/memc/stm32_sdram/src/main.c b/tests/drivers/memc/stm32_sdram/src/main.c
deleted file mode 100644
index 01a5963..0000000
--- a/tests/drivers/memc/stm32_sdram/src/main.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2020 Teslabs Engineering S.L.
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-
-#include <zephyr/zephyr.h>
-#include <zephyr/ztest.h>
-
-/** Buffer size. */
-#define BUF_SIZE 64U
-
-/**
- * @brief Helper function to test SDRAM r/w.
- *
- * @param mem SDRAM memory location to be tested.
- */
-static void test_sdram_rw(uint32_t *mem)
-{
-	/* fill memory with number range (0, BUF_SIZE - 1) */
-	for (size_t i = 0U; i < BUF_SIZE; i++) {
-		mem[i] = i;
-	}
-
-	/* check that memory contains written range */
-	for (size_t i = 0U; i < BUF_SIZE; i++) {
-		zassert_equal(mem[i], i, "Unexpected content");
-	}
-}
-
-#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay)
-/** Buffer on SDRAM1. */
-__stm32_sdram1_section uint32_t sdram1[BUF_SIZE];
-
-static void test_sdram1_rw(void)
-{
-	test_sdram_rw(sdram1);
-}
-#else
-static void test_sdram1_rw(void)
-{
-	ztest_test_skip();
-}
-#endif
-
-#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay)
-/** Buffer on SDRAM2. */
-__stm32_sdram2_section uint32_t sdram2[BUF_SIZE];
-
-static void test_sdram2_rw(void)
-{
-	test_sdram_rw(sdram2);
-}
-
-#else
-static void test_sdram2_rw(void)
-{
-	ztest_test_skip();
-}
-#endif
-
-void test_main(void)
-{
-	ztest_test_suite(stm32_sdram,
-			 ztest_unit_test(test_sdram1_rw),
-			 ztest_unit_test(test_sdram2_rw));
-	ztest_run_test_suite(stm32_sdram);
-}
diff --git a/tests/drivers/memc/stm32_sdram/testcase.yaml b/tests/drivers/memc/stm32_sdram/testcase.yaml
deleted file mode 100644
index 4708710..0000000
--- a/tests/drivers/memc/stm32_sdram/testcase.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-tests:
-  drivers.memc.stm32_sdram:
-    tags: drivers memc
-    depends_on: memc
-    filter: dt_compat_enabled("st,stm32-fmc-sdram")