Skip to content

Commit 8df3ab6

Browse files
committed
use a new test wasm
1 parent abd6d7b commit 8df3ab6

File tree

9 files changed

+47
-7
lines changed

9 files changed

+47
-7
lines changed

language-bindings/rust/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
target/
1+
**/target/

language-bindings/rust/resources/test/.gitignore

-1
This file was deleted.

language-bindings/rust/resources/test/gcd/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "gcd"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[no_mangle]
2+
pub fn gcd(m: u32, n: u32) -> u32 {
3+
let mut a = m;
4+
let mut b = n;
5+
6+
while b != 0 {
7+
(a, b) = (b, a % b)
8+
}
9+
10+
println!("gcd({}, {}) = {}", m, n, a);
11+
a
12+
}
13+
14+
fn main() {
15+
println!("Hello, world! Please call gcd(10, 5) to see the result.");
16+
}
Binary file not shown.
Binary file not shown.

language-bindings/rust/src/function.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ mod tests {
150150
let call_result = function.call(instance, &params);
151151
assert!(call_result.is_ok());
152152
assert_eq!(call_result.unwrap(), WasmValue::I32(9));
153+
154+
let params: Vec<WasmValue> = vec![WasmValue::I32(128), WasmValue::I32(256)];
155+
let call_result = function.call(instance, &params);
156+
assert!(call_result.is_ok());
157+
assert_eq!(call_result.unwrap(), WasmValue::I32(384));
153158
}
154159

155160
#[test]
@@ -158,7 +163,7 @@ mod tests {
158163

159164
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
160165
d.push("resources/test");
161-
d.push("hello_wasm32-wasi.wasm");
166+
d.push("gcd_wasm32_wasi.wasm");
162167
let module = Module::from_file(d.as_path());
163168
assert!(module.is_ok());
164169
let mut module = module.unwrap();
@@ -169,11 +174,16 @@ mod tests {
169174
assert!(instance.is_ok());
170175
let instance: &Instance = &instance.unwrap();
171176

172-
let function = Function::find_export_func(instance, "_start");
177+
let function = Function::find_export_func(instance, "gcd");
173178
assert!(function.is_ok());
174179
let function = function.unwrap();
175180

176-
let result = function.call(instance, &vec![]);
177-
assert!(result.is_ok());
181+
let params: Vec<WasmValue> = vec![WasmValue::I32(9), WasmValue::I32(27)];
182+
let result = function.call(instance, &params);
183+
assert_eq!(result.unwrap(), WasmValue::I32(9));
184+
185+
let params: Vec<WasmValue> = vec![WasmValue::I32(0), WasmValue::I32(27)];
186+
let result = function.call(instance, &params);
187+
assert_eq!(result.unwrap(), WasmValue::I32(27));
178188
}
179189
}

language-bindings/rust/src/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ mod tests {
281281

282282
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
283283
d.push("resources/test");
284-
d.push("hello_wasm32-wasi.wasm");
284+
d.push("gcd_wasm32_wasi.wasm");
285285
let module = Module::from_file(d.as_path());
286286
assert!(module.is_ok());
287287
}

0 commit comments

Comments
 (0)