ivila commented on code in PR #209:
URL: 
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/209#discussion_r2199782585


##########
optee-utee/src/object/persistent_object.rs:
##########
@@ -529,26 +484,186 @@ impl PersistentObject {
     }
 }
 
-impl ObjHandle for PersistentObject {
+impl GenericObject for PersistentObject {
     fn handle(&self) -> raw::TEE_ObjectHandle {
         self.0.handle()
     }
 }
 
-impl Drop for PersistentObject {
-    /// Close an opened [PersistentObject](PersistentObject).
-    ///
-    /// # Panics
-    ///
-    /// 1) If object is not a valid opened object.
-    /// 2) If the Implementation detects any other error associated with this 
function which is not
-    ///    explicitly associated with a defined return code for this function.
-    fn drop(&mut self) {
-        unsafe {
-            if self.0.raw != Box::into_raw(Box::new(ptr::null_mut())) {
-                raw::TEE_CloseObject(self.0.handle());
-            }
-            drop(Box::from_raw(self.0.raw));
+#[cfg(test)]
+mod tests {
+    extern crate std;
+
+    use std::sync::Arc;
+
+    use optee_utee_mock::{
+        object::{set_global_object_mock, MockObjectController, 
SERIAL_TEST_LOCK},
+        raw,
+    };
+
+    use super::*;
+
+    #[test]
+    // If a persistent object is successfully created, TEE_CloseObject will be
+    // called when it is dropped.
+    fn test_create_and_drop() {
+        let _lock = SERIAL_TEST_LOCK.lock();
+
+        let mut mock = MockObjectController::new();
+        let mut value: raw::__TEE_ObjectHandle = unsafe { core::mem::zeroed() 
};
+        let handle: Arc<raw::TEE_ObjectHandle> = Arc::new(&mut value);
+        {
+            let handle = handle.clone();
+            mock.expect_TEE_CreatePersistentObject()
+                .return_once_st(
+                    move |_, _, _, _, _, _, _, obj: *mut 
raw::TEE_ObjectHandle| {
+                        unsafe {
+                            *obj = *handle;
+                        }
+                        raw::TEE_SUCCESS
+                    },
+                )
+                .once();
+        }
+

Review Comment:
   I think the complexity arises from Rust's syntax, and the logic cannot be 
defined in a straightforward way due to its context-awareness. For instance, in 
this case, we need to generate a unique `raw::TEE_ObjectHandle`. When calling 
`TEE_CreatePersistentObject`, we provide this value. Later, when calling 
`TEE_CloseObject`, we must ensure the correct value is passed—not just any 
random value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org
For additional commands, e-mail: dev-h...@teaclave.apache.org

Reply via email to