feat(lib/s2tt): add device memory tests
- Add device memory related unit tests.
- Modify s2tte_get_ripas_tc2() and create
new s2tte_get_ripas_tc3() test to consider
RMI_ASSIGNED_DEV HIPAS value.
Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
Change-Id: I670458bb4425f3b130e4b7c056ce3d5ec856f4b2
diff --git a/lib/s2tt/tests/CMakeLists.txt b/lib/s2tt/tests/CMakeLists.txt
index 55f5ecf..6f0a3e7 100644
--- a/lib/s2tt/tests/CMakeLists.txt
+++ b/lib/s2tt/tests/CMakeLists.txt
@@ -13,6 +13,7 @@
SOURCES "tests/s2tt_test_helpers.c"
"tests/s2tt_tests_base_g1.cpp"
"tests/s2tt_tests_base_g2.cpp"
+ "tests/s2tt_tests_base_g3.cpp"
"tests/s2tt_non_lpa2.cpp"
ITERATIONS 10)
@@ -22,5 +23,6 @@
SOURCES "tests/s2tt_test_helpers.c"
"tests/s2tt_tests_base_g1.cpp"
"tests/s2tt_tests_base_g2.cpp"
+ "tests/s2tt_tests_base_g3.cpp"
"tests/s2tt_lpa2.cpp"
ITERATIONS 10)
diff --git a/lib/s2tt/tests/s2tt_lpa2.cpp b/lib/s2tt/tests/s2tt_lpa2.cpp
index 07a4943..4297780 100644
--- a/lib/s2tt/tests/s2tt_lpa2.cpp
+++ b/lib/s2tt/tests/s2tt_lpa2.cpp
@@ -7,6 +7,7 @@
#include <CppUTest/TestHarness.h>
#include <s2tt_tests_base_g1.h>
#include <s2tt_tests_base_g2.h>
+#include <s2tt_tests_base_g3.h>
extern "C" {
#include <test_helpers.h>
@@ -133,6 +134,56 @@
s2tte_create_assigned_ns_tc3();
}
+TEST(s2tt_lpa2, s2tte_create_assigned_dev_destroyed_tc1)
+{
+ s2tte_create_assigned_dev_destroyed_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_destroyed_tc2)
+{
+ s2tte_create_assigned_dev_destroyed_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_destroyed_tc3)
+{
+ s2tte_create_assigned_dev_destroyed_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_destroyed_tc4)
+{
+ s2tte_create_assigned_dev_destroyed_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_destroyed_tc5)
+{
+ s2tte_create_assigned_dev_destroyed_tc5();
+}
+
+TEST(s2tt_lpa2, s2tte_create_assigned_dev_empty_tc1)
+{
+ s2tte_create_assigned_dev_empty_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_empty_tc2)
+{
+ s2tte_create_assigned_dev_empty_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_empty_tc3)
+{
+ s2tte_create_assigned_dev_empty_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_empty_tc4)
+{
+ s2tte_create_assigned_dev_empty_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_empty_tc5)
+{
+ s2tte_create_assigned_dev_empty_tc5();
+}
+
TEST(s2tt_lpa2, s2tte_create_assigned_unchanged_tc1)
{
s2tte_create_assigned_unchanged_tc1();
@@ -163,6 +214,46 @@
s2tte_create_assigned_unchanged_tc6();
}
+TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc1)
+{
+ s2tte_create_assigned_dev_unchanged_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc2)
+{
+ s2tte_create_assigned_dev_unchanged_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc3)
+{
+ s2tte_create_assigned_dev_unchanged_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc4)
+{
+ s2tte_create_assigned_dev_unchanged_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc5)
+{
+ s2tte_create_assigned_dev_unchanged_tc5();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc6)
+{
+ s2tte_create_assigned_dev_unchanged_tc6();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc7)
+{
+ s2tte_create_assigned_dev_unchanged_tc7();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tte_create_assigned_dev_unchanged_tc8)
+{
+ s2tte_create_assigned_dev_unchanged_tc8();
+}
+
TEST(s2tt_lpa2, s2tte_create_table_tc1)
{
s2tte_create_table_tc1();
@@ -248,6 +339,16 @@
s2tte_has_ripas_tc2();
}
+TEST(s2tt_lpa2, s2tte_has_ripas_dev_tc1)
+{
+ s2tte_has_ripas_dev_tc1();
+}
+
+TEST(s2tt_lpa2, s2tte_has_ripas_dev_tc2)
+{
+ s2tte_has_ripas_dev_tc2();
+}
+
TEST(s2tt_lpa2, s2tte_is_unassigned_tc1)
{
s2tte_is_unassigned_tc1();
@@ -303,6 +404,36 @@
s2tte_is_assigned_destroyed_tc1();
}
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_destroyed_tc1)
+{
+ s2tte_is_assigned_dev_destroyed_tc1();
+}
+
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_empty_tc1)
+{
+ s2tte_is_assigned_dev_empty_tc1();
+}
+
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_dev_tc1)
+{
+ s2tte_is_assigned_dev_dev_tc1();
+}
+
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_dev_tc2)
+{
+ s2tte_is_assigned_dev_dev_tc2();
+}
+
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_dev_tc3)
+{
+ s2tte_is_assigned_dev_dev_tc3();
+}
+
+TEST(s2tt_lpa2, s2tte_is_assigned_dev_dev_tc4)
+{
+ s2tte_is_assigned_dev_dev_tc4();
+}
+
TEST(s2tt_lpa2, s2tte_is_table_tc1)
{
s2tte_is_table_tc1();
@@ -318,6 +449,21 @@
s2tte_get_ripas_tc2();
}
+ASSERT_TEST(s2tt_lpa2, s2tte_get_ripas_tc3)
+{
+ s2tte_get_ripas_tc3();
+}
+
+TEST(s2tt_lpa2, s2tte_get_ripas_dev_tc1)
+{
+ s2tte_get_ripas_dev_tc1();
+}
+
+TEST(s2tt_lpa2, s2tte_get_ripas_dev_tc2)
+{
+ s2tte_get_ripas_dev_tc2();
+}
+
TEST(s2tt_lpa2, s2tt_init_unassigned_empty_tc1)
{
s2tt_init_unassigned_empty_tc1();
@@ -473,6 +619,96 @@
s2tt_init_assigned_destroyed_tc6();
}
+TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc1)
+{
+ s2tt_init_assigned_dev_empty_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc2)
+{
+ s2tt_init_assigned_dev_empty_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc3)
+{
+ s2tt_init_assigned_dev_empty_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc4)
+{
+ s2tt_init_assigned_dev_empty_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc5)
+{
+ s2tt_init_assigned_dev_empty_tc5();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_empty_tc6)
+{
+ s2tt_init_assigned_dev_empty_tc6();
+}
+
+TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc1)
+{
+ s2tt_init_assigned_dev_destroyed_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc2)
+{
+ s2tt_init_assigned_dev_destroyed_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc3)
+{
+ s2tt_init_assigned_dev_destroyed_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc4)
+{
+ s2tt_init_assigned_dev_destroyed_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc5)
+{
+ s2tt_init_assigned_dev_destroyed_tc5();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_destroyed_tc6)
+{
+ s2tt_init_assigned_dev_destroyed_tc6();
+}
+
+TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc1)
+{
+ s2tt_init_assigned_dev_dev_tc1();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc2)
+{
+ s2tt_init_assigned_dev_dev_tc2();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc3)
+{
+ s2tt_init_assigned_dev_dev_tc3();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc4)
+{
+ s2tt_init_assigned_dev_dev_tc4();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc5)
+{
+ s2tt_init_assigned_dev_dev_tc5();
+}
+
+ASSERT_TEST(s2tt_lpa2, s2tt_init_assigned_dev_dev_tc6)
+{
+ s2tt_init_assigned_dev_dev_tc6();
+}
+
TEST(s2tt_lpa2, s2tte_pa_tc1)
{
s2tte_pa_tc1();
diff --git a/lib/s2tt/tests/s2tt_non_lpa2.cpp b/lib/s2tt/tests/s2tt_non_lpa2.cpp
index ec1d5e8..1bcbeb6 100644
--- a/lib/s2tt/tests/s2tt_non_lpa2.cpp
+++ b/lib/s2tt/tests/s2tt_non_lpa2.cpp
@@ -7,6 +7,7 @@
#include <CppUTest/TestHarness.h>
#include <s2tt_tests_base_g1.h>
#include <s2tt_tests_base_g2.h>
+#include <s2tt_tests_base_g3.h>
extern "C" {
#include <test_helpers.h>
@@ -133,6 +134,56 @@
s2tte_create_assigned_ns_tc3();
}
+TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_destroyed_tc1)
+{
+ s2tte_create_assigned_dev_destroyed_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_destroyed_tc2)
+{
+ s2tte_create_assigned_dev_destroyed_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_destroyed_tc3)
+{
+ s2tte_create_assigned_dev_destroyed_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_destroyed_tc4)
+{
+ s2tte_create_assigned_dev_destroyed_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_destroyed_tc5)
+{
+ s2tte_create_assigned_dev_destroyed_tc5();
+}
+
+TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_empty_tc1)
+{
+ s2tte_create_assigned_dev_empty_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_empty_tc2)
+{
+ s2tte_create_assigned_dev_empty_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_empty_tc3)
+{
+ s2tte_create_assigned_dev_empty_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_empty_tc4)
+{
+ s2tte_create_assigned_dev_empty_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_empty_tc5)
+{
+ s2tte_create_assigned_dev_empty_tc5();
+}
+
TEST(s2tt_non_lpa2, s2tte_create_assigned_unchanged_tc1)
{
s2tte_create_assigned_unchanged_tc1();
@@ -163,6 +214,46 @@
s2tte_create_assigned_unchanged_tc6();
}
+TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc1)
+{
+ s2tte_create_assigned_dev_unchanged_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc2)
+{
+ s2tte_create_assigned_dev_unchanged_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc3)
+{
+ s2tte_create_assigned_dev_unchanged_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc4)
+{
+ s2tte_create_assigned_dev_unchanged_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc5)
+{
+ s2tte_create_assigned_dev_unchanged_tc5();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc6)
+{
+ s2tte_create_assigned_dev_unchanged_tc6();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc7)
+{
+ s2tte_create_assigned_dev_unchanged_tc7();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tte_create_assigned_dev_unchanged_tc8)
+{
+ s2tte_create_assigned_dev_unchanged_tc8();
+}
+
TEST(s2tt_non_lpa2, s2tte_create_table_tc1)
{
s2tte_create_table_tc1();
@@ -248,6 +339,16 @@
s2tte_has_ripas_tc2();
}
+TEST(s2tt_non_lpa2, s2tte_has_ripas_dev_tc1)
+{
+ s2tte_has_ripas_dev_tc1();
+}
+
+TEST(s2tt_non_lpa2, s2tte_has_ripas_dev_tc2)
+{
+ s2tte_has_ripas_dev_tc2();
+}
+
TEST(s2tt_non_lpa2, s2tte_is_unassigned_tc1)
{
s2tte_is_unassigned_tc1();
@@ -303,6 +404,36 @@
s2tte_is_assigned_destroyed_tc1();
}
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_empty_tc1)
+{
+ s2tte_is_assigned_dev_empty_tc1();
+}
+
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_destroyed_tc1)
+{
+ s2tte_is_assigned_dev_empty_tc1();
+}
+
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_dev_tc1)
+{
+ s2tte_is_assigned_dev_dev_tc1();
+}
+
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_dev_tc2)
+{
+ s2tte_is_assigned_dev_dev_tc2();
+}
+
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_dev_tc3)
+{
+ s2tte_is_assigned_dev_dev_tc3();
+}
+
+TEST(s2tt_non_lpa2, s2tte_is_assigned_dev_dev_tc4)
+{
+ s2tte_is_assigned_dev_dev_tc4();
+}
+
TEST(s2tt_non_lpa2, s2tte_is_table_tc1)
{
s2tte_is_table_tc1();
@@ -318,6 +449,21 @@
s2tte_get_ripas_tc2();
}
+ASSERT_TEST(s2tt_non_lpa2, s2tte_get_ripas_tc3)
+{
+ s2tte_get_ripas_tc3();
+}
+
+TEST(s2tt_non_lpa2, s2tte_get_ripas_dev_tc1)
+{
+ s2tte_get_ripas_dev_tc1();
+}
+
+TEST(s2tt_non_lpa2, s2tte_get_ripas_dev_tc2)
+{
+ s2tte_get_ripas_dev_tc2();
+}
+
TEST(s2tt_non_lpa2, s2tt_init_unassigned_empty_tc1)
{
s2tt_init_unassigned_empty_tc1();
@@ -473,6 +619,97 @@
s2tt_init_assigned_destroyed_tc6();
}
+TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc1)
+{
+ s2tt_init_assigned_dev_empty_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc2)
+{
+ s2tt_init_assigned_dev_empty_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc3)
+{
+ s2tt_init_assigned_dev_empty_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc4)
+{
+ s2tt_init_assigned_dev_empty_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc5)
+{
+ s2tt_init_assigned_dev_empty_tc5();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_empty_tc6)
+{
+ s2tt_init_assigned_dev_empty_tc6();
+}
+
+TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc1)
+{
+ s2tt_init_assigned_dev_destroyed_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc2)
+{
+ s2tt_init_assigned_dev_destroyed_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc3)
+{
+ s2tt_init_assigned_dev_destroyed_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc4)
+{
+ s2tt_init_assigned_dev_destroyed_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc5)
+{
+ s2tt_init_assigned_dev_destroyed_tc5();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_destroyed_tc6)
+{
+ s2tt_init_assigned_dev_destroyed_tc6();
+}
+
+TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc1)
+{
+ s2tt_init_assigned_dev_dev_tc1();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc2)
+{
+ s2tt_init_assigned_dev_dev_tc2();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc3)
+{
+ s2tt_init_assigned_dev_dev_tc3();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc4)
+{
+ s2tt_init_assigned_dev_dev_tc4();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc5)
+{
+ s2tt_init_assigned_dev_dev_tc5();
+}
+
+ASSERT_TEST(s2tt_non_lpa2, s2tt_init_assigned_dev_dev_tc6)
+{
+ s2tt_init_assigned_dev_dev_tc6();
+}
+
+
TEST(s2tt_non_lpa2, s2tte_pa_tc1)
{
s2tte_pa_tc1();
diff --git a/lib/s2tt/tests/s2tt_test_helpers.c b/lib/s2tt/tests/s2tt_test_helpers.c
index b2f742f..1036d8b 100644
--- a/lib/s2tt/tests/s2tt_test_helpers.c
+++ b/lib/s2tt/tests/s2tt_test_helpers.c
@@ -222,6 +222,11 @@
return S2TT_MIN_BLOCK_LEVEL;
}
+long s2tt_test_helpers_min_dev_block_lvl(void)
+{
+ return S2TT_MIN_DEV_BLOCK_LEVEL;
+}
+
unsigned long s2tt_test_helpers_get_entry_va_space_size(long level)
{
assert(level >= s2tt_test_helpers_min_table_lvl());
@@ -265,6 +270,48 @@
return s2tte_create_assigned_ns(s2tt_ctx, pa, level);
}
+unsigned long s2tt_test_create_assigned_dev_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long pa, long level)
+{
+ unsigned long attr = S2TTE_TEST_DEV_ATTRS;
+
+ /* Add Shareability bits if FEAT_LPA2 is not enabled */
+ if (!s2tt_ctx->enable_lpa2) {
+ attr |= S2TTE_TEST_DEV_SH;
+ }
+ return s2tte_create_assigned_dev_dev(s2tt_ctx, (pa | attr), level);
+}
+
+unsigned long s2tt_test_create_assigned_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long pa, long level,
+ unsigned long ripas)
+{
+ if (ripas == S2TTE_INVALID_RIPAS_EMPTY) {
+ return s2tte_create_assigned_dev_empty(s2tt_ctx, pa, level);
+ } else if (ripas == S2TTE_INVALID_RIPAS_DESTROYED) {
+ return s2tte_create_assigned_dev_destroyed(s2tt_ctx, pa, level);
+ } else if (ripas == S2TTE_INVALID_RIPAS_DEV) {
+ return s2tt_test_create_assigned_dev_dev(s2tt_ctx, pa, level);
+ }
+
+ assert(false);
+ return 0UL;
+}
+
+void s2tt_test_init_assigned_dev_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long *s2tt, unsigned long pa,
+ long level)
+{
+ unsigned long attr = S2TTE_TEST_DEV_ATTRS;
+
+ /* Add Shareability bits if FEAT_LPA2 is not enabled */
+ if (!s2tt_ctx->enable_lpa2) {
+ attr |= S2TTE_TEST_DEV_SH;
+ }
+
+ s2tt_init_assigned_dev_dev(s2tt_ctx, s2tt, (attr | pa), pa, level);
+}
+
unsigned long s2tt_test_create_unassigned(const struct s2tt_context *s2tt_ctx,
unsigned long ripas)
{
diff --git a/lib/s2tt/tests/s2tt_test_helpers.h b/lib/s2tt/tests/s2tt_test_helpers.h
index 4755518..e493068 100644
--- a/lib/s2tt/tests/s2tt_test_helpers.h
+++ b/lib/s2tt/tests/s2tt_test_helpers.h
@@ -51,6 +51,10 @@
/* Invalid value for the RIPAS field */
#define S2TT_TEST_RIPAS_INVALID (3UL)
+/* Non-coherent device memory attributes, Outer Shareable */
+#define S2TTE_TEST_DEV_ATTRS S2TTE_DEV_NCOH_ATTRS
+#define S2TTE_TEST_DEV_SH S2TTE_SH_OS
+
/*
* Function to setup the environment for the tests specifying
* whether FEAT_LPA2 is supported or not.
@@ -112,6 +116,9 @@
/* Get the minimum block level */
long s2tt_test_helpers_min_block_lvl(void);
+/* Get the minimum device memory block level */
+long s2tt_test_helpers_min_dev_block_lvl(void);
+
/* For a given level return the VA space size of an S2TTE entry at such level */
unsigned long s2tt_test_helpers_get_entry_va_space_size(long level);
@@ -127,6 +134,20 @@
unsigned long pa, long level,
unsigned long ripas);
+/* Helper to create an assigned_dev S2TTE as per the passed parameters */
+unsigned long s2tt_test_create_assigned_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long pa, long level,
+ unsigned long ripas);
+
+/* Helper to create an assigned_dev_dev S2TTE as per the passed parameters */
+unsigned long s2tt_test_create_assigned_dev_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long pa, long level);
+
+/* Helper to init an assigned_dev_dev S2TTE as per the passed parameters */
+void s2tt_test_init_assigned_dev_dev(const struct s2tt_context *s2tt_ctx,
+ unsigned long *s2tt,
+ unsigned long pa, long level);
+
/* Helper to create an unassigned S2TTE as per the passed parameters */
unsigned long s2tt_test_create_unassigned(const struct s2tt_context *s2tt_ctx,
unsigned long ripas);
diff --git a/lib/s2tt/tests/s2tt_tests_base_g1.cpp b/lib/s2tt/tests/s2tt_tests_base_g1.cpp
index 9ab2b14..5a27754 100644
--- a/lib/s2tt/tests/s2tt_tests_base_g1.cpp
+++ b/lib/s2tt/tests/s2tt_tests_base_g1.cpp
@@ -184,7 +184,7 @@
* S2TTE with a level below the minimum.
***************************************************************/
- long level = s2tt_test_helpers_min_block_lvl() - 1;
+ long level = s2tt_test_helpers_min_block_lvl() - 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -212,7 +212,7 @@
* S2TTE with a level above the maximum.
***************************************************************/
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -339,7 +339,7 @@
* S2TTE with a level below the minimum.
***************************************************************/
- long level = s2tt_test_helpers_min_block_lvl() - 1;
+ long level = s2tt_test_helpers_min_block_lvl() - 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -367,7 +367,7 @@
* S2TTE with a level above the maximum.
***************************************************************/
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -492,7 +492,7 @@
* with a level below the minimum.
***************************************************************/
- long level = s2tt_test_helpers_min_block_lvl() - 1;
+ long level = s2tt_test_helpers_min_block_lvl() - 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -520,7 +520,7 @@
* with a level above the maximum.
***************************************************************/
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -643,7 +643,7 @@
* with a level above the maximum.
***************************************************************/
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
test_helpers_expect_assert_fail(true);
@@ -773,7 +773,7 @@
* assigned-unchanged S2TTE with a level below the minimum.
***************************************************************/
- long level = s2tt_test_helpers_min_block_lvl() - 1;
+ long level = s2tt_test_helpers_min_block_lvl() - 1L;
unsigned long ripas = test_helpers_get_rand_in_range(
RIPAS_EMPTY,
RIPAS_DESTROYED);
@@ -804,7 +804,7 @@
* assigned-unchanged S2TTE with a level above the maximum.
***************************************************************/
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long ripas = test_helpers_get_rand_in_range(
RIPAS_EMPTY,
RIPAS_DESTROYED);
@@ -1177,7 +1177,7 @@
* any level.
*/
unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
test_helpers_expect_assert_fail(true);
(void)host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
@@ -1723,7 +1723,7 @@
(const struct s2tt_context *)&s2tt_ctx,
pa, level);
- /* Validate s2tt_is_assigned_empty with an unassigned empty TTE */
+ /* Validate s2tt_is_assigned_empty with an assigned empty TTE */
CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
tte, level) == true);
@@ -1871,7 +1871,7 @@
s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
pa, level);
- /* Validate s2tt_is_assigned_empty with an assigned ram TTE */
+ /* Validate s2tt_is_assigned_ram with an assigned ram TTE */
CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
tte, level) == true);
@@ -2100,14 +2100,35 @@
unsigned long tte = s2tte_create_unassigned_destroyed(
(const struct s2tt_context *)NULL);
- tte &= ~S2TTE_INVALID_HIPAS_MASK;
-
/*
- * As per s2tt_pvt_defs.h, HIPAS field is 3 bits wide with
- * only the first bit used.
+ * As per s2tt_pvt_defs.h, HIPAS field is 3 bits wide with only the
+ * first 2 bits used. Get random invalid HIPAS to test with.
*/
- tte |= INPLACE(S2TTE_INVALID_HIPAS,
- EXTRACT(S2TTE_INVALID_HIPAS, S2TTE_INVALID_HIPAS_ASSIGNED) + 1UL);
+ unsigned long inv_hipas = test_helpers_get_rand_in_range(
+ RMI_ASSIGNED_DEV + 1UL, 7UL);
+
+ tte &= ~S2TTE_INVALID_HIPAS_MASK;
+ tte |= INPLACE(S2TTE_INVALID_HIPAS, inv_hipas);
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_get_ripas((const struct s2tt_context *)NULL, tte);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_get_ripas_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * Test s2tte_get_ripas() with an invalid S2TTE and an invalid
+ * HIPAS=RMI_TABLE.
+ ***************************************************************/
+
+ unsigned long tte = s2tte_create_unassigned_destroyed(
+ (const struct s2tt_context *)NULL);
+
+ tte &= ~S2TTE_INVALID_HIPAS_MASK;
+ tte |= INPLACE(S2TTE_INVALID_HIPAS, RMI_TABLE);
test_helpers_expect_assert_fail(true);
(void)s2tte_get_ripas((const struct s2tt_context *)NULL, tte);
@@ -2347,7 +2368,7 @@
***************************************************************/
unsigned long s2tt[S2TTES_PER_S2TT] = {0};
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -2520,7 +2541,7 @@
***************************************************************/
unsigned long s2tt[S2TTES_PER_S2TT] = {0};
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
@@ -2721,7 +2742,7 @@
***************************************************************/
unsigned long s2tt[S2TTES_PER_S2TT] = {0};
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
@@ -2853,7 +2874,7 @@
***************************************************************/
unsigned long s2tt[S2TTES_PER_S2TT] = {0};
- long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
unsigned long pa = 0UL; /* Valid for any level */
struct s2tt_context s2tt_ctx;
diff --git a/lib/s2tt/tests/s2tt_tests_base_g1.h b/lib/s2tt/tests/s2tt_tests_base_g1.h
index 0042868..133fe8d 100644
--- a/lib/s2tt/tests/s2tt_tests_base_g1.h
+++ b/lib/s2tt/tests/s2tt_tests_base_g1.h
@@ -112,6 +112,7 @@
/* s2tte_get_ripas() */
void s2tte_get_ripas_tc1(void);
void s2tte_get_ripas_tc2(void);
+void s2tte_get_ripas_tc3(void);
/* s2tt_init_unassigned_empty() */
void s2tt_init_unassigned_empty_tc1(void);
diff --git a/lib/s2tt/tests/s2tt_tests_base_g2.cpp b/lib/s2tt/tests/s2tt_tests_base_g2.cpp
index 1d62005..e853a21 100644
--- a/lib/s2tt/tests/s2tt_tests_base_g2.cpp
+++ b/lib/s2tt/tests/s2tt_tests_base_g2.cpp
@@ -323,7 +323,7 @@
/*
* Helper to implement a set of negative tests for
- * s2tte_is_unassigned_{x}_block() APIS where x belongs to
+ * s2tte_is_unassigned_{x}_block() APIs where x belongs to
* [RMI_EMPTY, RMI_RAM, RMI_DESTROYED, NS]:
*
* - Validate s2tt_is_unassigned_{x}_block() with a corresponding
diff --git a/lib/s2tt/tests/s2tt_tests_base_g3.cpp b/lib/s2tt/tests/s2tt_tests_base_g3.cpp
new file mode 100644
index 0000000..1051cc3
--- /dev/null
+++ b/lib/s2tt/tests/s2tt_tests_base_g3.cpp
@@ -0,0 +1,1617 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
+ */
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+
+extern "C" {
+#include <cpuid.h>
+#include <granule_types.h>
+#include <host_harness.h>
+#include <host_utils.h>
+#include <status.h>
+#include <stdlib.h>
+#include <string.h>
+#include <s2tt_pvt_defs.h>
+#include <s2tt_test_helpers.h>
+#include <ripas.h>
+#include <s2tt.h> /* Interface to exercise */
+#include <test_helpers.h>
+#include <unistd.h>
+#include <utils_def.h>
+}
+
+void s2tte_create_assigned_dev_destroyed_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * Create an assigned_dev destroyed S2TTE with valid parameters and
+ * verify that the S2TTE is valid.
+ ***************************************************************/
+
+ /* Test for each possible level */
+ for (long i = s2tt_test_helpers_min_dev_block_lvl();
+ i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
+
+ unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
+ unsigned long tte;
+ s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ tte = s2tte_create_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ pa, i);
+
+ /* Validate the address */
+ UNSIGNED_LONGS_EQUAL(
+ s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
+
+ /* Validate the RIPAS */
+ UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_RIPAS_MASK),
+ S2TTE_INVALID_RIPAS_DESTROYED);
+
+ /* Validate the HIPAS */
+ UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_HIPAS_MASK),
+ S2TTE_INVALID_HIPAS_ASSIGNED_DEV);
+
+ /* The rest of the fields must be all 0 */
+ UNSIGNED_LONGS_EQUAL(
+ (tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
+ S2TTE_INVALID_RIPAS_MASK |
+ S2TTE_INVALID_HIPAS_MASK)), 0UL);
+ }
+}
+
+void s2tte_create_assigned_dev_destroyed_tc2(void)
+{
+ /*******************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid level, try to create an assigned_dev destroyed S2TTE
+ * with an unaligned address.
+ ******************************************************************/
+
+ long level = (long)test_helpers_get_rand_in_range(
+ (unsigned long)s2tt_test_helpers_min_dev_block_lvl(),
+ (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_destroyed_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address, try to create an assigned_dev destroyed
+ * S2TTE with a level below the minimum.
+ ***************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_destroyed_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * For a valid address, try to create an assigned-destroyed
+ * S2TTE with a level above the maximum.
+ ***************************************************************/
+
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_destroyed_tc5(void)
+{
+ /***************************************************************
+ * TEST CASE 5:
+ *
+ * For a valid address, try to create an assigned_dev destroyed
+ * S2TTE with a null s2tt_context structure.
+ ***************************************************************/
+
+ long level = S2TT_TEST_HELPERS_MAX_LVL;
+ unsigned long pa = 0UL; /* Valid for any level */
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_destroyed((const struct s2tt_context *)NULL,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_empty_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * Create an assigned_dev empty S2TTE with valid parameters and
+ * verify that the S2TTE is valid.
+ ***************************************************************/
+
+ /* Test for each possible level */
+ for (long i = s2tt_test_helpers_min_dev_block_lvl();
+ i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
+
+ unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
+ unsigned long tte;
+ s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ tte = s2tte_create_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ pa, i);
+
+ /* Validate the address */
+ UNSIGNED_LONGS_EQUAL(
+ s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
+
+ /* Validate the RIPAS */
+ UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_RIPAS_MASK),
+ S2TTE_INVALID_RIPAS_EMPTY);
+
+ /* Validate the HIPAS */
+ UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_HIPAS_MASK),
+ S2TTE_INVALID_HIPAS_ASSIGNED_DEV);
+
+ /* The rest of the fields must be all 0 */
+ UNSIGNED_LONGS_EQUAL(
+ (tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
+ S2TTE_INVALID_RIPAS_MASK |
+ S2TTE_INVALID_HIPAS_MASK)), 0UL);
+ }
+}
+
+void s2tte_create_assigned_dev_empty_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid level, try to create an assigned_dev empty S2TTE
+ * with an unaligned address.
+ ***************************************************************/
+
+ long level = (long)test_helpers_get_rand_in_range(
+ (unsigned long)s2tt_test_helpers_min_dev_block_lvl(),
+ (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_empty_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address, try to create an assigned_dev empty
+ * S2TTE with a level below the minimum.
+ ***************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_empty_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * For a valid address, try to create an assigned_dev empty
+ * S2TTE with a level above the maximum.
+ ***************************************************************/
+
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * only s2tt_ctx.enable_lpa2 is of use on this API, so
+ * the rest of them can be uninitialized.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_empty_tc5(void)
+{
+ /***************************************************************
+ * TEST CASE 5:
+ *
+ * For a valid address, try to create an assigned_dev empty
+ * S2TTE with a null s2tt_context structure.
+ ***************************************************************/
+
+ long level = S2TT_TEST_HELPERS_MAX_LVL;
+ unsigned long pa = 0UL; /* Valid for any level */
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_empty((const struct s2tt_context *)NULL,
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For each possible level and RIPAS_EMPTY and RIPAS_DESTROYED,
+ * invoke create_assigned_dev_unchanged() and verify that the TTE is
+ * correct.
+ ***************************************************************/
+
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL;
+ level++) {
+ for (unsigned long ripas = RIPAS_EMPTY;
+ ripas < S2TT_TEST_RIPAS_INVALID;
+ ripas++) {
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ unsigned long tte;
+
+ /* Skip RIPAS_RAM */
+ if (ripas != RIPAS_RAM) {
+ tte = s2tte_create_assigned_dev_unchanged(
+ (const struct s2tt_context *)&s2tt_ctx,
+ INPLACE(S2TTE_INVALID_RIPAS, ripas),
+ pa, level);
+
+ /* Validate the address */
+ UNSIGNED_LONGS_EQUAL(
+ s2tt_test_helpers_s2tte_to_pa(tte, level), pa);
+
+ /* Verify the RIPAS */
+ UNSIGNED_LONGS_EQUAL(
+ (tte & S2TTE_INVALID_RIPAS_MASK),
+ INPLACE(S2TTE_INVALID_RIPAS,
+ ripas));
+
+ /* Verify the HIPAS */
+ UNSIGNED_LONGS_EQUAL(
+ (tte & S2TTE_INVALID_HIPAS_MASK),
+ S2TTE_INVALID_HIPAS_ASSIGNED_DEV);
+
+ /* The Descriptor type must be invalid */
+ UNSIGNED_LONGS_EQUAL(
+ (tte & S2TT_TEST_DESC_TYPE_MASK),
+ S2TT_TEST_INVALID_DESC);
+ }
+ }
+ }
+}
+
+void s2tte_create_assigned_dev_unchanged_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid level and ripas try to create an
+ * assigned_dev unchanged S2TTE with an unaligned address.
+ ***************************************************************/
+
+ long level = (long)test_helpers_get_rand_in_range(
+ (unsigned long)s2tt_test_helpers_min_dev_block_lvl(),
+ (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long ripas = test_helpers_get_rand_in_range(
+ RIPAS_EMPTY,
+ RIPAS_DESTROYED);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged((const struct s2tt_context *)&s2tt_ctx,
+ ripas, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address and ripas try to create an
+ * assigned_dev unchanged S2TTE with a level below the minimum.
+ ***************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long ripas = test_helpers_get_rand_in_range(
+ RIPAS_EMPTY,
+ RIPAS_DESTROYED);
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged((const struct s2tt_context *)&s2tt_ctx,
+ ripas, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * For a valid address and ripas, try to create an
+ * assigned_dev unchanged S2TTE with a level above the maximum.
+ ***************************************************************/
+
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
+ unsigned long ripas = test_helpers_get_rand_in_range(
+ RIPAS_EMPTY,
+ RIPAS_DESTROYED);
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged((const struct s2tt_context *)&s2tt_ctx,
+ ripas, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc5(void)
+{
+ /***************************************************************
+ * TEST CASE 5:
+ *
+ * For a valid level and pa try to create an
+ * assigned_dev unchanged S2TTE with an invalid RIPAS.
+ ***************************************************************/
+
+ long level = (long)test_helpers_get_rand_in_range(
+ (unsigned long)s2tt_test_helpers_min_dev_block_lvl(),
+ (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long ripas = INPLACE(S2TTE_INVALID_RIPAS,
+ S2TT_TEST_RIPAS_INVALID);
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged((const struct s2tt_context *)&s2tt_ctx,
+ ripas, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc6(void)
+{
+ /***************************************************************
+ * TEST CASE 6:
+ *
+ * For a valid level, pa and RIPAS, try to create an
+ * assigned_dev unchanged S2TTE with a null s2tt_context structure.
+ ***************************************************************/
+
+ long level = (long)test_helpers_get_rand_in_range(
+ (unsigned long)s2tt_test_helpers_min_dev_block_lvl(),
+ (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long ripas = test_helpers_get_rand_in_range(
+ RIPAS_EMPTY,
+ RIPAS_DESTROYED);
+ unsigned long pa = 0UL; /* Valid for any level */
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged((const struct s2tt_context *)NULL,
+ ripas, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc7(void)
+{
+ /***************************************************************
+ * TEST CASE 7:
+ *
+ * For maximum possible level and RIPAS_RAM, invoke
+ * create_assigned_dev_unchanged() and verify that the assertion
+ * fails.
+ ***************************************************************/
+
+ struct s2tt_context s2tt_ctx;
+ long level = S2TT_TEST_HELPERS_MAX_LVL;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged(
+ (const struct s2tt_context *)&s2tt_ctx,
+ INPLACE(S2TTE_INVALID_RIPAS, RIPAS_RAM),
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_create_assigned_dev_unchanged_tc8(void)
+{
+ /***************************************************************
+ * TEST CASE 8:
+ *
+ * For minimum possible level and RIPAS_RAM, invoke
+ * create_assigned_dev_unchanged() and verify that the assertion
+ * fails.
+ ***************************************************************/
+
+ struct s2tt_context s2tt_ctx;
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test.
+ * Only the 'enable_lpa2' field is needed for this API
+ * so we can safely ignore the rest.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ (void)s2tte_create_assigned_dev_unchanged(
+ (const struct s2tt_context *)&s2tt_ctx,
+ INPLACE(S2TTE_INVALID_RIPAS, RIPAS_RAM),
+ pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tte_has_ripas_dev_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For each valid level at which a TTE can have RIPAS,
+ * generate a set of assigned_dev S2TTEs with RIPAS and
+ * validate the output of s2tte_has_ripas().
+ ***************************************************************/
+
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
+ S2TTE_INVALID_RIPAS_DESTROYED,
+ S2TTE_INVALID_RIPAS_DEV};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ for (unsigned long i = 0UL; i < ARRAY_SIZE(ripas); i++) {
+ unsigned long tte;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+
+ /* Validate with an assigned_dev_dev S2TTE */
+ tte = s2tt_test_create_assigned_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[i]);
+ CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+ }
+ }
+}
+
+void s2tte_has_ripas_dev_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For each valid level and all RmmDevMemCoherent types generate
+ * a set of assigned_dev_dev S2TTEs and validate the output of
+ * s2tte_has_ripas().
+ ***************************************************************/
+
+ enum dev_coh_type type[] = {DEV_MEM_COHERENT,
+ DEV_MEM_NON_COHERENT};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ for (unsigned long i = 0UL; i < ARRAY_SIZE(type); i++) {
+ unsigned long tte;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+
+ /* Validate with an assigned_dev_dev S2TTE */
+ tte = s2tte_create_assigned_dev_dev_coh_type(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, type[i]);
+ CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+ }
+ }
+}
+
+void s2tte_is_assigned_dev_empty_tc1(void)
+{
+ /*****************************************************************
+ * TEST CASE 1:
+ *
+ * This test case cover positive tests for is_assigned_dev_empty()
+ * as well as a number of negative tests for each valid level.
+ *****************************************************************/
+
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_DESTROYED,
+ S2TTE_INVALID_RIPAS_DEV};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ unsigned int idx;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ unsigned long inv_tte, tte =
+ s2tte_create_assigned_dev_empty(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+
+ /* Validate s2tt_is_assigned_dev_empty with an assigned_dev empty TTE */
+ CHECK_TRUE(s2tte_is_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+
+ /* Negative test: Set DESC_TYPE to a valid descriptor */
+ inv_tte = tte | S2TT_TEST_PAGE_DESC;
+
+ CHECK_TRUE(s2tte_is_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Change the HIPAS to UNASSIGNED */
+ inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
+ inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
+ CHECK_TRUE(s2tte_is_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Test with a different type of assigned TTE */
+ idx = (unsigned int)test_helpers_get_rand_in_range(
+ 0UL, ARRAY_SIZE(ripas) - 1UL);
+ inv_tte = s2tt_test_create_assigned_dev((const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[idx]);
+ CHECK_TRUE(s2tte_is_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+ }
+}
+
+void s2tte_is_assigned_dev_destroyed_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * This test case cover positive tests for
+ * is_assigned_dev_destroyed() as well as a number of negative
+ * tests for each valid level.
+ ***************************************************************/
+
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
+ S2TTE_INVALID_RIPAS_DEV};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ unsigned int idx;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ unsigned long inv_tte, tte;
+
+ tte = s2tte_create_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+
+ /*
+ * Validate s2tt_is_assigned_dev_destroyed with an assigned_dev
+ * destroyed TTE
+ */
+ CHECK_TRUE(s2tte_is_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+
+ /* Negative test: Set DESC_TYPE to a valid descriptor */
+ inv_tte = tte | S2TT_TEST_PAGE_DESC;
+ CHECK_TRUE(s2tte_is_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Change the HIPAS to UNASSIGNED */
+ inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
+ inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
+ CHECK_TRUE(s2tte_is_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Test with a different RIPAS */
+ idx = (unsigned int)test_helpers_get_rand_in_range(
+ 0UL, ARRAY_SIZE(ripas) - 1UL);
+ inv_tte = s2tt_test_create_assigned_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[idx]);
+ CHECK_TRUE(s2tte_is_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+ }
+}
+
+void s2tte_is_assigned_dev_dev_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * Calling s2tt_create_assigned_dev_dev() this test case covers
+ * positive tests for is_assigned_dev_dev() as well as a number
+ * of negative tests for each valid level.
+ ***************************************************************/
+
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
+ S2TTE_INVALID_RIPAS_DESTROYED};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ unsigned int idx;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ unsigned long inv_tte, tte;
+
+ tte = s2tt_test_create_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+
+ /* Validate s2tt_is_assigned_dev_dev with an assigned_dev TTE */
+ CHECK_TRUE(s2tte_is_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+ /*
+ * Negative test: Test with UNASSIGNED-RAM
+ * We test with UNASSIGNED-RAM as in the current RMM implementation,
+ * an ASSIGNED-RAM S2TTE does not have HIPAS field, so we pick
+ * up an S2TTE with a HIPAS other than ASSIGNED.
+ */
+ inv_tte = s2tte_create_unassigned_ram(
+ (const struct s2tt_context *)&s2tt_ctx);
+ CHECK_TRUE(s2tte_is_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Test with a different type of RIPAS */
+ idx = (unsigned int)test_helpers_get_rand_in_range(
+ 0UL, ARRAY_SIZE(ripas) - 1UL);
+ inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[idx]);
+ CHECK_TRUE(s2tte_is_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+ }
+}
+
+void s2tte_is_assigned_dev_dev_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * Calling s2tte_create_assigned_dev_dev_coh_type() for all
+ * RmmDevMemCoherent types this test case covers positive tests
+ * for is_assigned_dev_dev() as well as a number of negative
+ * tests for each valid level.
+ ***************************************************************/
+
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
+ S2TTE_INVALID_RIPAS_DESTROYED};
+ enum dev_coh_type type[] = {DEV_MEM_COHERENT,
+ DEV_MEM_NON_COHERENT};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ for (unsigned long i = 0UL; i < ARRAY_SIZE(type); i++) {
+ unsigned int idx;
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
+ unsigned long inv_tte, tte;
+
+ tte = s2tte_create_assigned_dev_dev_coh_type(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, type[i]);
+
+ /* Validate s2tt_is_assigned_dev_dev with an assigned_dev TTE */
+ CHECK_TRUE(s2tte_is_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ tte, level) == true);
+ /*
+ * Negative test: Test with UNASSIGNED-RAM
+ * We test with UNASSIGNED-RAM as in the current RMM implementation,
+ * an ASSIGNED-RAM S2TTE does not have HIPAS field, so we pick
+ * up an S2TTE with a HIPAS other than ASSIGNED.
+ */
+ inv_tte = s2tte_create_unassigned_ram(
+ (const struct s2tt_context *)&s2tt_ctx);
+ CHECK_TRUE(s2tte_is_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+
+ /* Negative test: Test with a different type of RIPAS */
+ idx = (unsigned int)test_helpers_get_rand_in_range(
+ 0UL, ARRAY_SIZE(ripas) - 1UL);
+ inv_tte = s2tt_test_create_assigned(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[idx]);
+ CHECK_TRUE(s2tte_is_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ inv_tte, level) == false);
+ }
+ }
+}
+
+void s2tte_is_assigned_dev_dev_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * Calling s2tte_create_assigned_dev_dev() test
+ * s2tte_is_assigned_dev_dev() with invalid levels.
+ ***************************************************************/
+
+ unsigned long pa = 0UL;
+ unsigned long tte;
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ tte = s2tt_test_create_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+
+ /* Validate s2tt_is_assigned_dev_dev with an assigned_dev TTE */
+ CHECK_FALSE(s2tte_is_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ tte, level - 1L));
+ CHECK_FALSE(s2tte_is_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ tte, S2TT_TEST_HELPERS_MAX_LVL));
+}
+
+void s2tte_is_assigned_dev_dev_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * Calling s2tte_create_assigned_dev_dev_coh_type() for all
+ * RmmDevMemCoherent types test s2tte_is_assigned_dev_dev() with
+ * invalid levels.
+ ***************************************************************/
+
+ enum dev_coh_type type[] = {DEV_MEM_COHERENT,
+ DEV_MEM_NON_COHERENT};
+ unsigned long pa = 0UL;
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (unsigned long i = 0UL; i < ARRAY_SIZE(type); i++) {
+ unsigned long tte = s2tte_create_assigned_dev_dev_coh_type(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, type[i]);
+
+ /* Validate s2tt_is_assigned_dev_dev with an assigned_dev TTE */
+ CHECK_FALSE(s2tte_is_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ tte, level - 1L));
+ CHECK_FALSE(s2tte_is_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ tte, S2TT_TEST_HELPERS_MAX_LVL));
+ }
+}
+
+void s2tte_get_ripas_dev_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For all possible RIPAS types, generate a HIPAS ASSIGNED and
+ * verify that s2tt_get_ripas() returns the right RIPAS
+ ***************************************************************/
+
+ unsigned long tte, pa;
+ unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
+ S2TTE_INVALID_RIPAS_DESTROYED,
+ S2TTE_INVALID_RIPAS_DEV};
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (unsigned long i = 0UL; i < ARRAY_SIZE(ripas); i++) {
+ /* HIPAS = ASSIGNED */
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ pa = s2tt_test_helpers_gen_addr(level, true);
+ tte = s2tt_test_create_assigned_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, ripas[i]);
+ UNSIGNED_LONGS_EQUAL(
+ (unsigned int)s2tte_get_ripas(
+ (const struct s2tt_context *)&s2tt_ctx, tte),
+ EXTRACT(S2TTE_INVALID_RIPAS, ripas[i]));
+ }
+ }
+}
+
+void s2tte_get_ripas_dev_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For each valid level and all RmmDevMemCoherent types generate
+ * assigned_dev_dev and verify that s2tt_get_ripas() returns the
+ * right RIPAS
+ ***************************************************************/
+
+ enum dev_coh_type type[] = {DEV_MEM_COHERENT,
+ DEV_MEM_NON_COHERENT};
+ unsigned long tte, pa;
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Initialize an s2tt_context structure for the test.
+ * Only 'enable_lpa2' is used by the API, so the rest of fields
+ * can be left untouched.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+ for (unsigned long i = 0U; i < ARRAY_SIZE(type); i++) {
+ pa = s2tt_test_helpers_gen_addr(level, true);
+ tte = s2tte_create_assigned_dev_dev_coh_type(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level, type[i]);
+ UNSIGNED_LONGS_EQUAL(
+ (unsigned int)s2tte_get_ripas(
+ (const struct s2tt_context *)&s2tt_ctx, tte),
+ EXTRACT(S2TTE_INVALID_RIPAS, S2TTE_INVALID_RIPAS_DEV));
+ }
+ }
+}
+
+void s2tt_init_assigned_dev_empty_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For each valid level, initialize a table with assigned_dev
+ * empty S2TTEs and validate its contents.
+ ***************************************************************/
+
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
+
+ /* Generate the table */
+ s2tt_init_assigned_dev_empty(
+ (const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+
+ /* Validate the content of the table */
+ for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
+ unsigned long s2tte;
+
+ s2tte = s2tte_create_assigned_dev_empty(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ pa += s2tte_map_size(level);
+
+ UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
+ }
+ }
+}
+
+void s2tt_init_assigned_dev_empty_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid address, try to create an assigned_dev empty S2TT
+ * with a level above the maximum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0U], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_empty_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address, try to create an assigned_dev empty S2TT
+ * with a level below the minimum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0U], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_empty_tc4(void)
+{
+ /******************************************************************
+ * TEST CASE 4:
+ *
+ * Invoke s2tt_init_assigned_dev_empty() with a NULL table pointer.
+ ******************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ NULL, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_empty_tc5(void)
+{
+ /******************************************************************
+ * TEST CASE 5:
+ *
+ * Invoke s2tt_init_assigned_dev_empty() with an unaligned address.
+ ******************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level =
+ test_helpers_get_rand_in_range(s2tt_test_helpers_min_dev_block_lvl(),
+ S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
+ test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_empty((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0U], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_empty_tc6(void)
+{
+ /***************************************************************
+ * TEST CASE 6:
+ *
+ * Invoke s2tt_init_assigned_dev_empty() with a NULL s2tt_context
+ * structure.
+ ***************************************************************/
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_empty((const struct s2tt_context *)NULL,
+ &s2tt[0U], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_destroyed_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For each valid level, initialize a table with
+ * assigned_dev destroyed S2TTEs and validate its contents.
+ ***************************************************************/
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
+
+ /* Generate the table */
+ s2tt_init_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+
+ /* Validate the content of the table */
+ for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
+ unsigned long s2tte;
+
+ s2tte = s2tte_create_assigned_dev_destroyed(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ pa += s2tte_map_size(level);
+
+ UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
+ }
+ }
+}
+
+void s2tt_init_assigned_dev_destroyed_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid address, try to create an assigned_dev destroyed
+ * S2TT with a level above the maximum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_destroyed_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address, try to create an assigned_dev destroyed
+ * S2TT with a level below the minimum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_destroyed_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * Invoke s2tt_init_assigned_dev_destroyed() with a NULL table
+ * pointer.
+ ***************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ NULL, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_destroyed_tc5(void)
+{
+ /***************************************************************
+ * TEST CASE 5:
+ *
+ * Invoke s2tt_init_assigned_dev_destroyed() with an unaligned
+ * address.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level =
+ test_helpers_get_rand_in_range(s2tt_test_helpers_min_dev_block_lvl(),
+ S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
+ test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_destroyed((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_destroyed_tc6(void)
+{
+ /***************************************************************
+ * TEST CASE 6:
+ *
+ * Call s2tt_init_assigned_dev_destroyed() with a NULL struct
+ * s2tt_context pointer.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_destroyed((const struct s2tt_context *)NULL,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_dev_tc1(void)
+{
+ /***************************************************************
+ * TEST CASE 1:
+ *
+ * For each valid level, initialize a table with
+ * assigned_dev dev S2TTEs and validate its contents.
+ ***************************************************************/
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ for (long level = s2tt_test_helpers_min_dev_block_lvl();
+ level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
+
+ /* Generate the table */
+ s2tt_test_init_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+
+ /* Validate the content of the table */
+ for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
+ unsigned long s2tte;
+
+ s2tte = s2tt_test_create_assigned_dev_dev(
+ (const struct s2tt_context *)&s2tt_ctx,
+ pa, level);
+ pa += s2tte_map_size(level);
+
+ UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
+ }
+ }
+}
+
+void s2tt_init_assigned_dev_dev_tc2(void)
+{
+ /***************************************************************
+ * TEST CASE 2:
+ *
+ * For a valid address, try to create an assigned_dev dev S2TT
+ * with a level above the maximum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = S2TT_TEST_HELPERS_MAX_LVL + 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_test_init_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_dev_tc3(void)
+{
+ /***************************************************************
+ * TEST CASE 3:
+ *
+ * For a valid address, try to create an assigned_dev dev S2TT
+ * with a level below the minimum.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl() - 1L;
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_test_init_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_dev_tc4(void)
+{
+ /***************************************************************
+ * TEST CASE 4:
+ *
+ * Invoke s2tt_init_assigned_dev_dev() with a NULL table
+ * pointer.
+ ***************************************************************/
+
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_test_init_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ NULL, pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_dev_tc5(void)
+{
+ /***************************************************************
+ * TEST CASE 5:
+ *
+ * Invoke s2tt_init_assigned_dev_dev() with an unaligned
+ * address.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level =
+ test_helpers_get_rand_in_range(s2tt_test_helpers_min_dev_block_lvl(),
+ S2TT_TEST_HELPERS_MAX_LVL);
+ unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
+ test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
+ struct s2tt_context s2tt_ctx;
+
+ (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
+
+ /*
+ * Generate an s2tt context to be used for the test. Only
+ * enable_lpa2 field is needed for the current test.
+ */
+ s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_test_init_assigned_dev_dev((const struct s2tt_context *)&s2tt_ctx,
+ &s2tt[0], pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
+
+void s2tt_init_assigned_dev_dev_tc6(void)
+{
+ /***************************************************************
+ * TEST CASE 6:
+ *
+ * Call s2tt_init_assigned_dev_dev() with a NULL struct
+ * s2tt_context pointer.
+ ***************************************************************/
+
+ unsigned long s2tt[S2TTES_PER_S2TT] = {0};
+ long level = s2tt_test_helpers_min_dev_block_lvl();
+ unsigned long pa = 0UL; /* Valid for any level */
+ unsigned long attr = S2TTE_TEST_DEV_ATTRS;
+
+ /* Add Shareability bits if FEAT_LPA2 is not enabled */
+ if (!s2tt_test_helpers_lpa2_enabled()) {
+ attr |= S2TTE_TEST_DEV_SH;
+ }
+
+ test_helpers_expect_assert_fail(true);
+ s2tt_init_assigned_dev_dev((const struct s2tt_context *)NULL,
+ &s2tt[0], (attr | pa), pa, level);
+ test_helpers_fail_if_no_assert_failed();
+}
diff --git a/lib/s2tt/tests/s2tt_tests_base_g3.h b/lib/s2tt/tests/s2tt_tests_base_g3.h
new file mode 100644
index 0000000..3b98b2b
--- /dev/null
+++ b/lib/s2tt/tests/s2tt_tests_base_g3.h
@@ -0,0 +1,77 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
+ */
+
+#ifndef S2TT_TESTS_BASE_G3
+#define S2TT_TESTS_BASE_G3
+
+/* s2tte_create_assigned_dev_destroyed() */
+void s2tte_create_assigned_dev_destroyed_tc1(void);
+void s2tte_create_assigned_dev_destroyed_tc2(void);
+void s2tte_create_assigned_dev_destroyed_tc3(void);
+void s2tte_create_assigned_dev_destroyed_tc4(void);
+void s2tte_create_assigned_dev_destroyed_tc5(void);
+
+/* s2tte_create_assigned_dev_empty() */
+void s2tte_create_assigned_dev_empty_tc1(void);
+void s2tte_create_assigned_dev_empty_tc2(void);
+void s2tte_create_assigned_dev_empty_tc3(void);
+void s2tte_create_assigned_dev_empty_tc4(void);
+void s2tte_create_assigned_dev_empty_tc5(void);
+
+/* s2tte_create_assigned_dev_unchanged() */
+void s2tte_create_assigned_dev_unchanged_tc1(void);
+void s2tte_create_assigned_dev_unchanged_tc2(void);
+void s2tte_create_assigned_dev_unchanged_tc3(void);
+void s2tte_create_assigned_dev_unchanged_tc4(void);
+void s2tte_create_assigned_dev_unchanged_tc5(void);
+void s2tte_create_assigned_dev_unchanged_tc6(void);
+void s2tte_create_assigned_dev_unchanged_tc7(void);
+void s2tte_create_assigned_dev_unchanged_tc8(void);
+
+/* s2tte_has_ripas_dev() */
+void s2tte_has_ripas_dev_tc1(void);
+void s2tte_has_ripas_dev_tc2(void);
+
+/* s2tte_is_assigned_dev_empty() */
+void s2tte_is_assigned_dev_empty_tc1(void);
+
+/* s2tte_is_assigned_dev_destroyed() */
+void s2tte_is_assigned_dev_destroyed_tc1(void);
+
+/* s2tte_is_assigned_dev_dev() */
+void s2tte_is_assigned_dev_dev_tc1(void);
+void s2tte_is_assigned_dev_dev_tc2(void);
+void s2tte_is_assigned_dev_dev_tc3(void);
+void s2tte_is_assigned_dev_dev_tc4(void);
+
+/* s2tte_get_ripas() */
+void s2tte_get_ripas_dev_tc1(void);
+void s2tte_get_ripas_dev_tc2(void);
+
+/* s2tt_init_assigned_dev_empty() */
+void s2tt_init_assigned_dev_empty_tc1(void);
+void s2tt_init_assigned_dev_empty_tc2(void);
+void s2tt_init_assigned_dev_empty_tc3(void);
+void s2tt_init_assigned_dev_empty_tc4(void);
+void s2tt_init_assigned_dev_empty_tc5(void);
+void s2tt_init_assigned_dev_empty_tc6(void);
+
+/* s2tt_init_assigned_dev_destroyed() */
+void s2tt_init_assigned_dev_destroyed_tc1(void);
+void s2tt_init_assigned_dev_destroyed_tc2(void);
+void s2tt_init_assigned_dev_destroyed_tc3(void);
+void s2tt_init_assigned_dev_destroyed_tc4(void);
+void s2tt_init_assigned_dev_destroyed_tc5(void);
+void s2tt_init_assigned_dev_destroyed_tc6(void);
+
+/* void s2tt_init_assigned_dev_dev() */
+void s2tt_init_assigned_dev_dev_tc1(void);
+void s2tt_init_assigned_dev_dev_tc2(void);
+void s2tt_init_assigned_dev_dev_tc3(void);
+void s2tt_init_assigned_dev_dev_tc4(void);
+void s2tt_init_assigned_dev_dev_tc5(void);
+void s2tt_init_assigned_dev_dev_tc6(void);
+
+#endif /* S2TT_TESTS_BASE_G3 */