To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

test_thread.rs 3.99 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3
4
5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9
10
11
12
13
14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

qinsoon's avatar
qinsoon committed
15
16
#![allow(unused_imports)]

17
18
19
20
21
22
23
24
extern crate mu;

use self::mu::ast::types::*;
use self::mu::ast::ir::*;
use self::mu::ast::inst::*;
use self::mu::ast::op::*;
use self::mu::vm::*;
use self::mu::compiler::*;
25
use self::mu::utils::LinkedHashMap;
qinsoon's avatar
qinsoon committed
26
27
use self::mu::linkutils;
use self::mu::linkutils::aot;
28
29

use std::sync::Arc;
30
use std::sync::RwLock;
31
32
33

#[test]
fn test_thread_create() {
qinsoon's avatar
qinsoon committed
34
    VM::start_logging_trace();
35

36
    let vm = Arc::new(primordial_main());
37

qinsoon's avatar
qinsoon committed
38
    let compiler = Compiler::new(CompilerPolicy::default(), &vm);
39
40

    let func_id = vm.id_of("primordial_main");
41
42
43
44
    {
        let funcs = vm.funcs().read().unwrap();
        let func = funcs.get(&func_id).unwrap().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();
45
46
47
48
49
50
        let mut func_ver = func_vers
            .get(&func.cur_ver.unwrap())
            .unwrap()
            .write()
            .unwrap();

51
52
        compiler.compile(&mut func_ver);
    }
53

qinsoon's avatar
qinsoon committed
54
    vm.set_primordial_thread(func_id, true, vec![]);
55
    backend::emit_context(&vm);
56
57
58
59

    let executable = aot::link_primordial(
        vec!["primordial_main".to_string()],
        "primordial_main_test",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
60
        &vm,
61
    );
qinsoon's avatar
qinsoon committed
62
    linkutils::exec_path(executable);
63
64
65
66
}

fn primordial_main() -> VM {
    let vm = VM::new();
67
68
69
70

    funcsig!    ((vm) sig = () -> ());
    funcdecl!   ((vm) <sig> primordial_main);
    funcdef!    ((vm) <sig> primordial_main VERSION primordial_main_v1);
71

72
73
74
75
76
77
78
79
80
81
82
    block!      ((vm, primordial_main_v1) blk_entry);
    inst!       ((vm, primordial_main_v1) blk_entry_threadexit:
        THREADEXIT
    );

    define_block!((vm, primordial_main_v1) blk_entry() {
        blk_entry_threadexit
    });

    define_func_ver!((vm) primordial_main_v1(entry: blk_entry) {
        blk_entry
83
    });
84

85
    vm
86
}
87
88
89
90
91

#[test]
fn test_main_with_retval() {
    let vm = Arc::new(main_with_retval());

92
    let func_id = vm.id_of("main_with_retval");
93
94
95
    let func_handle = vm.handle_from_func(func_id);
    vm.make_boot_image(
        vec![func_id],
96
        Some(&func_handle),
97
        None,
98
99
100
101
102
        None,
        vec![],
        vec![],
        vec![],
        vec![],
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
103
        "test_main_with_retval".to_string(),
104
105
106
107
108
109
110
111
112
113
    );

    // run
    let executable = {
        use std::path;
        let mut path = path::PathBuf::new();
        path.push(&vm.vm_options.flag_aot_emit_dir);
        path.push("test_main_with_retval");
        path
    };
qinsoon's avatar
qinsoon committed
114
    let output = linkutils::exec_path_nocheck(executable);
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

    assert!(output.status.code().is_some());

    let ret_code = output.status.code().unwrap();
    println!("return code: {}", ret_code);
    assert!(ret_code == 42);
}

fn main_with_retval() -> VM {
    let vm = VM::new();

    typedef!    ((vm) int32 = mu_int(32));
    constdef!   ((vm) <int32> int32_42 = Constant::Int(42));

    funcsig!    ((vm) sig = () -> ());
    funcdecl!   ((vm) <sig> main_with_retval);
    funcdef!    ((vm) <sig> main_with_retval VERSION main_with_retval_v1);

    block!      ((vm, main_with_retval_v1) blk_entry);

    consta!     ((vm, main_with_retval_v1) int32_42_local = int32_42);
    inst!       ((vm, main_with_retval_v1) blk_entry_set_retval:
        SET_RETVAL int32_42_local
    );

    inst!       ((vm, main_with_retval_v1) blk_entry_threadexit:
        THREADEXIT
    );

    define_block!((vm, main_with_retval_v1) blk_entry() {
        blk_entry_set_retval,
        blk_entry_threadexit
    });

    define_func_ver!((vm) main_with_retval_v1(entry: blk_entry) {
        blk_entry
    });

    vm
154
}