mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 13:26:48 +00:00
add reexport test
This commit is contained in:
parent
99e6ffb7f8
commit
394e146f3a
25
src/services/comp-sys/cargo-component/tests/reexport.rs
Normal file
25
src/services/comp-sys/cargo-component/tests/reexport.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//! This test checks that if cargo-component can control reexported entry points.
|
||||||
|
|
||||||
|
#![feature(once_cell)]
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use test_utils::{cargo_clean, cargo_component, clean_after_test};
|
||||||
|
mod test_utils;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reexport() {
|
||||||
|
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
let target_dir = root_dir.join("target").join("reexport_test");
|
||||||
|
let cwd = root_dir.join("tests").join("reexport_test");
|
||||||
|
let output = cargo_clean(&cwd, &target_dir);
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
let output = cargo_component(&cwd, &target_dir);
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
println!("stderr: {stderr}");
|
||||||
|
|
||||||
|
assert!(output.status.success());
|
||||||
|
assert!(!stderr.contains("access controlled entry point is disallowed"));
|
||||||
|
|
||||||
|
clean_after_test(&cwd);
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
[workspace]
|
||||||
|
members = ["foo", "bar", "baz"]
|
@ -0,0 +1,20 @@
|
|||||||
|
[components]
|
||||||
|
foo = { name = "foo" }
|
||||||
|
bar = { name = "bar" }
|
||||||
|
baz = { name = "baz" }
|
||||||
|
|
||||||
|
[whitelist]
|
||||||
|
[whitelist.foo.f1]
|
||||||
|
baz = true
|
||||||
|
|
||||||
|
[whitelist.foo.Foo.new]
|
||||||
|
baz = true
|
||||||
|
|
||||||
|
[whitelist.foo.Foo.get]
|
||||||
|
baz = true
|
||||||
|
|
||||||
|
[whitelist.foo.FooTrait.t_new]
|
||||||
|
baz = true
|
||||||
|
|
||||||
|
[whitelist.foo.FooTrait.t_get]
|
||||||
|
baz = true
|
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "bar"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
foo = {path ="../foo"}
|
@ -0,0 +1,3 @@
|
|||||||
|
pub use foo::f1;
|
||||||
|
pub use foo::Foo;
|
||||||
|
pub use foo::FooTrait;
|
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "baz"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
foo = {path ="../foo"}
|
||||||
|
bar = {path ="../bar"}
|
@ -0,0 +1,24 @@
|
|||||||
|
pub fn reexport_fn() {
|
||||||
|
foo::f1();
|
||||||
|
bar::f1();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reexport_method() {
|
||||||
|
let foo_struct = foo::Foo::new();
|
||||||
|
foo_struct.get();
|
||||||
|
|
||||||
|
let another_foo = bar::Foo::new();
|
||||||
|
another_foo.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reexport_trait_1() {
|
||||||
|
use foo::FooTrait;
|
||||||
|
let foo_struct = foo::Foo::t_new();
|
||||||
|
foo_struct.t_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reexport_trait_2() {
|
||||||
|
use bar::FooTrait;
|
||||||
|
let foo_struct = bar::Foo::t_new();
|
||||||
|
foo_struct.t_get();
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
controlled = {path = "../../../../controlled"}
|
@ -0,0 +1,39 @@
|
|||||||
|
#![feature(register_tool)]
|
||||||
|
#![register_tool(component_access_control)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate controlled;
|
||||||
|
|
||||||
|
#[controlled]
|
||||||
|
pub fn f1() {}
|
||||||
|
|
||||||
|
pub struct Foo;
|
||||||
|
|
||||||
|
impl Foo {
|
||||||
|
#[controlled]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
#[controlled]
|
||||||
|
pub fn get(&self) -> usize {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FooTrait {
|
||||||
|
#[controlled]
|
||||||
|
fn t_new() -> Self;
|
||||||
|
#[controlled]
|
||||||
|
fn t_get(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FooTrait for Foo {
|
||||||
|
fn t_new() -> Self {
|
||||||
|
Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fn t_get(&self) -> usize {
|
||||||
|
43
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ pub fn cargo_component(cwd: &PathBuf, target_dir: &PathBuf) -> Output {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean_after_test(cwd: &PathBuf) {
|
pub fn clean_after_test(cwd: &PathBuf) {
|
||||||
|
Command::new("cargo").arg("clean").current_dir(cwd).status().unwrap();
|
||||||
let cargo_lock = cwd.join("Cargo.lock");
|
let cargo_lock = cwd.join("Cargo.lock");
|
||||||
std::fs::remove_file(cargo_lock);
|
std::fs::remove_file(cargo_lock);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user