Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions test/extensions/bootstrap/wasm/test_data/logging_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ proxy_wasm::main! {{
struct TestRoot;

impl RootContext for TestRoot {
fn on_vm_start(&mut self, _: usize) -> bool {
true
}
fn on_vm_start(&mut self, _: usize) -> bool {
true
}

fn on_configure(&mut self, _: usize) -> bool {
trace!("ON_CONFIGURE: {}", std::env::var("ON_CONFIGURE").unwrap());
trace!("test trace logging");
debug!("test debug logging");
error!("test error logging");
if let Some(value) = self.get_plugin_configuration() {
warn!("warn {}", String::from_utf8(value).unwrap());
}
true
fn on_configure(&mut self, _: usize) -> bool {
trace!("ON_CONFIGURE: {}", std::env::var("ON_CONFIGURE").unwrap());
trace!("test trace logging");
debug!("test debug logging");
error!("test error logging");
if let Some(value) = self.get_plugin_configuration() {
warn!("warn {}", String::from_utf8(value).unwrap());
}
true
}

fn on_tick(&mut self) {
trace!("ON_TICK: {}", std::env::var("ON_TICK").unwrap());
if let Some(value) = self.get_property(vec!["plugin_root_id"]) {
info!("test tick logging{}", String::from_utf8(value).unwrap());
} else {
info!("test tick logging");
}
self.done();
fn on_tick(&mut self) {
trace!("ON_TICK: {}", std::env::var("ON_TICK").unwrap());
if let Some(value) = self.get_property(vec!["plugin_root_id"]) {
info!("test tick logging{}", String::from_utf8(value).unwrap());
} else {
info!("test tick logging");
}
self.done();
}
}

impl Context for TestRoot {
fn on_done(&mut self) -> bool {
info!("onDone logging");
false
}
fn on_done(&mut self) -> bool {
info!("onDone logging");
false
}
}

impl Drop for TestRoot {
fn drop(&mut self) {
info!("onDelete logging");
}
fn drop(&mut self) {
info!("onDelete logging");
}
}
19 changes: 10 additions & 9 deletions test/extensions/common/wasm/test_data/test_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
// See: https://github.com/envoyproxy/envoy/issues/9733
//
// Build using:
// $ rustc -C lto -C opt-level=3 -C panic=abort -C link-arg=-S -C link-arg=-zstack-size=32768 --crate-type cdylib --target wasm32-unknown-unknown test_rust.rs
// $ ../../../../../bazel-bin/test/tools/wee8_compile/wee8_compile_tool test_rust.wasm test_rust.wasm
// $ rustc -C lto -C opt-level=3 -C panic=abort -C link-arg=-S -C link-arg=-zstack-size=32768
// --crate-type cdylib --target wasm32-unknown-unknown test_rust.rs $ ../../../../../bazel-bin/test/
// tools/wee8_compile/wee8_compile_tool test_rust.wasm test_rust.wasm

// Import functions exported from the host environment.
extern "C" {
fn pong(value: u32);
fn random() -> u32;
fn pong(value: u32);
fn random() -> u32;
}

#[no_mangle]
extern "C" fn ping(value: u32) {
unsafe { pong(value) }
unsafe { pong(value) }
}

#[no_mangle]
extern "C" fn lucky(number: u32) -> bool {
unsafe { number == random() }
unsafe { number == random() }
}

#[no_mangle]
extern "C" fn sum(a: u32, b: u32, c: u32) -> u32 {
a + b + c
a + b + c
}

#[no_mangle]
extern "C" fn div(a: u32, b: u32) -> u32 {
a / b
a / b
}

#[no_mangle]
extern "C" fn abort() {
panic!("abort")
panic!("abort")
}
12 changes: 0 additions & 12 deletions test/extensions/dynamic_modules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load(
"rust_clippy",
"rust_doc_test",
"rust_test",
"rustfmt_test",
)
load(
"//bazel:envoy_build_system.bzl",
Expand Down Expand Up @@ -90,17 +89,6 @@ rust_doc_test(
],
)

# As per the discussion in https://github.com/envoyproxy/envoy/pull/35627,
# we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now.
rustfmt_test(
name = "rust_sdk_fmt",
tags = ["nocoverage"],
targets = [
"//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk",
"//source/extensions/dynamic_modules/sdk/rust:build_script_",
],
)

rust_clippy(
name = "rust_sdk_clippy",
tags = ["nocoverage"],
Expand Down
10 changes: 1 addition & 9 deletions test/extensions/dynamic_modules/test_data/rust/test_data.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_shared_library", "rust_static_library", "rust_test", "rustfmt_test")
load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_shared_library", "rust_static_library", "rust_test")
load("//source/extensions/dynamic_modules:dynamic_modules.bzl", "envoy_dynamic_module_prefix_symbols")

def test_program(name):
Expand Down Expand Up @@ -39,14 +39,6 @@ def test_program(name):
archive = ":" + _static_lib_name,
)

# As per the discussion in https://github.com/envoyproxy/envoy/pull/35627,
# we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now.
rustfmt_test(
name = "fmt_" + name,
tags = ["nocoverage"],
targets = [":" + _name],
testonly = True,
)
rust_clippy(
name = "clippy_" + name,
tags = ["nocoverage"],
Expand Down
134 changes: 69 additions & 65 deletions test/extensions/filters/http/wasm/test_data/async_call_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,81 @@ proxy_wasm::main! {{
struct TestStream;

impl HttpContext for TestStream {
fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action {
if end_of_stream {
self.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();
Action::Continue
} else {
// bogus cluster name
self.dispatch_http_call(
"bogus cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();
fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action {
if end_of_stream {
self
.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();
Action::Continue
} else {
// bogus cluster name
self
.dispatch_http_call(
"bogus cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();

// bogus duration
self.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::new(u64::MAX, 0),
)
.unwrap_err();
// bogus duration
self
.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::new(u64::MAX, 0),
)
.unwrap_err();

// missing :path
self.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();
// missing :path
self
.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(1),
)
.unwrap_err();

match self.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(5),
) {
Ok(_) => info!("onRequestHeaders"),
Err(_) => info!("async_call rejected"),
};
Action::Pause
}
match self.dispatch_http_call(
"cluster",
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")],
Some(b"hello world"),
vec![("trail", "cow")],
Duration::from_secs(5),
) {
Ok(_) => info!("onRequestHeaders"),
Err(_) => info!("async_call rejected"),
};
Action::Pause
}
}
}

impl Context for TestStream {
fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) {
if body_size == 0 {
info!("async_call failed");
return;
}
for (name, value) in &self.get_http_call_response_headers() {
info!("{} -> {}", name, value);
}
if let Some(body) = self.get_http_call_response_body(0, body_size) {
debug!("{}", String::from_utf8(body).unwrap());
}
for (name, value) in &self.get_http_call_response_trailers() {
warn!("{} -> {}", name, value);
}
fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) {
if body_size == 0 {
info!("async_call failed");
return;
}
for (name, value) in &self.get_http_call_response_headers() {
info!("{} -> {}", name, value);
}
if let Some(body) = self.get_http_call_response_body(0, body_size) {
debug!("{}", String::from_utf8(body).unwrap());
}
for (name, value) in &self.get_http_call_response_trailers() {
warn!("{} -> {}", name, value);
}
}
}
Loading
Loading