To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

test_compiler.rs 747 Bytes
Newer Older
John Zhang's avatar
John Zhang committed
1
extern crate libloading as ll;
2
extern crate mu;
3
4
5

use test_ir::test_ir::sum;
use test_ir::test_ir::factorial;
6
use mu::testutil;
7
8

#[test]
John Zhang's avatar
John Zhang committed
9
10
fn test_factorial() {
    let lib = testutil::compile_fnc("fac", &factorial);
11
    unsafe {
John Zhang's avatar
John Zhang committed
12
13
14
        let fac: ll::Symbol<unsafe extern fn (u64) -> u64> = lib.get(b"fac").unwrap();
        println!("fac(10) = {}", fac(10));
        assert!(fac(10) == 3628800);
15
16
17
18
    }
}

#[test]
John Zhang's avatar
John Zhang committed
19
20
fn test_sum() {
    let lib = testutil::compile_fnc("sum", &sum);
21
    unsafe {
John Zhang's avatar
John Zhang committed
22
        let sumptr: ll::Symbol<unsafe extern fn (u64) -> u64> = lib.get(b"sum").unwrap();
23
24
25
26
        println!("sum(5) = {}", sumptr(5));
        assert!(sumptr(5) == 15);
        println!("sun(10) = {}", sumptr(10));
        assert!(sumptr(10) == 55);
John Zhang's avatar
John Zhang committed
27
28
    }
}