storage: Add aidl tests for TDEA, TDP, and TD

Bug: 300673823
Change-Id: I6cc6305e2d5bd53d4f16be8f5156f799c4f36973
diff --git a/build-config-usertests b/build-config-usertests
index 568ad2f..7013e1c 100644
--- a/build-config-usertests
+++ b/build-config-usertests
@@ -50,6 +50,7 @@
     # in testrunner is insufficient.
     needs(
         [
+            porttest("com.android.trusty.rust.storage_unittest_aidl_ns.test", timeout=(60 * 30)),
             porttest("com.android.storage-unittest.nsp", timeout=(60 * 30)),
             porttest("com.android.storage-unittest.td"),
             porttest("com.android.storage-unittest.tdp", timeout=(60 * 30)),
diff --git a/test/storage-unittest-aidl/aidl-test-inc.mk b/test/storage-unittest-aidl/aidl-test-inc.mk
new file mode 100644
index 0000000..379e5b6
--- /dev/null
+++ b/test/storage-unittest-aidl/aidl-test-inc.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+MODULE_SRCS += \
+	$(SRC_DIR)/lib.rs \
+
+MODULE_LIBRARY_DEPS += \
+	$(call FIND_CRATE,libc) \
+	$(call FIND_CRATE,log) \
+	frameworks/native/libs/binder/trusty/rust \
+	frameworks/native/libs/binder/trusty/rust/binder_rpc_server \
+	frameworks/native/libs/binder/trusty/rust/rpcbinder \
+	trusty/user/base/interface/secure_storage/rust \
+	trusty/user/base/lib/trusty-std \
+	trusty/user/base/lib/trusty-log \
+	trusty/user/base/lib/tipc/rust \
+
+MODULE_RUST_TESTS := true
+
+include make/library.mk
diff --git a/test/storage-unittest-aidl/lib.rs b/test/storage-unittest-aidl/lib.rs
index 6eb0e47..8284e36 100644
--- a/test/storage-unittest-aidl/lib.rs
+++ b/test/storage-unittest-aidl/lib.rs
@@ -5,7 +5,7 @@
 
 #[cfg(test)]
 mod tests {
-    use crate::unittests;
+    use crate::define_tests_for;
     use android_hardware_security_see_storage::aidl::android::hardware::security::see::storage::{
         FileAvailability::FileAvailability, FileIntegrity::FileIntegrity,
         FileProperties::FileProperties, ISecureStorage::ISecureStorage,
@@ -37,33 +37,65 @@
         assert_ok!(secure_storage.as_binder().ping_binder());
     }
 
-    mod tp {
-        use super::*;
-        const TP: &'static FileProperties = &FileProperties {
-            integrity: FileIntegrity::TAMPER_PROOF_AT_REST,
-            availability: FileAvailability::AFTER_USERDATA,
-            persistent: false,
-        };
+    const TP: &'static FileProperties = &FileProperties {
+        integrity: FileIntegrity::TAMPER_PROOF_AT_REST,
+        availability: FileAvailability::AFTER_USERDATA,
+        persistent: false,
+    };
+    const TDEA: &'static FileProperties = &FileProperties {
+        integrity: FileIntegrity::TAMPER_DETECT,
+        availability: FileAvailability::BEFORE_USERDATA,
+        persistent: false,
+    };
+    #[cfg(feature = "has_ns")]
+    const TDP: &'static FileProperties = &FileProperties {
+        integrity: FileIntegrity::TAMPER_DETECT,
+        availability: FileAvailability::AFTER_USERDATA,
+        persistent: true,
+    };
+    #[cfg(feature = "has_ns")]
+    const TD: &'static FileProperties = &FileProperties {
+        integrity: FileIntegrity::TAMPER_DETECT,
+        availability: FileAvailability::AFTER_USERDATA,
+        persistent: false,
+    };
 
-        #[test]
-        fn create_delete() {
-            let ss = assert_ok!(start_session(TP));
-            unittests::create_delete(&*ss);
-        }
-        #[test]
-        fn create_move_delete() {
-            let ss = assert_ok!(start_session(TP));
-            unittests::create_move_delete(&*ss);
-        }
-        #[test]
-        fn file_list() {
-            let ss = assert_ok!(start_session(TP));
-            unittests::file_list(&*ss);
-        }
-        #[test]
-        fn write_read_sequential() {
-            let ss = assert_ok!(start_session(TP));
-            unittests::write_read_sequential(&*ss);
-        }
+    define_tests_for!(tp, TP);
+    define_tests_for!(tdea, TDEA);
+    #[cfg(feature = "has_ns")]
+    define_tests_for!(tdp, TDP);
+    #[cfg(feature = "has_ns")]
+    define_tests_for!(td, TD);
+
+    #[macro_export]
+    macro_rules! define_tests_for {
+        ($mod_name:ident, $file_properties:ident) => {
+            mod $mod_name {
+                use super::$file_properties;
+                use test::assert_ok;
+                use $crate::{tests::start_session, unittests};
+
+                #[test]
+                fn create_delete() {
+                    let ss = assert_ok!(start_session($file_properties));
+                    unittests::create_delete(&*ss);
+                }
+                #[test]
+                fn create_move_delete() {
+                    let ss = assert_ok!(start_session($file_properties));
+                    unittests::create_move_delete(&*ss);
+                }
+                #[test]
+                fn file_list() {
+                    let ss = assert_ok!(start_session($file_properties));
+                    unittests::file_list(&*ss);
+                }
+                #[test]
+                fn write_read_sequential() {
+                    let ss = assert_ok!(start_session($file_properties));
+                    unittests::write_read_sequential(&*ss);
+                }
+            }
+        };
     }
 }
diff --git a/test/storage-unittest-aidl/ns/manifest.json b/test/storage-unittest-aidl/ns/manifest.json
new file mode 100644
index 0000000..f0df82a
--- /dev/null
+++ b/test/storage-unittest-aidl/ns/manifest.json
@@ -0,0 +1,9 @@
+{
+    "app_name": "storage_unittest_aidl_ns_lib",
+    "uuid": "05ed8f7d-3056-4805-af1c-1e469cb56cda",
+    "min_heap": 65536,
+    "min_stack": 32768,
+    "mgmt_flags": {
+        "non_critical_app": true
+    }
+}
\ No newline at end of file
diff --git a/test/storage-unittest-aidl/ns/rules.mk b/test/storage-unittest-aidl/ns/rules.mk
new file mode 100644
index 0000000..5cf894b
--- /dev/null
+++ b/test/storage-unittest-aidl/ns/rules.mk
@@ -0,0 +1,28 @@
+# Copyright (C) 2023 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MANIFEST := $(LOCAL_DIR)/manifest.json
+
+MODULE_CRATE_NAME := storage_unittest_aidl_ns
+
+SRC_DIR := $(LOCAL_DIR)/..
+
+MODULE_RUSTFLAGS += \
+	--cfg 'feature="has_ns"' \
+
+include trusty/user/app/storage/test/storage-unittest-aidl/aidl-test-inc.mk
diff --git a/test/storage-unittest-aidl/rules.mk b/test/storage-unittest-aidl/rules.mk
index 4b245b6..48d67c7 100644
--- a/test/storage-unittest-aidl/rules.mk
+++ b/test/storage-unittest-aidl/rules.mk
@@ -18,22 +18,8 @@
 
 MANIFEST := $(LOCAL_DIR)/manifest.json
 
-MODULE_SRCS += \
-	$(LOCAL_DIR)/lib.rs \
-
 MODULE_CRATE_NAME := storage_unittest_aidl
 
-MODULE_LIBRARY_DEPS += \
-	$(call FIND_CRATE,libc) \
-	$(call FIND_CRATE,log) \
-	frameworks/native/libs/binder/trusty/rust \
-	frameworks/native/libs/binder/trusty/rust/binder_rpc_server \
-	frameworks/native/libs/binder/trusty/rust/rpcbinder \
-	trusty/user/base/interface/secure_storage/rust \
-	trusty/user/base/lib/trusty-std \
-	trusty/user/base/lib/trusty-log \
-	trusty/user/base/lib/tipc/rust \
+SRC_DIR := $(LOCAL_DIR)/
 
-MODULE_RUST_TESTS := true
-
-include make/library.mk
+include trusty/user/app/storage/test/storage-unittest-aidl/aidl-test-inc.mk
diff --git a/usertests-inc.mk b/usertests-inc.mk
index 95be4c3..2f25730 100644
--- a/usertests-inc.mk
+++ b/usertests-inc.mk
@@ -20,5 +20,6 @@
 ifeq (true,$(call TOBOOL,$(STORAGE_AIDL_ENABLED)))
 TRUSTY_RUST_USER_TESTS += \
 	trusty/user/app/storage/test/storage-unittest-aidl \
+	trusty/user/app/storage/test/storage-unittest-aidl/ns \
 
 endif