Skip to content

Commit

Permalink
[5/n][enums] All Move tests except source lang tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Apr 19, 2024
1 parent 904f587 commit 2ce2dab
Show file tree
Hide file tree
Showing 273 changed files with 7,851 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] }
cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }]
cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] }
cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }]
cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = []
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn invalid_struct_in_fn_return_() {
let mut m = basic_test_module();
m.function_handles[0].return_ = SignatureIndex(1);
m.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(1))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(1))]));
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
Expand Down Expand Up @@ -104,7 +104,7 @@ fn invalid_struct_in_field() {
let mut m = basic_test_module();
match &mut m.struct_defs[0].field_information {
StructFieldInformation::Declared(ref mut fields) => {
fields[0].signature.0 = Struct(StructHandleIndex::new(3));
fields[0].signature.0 = Datatype(DatatypeHandleIndex::new(3));
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
Expand All @@ -121,8 +121,8 @@ fn invalid_struct_with_actuals_in_field() {
let mut m = basic_test_module();
match &mut m.struct_defs[0].field_information {
StructFieldInformation::Declared(ref mut fields) => {
fields[0].signature.0 = StructInstantiation(Box::new((
StructHandleIndex::new(0),
fields[0].signature.0 = DatatypeInstantiation(Box::new((
DatatypeHandleIndex::new(0),
vec![TypeParameter(0)],
)));
assert_eq!(
Expand Down Expand Up @@ -177,7 +177,7 @@ fn invalid_struct_as_type_actual_in_exists() {

let mut m = basic_test_module();
m.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))]));
m.function_instantiations.push(FunctionInstantiation {
handle: FunctionHandleIndex::new(0),
type_parameters: SignatureIndex::new(1),
Expand Down Expand Up @@ -249,7 +249,7 @@ fn invalid_struct_for_vector_operation() {
let mut skeleton = basic_test_module();
skeleton
.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3))]));
.push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))]));
let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16);
for bytecode in [
VecPack(sig_index, 0),
Expand Down Expand Up @@ -297,6 +297,80 @@ fn invalid_type_param_for_vector_operation() {
}
}

#[test]
fn invalid_variant_handle_index_for_enum_operation() {
use Bytecode::*;

let skeleton = basic_test_module();
let variant_handle_index = VariantHandleIndex(skeleton.variant_handles.len() as u16);
let variant_handle_inst_index =
VariantInstantiationHandleIndex(skeleton.variant_instantiation_handles.len() as u16);
for bytecode in [
PackVariant(variant_handle_index),
UnpackVariant(variant_handle_index),
UnpackVariantImmRef(variant_handle_index),
UnpackVariantMutRef(variant_handle_index),
PackVariantGeneric(variant_handle_inst_index),
UnpackVariantGeneric(variant_handle_inst_index),
UnpackVariantGenericImmRef(variant_handle_inst_index),
UnpackVariantGenericMutRef(variant_handle_inst_index),
] {
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![bytecode];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}
}

#[test]
fn invalid_variant_jump_table_index() {
use Bytecode::*;

let skeleton = basic_test_module();
let jt_index = VariantJumpTableIndex(
skeleton.function_defs[0]
.code
.as_ref()
.map(|c| c.jump_tables.len() as u16)
.unwrap_or(0u16),
);
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![VariantSwitch(jt_index)];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}

#[test]
fn invalid_variant_jump_table_code_offset() {
use Bytecode::*;

let mut skeleton = basic_test_module_with_enum();
let enum_index = EnumDefinitionIndex(0);
skeleton.function_defs[0].code.as_mut().unwrap().code = vec![LdU64(0), Pop, Ret];
skeleton.function_defs[0].code.as_mut().unwrap().jump_tables = vec![VariantJumpTable {
head_enum: enum_index,
jump_table: JumpTableInner::Full(vec![100]),
}];

let jt_index = VariantJumpTableIndex(
skeleton.function_defs[0]
.code
.as_ref()
.map(|c| c.jump_tables.len() as u16)
.unwrap_or(0u16),
);
let mut m = skeleton.clone();
m.function_defs[0].code.as_mut().unwrap().code = vec![VariantSwitch(jt_index)];
assert_eq!(
BoundsChecker::verify_module(&m).unwrap_err().major_status(),
StatusCode::INDEX_OUT_OF_BOUNDS
);
}

proptest! {
#[test]
fn valid_bounds(_module in CompiledModule::valid_strategy(20)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn invalid_types() {

// TODO cannot check structs are banned currently. This can be handled by IR and source lang
// tests
// invalid_type(SignatureToken::Struct(StructHandleIndex(0)), vec![0]);
// invalid_type(SignatureToken::Datatype(DatatypeHandleIndex(0)), vec![0]);
}

fn tvec(s: SignatureToken) -> SignatureToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ fn duplicated_friend_decls() {
DuplicationChecker::verify_module(&m).unwrap_err();
}

#[test]
fn duplicated_variant_handles() {
let mut m = basic_test_module_with_enum();
m.variant_handles.push(m.variant_handles[0].clone());
DuplicationChecker::verify_module(&m).unwrap_err();
}

proptest! {
#[test]
fn valid_duplication(module in CompiledModule::valid_strategy(20)) {
prop_assert!(DuplicationChecker::verify_module(&module).is_ok());
// println!("{:#?}", module);
let x = DuplicationChecker::verify_module(&module);
println!("{:#?}", x);
prop_assert!(x.is_ok());
}
}
Loading

0 comments on commit 2ce2dab

Please sign in to comment.