New working test groups: test_exception

parent 42a81bd3
......@@ -1055,6 +1055,51 @@ macro_rules! emit_test {
};
/*
emit_test! ((vm) (catch_exception catch_exception_test1 catch_exception_test1_v1 (catch_exception_sig)));
*/
(($vm: expr) ($name: ident $test_name: ident $tester_name: ident ($test_sig: ident))) => {
typedef! (($vm) int1 = mu_int(1));
typedef! (($vm) int64t = mu_int(64));
constdef! (($vm) <int64t> int64_pass = Constant::Int(0));
constdef! (($vm) <int64t> int64_fail = Constant::Int(1));
funcsig! (($vm) tester_sig = () -> ());
funcdecl! (($vm) <tester_sig> $test_name);
funcdef! (($vm) <tester_sig> $test_name VERSION $tester_name);
typedef! (($vm) type_funcref = mu_funcref($test_sig));
constdef! (($vm) <type_funcref> const_funcref = Constant::FuncRef($vm.id_of(stringify!($name))));
// blk_entry
block! (($vm, $tester_name) blk_entry);
consta! (($vm, $tester_name) const_funcref_local = const_funcref);
inst! (($vm, $tester_name) blk_entry_call:
EXPRCALL (CallConvention::Mu, is_abort: false) const_funcref_local ()
);
consta! (($vm, $tester_name) int64_pass_local = int64_pass);
consta! (($vm, $tester_name) int64_fail_local = int64_fail);
inst! (($vm, $tester_name) blk_entry_inst_ret:
SET_RETVAL int64_pass_local
);
inst! (($vm, $tester_name) blk_entry_inst_exit:
THREADEXIT
);
define_block! (($vm, $tester_name) blk_entry() {
blk_entry_call,
blk_entry_inst_ret,
blk_entry_inst_exit
});
define_func_ver! (($vm) $tester_name (entry: blk_entry) {
blk_entry
});
};
}
/*
......@@ -1173,4 +1218,47 @@ macro_rules! build_and_run_test {
backend::emit_context(&vm);
aot::run_test_2f(&vm, stringify!($test_name), stringify!($dep_name), stringify!($tester_name));
};
($test_name: ident AND $dep_name: ident, $tester_name: ident, $fnc_name: ident) => {
VM::start_logging_trace();
let vm = Arc::new($fnc_name());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_id = vm.id_of(stringify!($tester_name));
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
vm.make_primordial_thread(func_id, true, vec![]);
let func_id = vm.id_of(stringify!($test_name));
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
let func_id = vm.id_of(stringify!($dep_name));
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm);
aot::run_test_2f(&vm, stringify!($test_name), stringify!($dep_name), stringify!($tester_name));
};
}
\ No newline at end of file
......@@ -31,36 +31,7 @@ use std::sync::Arc;
#[test]
fn test_exception_throw_catch_simple() {
VM::start_logging_trace();
let vm = Arc::new(throw_catch_simple());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_throw = vm.id_of("throw_exception");
let func_catch = vm.id_of("catch_exception");
{
let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
{
let func = funcs.get(&func_throw).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
{
let func = funcs.get(&func_catch).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
}
vm.make_primordial_thread(func_catch, true, vec![]);
backend::emit_context(&vm);
let executable = aot::link_primordial(vec![Mu("throw_exception"), Mu("catch_exception")], "throw_catch_simple_test", &vm);
aot::execute(executable);
build_and_run_test!(catch_exception AND throw_exception, catch_exception_test1, throw_catch_simple);
}
fn declare_commons(vm: &VM) {
......@@ -141,6 +112,8 @@ fn create_catch_exception_func (vm: &VM, use_exception_arg: bool) {
define_func_ver!((vm) catch_exception_v1 (entry: blk_0) {
blk_0, blk_normal_cont, blk_exn_cont
});
emit_test! ((vm) (catch_exception catch_exception_test1 catch_exception_test1_v1 (catch_exception_sig)));
}
fn create_throw_exception_func (vm: &VM) {
......@@ -193,36 +166,7 @@ fn create_throw_exception_func (vm: &VM) {
#[test]
fn test_exception_throw_catch_dont_use_exception_arg() {
VM::start_logging_trace();
let vm = Arc::new(throw_catch_dont_use_exception_arg());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_throw = vm.id_of("throw_exception");
let func_catch = vm.id_of("catch_exception");
{
let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
{
let func = funcs.get(&func_throw).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
{
let func = funcs.get(&func_catch).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
}
vm.make_primordial_thread(func_catch, true, vec![]);
backend::emit_context(&vm);
let executable = aot::link_primordial(vec![Mu("throw_exception"), Mu("catch_exception")], "throw_catch_simple_test", &vm);
aot::execute(executable);
build_and_run_test!(catch_exception AND throw_exception, catch_exception_test1, throw_catch_dont_use_exception_arg);
}
fn throw_catch_dont_use_exception_arg() -> VM {
......@@ -238,40 +182,7 @@ fn throw_catch_dont_use_exception_arg() -> VM {
#[test]
fn test_exception_throw_catch_and_add() {
VM::start_logging_trace();
let vm = Arc::new(throw_catch_and_add());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_throw = vm.id_of("throw_exception");
let func_catch = vm.id_of("catch_and_add");
{
let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
{
let func = funcs.get(&func_throw).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
{
let func = funcs.get(&func_catch).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
}
vm.make_primordial_thread(func_catch, true, vec![]);
backend::emit_context(&vm);
let executable = aot::link_primordial(vec![Mu("throw_exception"), Mu("catch_and_add")], "throw_catch_and_add", &vm);
let output = aot::execute_nocheck(executable);
// throw 1, add 0, 1, 2, 3, 4
assert!(output.status.code().is_some());
assert_eq!(output.status.code().unwrap(), 11);
build_and_run_test!(catch_and_add AND throw_exception, catch_and_add_test1, throw_catch_and_add);
}
fn throw_catch_and_add() -> VM {
......@@ -300,7 +211,7 @@ fn create_catch_exception_and_add(vm: &VM) {
typedef! ((vm) type_funcref_throw_exception = mu_funcref(throw_exception_sig));
constdef! ((vm) <type_funcref_throw_exception> const_funcref_throw_exception = Constant::FuncRef(throw_exception_id));
funcsig! ((vm) catch_exception_sig = () -> ());
funcsig! ((vm) catch_exception_sig = () -> (int64));
funcdecl! ((vm) <catch_exception_sig> catch_and_add);
funcdef! ((vm) <catch_exception_sig> catch_and_add VERSION catch_and_add_v1);
......@@ -417,7 +328,7 @@ fn create_catch_exception_and_add(vm: &VM) {
res4 = BINOP (BinOp::Add) res3 ev4
);
let blk_exception_exit = gen_ccall_exit(res4.clone(), &mut catch_and_add_v1, &vm);
// let blk_exception_exit = gen_ccall_exit(res4.clone(), &mut catch_and_add_v1, &vm);
inst! ((vm, catch_and_add_v1) blk_exception_ret:
RET (res4)
......@@ -440,51 +351,20 @@ fn create_catch_exception_and_add(vm: &VM) {
blk_exception_add3,
blk_exception_add4,
blk_exception_exit,
// blk_exception_exit,
blk_exception_ret
});
define_func_ver!((vm) catch_and_add_v1 (entry: blk_entry) {
blk_entry, blk_main, blk_normal, blk_exception
});
emit_test! ((vm) (catch_and_add catch_and_add_test1 catch_and_add_test1_v1 Int,EQ (catch_exception_sig, int64(11u64))));
}
#[test]
fn test_exception_throw_catch_twice() {
VM::start_logging_trace();
let vm = Arc::new(throw_catch_twice());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_throw = vm.id_of("throw_exception");
let func_catch = vm.id_of("catch_twice");
{
let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
{
let func = funcs.get(&func_throw).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
{
let func = funcs.get(&func_catch).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
}
vm.make_primordial_thread(func_catch, true, vec![]);
backend::emit_context(&vm);
let executable = aot::link_primordial(vec![Mu("throw_exception"), Mu("catch_twice")], "throw_catch_twice", &vm);
let output = aot::execute_nocheck(executable);
// throw 1 twice, add 1 and 1 (equals 2)
assert!(output.status.code().is_some());
assert_eq!(output.status.code().unwrap(), 2);
build_and_run_test!(catch_twice AND throw_exception, catch_twice_test1, throw_catch_twice);
}
fn throw_catch_twice() -> VM {
......@@ -509,7 +389,7 @@ fn create_catch_twice(vm: &VM) {
typedef! ((vm) type_funcref_throw_exception = mu_funcref(throw_exception_sig));
constdef! ((vm) <type_funcref_throw_exception> const_funcref_throw_exception = Constant::FuncRef(throw_exception_id));
funcsig! ((vm) catch_exception_sig = () -> ());
funcsig! ((vm) catch_exception_sig = () -> (int64));
funcdecl! ((vm) <catch_exception_sig> catch_twice);
funcdef! ((vm) <catch_exception_sig> catch_twice VERSION catch_twice_v1);
......@@ -575,7 +455,7 @@ fn create_catch_twice(vm: &VM) {
res = BINOP (BinOp::Add) exc_arg1_val exc_arg2_val
);
let blk_exception2_exit = gen_ccall_exit(res.clone(), &mut catch_twice_v1, &vm);
// let blk_exception2_exit = gen_ccall_exit(res.clone(), &mut catch_twice_v1, &vm);
inst! ((vm, catch_twice_v1) blk_exception2_ret:
RET (res)
......@@ -588,7 +468,7 @@ fn create_catch_twice(vm: &VM) {
blk_exception2_load2,
blk_exception2_add,
blk_exception2_exit,
// blk_exception2_exit,
blk_exception2_ret
});
......@@ -598,4 +478,6 @@ fn create_catch_twice(vm: &VM) {
blk_exception1,
blk_exception2
});
emit_test! ((vm) (catch_twice catch_twice_test1 catch_twice_test1_v1 Int,EQ (catch_exception_sig, int64(2u64))));
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment