mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 08:10:49 +00:00
Implement named modules
This commit is contained in:
parent
8c911cb1c3
commit
665f8707dc
@ -138,7 +138,10 @@ mod tests {
|
|||||||
|
|
||||||
use std::panic;
|
use std::panic;
|
||||||
|
|
||||||
let mut instance: Option<Instance> = None;
|
let mut instance: Option<Rc<Instance>> = None;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
let mut named_modules: HashMap<String, Rc<Instance>> = HashMap::new();
|
||||||
|
|
||||||
while let Some(Command { kind, line }) =
|
while let Some(Command { kind, line }) =
|
||||||
parser.next().map_err(|e| format!("Parse err: {:?}", e))?
|
parser.next().map_err(|e| format!("Parse err: {:?}", e))?
|
||||||
@ -179,6 +182,10 @@ mod tests {
|
|||||||
instance = None;
|
instance = None;
|
||||||
}
|
}
|
||||||
Ok(i) => {
|
Ok(i) => {
|
||||||
|
let i = Rc::new(i);
|
||||||
|
if name.is_some() {
|
||||||
|
named_modules.insert(name.unwrap(), Rc::clone(&i));
|
||||||
|
}
|
||||||
instance = Some(i);
|
instance = Some(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,18 +197,30 @@ mod tests {
|
|||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
if (&instance).is_none() {
|
let instance: Option<&Instance> = match module {
|
||||||
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
kind: format!("{:?}", "AssertReturn"),
|
kind: format!("{:?}", "AssertReturn"),
|
||||||
message: format!("No instance available"),
|
message: format!("No instance available: {:?}", &module),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
let call_result =
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
|
||||||
match call_result {
|
match call_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
@ -234,47 +253,58 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Get { module, field } => {
|
Action::Get { module, field } => {
|
||||||
if module.is_some() {
|
let instance: Option<&Instance> = match module {
|
||||||
println!("named modules not yet implemented");
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
|
test_report.addFailure(SpecFailure {
|
||||||
|
file: filename.to_string(),
|
||||||
|
line: line,
|
||||||
|
kind: format!("{:?}", "AssertReturn Get"),
|
||||||
|
message: format!("No instance available {:?}", &module),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (&instance).is_none() {
|
let export: Export = instance
|
||||||
test_report.addFailure(SpecFailure {
|
.unwrap()
|
||||||
file: filename.to_string(),
|
.get_export(&field)
|
||||||
line: line,
|
.expect(&format!("missing global {:?}", &field));
|
||||||
kind: format!("{:?}", "AssertReturn Get"),
|
match export {
|
||||||
message: format!("No instance available"),
|
Export::Global(g) => {
|
||||||
});
|
let value = g.get();
|
||||||
} else {
|
let expected_value =
|
||||||
let export: Export =
|
convert_value(*expected.get(0).unwrap());
|
||||||
instance.as_ref().unwrap().get_export(&field).unwrap();
|
if value == expected_value {
|
||||||
match export {
|
test_report.countPassed();
|
||||||
Export::Global(g) => {
|
} else {
|
||||||
let value = g.get();
|
|
||||||
let expected_value =
|
|
||||||
convert_value(*expected.get(0).unwrap());
|
|
||||||
if value == expected_value {
|
|
||||||
test_report.countPassed();
|
|
||||||
} else {
|
|
||||||
test_report.addFailure(SpecFailure {
|
|
||||||
file: filename.to_string(),
|
|
||||||
line: line,
|
|
||||||
kind: format!("{:?}", "AssertReturn Get"),
|
|
||||||
message: format!(
|
|
||||||
"Expected Global {:?} got: {:?}",
|
|
||||||
expected_value, value
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
kind: format!("{:?}", "AssertReturn Get"),
|
kind: format!("{:?}", "AssertReturn Get"),
|
||||||
message: format!("Expected Global"),
|
message: format!(
|
||||||
|
"Expected Global {:?} got: {:?}",
|
||||||
|
expected_value, value
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
|
test_report.addFailure(SpecFailure {
|
||||||
|
file: filename.to_string(),
|
||||||
|
line: line,
|
||||||
|
kind: format!("{:?}", "AssertReturn Get"),
|
||||||
|
message: format!("Expected Global"),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,17 +317,30 @@ mod tests {
|
|||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
if (&instance).is_none() {
|
let instance: Option<&Instance> = match module {
|
||||||
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
kind: format!("{:?}", "AssertReturnCanonicalNan"),
|
kind: format!("{:?}", "AssertReturnCanonicalNan"),
|
||||||
message: format!("No instance available"),
|
message: format!("No instance available {:?}", &module),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
let call_result = instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
match call_result {
|
match call_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
@ -335,7 +378,20 @@ mod tests {
|
|||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
if (&instance).is_none() {
|
let instance: Option<&Instance> = match module {
|
||||||
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
@ -345,7 +401,7 @@ mod tests {
|
|||||||
} else {
|
} else {
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
let call_result = instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
match call_result {
|
match call_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
@ -383,7 +439,20 @@ mod tests {
|
|||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
if (&instance).is_none() {
|
let instance: Option<&Instance> = match module {
|
||||||
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
@ -393,7 +462,7 @@ mod tests {
|
|||||||
} else {
|
} else {
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
let call_result = instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
use wasmer_runtime_core::error::{CallError, RuntimeError};
|
use wasmer_runtime_core::error::{CallError, RuntimeError};
|
||||||
match call_result {
|
match call_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -521,7 +590,20 @@ mod tests {
|
|||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
if (&instance).is_none() {
|
let instance: Option<&Instance> = match module {
|
||||||
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if instance.is_none() {
|
||||||
test_report.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
file: filename.to_string(),
|
file: filename.to_string(),
|
||||||
line: line,
|
line: line,
|
||||||
@ -531,8 +613,7 @@ mod tests {
|
|||||||
} else {
|
} else {
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
let call_result =
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
|
||||||
match call_result {
|
match call_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
test_report.countPassed();
|
test_report.countPassed();
|
||||||
@ -608,33 +689,42 @@ mod tests {
|
|||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
println!("PerformAction: {:?} {:?}", filename, line);
|
println!("PerformAction: {:?} {:?}", filename, line);
|
||||||
if module.is_some() {
|
let instance: Option<&Instance> = match module {
|
||||||
panic!("unexpected module in invoke");
|
Some(ref name) => {
|
||||||
|
let i = named_modules.get(name);
|
||||||
|
match i {
|
||||||
|
Some(ins) => Some(ins.borrow()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => match instance {
|
||||||
|
Some(ref i) => Some(i.borrow()),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if instance.is_none() {
|
||||||
|
test_report.addFailure(SpecFailure {
|
||||||
|
file: filename.to_string(),
|
||||||
|
line: line,
|
||||||
|
kind: format!("{:?}", "PerformAction"),
|
||||||
|
message: format!("No instance available"),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (&instance).is_none() {
|
let params: Vec<wasmer_runtime_core::types::Value> =
|
||||||
test_report.addFailure(SpecFailure {
|
args.iter().cloned().map(|x| convert_value(x)).collect();
|
||||||
file: filename.to_string(),
|
let call_result = instance.unwrap().call(&field, ¶ms[..]);
|
||||||
line: line,
|
match call_result {
|
||||||
kind: format!("{:?}", "PerformAction"),
|
Err(e) => {
|
||||||
message: format!("No instance available"),
|
test_report.addFailure(SpecFailure {
|
||||||
});
|
file: filename.to_string(),
|
||||||
} else {
|
line,
|
||||||
let params: Vec<wasmer_runtime_core::types::Value> =
|
kind: format!("{:?}", "PerformAction"),
|
||||||
args.iter().cloned().map(|x| convert_value(x)).collect();
|
message: format!("Call failed {:?}", e),
|
||||||
let call_result =
|
});
|
||||||
instance.as_ref().unwrap().call(&field, ¶ms[..]);
|
}
|
||||||
match call_result {
|
Ok(values) => {
|
||||||
Err(e) => {
|
test_report.countPassed();
|
||||||
test_report.addFailure(SpecFailure {
|
|
||||||
file: filename.to_string(),
|
|
||||||
line,
|
|
||||||
kind: format!("{:?}", "PerformAction"),
|
|
||||||
message: format!("Call failed {:?}", e),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(values) => {
|
|
||||||
test_report.countPassed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -725,6 +815,7 @@ mod tests {
|
|||||||
Fail,
|
Fail,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use core::borrow::{Borrow, BorrowMut};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Error};
|
use std::io::{BufRead, BufReader, Error};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user