• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //! Test end-to-end IAccessor implementation with accessor_demo.
18 
19 use com_android_virt_accessor_demo_vm_service::aidl::com::android::virt::accessor_demo::vm_service::IAccessorVmService::IAccessorVmService;
20 use binder::{Strong, ProcessState};
21 
22 const VM_SERVICE: &str = "com.android.virt.accessor_demo.vm_service.IAccessorVmService/default";
23 
init()24 fn init() {
25     ProcessState::set_thread_pool_max_thread_count(5);
26     ProcessState::start_thread_pool();
27 }
28 
wait_for_interface() -> Strong<dyn IAccessorVmService>29 fn wait_for_interface() -> Strong<dyn IAccessorVmService> {
30     binder::wait_for_interface(VM_SERVICE).unwrap()
31 }
32 
get_interface() -> Strong<dyn IAccessorVmService>33 fn get_interface() -> Strong<dyn IAccessorVmService> {
34     binder::get_interface(VM_SERVICE).unwrap()
35 }
36 
check_interface() -> Strong<dyn IAccessorVmService>37 fn check_interface() -> Strong<dyn IAccessorVmService> {
38     binder::check_interface(VM_SERVICE).unwrap()
39 }
40 
41 #[test]
test_wait_for_interface()42 fn test_wait_for_interface() {
43     init();
44 
45     let service = wait_for_interface();
46     let sum = service.add(11, 12).unwrap();
47 
48     assert_eq!(sum, 23);
49 }
50 
51 #[test]
test_wait_for_interface_twice()52 fn test_wait_for_interface_twice() {
53     init();
54 
55     let service1 = wait_for_interface();
56     let service2 = wait_for_interface();
57 
58     assert_eq!(service1.add(11, 12).unwrap(), 23);
59     assert_eq!(service2.add(11, 12).unwrap(), 23);
60 }
61 
62 #[test]
test_wait_and_get_interface()63 fn test_wait_and_get_interface() {
64     init();
65 
66     let service1 = wait_for_interface();
67     let service2 = get_interface();
68 
69     assert_eq!(service1.add(11, 12).unwrap(), 23);
70     assert_eq!(service2.add(11, 12).unwrap(), 23);
71 }
72 
73 #[test]
test_wait_and_check_interface()74 fn test_wait_and_check_interface() {
75     init();
76 
77     let service1 = wait_for_interface();
78     let service2 = check_interface();
79 
80     assert_eq!(service1.add(11, 12).unwrap(), 23);
81     assert_eq!(service2.add(11, 12).unwrap(), 23);
82 }
83