Skip to content

Commit

Permalink
[virtualization][gpu] Do not hardcode display-coordinator device path.
Browse files Browse the repository at this point in the history
This change replaces the hardcoded display-coordinator device path
(000) with the first available device from the path.

This makes it possible to obfuscate device paths in devfs.

Test: virtualization-gpu-tests
Bug: 42065065
Change-Id: I81db9904208f3ba47426ec178bebe25cde27cad5
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1086775
Commit-Queue: Yilong Li <[email protected]>
Reviewed-by: Victor Costan <[email protected]>
Reviewed-by: Tim Kilbourn <[email protected]>
  • Loading branch information
gnoliyil authored and CQ Bot committed Jul 22, 2024
1 parent 8c846ad commit f3fe774
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/virtualization/tests/virtio_gpu_test_util/src/zirconfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

use crate::framebuffer::{DetectResult, DisplayInfo, Framebuffer};
use anyhow::Error;
use anyhow::{Context, Error};
use fidl::endpoints;
use fidl_fuchsia_hardware_display::{
CoordinatorEvent, CoordinatorMarker, CoordinatorSynchronousProxy, Info,
Expand All @@ -12,7 +12,18 @@ use fidl_fuchsia_hardware_display::{
use fuchsia_zircon as zx;
use serde_json::json;

const DEVICE_PATH: &'static str = "/dev/class/display-coordinator/000";
fn get_display_coordinator_path() -> anyhow::Result<String> {
// TODO(liyl): This assumes that a display-coordinator device is ready before the test binary
// starts. Consider switching to `fuchsia_fs::directory::Watcher` if this flakes.
const DEVICE_CLASS_PATH: &'static str = "/dev/class/display-coordinator";
let entries = std::fs::read_dir(DEVICE_CLASS_PATH).context("read directory")?;
let entry = entries
.into_iter()
.next()
.context("no valid display-coordinator")?
.context("entry invalid")?;
Ok(String::from(entry.path().to_string_lossy()))
}

fn convert_info(info: &Info) -> DisplayInfo {
DisplayInfo {
Expand All @@ -26,7 +37,12 @@ fn read_info() -> Result<DetectResult, Error> {
// Connect to the display coordinator.
let provider = {
let (client_end, server_end) = zx::Channel::create();
fuchsia_component::client::connect_channel_to_protocol_at_path(server_end, DEVICE_PATH)?;
let display_coordinator_path =
get_display_coordinator_path().context("get display coordinator path")?;
fuchsia_component::client::connect_channel_to_protocol_at_path(
server_end,
&display_coordinator_path,
)?;
ProviderSynchronousProxy::new(client_end)
};
let coordinator = {
Expand Down

0 comments on commit f3fe774

Please sign in to comment.