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