WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit b19c268f authored by qinsoon's avatar qinsoon
Browse files

struct layout tests

parent 27541764
mod test_threadlocal;
mod test_entry_offset;
\ No newline at end of file
mod test_entry_offset;
mod test_struct_layout;
\ No newline at end of file
use mu::ast::types::*;
use mu::ast::ir::*;
use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use utils::Address;
use mu::runtime::mm;
use mu::runtime::thread;
use mu::runtime::thread::MuThread;
use mu::vm::VM;
use std::sync::Arc;
#[test]
fn test_struct_layout() {
let vm = Arc::new(VM::new());
typedef! ((vm) int8 = mu_int(8));
typedef! ((vm) int16 = mu_int(16));
typedef! ((vm) int32 = mu_int(32));
typedef! ((vm) int64 = mu_int(64));
typedef! ((vm) struct1 = mu_struct(int64, int8, int64));
let struct1_backend_ty = vm.get_backend_type_info(struct1.id());
assert_eq!(struct1_backend_ty.get_field_offset(0), 0);
assert_eq!(struct1_backend_ty.get_field_offset(1), 8);
assert_eq!(struct1_backend_ty.get_field_offset(2), 16);
typedef! ((vm) struct2 = mu_struct(int64, int8, int8, int16, int32, int64));
let struct2_backend_ty = vm.get_backend_type_info(struct2.id());
assert_eq!(struct2_backend_ty.get_field_offset(0), 0);
assert_eq!(struct2_backend_ty.get_field_offset(1), 8);
assert_eq!(struct2_backend_ty.get_field_offset(2), 9);
assert_eq!(struct2_backend_ty.get_field_offset(3), 10);
assert_eq!(struct2_backend_ty.get_field_offset(4), 12);
assert_eq!(struct2_backend_ty.get_field_offset(5), 16);
typedef! ((vm) struct3 = mu_struct(int64, int8, int16, int32, int64));
let struct3_backend_ty = vm.get_backend_type_info(struct3.id());
assert_eq!(struct3_backend_ty.get_field_offset(0), 0);
assert_eq!(struct3_backend_ty.get_field_offset(1), 8);
assert_eq!(struct3_backend_ty.get_field_offset(2), 10);
assert_eq!(struct3_backend_ty.get_field_offset(3), 12);
assert_eq!(struct3_backend_ty.get_field_offset(4), 16);
}
\ 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