blob: 9f0b7fd29b6af69b0799d5e0e02e4e214591efd7 [file] [log] [blame]
Nikita Ioffe344dc462024-12-10 18:31:24 +00001/*
2 * Copyright (C) 2025 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
17use android_hardware_virtualization_capabilities_capabilities_service::aidl::android::hardware::virtualization::capabilities::IVmCapabilitiesService::IVmCapabilitiesService;
18use rdroidtest::rdroidtest;
19use std::fs::File;
20
21const VM_CAPABILITIES_SERVICE: &str =
22 "android.hardware.virtualization.capabilities.IVmCapabilitiesService";
23
24/// Returns all available instances of VmCapabilitiesService.
25/// Note: it actually returns a pair of (<instance_name>, <instance_name)). This is a requirement
26/// of the rdroidtest framework for parameterized tests. See
27/// platform_testing/libraries/rdroidtest/README.md for more information.
28fn get_instances() -> Vec<(String, String)> {
29 binder::get_declared_instances(VM_CAPABILITIES_SERVICE)
30 .unwrap_or_default()
31 .into_iter()
32 .map(|v| (v.clone(), v))
33 .collect()
34}
35
36fn connect(instance: &str) -> binder::Strong<dyn IVmCapabilitiesService> {
37 let name = format!("{VM_CAPABILITIES_SERVICE}/{instance}");
38 binder::wait_for_interface(&name).unwrap()
39}
40
41/// A very basic test that simply connects to the service and send bogus data.
42#[rdroidtest(get_instances())]
43fn connect_to_service(instance: String) {
44 let service = connect(&instance);
45 let dev_null = File::open("/dev/null").expect("failed to open /dev/null");
46 let fd = binder::ParcelFileDescriptor::new(dev_null);
47 // In this test we don't care what service returns.
48 let _ = service.grantAccessToVendorTeeServices(&fd, &[]);
49}
50
51rdroidtest::test_main!();