ivila commented on code in PR #209:
URL:
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/209#discussion_r2200251856
##########
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:
Done by adding functions for `MockObjectController` like
`new_valid_test_handle`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]