mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-28 05:21:04 +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,19 +253,31 @@ 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) => {
|
||||||
} else {
|
let i = named_modules.get(name);
|
||||||
if (&instance).is_none() {
|
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 Get"),
|
kind: format!("{:?}", "AssertReturn Get"),
|
||||||
message: format!("No instance available"),
|
message: format!("No instance available {:?}", &module),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let export: Export =
|
let export: Export = instance
|
||||||
instance.as_ref().unwrap().get_export(&field).unwrap();
|
.unwrap()
|
||||||
|
.get_export(&field)
|
||||||
|
.expect(&format!("missing global {:?}", &field));
|
||||||
match export {
|
match export {
|
||||||
Export::Global(g) => {
|
Export::Global(g) => {
|
||||||
let value = g.get();
|
let value = g.get();
|
||||||
@ -278,7 +309,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// println!("in assert return");
|
// println!("in assert return");
|
||||||
}
|
}
|
||||||
CommandKind::AssertReturnCanonicalNan { action } => match action {
|
CommandKind::AssertReturnCanonicalNan { action } => match action {
|
||||||
@ -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,10 +689,21 @@ 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) => {
|
||||||
} else {
|
let i = named_modules.get(name);
|
||||||
if (&instance).is_none() {
|
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,
|
||||||
@ -621,8 +713,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.addFailure(SpecFailure {
|
test_report.addFailure(SpecFailure {
|
||||||
@ -638,7 +729,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Action::Get { module, field } => {
|
Action::Get { module, field } => {
|
||||||
println!("Action Get not implemented {:?} {:?}", filename, line)
|
println!("Action Get not implemented {:?} {:?}", filename, line)
|
||||||
}
|
}
|
||||||
@ -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