Skip to content

Commit

Permalink
[component_manager][tests] Convert tests to name-based capabilities #3
Browse files Browse the repository at this point in the history
Change-Id: I17fd31e617e8791ec90c66286f3b7a76f5cd0bc3
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/420302
Reviewed-by: Justin Mattson <[email protected]>
Reviewed-by: Miguel Flores <[email protected]>
Testability-Review: Gary Bressler <[email protected]>
Testability-Review: Miguel Flores <[email protected]>
Commit-Queue: Gary Bressler <[email protected]>
  • Loading branch information
gebressler authored and CQ Bot committed Aug 31, 2020
1 parent 9e6a467 commit 4dfe7bd
Show file tree
Hide file tree
Showing 55 changed files with 388 additions and 192 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Component manifest for the `echo_server` example program, which hosts the Echo service used
// by `echo_client`.
// TODO(56604): Replace `echo_server.cml` with this.
{
program: {
binary: "bin/echo_server",
},
capabilities: [
{ protocol: "fidl.examples.routing.echo.Echo" },
],
use: [
{ runner: "elf" },
],
expose: [
{
protocol: "fidl.examples.routing.echo.Echo",
from: "self",
},
{
directory: "hub",
from: "framework",
},
],
}
34 changes: 20 additions & 14 deletions src/sys/component_manager/src/model/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,28 @@ impl Hub {
trace::duration!("component_manager", "hub:on_capability_routed_async");
// If this is a scoped framework directory capability, then check the source path
if let CapabilitySource::Framework {
capability: InternalCapability::Directory(source_name_or_path),
capability: InternalCapability::Directory(name_or_path),
scope_moniker,
} = source
{
// TODO(56604): Support routing hub by name
let source_path = match source_name_or_path {
CapabilityNameOrPath::Path(source_path) => source_path,
CapabilityNameOrPath::Name(_) => {
return Ok(());
let relative_path = match name_or_path {
CapabilityNameOrPath::Path(source_path) => {
let mut relative_path = source_path.split();
// The source path must begin with "hub"
if relative_path.is_empty() || relative_path.remove(0) != "hub" {
return Ok(());
}
relative_path
}
CapabilityNameOrPath::Name(source_name) => {
// There's only one "hub" name-based capability, but `subdir` (handled by
// routing logic, not here) can achieve the same effect.
if source_name.str() != "hub" {
return Ok(());
}
vec![]
}
};
let mut relative_path = source_path.split();
// The source path must begin with "hub"
if relative_path.is_empty() || relative_path.remove(0) != "hub" {
return Ok(());
}

// Set the capability provider, if not already set.
let mut capability_provider = capability_provider.lock().await;
Expand Down Expand Up @@ -777,7 +783,7 @@ mod tests {
.add_lazy_child("a")
.use_(UseDecl::Directory(UseDirectoryDecl {
source: UseSource::Framework,
source_path: CapabilityNameOrPath::try_from("/hub").unwrap(),
source_path: CapabilityNameOrPath::try_from("hub").unwrap(),
target_path: CapabilityPath::try_from("/hub").unwrap(),
rights: *rights::READ_RIGHTS | *rights::WRITE_RIGHTS,
subdir: None,
Expand Down Expand Up @@ -830,10 +836,10 @@ mod tests {
.add_lazy_child("a")
.use_(UseDecl::Directory(UseDirectoryDecl {
source: UseSource::Framework,
source_path: CapabilityNameOrPath::try_from("/hub/exec").unwrap(),
source_path: CapabilityNameOrPath::try_from("hub").unwrap(),
target_path: CapabilityPath::try_from("/hub").unwrap(),
rights: *rights::READ_RIGHTS | *rights::WRITE_RIGHTS,
subdir: None,
subdir: Some("exec".into()),
}))
.use_(UseDecl::Protocol(UseProtocolDecl {
source: UseSource::Parent,
Expand Down
25 changes: 18 additions & 7 deletions src/sys/component_manager/src/model/testing/test_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,28 @@ impl HubInjectionTestHook {
) -> Result<Option<Box<dyn CapabilityProvider>>, ModelError> {
// This Hook is about injecting itself between the Hub and the Model.
// If the Hub hasn't been installed, then there's nothing to do here.
let mut relative_path = match (&capability_provider, capability) {
(Some(_), InternalCapability::Directory(CapabilityNameOrPath::Path(source_path))) => {
source_path.split()
let relative_path = match (&capability_provider, capability) {
(Some(_), InternalCapability::Directory(name_or_path)) => {
match name_or_path {
CapabilityNameOrPath::Path(source_path) => {
let mut relative_path = source_path.split();
// The source path must begin with "hub"
if relative_path.is_empty() || relative_path.remove(0) != "hub" {
return Ok(capability_provider);
}
relative_path
}
CapabilityNameOrPath::Name(source_name) => {
if source_name.str() != "hub" {
return Ok(capability_provider);
}
vec![]
}
}
}
_ => return Ok(capability_provider),
};

if relative_path.is_empty() || relative_path.remove(0) != "hub" {
return Ok(capability_provider);
}

Ok(Some(Box::new(HubInjectionCapabilityProvider::new(
scope_moniker,
relative_path,
Expand Down
2 changes: 1 addition & 1 deletion src/sys/component_manager/tests/collections/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_package("collections_integration_test") {
meta = [
{
path = rebase_path(
"//examples/components/routing/echo_server/meta/echo_server.cml")
"//examples/components/routing/echo_server/meta/echo_server_name_based.cml")
dest = "echo_server.cm"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn list_children(realm: &fsys::RealmProxy) -> Result<String, Error> {
fn open_trigger_svc(dir: &DirectoryProxy) -> Result<ftest::TriggerProxy, Error> {
let node_proxy = io_util::open_node(
dir,
&PathBuf::from("svc/fidl.test.components.Trigger"),
&PathBuf::from("fidl.test.components.Trigger"),
OPEN_RIGHT_READABLE,
MODE_TYPE_SERVICE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
durability: "transient",
},
],
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
use: [
{ runner: "rust_test_runner" },

// Needed to bind to and create children
{
protocol: "/svc/fuchsia.sys2.Realm",
protocol: "fuchsia.sys2.Realm",
from: "framework",
},
{
Expand All @@ -31,7 +34,7 @@
// Route Echo service from server to collection.
offer: [
{
protocol: "/svc/fidl.examples.routing.echo.Echo",
protocol: "fidl.examples.routing.echo.Echo",
from: "#echo_server",
to: [ "#coll" ],
},
Expand All @@ -43,7 +46,7 @@
],
expose: [
{
protocol: "/svc/fuchsia.test.Suite",
protocol: "fuchsia.test.Suite",
from: "self",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
"a",
],
},
capabilities: [
{ protocol: "fidl.test.components.Trigger" },
],
use: [
{ runner: "elf" },
{ protocol: "/svc/fidl.examples.routing.echo.Echo" },
{ protocol: "fidl.examples.routing.echo.Echo" },
],
expose: [
{
protocol: "/svc/fidl.test.components.Trigger",
protocol: "fidl.test.components.Trigger",
from: "self",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
"b",
],
},
capabilities: [
{ protocol: "fidl.test.components.Trigger" },
],
use: [
{ runner: "elf" },
{ protocol: "/svc/fidl.examples.routing.echo.Echo" },
{ protocol: "fidl.examples.routing.echo.Echo" },
],
expose: [
{
protocol: "/svc/fidl.test.components.Trigger",
protocol: "fidl.test.components.Trigger",
from: "self",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
offer: [
{
protocol: [
"/svc/fidl.examples.routing.echo.Echo",
"/svc/fuchsia.logger.LogSink",
"fidl.examples.routing.echo.Echo",
],
from: "parent",
to: [ "#trigger" ],
Expand All @@ -22,7 +22,7 @@
// Expose Trigger service from child.
expose: [
{
protocol: "/svc/fidl.test.components.Trigger",
protocol: "fidl.test.components.Trigger",
from: "#trigger",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
program: {
binary: "bin/component_time_test",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
use: [
// Use test runner which will expose `fuchsia.test.Suite` on test's behalf.
{ runner: "rust_test_runner" },
Expand All @@ -13,7 +16,7 @@
// The Fuchsia Test Framework expects this service to be exposed from the
// test component. The Rust test adapter provides this service.
{
protocol: "/svc/fuchsia.test.Suite",
protocol: "fuchsia.test.Suite",
from: "self",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn main() {
fn open_trigger_svc(dir: &DirectoryProxy) -> Result<ftest::TriggerProxy, Error> {
let node_proxy = io_util::open_node(
dir,
&PathBuf::from("svc/fidl.test.components.Trigger"),
&PathBuf::from("fidl.test.components.Trigger"),
OPEN_RIGHT_READABLE,
MODE_TYPE_SERVICE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{ runner: "elf" },
{ protocol: "/svc/fuchsia.logger.LogSink" },
{
protocol: "/svc/fuchsia.sys2.Realm",
protocol: "fuchsia.sys2.Realm",
from: "framework",
},
],
Expand Down
5 changes: 4 additions & 1 deletion src/sys/component_manager/tests/destruction/meta/trigger.cml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
program: {
binary: "bin/trigger",
},
capabilities: [
{ protocol: "fidl.test.components.Trigger" },
],
use: [
{ runner: "elf" },
],
expose: [
{
protocol: "/svc/fidl.test.components.Trigger",
protocol: "fidl.test.components.Trigger",
from: "self",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
startup: "eager",
},
],
capabilities: [
{ protocol: "fidl.test.components.Trigger" },
],
use: [
{ runner: "elf" },
],

// Expose my Trigger service so the integration test can invoke it.
expose: [
{
protocol: "/svc/fidl.test.components.Trigger",
protocol: "fidl.test.components.Trigger",
from: "self",
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/sys/component_manager/tests/hub/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test_package("hub_integration_test") {
meta = [
{
path = rebase_path(
"//examples/components/routing/echo_server/meta/echo_server.cml")
"//examples/components/routing/echo_server/meta/echo_server_name_based.cml")
dest = "echo_server.cm"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
// Route Echo service from server to client.
offer: [
{
protocol: "/svc/fidl.examples.routing.echo.Echo",
protocol: "fidl.examples.routing.echo.Echo",
from: "#echo_server",
to: [ "#reporter" ],
},
{
directory: "/hub",
directory: "hub",
from: "framework",
to: [ "#reporter" ],
},
{
directory: "/hub",
directory: "hub",
from: "#echo_server",
as: "/sibling_hub",
as: "sibling_hub",
to: [ "#reporter" ],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@
use: [
{ runner: "elf" },
{
directory: "/hub",
directory: "hub",
from: "parent",
as: "/parent_hub",
rights: [ "r*" ],
path: "/parent_hub",
},
{
directory: "/hub/exec",
directory: "hub",
from: "framework",
as: "/hub",
rights: [ "r*" ],
path: "/hub",
subdir: "exec",
},
{
directory: "/sibling_hub",
directory: "sibling_hub",
from: "parent",
rights: [ "r*" ],
path: "/sibling_hub",
},
{ protocol: "/svc/fidl.examples.routing.echo.Echo" },
{ protocol: "fidl.examples.routing.echo.Echo" },
{
protocol: [ "/svc/fuchsia.test.hub.HubReport" ],
protocol: [ "fuchsia.test.hub.HubReport" ],
from: "framework",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
{ protocol: "/svc/fuchsia.sys2.BlockingEventSource" },
{
protocol: [
"/svc/fuchsia.sys2.Realm",
"/svc/fuchsia.test.hub.HubReport",
"fuchsia.sys2.Realm",
"fuchsia.test.hub.HubReport",
],
from: "framework",
},
{
directory: "/hub",
directory: "hub",
from: "framework",
rights: [ "r*" ],
path: "/hub",
},
{
event: [
Expand Down
Loading

0 comments on commit 4dfe7bd

Please sign in to comment.