diff --git a/tests/tests/swfs/from_avmplus/generated/intrinsics.abc b/tests/tests/swfs/from_avmplus/generated/intrinsics.abc new file mode 100644 index 000000000..7fa3dc608 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/generated/intrinsics.abc differ diff --git a/tests/tests/swfs/from_avmplus/generated/intrinsics.abs b/tests/tests/swfs/from_avmplus/generated/intrinsics.abs new file mode 100644 index 000000000..8f4b1fa68 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/generated/intrinsics.abs @@ -0,0 +1,183 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * intrinsics.abs + * + * This file declares functions that wrap single ABC opcodes, for + * opcodes that don't have any operands in the ABC stream or any + * explicit control flow. Its easier to write test cases that call + * these functions than to handwrite abcasm. + * + * COMPILE: + * >$ ../../../utils/abcasm/abcasm.sh intrinsics.abs + * >$ mv intrinsics.abc intrinsics.abc_ + */ + +// script initializer +function main() { returnvoid } + +// loads +function LI8(*) { getlocal1 li8 returnvalue } +function LIX8(*) { getlocal1 li8 sxi8 returnvalue } +function LI16(*) { getlocal1 li16 returnvalue } +function LIX16(*) { getlocal1 li16 sxi16 returnvalue } +function LI32(*) { getlocal1 li32 returnvalue } +function LF32(*) { getlocal1 lf32 returnvalue } +function LF64(*) { getlocal1 lf64 returnvalue } + +// stores +function SI8(*,*) { getlocal1 getlocal2 si8 returnvoid } +function SI16(*,*) { getlocal1 getlocal2 si16 returnvoid } +function SI32(*,*) { getlocal1 getlocal2 si32 returnvoid } +function SF32(*,*) { getlocal1 getlocal2 sf32 returnvoid } +function SF64(*,*) { getlocal1 getlocal2 sf64 returnvoid } + +// sign extension (pure integer ops) +function SXI1(*) { getlocal1 sxi1 returnvalue } +function SXI8(*) { getlocal1 sxi8 returnvalue } +function SXI16(*) { getlocal1 sxi16 returnvalue } + +// other +function NEXTNAME(*,int) { getlocal1 getlocal2 nextname returnvalue } +function NEXTVALUE(*,int) { getlocal1 getlocal2 nextvalue returnvalue } +function HASNEXT(*,int):int { getlocal1 getlocal2 hasnext returnvalue } +function CHECKFILTER(*) { getlocal1 checkfilter returnvalue } + +// conversion +function ESC_XELEM(*) { getlocal1 esc_xelem returnvalue } +function ESC_XATTR(*) { getlocal1 esc_xattr returnvalue } +function CONVERT_S(*) { getlocal1 convert_s returnvalue } +function CONVERT_I(*) { getlocal1 convert_i returnvalue } +function CONVERT_U(*) { getlocal1 convert_u returnvalue } +function CONVERT_D(*) { getlocal1 convert_d returnvalue } +function CONVERT_B(*) { getlocal1 convert_b returnvalue } +function CONVERT_O(*) { getlocal1 convert_o returnvalue } +function COERCE_B(*) { getlocal1 coerce_b returnvalue } +function COERCE_A(*) { getlocal1 coerce_a returnvalue } +function COERCE_I(*) { getlocal1 coerce_i returnvalue } +function COERCE_D(*) { getlocal1 coerce_d returnvalue } +function COERCE_S(*) { getlocal1 coerce_s returnvalue } +function COERCE_U(*) { getlocal1 coerce_u returnvalue } +function COERCE_O(*) { getlocal1 coerce_o returnvalue } + +function ASTYPELATE(*,*) { getlocal1 getlocal2 astypelate returnvalue } +function ISTYPELATE(*,*) { getlocal1 getlocal2 istypelate returnvalue } +function INSTANCEOF(*,*) { getlocal1 getlocal2 instanceof returnvalue } +function IN(*,*) { getlocal1 getlocal2 in returnvalue } + +// unary operators +function NEGATE(*) { getlocal1 negate returnvalue } +function INCREMENT(*) { getlocal1 increment returnvalue } +function DECREMENT(*) { getlocal1 decrement returnvalue } +function TYPEOF(*) { getlocal1 typeof returnvalue } +function NOT(*) { getlocal1 not returnvalue } +function BITNOT(*) { getlocal1 bitnot returnvalue } // needs abcasm fix - bitnot stack off by 1 +function INCREMENT_I(*) { getlocal1 increment_i returnvalue } +function DECREMENT_I(*) { getlocal1 decrement_i returnvalue } +function NEGATE_I(*) { getlocal1 negate_i returnvalue } + +// binary operators +function ADD(*,*) { getlocal1 getlocal2 add returnvalue } +function SUBTRACT(*,*) { getlocal1 getlocal2 subtract returnvalue } +function MULTIPLY(*,*) { getlocal1 getlocal2 multiply returnvalue } +function DIVIDE(*,*) { getlocal1 getlocal2 divide returnvalue } +function MODULO(*,*) { getlocal1 getlocal2 modulo returnvalue } +function LSHIFT(*,*) { getlocal1 getlocal2 lshift returnvalue } +function RSHIFT(*,*) { getlocal1 getlocal2 rshift returnvalue } +function URSHIFT(*,*) { getlocal1 getlocal2 urshift returnvalue } +function BITAND(*,*) { getlocal1 getlocal2 bitand returnvalue } +function BITOR(*,*) { getlocal1 getlocal2 bitor returnvalue } +function BITXOR(*,*) { getlocal1 getlocal2 bitxor returnvalue } +function EQUALS(*,*) { getlocal1 getlocal2 equals returnvalue } +function STRICTEQUALS(*,*) { getlocal1 getlocal2 strictequals returnvalue } +function LESSTHAN(*,*) { getlocal1 getlocal2 lessthan returnvalue } +function LESSEQUALS(*,*) { getlocal1 getlocal2 lessequals returnvalue } +function GREATERTHAN(*,*) { getlocal1 getlocal2 greaterthan returnvalue } +function GREATEREQUALS(*,*) { getlocal1 getlocal2 greaterequals returnvalue } +function ADD_I(*,*) { getlocal1 getlocal2 add_i returnvalue } +function SUBTRACT_I(*,*) { getlocal1 getlocal2 subtract_i returnvalue } +function MULTIPLY_I(*,*) { getlocal1 getlocal2 multiply_i returnvalue } + +.script_info { + init : .function_id(main) + traits : { + .trait { kind: method method: .function_id(LI8) name: LI8 } + .trait { kind: method method: .function_id(LIX8) name: LIX8 } + .trait { kind: method method: .function_id(LI16) name: LI16 } + .trait { kind: method method: .function_id(LIX16) name: LIX16} + .trait { kind: method method: .function_id(LI32) name: LI32 } + .trait { kind: method method: .function_id(LF32) name: LF32 } + .trait { kind: method method: .function_id(LF64) name: LF64 } + + .trait { kind: method method: .function_id(SI8) name: SI8 } + .trait { kind: method method: .function_id(SI16) name: SI16 } + .trait { kind: method method: .function_id(SI32) name: SI32 } + .trait { kind: method method: .function_id(SF32) name: SF32 } + .trait { kind: method method: .function_id(SF64) name: SF64 } + + .trait { kind: method method: .function_id(SXI1) name: SXI1 } + .trait { kind: method method: .function_id(SXI8) name: SXI8 } + .trait { kind: method method: .function_id(SXI16) name: SXI16 } + + .trait { kind: method method: .function_id(NEXTNAME) name: NEXTNAME } + .trait { kind: method method: .function_id(NEXTVALUE) name: NEXTVALUE } + .trait { kind: method method: .function_id(HASNEXT) name: HASNEXT } + .trait { kind: method method: .function_id(CHECKFILTER) name: CHECKFILTER } + + .trait { kind: method method: .function_id(ESC_XELEM) name: ESC_XELEM } + .trait { kind: method method: .function_id(ESC_XATTR) name: ESC_XATTR } + .trait { kind: method method: .function_id(CONVERT_S) name: CONVERT_S } + .trait { kind: method method: .function_id(CONVERT_I) name: CONVERT_I } + .trait { kind: method method: .function_id(CONVERT_U) name: CONVERT_U } + .trait { kind: method method: .function_id(CONVERT_D) name: CONVERT_D } + .trait { kind: method method: .function_id(CONVERT_B) name: CONVERT_B } + .trait { kind: method method: .function_id(CONVERT_O) name: CONVERT_O } + .trait { kind: method method: .function_id(COERCE_B) name: COERCE_B } + .trait { kind: method method: .function_id(COERCE_A) name: COERCE_A } + .trait { kind: method method: .function_id(COERCE_I) name: COERCE_I } + .trait { kind: method method: .function_id(COERCE_D) name: COERCE_D } + .trait { kind: method method: .function_id(COERCE_S) name: COERCE_S } + .trait { kind: method method: .function_id(COERCE_U) name: COERCE_U } + .trait { kind: method method: .function_id(COERCE_O) name: COERCE_O } + + .trait { kind: method method: .function_id(ASTYPELATE) name: ASTYPELATE } + .trait { kind: method method: .function_id(ISTYPELATE) name: ISTYPELATE } + .trait { kind: method method: .function_id(INSTANCEOF) name: INSTANCEOF } + .trait { kind: method method: .function_id(IN) name: IN } + + .trait { kind: method method: .function_id(NEGATE) name: NEGATE } + .trait { kind: method method: .function_id(INCREMENT) name: INCREMENT } + .trait { kind: method method: .function_id(DECREMENT) name: DECREMENT } + .trait { kind: method method: .function_id(TYPEOF) name: TYPEOF } + .trait { kind: method method: .function_id(NOT) name: NOT } + .trait { kind: method method: .function_id(BITNOT) name: BITNOT } + .trait { kind: method method: .function_id(INCREMENT_I) name: INCREMENT_I } + .trait { kind: method method: .function_id(DECREMENT_I) name: DECREMENT_I } + .trait { kind: method method: .function_id(NEGATE_I) name: NEGATE_I } + + .trait { kind: method method: .function_id(ADD) name: ADD } + .trait { kind: method method: .function_id(SUBTRACT) name: SUBTRACT } + .trait { kind: method method: .function_id(MULTIPLY) name: MULTIPLY } + .trait { kind: method method: .function_id(DIVIDE) name: DIVIDE } + .trait { kind: method method: .function_id(MODULO) name: MODULO } + .trait { kind: method method: .function_id(LSHIFT) name: LSHIFT } + .trait { kind: method method: .function_id(RSHIFT) name: RSHIFT } + .trait { kind: method method: .function_id(URSHIFT) name: URSHIFT } + .trait { kind: method method: .function_id(BITAND) name: BITAND } + .trait { kind: method method: .function_id(BITOR) name: BITOR } + .trait { kind: method method: .function_id(BITXOR) name: BITXOR } + .trait { kind: method method: .function_id(EQUALS) name: EQUALS } + .trait { kind: method method: .function_id(STRICTEQUALS) name: STRICTEQUALS } + .trait { kind: method method: .function_id(LESSTHAN) name: LESSTHAN } + .trait { kind: method method: .function_id(LESSEQUALS) name: LESSEQUALS } + .trait { kind: method method: .function_id(GREATERTHAN) name: GREATERTHAN } + .trait { kind: method method: .function_id(GREATEREQUALS) name: GREATEREQUALS } + .trait { kind: method method: .function_id(ADD_I) name: ADD_I } + .trait { kind: method method: .function_id(SUBTRACT_I) name: SUBTRACT_I } + .trait { kind: method method: .function_id(MULTIPLY_I) name: MULTIPLY_I } + } +} diff --git a/tests/tests/swfs/from_avmplus/mops/README.md b/tests/tests/swfs/from_avmplus/mops/README.md new file mode 100644 index 000000000..3f5551d24 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/README.md @@ -0,0 +1,48 @@ +These tests are built with ASC with something like: + +``` +asc +-import playerglobal.abc +-in ../lib/print.as +-in ../lib/com/adobe/test/Assert.as +-in ../lib/com/adobe/test/Utils.as +lf32/Test.as +``` + +Then combine the resulting `asc` file with `generated/intrinsics.asc` and stuff them both into a swf. + +Example code: + +```rust +let mut swf = vec![]; +swf::write::write_swf( + &swf::Header { + compression: swf::Compression::None, + version: 30, + stage_size: swf::Rectangle { + x_min: swf::Twips::ZERO, + x_max: swf::Twips::from_pixels(100.0), + y_min: swf::Twips::ZERO, + y_max: swf::Twips::from_pixels(100.0), + }, + frame_rate: swf::Fixed8::ONE, + num_frames: 1, + }, + &[ + swf::Tag::FileAttributes(swf::FileAttributes::IS_ACTION_SCRIPT_3), + swf::Tag::DoAbc(swf::DoAbc { + name: SwfStr::from_utf8_str("intrinsics"), + is_lazy_initialize: false, + data: intrinsics_abc, + }), + swf::Tag::DoAbc(swf::DoAbc { + name: SwfStr::from_utf8_str(name), + is_lazy_initialize: false, + data: test_abc, + }), + swf::Tag::ShowFrame, + ], + &mut swf, +)?; +write(testdir.join("test.swf"), swf)?; +``` \ No newline at end of file diff --git a/tests/tests/swfs/from_avmplus/mops/lf32/Test.as b/tests/tests/swfs/from_avmplus/mops/lf32/Test.as new file mode 100644 index 000000000..e9cde7719 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf32/Test.as @@ -0,0 +1,206 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "lf32"; + + + Assert.expectError("lf32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LF32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("lf32(-1)", Utils.RANGEERROR+1506, function(){ LF32(-1); }); + Assert.expectError("lf32(mem.length)", Utils.RANGEERROR+1506, function(){ LF32(mem.length); }); + Assert.expectError("lf32(mem.length-1)", Utils.RANGEERROR+1506, function(){ LF32(mem.length-1); }); + Assert.expectError("lf32(mem.length-2)", Utils.RANGEERROR+1506, function(){ LF32(mem.length-2); }); + Assert.expectError("lf32(mem.length-3)", Utils.RANGEERROR+1506, function(){ LF32(mem.length-3); }); + Assert.expectEq("lf32(mem.length-4)", 0, LF32(mem.length-4)); + + SI32(0x41460200, 1); // 0x41460200 == 12.37548828125 + Assert.expectEq("lf32(1) loads do not need to be aligned", 12.37548828125, LF32(1)); + + testsi8(); + testsi16(); + testsi32(); + testsf32(); + testsf64(); + testwriteByte(); + testwriteBoolean(); + testwriteInt(); + testwriteFloat(); + testwriteDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + /** + * 0x41460200 = 01000001 01000110 00000010 00000000 + * 12.37548828125 + */ + clearMemory(); + SI8(0x00, 0); + SI8(0x02, 1); + SI8(0x46, 2); + SI8(0x41, 3); + Assert.expectEq("lf32 load float written by si8()", 12.37548828125, LF32(0)); + } + + function testsi16():void + { + /** + * 0x41460200 = 01000001 01000110 00000010 00000000 + * 12.37548828125 + */ + clearMemory(); + SI16(0x0200, 0); + SI16(0x4146, 2); + Assert.expectEq("lf32 load float written by si16()", 12.37548828125, LF32(0)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x41460200, 0); + Assert.expectEq("lf32 load float written by si32(0x41460200)", 12.37548828125, LF32(0)); + } + + function testsf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + // Can't use hex representation here since asc will just treat it + // as an int|Number and not as a float. + clearMemory(); + SF32(12.37548828125, 0); + Assert.expectEq("lf32 load float written by sf32(12.37548828125)", 12.37548828125, LF32(0)); + } + + function testsf64():void + { + /****************************************** + * 2.8846085099489688873291015625E6 + * 0x4146020041460200 + * sign = 0 + * exponent = 10000010100 + * mantissa = 0110000000100000000001000001010001100000001000000000 + *****************************************/ + clearMemory(); + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("lf32 load 1st float written by sf64(0x4146020041460200)", 12.37548828125, LF32(4)); + Assert.expectEq("lf32 load 2nd float written by sf64(0x4146020041460200)", 12.37548828125, LF32(0)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(0x00); + mem.writeByte(0x02); + mem.writeByte(0x46); + mem.writeByte(0x41); + + Assert.expectEq("lf32 load float written by writeByte()", 12.37548828125, LF32(0)); + } + + function testwriteBoolean():void + { + clearMemory(); + mem.position = 0; + mem.writeBoolean(true); + mem.writeBoolean(false); + mem.writeBoolean(false); + mem.writeBoolean(true); + + Assert.expectEq("lf32 load float written by writeBoolean()", 2.3510604481259484465715043694E-38, LF32(0)); + } + + function testwriteInt():void + { + /****************************************** + * 1095107072 = 0x41460200 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(1095107072); + + Assert.expectEq("lf32 load float written by writeInt(2147473647)", 12.37548828125, LF32(0)); + } + + function testwriteFloat():void + { + /****************************************** + * 12.375f + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeFloat(12.375); + Assert.expectEq("lf32 load float written by writeFloat(12.375)", 12.375, LF32(0)); + } + + + function testwriteDouble():void + { + /****************************************** + * 2.8846085099489688873291015625E6 + * 0x4146020041460200 + * sign = 0 + * exponent = 10000010100 + * mantissa = 0110000000100000000001000001010001100000001000000000 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeDouble(2.8846085099489688873291015625E6); + Assert.expectEq("lf32 load 1st float written by writeDouble(2.8846085099489688873291015625E6)", 12.37548828125, LF32(4)); + Assert.expectEq("lf32 load 2nd float written by writeDouble(2.8846085099489688873291015625E6)", 12.37548828125, LF32(0)); + + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/lf32/output.txt b/tests/tests/swfs/from_avmplus/mops/lf32/output.txt new file mode 100644 index 000000000..c8388ac04 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf32/output.txt @@ -0,0 +1,20 @@ +lf32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +lf32(-1) PASSED! +lf32(mem.length) PASSED! +lf32(mem.length-1) PASSED! +lf32(mem.length-2) PASSED! +lf32(mem.length-3) PASSED! +lf32(mem.length-4) PASSED! +lf32(1) loads do not need to be aligned PASSED! +lf32 load float written by si8() PASSED! +lf32 load float written by si16() PASSED! +lf32 load float written by si32(0x41460200) PASSED! +lf32 load float written by sf32(12.37548828125) PASSED! +lf32 load 1st float written by sf64(0x4146020041460200) PASSED! +lf32 load 2nd float written by sf64(0x4146020041460200) PASSED! +lf32 load float written by writeByte() PASSED! +lf32 load float written by writeBoolean() PASSED! +lf32 load float written by writeInt(2147473647) PASSED! +lf32 load float written by writeFloat(12.375) PASSED! +lf32 load 1st float written by writeDouble(2.8846085099489688873291015625E6) PASSED! +lf32 load 2nd float written by writeDouble(2.8846085099489688873291015625E6) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/lf32/test.swf b/tests/tests/swfs/from_avmplus/mops/lf32/test.swf new file mode 100644 index 000000000..0797f7048 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/lf32/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/lf32/test.toml b/tests/tests/swfs/from_avmplus/mops/lf32/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf32/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/lf64/Test.as b/tests/tests/swfs/from_avmplus/mops/lf64/Test.as new file mode 100644 index 000000000..97cf24dfe --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf64/Test.as @@ -0,0 +1,196 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "lf64"; + + + Assert.expectError("lf64(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LF64(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("lf64(-1)", Utils.RANGEERROR+1506, function(){ LF64(-1); }); + Assert.expectError("lf64(mem.length)", Utils.RANGEERROR+1506, function(){ LF64(mem.length); }); + Assert.expectError("lf64(mem.length-1)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-1); }); + Assert.expectError("lf64(mem.length-2)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-2); }); + Assert.expectError("lf64(mem.length-3)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-3); }); + Assert.expectError("lf64(mem.length-4)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-4); }); + Assert.expectError("lf64(mem.length-5)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-5); }); + Assert.expectError("lf64(mem.length-6)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-6); }); + Assert.expectError("lf64(mem.length-7)", Utils.RANGEERROR+1506, function(){ LF64(mem.length-7); }); + Assert.expectEq("lf64(mem.length-8)", 0, LF64(mem.length-8)); + + SI32(0x4237D796, 5); // 0x4237D796EFC00000 == 102401241024 + SI32(0xEFC00000, 1); // 0x4237D796EFC00000 == 102401241024 + Assert.expectEq("lf64(1) loads do not need to be aligned", 102401241024, LF64(1)); + + testsi8(); + testsi16(); + testsi32(); + testsf32(); + testsf64(); + testwriteByte(); + //testwriteBoolean(); + testwriteInt(); + testwriteFloat(); + testwriteDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + /** + * 0x4237D796EFC00000 = 102401241024 + */ + clearMemory(); + SI8(0x00, 0); + SI8(0x00, 1); + SI8(0xC0, 2); + SI8(0xEF, 3); + SI8(0x96, 4); + SI8(0xD7, 5); + SI8(0x37, 6); + SI8(0x42, 7); + Assert.expectEq("lf64 load double written by si8()", 102401241024, LF64(0)); + } + + function testsi16():void + { + /** + * 0x4237D796EFC00000 = 102401241024 + */ + clearMemory(); + SI16(0x0000, 0); + SI16(0xEFC0, 2); + SI16(0xD796, 4); + SI16(0x4237, 6); + Assert.expectEq("lf64 load double written by si16()", 102401241024, LF64(0)); + } + + function testsi32():void + { + /** + * 0x4237D796EFC00000 = 102401241024 + */ + clearMemory(); + SI32(0xEFC00000, 0); + SI32(0x4237D796, 4); + Assert.expectEq("lf64 load double written by si32()", 102401241024, LF64(0)); + } + + function testsf32():void + { + // Can't use hex representation here since asc will just treat it + // as an int|Number and not as a float. + clearMemory(); + SF32(12.37548828125, 0); + SF32(12.37548828125, 4); + Assert.expectEq("lf64 load double written by sf32()", 2884608.5099489688873291015625, LF64(0)); + } + + function testsf64():void + { + clearMemory(); + SF64(102401241024, 0); + Assert.expectEq("lflf load double written by sf64(102401241024)", 102401241024, LF64(0)); + } + + function testwriteByte():void + { + /** + * 0x4237D796EFC00000 = 102401241024 + */ + clearMemory(); + mem.position = 0; + mem.writeByte(0x00); + mem.writeByte(0x00); + mem.writeByte(0xC0); + mem.writeByte(0xEF); + mem.writeByte(0x96); + mem.writeByte(0xD7); + mem.writeByte(0x37); + mem.writeByte(0x42); + + Assert.expectEq("lf64 load double written by writeByte()", 102401241024, LF64(0)); + } + + function testwriteBoolean():void + { + clearMemory(); + mem.position = 0; + mem.writeBoolean(true); + mem.writeBoolean(false); + mem.writeBoolean(false); + mem.writeBoolean(true); + + Assert.expectEq("lf32 load float written by writeBoolean()", 2.3510604481259484465715043694E-38, LF32(0)); + } + + function testwriteInt():void + { + /****************************************** + * 0x4237D796EFC00000 = 102401241024 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(-272629760); // 0xEFC00000 + mem.writeInt(1110955926); // 0x4237D796 + + Assert.expectEq("lf64 load double written by writeInt()", 102401241024, LF64(0)); + } + + function testwriteFloat():void + { + clearMemory(); + mem.position = 0; + mem.writeFloat(12.37548828125); + mem.writeFloat(12.37548828125); + Assert.expectEq("lf64 load double written by writeFloat(12.37548828125)", 2884608.5099489688873291015625, LF64(0)); + } + + + function testwriteDouble():void + { + clearMemory(); + mem.position = 0; + mem.writeDouble(102401241024); + Assert.expectEq("lf64 load double written by writeDouble(102401241024)", 102401241024, LF64(0)); + + } +} diff --git a/tests/tests/swfs/from_avmplus/mops/lf64/output.txt b/tests/tests/swfs/from_avmplus/mops/lf64/output.txt new file mode 100644 index 000000000..84236eaca --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf64/output.txt @@ -0,0 +1,21 @@ +lf64(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +lf64(-1) PASSED! +lf64(mem.length) PASSED! +lf64(mem.length-1) PASSED! +lf64(mem.length-2) PASSED! +lf64(mem.length-3) PASSED! +lf64(mem.length-4) PASSED! +lf64(mem.length-5) PASSED! +lf64(mem.length-6) PASSED! +lf64(mem.length-7) PASSED! +lf64(mem.length-8) PASSED! +lf64(1) loads do not need to be aligned PASSED! +lf64 load double written by si8() PASSED! +lf64 load double written by si16() PASSED! +lf64 load double written by si32() PASSED! +lf64 load double written by sf32() PASSED! +lflf load double written by sf64(102401241024) PASSED! +lf64 load double written by writeByte() PASSED! +lf64 load double written by writeInt() PASSED! +lf64 load double written by writeFloat(12.37548828125) PASSED! +lf64 load double written by writeDouble(102401241024) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/lf64/test.swf b/tests/tests/swfs/from_avmplus/mops/lf64/test.swf new file mode 100644 index 000000000..d9eb14a81 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/lf64/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/lf64/test.toml b/tests/tests/swfs/from_avmplus/mops/lf64/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lf64/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/li16/Test.as b/tests/tests/swfs/from_avmplus/mops/li16/Test.as new file mode 100644 index 000000000..9b85b8572 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li16/Test.as @@ -0,0 +1,215 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "li16"; + + + Assert.expectError("li16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LI16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("li16(-1)", Utils.RANGEERROR+1506, function(){ LI16(-1); }); + Assert.expectError("li16(mem.length)", Utils.RANGEERROR+1506, function(){ LI16(mem.length); }); + Assert.expectError("li16(mem.length-1)", Utils.RANGEERROR+1506, function(){ LI16(mem.length-1); }); + Assert.expectEq("li16(mem.length-2)", 0, LI16(mem.length-2)); + + SI16(0x7FDE, 1); + Assert.expectEq("li16(1) loads do not need to be aligned", 0x7FDE, LI16(1)); + + testsi8(); + testsi16(); + testsi32(); + testsf32(); + testsf64(); + testwriteByte(); + testwriteBoolean(); + testwriteInt(); + testwriteFloat(); + testwriteDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + clearMemory(); + SI8(0x7F, 0); + SI8(0x80, 1); + Assert.expectEq("li16 load short written by si8()", 0x807F, LI16(0)); + } + + function testsi16():void + { + clearMemory(); + SI16(0x80DE, 0); + Assert.expectEq("li16 load short written by si16(0x80DE)", 0x80DE, LI16(0)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x80DE32F1, 0); + Assert.expectEq("li16 load 1st short written by si32(0x80DE32F1)", 0x80DE, LI16(2)); + Assert.expectEq("li16 load 2nd short written by si32(0x80DE32F1)", 0x32F1, LI16(0)); + } + + function testsf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SF32(12.375, 0); + Assert.expectEq("li16 load 1st short written by sf32(12.375)", 0x4146, LI16(2)); + Assert.expectEq("li16 load 2nd short written by sf32(12.375)", 0x0000, LI16(0)); + } + + function testsf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SF64(1.0241024102410242048E19, 0); + Assert.expectEq("li16 load 1st short written by sf64(10241024102410241024)", 0x43E1, LI16(6)); + Assert.expectEq("li16 load 2nd short written by sf64(10241024102410241024)", 0xC3ED, LI16(4)); + Assert.expectEq("li16 load 3rd short written by sf64(10241024102410241024)", 0xA52E, LI16(2)); + Assert.expectEq("li16 load 4th short written by sf64(10241024102410241024)", 0x0C09, LI16(0)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(127); + mem.writeByte(128); + + Assert.expectEq("li16 load short written by writeByte()", 0x807F, LI16(0)); + } + + function testwriteBoolean():void + { + clearMemory(); + mem.position = 0; + mem.writeBoolean(false); + mem.writeBoolean(true); + + Assert.expectEq("li16 load short written by writeBoolean()", 0x0100, LI16(0)); + } + + function testwriteInt():void + { + /****************************************** + * 2147473647 = 0x7FFFD8EF = 01111111 11111111 11011000 11101111 + * 01111111 = 127 = 0x7F + * 11111111 = 255 = 0xFF + * 11011000 = 216 = 0xD8 + * 11101111 = 239 = 0xEF + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(2147473647); + + Assert.expectEq("li16 load 1st short written by writeInt(2147473647)", 0x7FFF, LI16(2)); + Assert.expectEq("li16 load 2nd short written by writeInt(2147473647)", 0xD8EF, LI16(0)); + } + + function testwriteFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeFloat(12.375); + Assert.expectEq("li16 load 1st short written by writeFloat(12.375)", 0x4146, LI16(2)); + Assert.expectEq("li16 load 2nd short written by writeFloat(12.375)", 0x0000, LI16(0)); + } + + + function testwriteDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeDouble(1.0241024102410242048E19); + Assert.expectEq("li16 load 1st short written by writeDouble(1.0241024102410242048E19)", 0x43E1, LI16(6)); + Assert.expectEq("li16 load 2nd short written by writeDouble(1.0241024102410242048E19)", 0xC3ED, LI16(4)); + Assert.expectEq("li16 load 3rd short written by writeDouble(1.0241024102410242048E19)", 0xA52E, LI16(2)); + Assert.expectEq("li16 load 4th short written by writeDouble(1.0241024102410242048E19)", 0x0C09, LI16(0)); + + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/li16/output.txt b/tests/tests/swfs/from_avmplus/mops/li16/output.txt new file mode 100644 index 000000000..35894ed57 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li16/output.txt @@ -0,0 +1,26 @@ +li16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +li16(-1) PASSED! +li16(mem.length) PASSED! +li16(mem.length-1) PASSED! +li16(mem.length-2) PASSED! +li16(1) loads do not need to be aligned PASSED! +li16 load short written by si8() PASSED! +li16 load short written by si16(0x80DE) PASSED! +li16 load 1st short written by si32(0x80DE32F1) PASSED! +li16 load 2nd short written by si32(0x80DE32F1) PASSED! +li16 load 1st short written by sf32(12.375) PASSED! +li16 load 2nd short written by sf32(12.375) PASSED! +li16 load 1st short written by sf64(10241024102410241024) PASSED! +li16 load 2nd short written by sf64(10241024102410241024) PASSED! +li16 load 3rd short written by sf64(10241024102410241024) PASSED! +li16 load 4th short written by sf64(10241024102410241024) PASSED! +li16 load short written by writeByte() PASSED! +li16 load short written by writeBoolean() PASSED! +li16 load 1st short written by writeInt(2147473647) PASSED! +li16 load 2nd short written by writeInt(2147473647) PASSED! +li16 load 1st short written by writeFloat(12.375) PASSED! +li16 load 2nd short written by writeFloat(12.375) PASSED! +li16 load 1st short written by writeDouble(1.0241024102410242048E19) PASSED! +li16 load 2nd short written by writeDouble(1.0241024102410242048E19) PASSED! +li16 load 3rd short written by writeDouble(1.0241024102410242048E19) PASSED! +li16 load 4th short written by writeDouble(1.0241024102410242048E19) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/li16/test.swf b/tests/tests/swfs/from_avmplus/mops/li16/test.swf new file mode 100644 index 000000000..d8f0fa6bf Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/li16/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/li16/test.toml b/tests/tests/swfs/from_avmplus/mops/li16/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li16/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/li32/Test.as b/tests/tests/swfs/from_avmplus/mops/li32/Test.as new file mode 100644 index 000000000..591c58250 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li32/Test.as @@ -0,0 +1,217 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "li32"; + + + Assert.expectError("li32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LI32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("li32(-1)", Utils.RANGEERROR+1506, function(){ LI32(-1); }); + Assert.expectError("li32(mem.length)", Utils.RANGEERROR+1506, function(){ LI32(mem.length); }); + Assert.expectError("li32(mem.length-1)", Utils.RANGEERROR+1506, function(){ LI32(mem.length-1); }); + Assert.expectError("li32(mem.length-2)", Utils.RANGEERROR+1506, function(){ LI32(mem.length-2); }); + Assert.expectError("li32(mem.length-3)", Utils.RANGEERROR+1506, function(){ LI32(mem.length-3); }); + Assert.expectEq("li32(mem.length-4)", 0, LI32(mem.length-4)); + + SI32(0x7FDE8001, 1); + Assert.expectEq("li32(1) loads do not need to be aligned", 0x7FDE8001, LI32(1)); + + + testsi8(); + testsi16(); + testsi32(); + testsf32(); + testsf64(); + testwriteByte(); + testwriteBoolean(); + testwriteInt(); + testwriteFloat(); + testwriteDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + clearMemory(); + SI8(0x7F, 0); + SI8(0x80, 1); + SI8(0x80, 2); + SI8(0x01, 3); + Assert.expectEq("li32 load int32 written by si8()", 0x0180807F, LI32(0)); + } + + function testsi16():void + { + clearMemory(); + SI16(0x80DE, 0); + SI16(0x07A5, 2); + Assert.expectEq("li32 load int32 written by si16()", 0x07A580DE, LI32(0)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x07DE32F1, 0); + Assert.expectEq("li32 load int32 written by si32(0x07DE32F1)", 0x07DE32F1, LI32(0)); + } + + function testsf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SF32(12.375, 0); + Assert.expectEq("li32 load int32 written by sf32(12.375)", 0x41460000, LI32(0)); + } + + function testsf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SF64(1.0241024102410242048E19, 0); + Assert.expectEq("li32 load 1st int32 written by si64(10241024102410241024)", 0x43E1C3ED, LI32(4)); + Assert.expectEq("li32 load 2nd int32 written by si64(10241024102410241024)", int(0xA52E0C09), LI32(0)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(127); + mem.writeByte(128); + mem.writeByte(0x77); + mem.writeByte(0x5A); + + Assert.expectEq("li32 load int32 written by writeByte()", 0x5A77807F, LI32(0)); + } + + function testwriteBoolean():void + { + clearMemory(); + mem.position = 0; + mem.writeBoolean(true); + mem.writeBoolean(true); + mem.writeBoolean(false); + mem.writeBoolean(true); + + Assert.expectEq("li32 load int32 written by writeBoolean()", 0x01000101, LI32(0)); + } + + function testwriteInt():void + { + /****************************************** + * 2147473647 = 0x7FFFD8EF = 01111111 11111111 11011000 11101111 + * 01111111 = 127 = 0x7F + * 11111111 = 255 = 0xFF + * 11011000 = 216 = 0xD8 + * 11101111 = 239 = 0xEF + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(2147473647); + + Assert.expectEq("li32 load int32 written by writeInt(2147473647)", 0x7FFFD8EF, LI32(0)); + } + + function testwriteFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeFloat(12.375); + Assert.expectEq("li32 load int32 written by writeFloat(12.375)", 0x41460000, LI32(0)); + } + + + function testwriteDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeDouble(1.0241024102410242048E19); + Assert.expectEq("li32 load 1st int32 written by writeDouble(1.0241024102410242048E19)", 0x43E1C3ED, LI32(4)); + Assert.expectEq("li32 load 2nd int32 written by writeDouble(1.0241024102410242048E19)", int(0xA52E0C09), LI32(0)); + + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/li32/output.txt b/tests/tests/swfs/from_avmplus/mops/li32/output.txt new file mode 100644 index 000000000..d51c5f700 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li32/output.txt @@ -0,0 +1,20 @@ +li32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +li32(-1) PASSED! +li32(mem.length) PASSED! +li32(mem.length-1) PASSED! +li32(mem.length-2) PASSED! +li32(mem.length-3) PASSED! +li32(mem.length-4) PASSED! +li32(1) loads do not need to be aligned PASSED! +li32 load int32 written by si8() PASSED! +li32 load int32 written by si16() PASSED! +li32 load int32 written by si32(0x07DE32F1) PASSED! +li32 load int32 written by sf32(12.375) PASSED! +li32 load 1st int32 written by si64(10241024102410241024) PASSED! +li32 load 2nd int32 written by si64(10241024102410241024) PASSED! +li32 load int32 written by writeByte() PASSED! +li32 load int32 written by writeBoolean() PASSED! +li32 load int32 written by writeInt(2147473647) PASSED! +li32 load int32 written by writeFloat(12.375) PASSED! +li32 load 1st int32 written by writeDouble(1.0241024102410242048E19) PASSED! +li32 load 2nd int32 written by writeDouble(1.0241024102410242048E19) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/li32/test.swf b/tests/tests/swfs/from_avmplus/mops/li32/test.swf new file mode 100644 index 000000000..42f9ac7e9 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/li32/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/li32/test.toml b/tests/tests/swfs/from_avmplus/mops/li32/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li32/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/li8/Test.as b/tests/tests/swfs/from_avmplus/mops/li8/Test.as new file mode 100644 index 000000000..a8d5345b9 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li8/Test.as @@ -0,0 +1,237 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "li8"; + + + + Assert.expectError("li8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LI8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("li8(-1)", Utils.RANGEERROR+1506, function(){ LI8(-1); }); + Assert.expectError("li8(mem.length)", Utils.RANGEERROR+1506, function(){ LI8(mem.length); }); + Assert.expectEq("li8(mem.length-1)", 0, LI8(mem.length-1)); + + testsi8(); + testsi16(); + testsi32(); + testsf32(); + testsf64(); + testwriteByte(); + testwriteBoolean(); + testwriteInt(); + testwriteFloat(); + testwriteDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + clearMemory(); + SI8(0x7F, 0); + SI8(0x80, 1); + Assert.expectEq("li8 load byte written by si8(0x7F)", 0x7F, LI8(0)); + Assert.expectEq("li8 load byte written by si8(0x80)", 0x80, LI8(1)); + } + + function testsi16():void + { + clearMemory(); + SI16(0x80DE, 0); + Assert.expectEq("li8 load 1st byte written by si16(0x80DE)", 0x80, LI8(1)); + Assert.expectEq("li8 load 2nd byte written by si16(0x80De)", 0xDE, LI8(0)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x80DE32F1, 0); + Assert.expectEq("li8 load 1st byte written by si32(0x80DE32F1)", 0x80, LI8(3)); + Assert.expectEq("li8 load 2nd byte written by si32(0x80DE32F1)", 0xDE, LI8(2)); + Assert.expectEq("li8 load 3rd byte written by si32(0x80DE32F1)", 0x32, LI8(1)); + Assert.expectEq("li8 load 4th byte written by si32(0x80DE32F1)", 0xF1, LI8(0)); + } + + function testsf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SF32(12.375, 0); + Assert.expectEq("li8 load 1st byte written by sf32(12.375)", 0x41, LI8(3)); + Assert.expectEq("li8 load 2nd byte written by sf32(12.375)", 0x46, LI8(2)); + Assert.expectEq("li8 load 3rd byte written by sf32(12.375)", 0x00, LI8(1)); + Assert.expectEq("li8 load 4th byte written by sf32(12.375)", 0x00, LI8(0)); + } + + function testsf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SF64(1.0241024102410242048E19, 0); + Assert.expectEq("li8 load 1st byte written by sf64(10241024102410241024)", 0x43, LI8(7)); + Assert.expectEq("li8 load 2nd byte written by sf64(10241024102410241024)", 0xE1, LI8(6)); + Assert.expectEq("li8 load 3rd byte written by sf64(10241024102410241024)", 0xC3, LI8(5)); + Assert.expectEq("li8 load 4th byte written by sf64(10241024102410241024)", 0xED, LI8(4)); + Assert.expectEq("li8 load 5th byte written by sf64(10241024102410241024)", 0xA5, LI8(3)); + Assert.expectEq("li8 load 6th byte written by sf64(10241024102410241024)", 0x2E, LI8(2)); + Assert.expectEq("li8 load 7th byte written by sf64(10241024102410241024)", 0x0C, LI8(1)); + Assert.expectEq("li8 load 8th byte written by sf64(10241024102410241024)", 0x09, LI8(0)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(0); + mem.writeByte(127); + mem.writeByte(128); + mem.writeByte(255); + + Assert.expectEq("li8 load byte written by writeByte(0)", 0, LI8(0)); + Assert.expectEq("li8 load byte written by writeByte(127)", 127, LI8(1)); + Assert.expectEq("li8 load byte written by writeByte(128)", 128, LI8(2)); + Assert.expectEq("li8 load byte written by writeByte(255)", 255, LI8(3)); + } + + function testwriteBoolean():void + { + clearMemory(); + mem.position = 0; + mem.writeBoolean(true); + mem.writeBoolean(false); + + Assert.expectEq("li8 load byte written by writeBoolean(true)", 1, LI8(0)); + Assert.expectEq("li8 load byte written by writeBoolean(false)", 0, LI8(1)); + } + + function testwriteInt():void + { + /****************************************** + * 2147473647 = 0x7FFFD8EF = 01111111 11111111 11011000 11101111 + * 01111111 = 127 = 0x7F + * 11111111 = 255 = 0xFF + * 11011000 = 216 = 0xD8 + * 11101111 = 239 = 0xEF + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(2147473647); + + Assert.expectEq("li8 load 1st byte written by writeInt(2147473647)", 0x7F, LI8(3)); + Assert.expectEq("li8 load 2nd byte written by writeInt(2147473647)", 0xFF, LI8(2)); + Assert.expectEq("li8 load 3rd byte written by writeInt(2147473647)", 0xD8, LI8(1)); + Assert.expectEq("li8 load 4th byte written by writeInt(2147473647)", 0xEF, LI8(0)); + } + + function testwriteFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeFloat(12.375); + Assert.expectEq("li8 load 1st byte written by writeFloat(12.375)", 0x41, LI8(3)); + Assert.expectEq("li8 load 2nd byte written by writeFloat(12.375)", 0x46, LI8(2)); + Assert.expectEq("li8 load 3rd byte written by writeFloat(12.375)", 0x00, LI8(1)); + Assert.expectEq("li8 load 4th byte written by writeFloat(12.375)", 0x00, LI8(0)); + } + + + function testwriteDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeDouble(1.0241024102410242048E19); + Assert.expectEq("li8 load 1st byte written by writeDouble(1.0241024102410242048E19)", 0x43, LI8(7)); + Assert.expectEq("li8 load 2nd byte written by writeDouble(1.0241024102410242048E19)", 0xE1, LI8(6)); + Assert.expectEq("li8 load 3rd byte written by writeDouble(1.0241024102410242048E19)", 0xC3, LI8(5)); + Assert.expectEq("li8 load 4th byte written by writeDouble(1.0241024102410242048E19)", 0xED, LI8(4)); + Assert.expectEq("li8 load 5th byte written by writeDouble(1.0241024102410242048E19)", 0xA5, LI8(3)); + Assert.expectEq("li8 load 6th byte written by writeDouble(1.0241024102410242048E19)", 0x2E, LI8(2)); + Assert.expectEq("li8 load 7th byte written by writeDouble(1.0241024102410242048E19)", 0x0C, LI8(1)); + Assert.expectEq("li8 load 8th byte written by writeDouble(1.0241024102410242048E19)", 0x09, LI8(0)); + + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/li8/output.txt b/tests/tests/swfs/from_avmplus/mops/li8/output.txt new file mode 100644 index 000000000..9900b415f --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li8/output.txt @@ -0,0 +1,46 @@ +li8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +li8(-1) PASSED! +li8(mem.length) PASSED! +li8(mem.length-1) PASSED! +li8 load byte written by si8(0x7F) PASSED! +li8 load byte written by si8(0x80) PASSED! +li8 load 1st byte written by si16(0x80DE) PASSED! +li8 load 2nd byte written by si16(0x80De) PASSED! +li8 load 1st byte written by si32(0x80DE32F1) PASSED! +li8 load 2nd byte written by si32(0x80DE32F1) PASSED! +li8 load 3rd byte written by si32(0x80DE32F1) PASSED! +li8 load 4th byte written by si32(0x80DE32F1) PASSED! +li8 load 1st byte written by sf32(12.375) PASSED! +li8 load 2nd byte written by sf32(12.375) PASSED! +li8 load 3rd byte written by sf32(12.375) PASSED! +li8 load 4th byte written by sf32(12.375) PASSED! +li8 load 1st byte written by sf64(10241024102410241024) PASSED! +li8 load 2nd byte written by sf64(10241024102410241024) PASSED! +li8 load 3rd byte written by sf64(10241024102410241024) PASSED! +li8 load 4th byte written by sf64(10241024102410241024) PASSED! +li8 load 5th byte written by sf64(10241024102410241024) PASSED! +li8 load 6th byte written by sf64(10241024102410241024) PASSED! +li8 load 7th byte written by sf64(10241024102410241024) PASSED! +li8 load 8th byte written by sf64(10241024102410241024) PASSED! +li8 load byte written by writeByte(0) PASSED! +li8 load byte written by writeByte(127) PASSED! +li8 load byte written by writeByte(128) PASSED! +li8 load byte written by writeByte(255) PASSED! +li8 load byte written by writeBoolean(true) PASSED! +li8 load byte written by writeBoolean(false) PASSED! +li8 load 1st byte written by writeInt(2147473647) PASSED! +li8 load 2nd byte written by writeInt(2147473647) PASSED! +li8 load 3rd byte written by writeInt(2147473647) PASSED! +li8 load 4th byte written by writeInt(2147473647) PASSED! +li8 load 1st byte written by writeFloat(12.375) PASSED! +li8 load 2nd byte written by writeFloat(12.375) PASSED! +li8 load 3rd byte written by writeFloat(12.375) PASSED! +li8 load 4th byte written by writeFloat(12.375) PASSED! +li8 load 1st byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 2nd byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 3rd byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 4th byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 5th byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 6th byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 7th byte written by writeDouble(1.0241024102410242048E19) PASSED! +li8 load 8th byte written by writeDouble(1.0241024102410242048E19) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/li8/test.swf b/tests/tests/swfs/from_avmplus/mops/li8/test.swf new file mode 100644 index 000000000..c6b81815b Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/li8/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/li8/test.toml b/tests/tests/swfs/from_avmplus/mops/li8/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/li8/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/lix16/Test.as b/tests/tests/swfs/from_avmplus/mops/lix16/Test.as new file mode 100644 index 000000000..d9f552a32 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix16/Test.as @@ -0,0 +1,123 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "lix16"; + + + Assert.expectError("lix16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LIX16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("lix16(-1)", Utils.RANGEERROR+1506, function(){ LIX16(-1); }); + Assert.expectError("lix16(mem.length)", Utils.RANGEERROR+1506, function(){ LIX16(mem.length); }); + Assert.expectError("lix16(mem.length-1)", Utils.RANGEERROR+1506, function(){ LIX16(mem.length-1); }); + Assert.expectEq("lix16(mem.length-2)", 0, LIX16(mem.length-2)); + + testsi8(); + testsi16(); + testsi32(); + testwriteByte(); + testwriteInt(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + // 0x8000 -32768 + // 0xFFFF -1 + // 0x7FFF 32767 + clearMemory(); + SI8(0x00, 0); + SI8(0x80, 1); + SI8(0xFF, 2); + SI8(0xFF, 3); + SI8(0xFF, 4); + SI8(0x7F, 5); + Assert.expectEq("lix16 load byte written by si8()", -32768, LIX16(0)); + Assert.expectEq("lix16 load byte written by si8()", -1, LIX16(2)); + Assert.expectEq("lix16 load byte written by si8()", 32767, LIX16(4)); + } + + function testsi16():void + { + // 0x8000 -32768 + // 0xFFFF -1 + // 0x7FFF 32767 + clearMemory(); + SI16(0x8000, 0); + SI16(0xFFFF, 2); + SI16(0x7FFF, 4); + Assert.expectEq("lix16 load bytes written by si16(0x8000)", -32768, LIX16(0)); + Assert.expectEq("lix16 load bytes written by si16(0xFFFF)", -1, LIX16(2)); + Assert.expectEq("lix16 load bytes written by si16(0x7FFF)", 32767, LIX16(4)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x7FFF8000, 0); + Assert.expectEq("lix16 load 1st short written by si32(0x7FFF8000)", -32768, LIX16(0)); + Assert.expectEq("lix16 load 2nd short written by si32(0x7FFF8000)", 32767, LIX16(2)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(0x00); + mem.writeByte(0x80); + mem.writeByte(0xFF); + mem.writeByte(0x7F); + + Assert.expectEq("lix16 load bytes written by writeByte()", -32768, LIX16(0)); + Assert.expectEq("lix16 load bytes written by writeByte()", 32767, LIX16(2)); + } + + function testwriteInt():void + { + clearMemory(); + mem.position = 0; + mem.writeInt(2147450880); + + Assert.expectEq("lix16 load 1st short written by writeInt(2147450880)", -32768, LIX16(0)); + Assert.expectEq("lix16 load 2nd short written by writeInt(2147450880)", 32767, LIX16(2)); + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/lix16/output.txt b/tests/tests/swfs/from_avmplus/mops/lix16/output.txt new file mode 100644 index 000000000..11362d51f --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix16/output.txt @@ -0,0 +1,17 @@ +lix16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +lix16(-1) PASSED! +lix16(mem.length) PASSED! +lix16(mem.length-1) PASSED! +lix16(mem.length-2) PASSED! +lix16 load byte written by si8() PASSED! +lix16 load byte written by si8() PASSED! +lix16 load byte written by si8() PASSED! +lix16 load bytes written by si16(0x8000) PASSED! +lix16 load bytes written by si16(0xFFFF) PASSED! +lix16 load bytes written by si16(0x7FFF) PASSED! +lix16 load 1st short written by si32(0x7FFF8000) PASSED! +lix16 load 2nd short written by si32(0x7FFF8000) PASSED! +lix16 load bytes written by writeByte() PASSED! +lix16 load bytes written by writeByte() PASSED! +lix16 load 1st short written by writeInt(2147450880) PASSED! +lix16 load 2nd short written by writeInt(2147450880) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/lix16/test.swf b/tests/tests/swfs/from_avmplus/mops/lix16/test.swf new file mode 100644 index 000000000..e6f3980e7 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/lix16/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/lix16/test.toml b/tests/tests/swfs/from_avmplus/mops/lix16/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix16/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/lix8/Test.as b/tests/tests/swfs/from_avmplus/mops/lix8/Test.as new file mode 100644 index 000000000..1a7c7f9a0 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix8/Test.as @@ -0,0 +1,123 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "lix8"; + + + Assert.expectError("lix8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ LIX8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + Assert.expectError("lix8(-1)", Utils.RANGEERROR+1506, function(){ LIX8(-1); }); + Assert.expectError("lix8(mem.length)", Utils.RANGEERROR+1506, function(){ LIX8(mem.length); }); + Assert.expectEq("lix8(mem.length-1)", 0, LIX8(mem.length-1)); + + testsi8(); + testsi16(); + testsi32(); + testwriteByte(); + testwriteInt(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testsi8():void + { + clearMemory(); + SI8(0x7F, 0); + SI8(0x80, 1); + SI8(0xFF, 2); + Assert.expectEq("lix8 load byte written by si8(0x7F)", 127, LIX8(0)); + Assert.expectEq("lix8 load byte written by si8(0x80)", -128, LIX8(1)); + Assert.expectEq("lix8 load byte written by si8(0xFF)", -1, LIX8(2)); + } + + function testsi16():void + { + clearMemory(); + SI16(0x7F80, 0); + Assert.expectEq("lix8 load 1st byte written by si16(0x7F80)", 127, LIX8(1)); + Assert.expectEq("lix8 load 2nd byte written by si16(0x7F80)", -128, LIX8(0)); + } + + function testsi32():void + { + clearMemory(); + SI32(0x007F80FF, 0); + Assert.expectEq("lix8 load 1st byte written by si32(0x007F80FF)", 0, LIX8(3)); + Assert.expectEq("lix8 load 2nd byte written by si32(0x007F80FF)", 127, LIX8(2)); + Assert.expectEq("lix8 load 3rd byte written by si32(0x007F80FF)", -128, LIX8(1)); + Assert.expectEq("lix8 load 4th byte written by si32(0x007F80FF)", -1, LIX8(0)); + } + + function testwriteByte():void + { + clearMemory(); + mem.position = 0; + mem.writeByte(0); + mem.writeByte(127); + mem.writeByte(128); + mem.writeByte(255); + + Assert.expectEq("lix8 load byte written by writeByte(0)", 0, LIX8(0)); + Assert.expectEq("lix8 load byte written by writeByte(127)", 127, LIX8(1)); + Assert.expectEq("lix8 load byte written by writeByte(128)", -128, LIX8(2)); + Assert.expectEq("lix8 load byte written by writeByte(255)", -1, LIX8(3)); + } + + function testwriteInt():void + { + /****************************************** + * 2147473647 = 0x7FFFD8EF = 01111111 11111111 11011000 11101111 + * 01111111 = 127 = 0x7F + * 11111111 = 255 = 0xFF + * 11011000 = 216 = 0xD8 + * 11101111 = 239 = 0xEF + *****************************************/ + clearMemory(); + mem.position = 0; + mem.writeInt(2147473647); + + Assert.expectEq("lix8 load 1st byte written by writeInt(2147473647)", 127, LIX8(3)); + Assert.expectEq("lix8 load 2nd byte written by writeInt(2147473647)", -1, LIX8(2)); + Assert.expectEq("lix8 load 3rd byte written by writeInt(2147473647)", -40, LIX8(1)); + Assert.expectEq("lix8 load 4th byte written by writeInt(2147473647)", -17, LIX8(0)); + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/lix8/output.txt b/tests/tests/swfs/from_avmplus/mops/lix8/output.txt new file mode 100644 index 000000000..fd071a1f1 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix8/output.txt @@ -0,0 +1,21 @@ +lix8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +lix8(-1) PASSED! +lix8(mem.length) PASSED! +lix8(mem.length-1) PASSED! +lix8 load byte written by si8(0x7F) PASSED! +lix8 load byte written by si8(0x80) PASSED! +lix8 load byte written by si8(0xFF) PASSED! +lix8 load 1st byte written by si16(0x7F80) PASSED! +lix8 load 2nd byte written by si16(0x7F80) PASSED! +lix8 load 1st byte written by si32(0x007F80FF) PASSED! +lix8 load 2nd byte written by si32(0x007F80FF) PASSED! +lix8 load 3rd byte written by si32(0x007F80FF) PASSED! +lix8 load 4th byte written by si32(0x007F80FF) PASSED! +lix8 load byte written by writeByte(0) PASSED! +lix8 load byte written by writeByte(127) PASSED! +lix8 load byte written by writeByte(128) PASSED! +lix8 load byte written by writeByte(255) PASSED! +lix8 load 1st byte written by writeInt(2147473647) PASSED! +lix8 load 2nd byte written by writeInt(2147473647) PASSED! +lix8 load 3rd byte written by writeInt(2147473647) PASSED! +lix8 load 4th byte written by writeInt(2147473647) PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/lix8/test.swf b/tests/tests/swfs/from_avmplus/mops/lix8/test.swf new file mode 100644 index 000000000..820febff9 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/lix8/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/lix8/test.toml b/tests/tests/swfs/from_avmplus/mops/lix8/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/lix8/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/mops_basics/Test.as b/tests/tests/swfs/from_avmplus/mops/mops_basics/Test.as new file mode 100644 index 000000000..a950ddfab --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/mops_basics/Test.as @@ -0,0 +1,712 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; + import com.adobe.test.Assert; + + +// var SECTION:String = "Actionscript"; +// var VERSION:String = "AS3"; +// var TITLE:String = "Memory Opcodes"; + + + var inPlayer:Boolean = false; + + function getApplicationDomainClass():Class + { + var ns:Namespace; + + try + { + ns = new Namespace("avmplus"); + return ns::["ApplicationDomain"]; + } + catch(e:*) {} + try + { + ns = new Namespace("flash.system"); + var result:Class = ns::["ApplicationDomain"]; + inPlayer = true; + return result; + } + catch(e:*) {} + return null; + } + + function getByteArrayClass():Class + { + var ns:Namespace = new Namespace("flash.utils"); + + try + { + return (ns::["ByteArray"]); + } + catch(e:*) {} + return null; + } + + var domainClass:Class = getApplicationDomainClass(); + Assert.expectEq("domainClass != null", true, domainClass != null); + + var byteArrayClass:Class = getByteArrayClass(); + Assert.expectEq("byteArrayClass != null", true, byteArrayClass != null); + + var currentDomain:Object = domainClass.currentDomain; + Assert.expectEq("currentDomain != null", true, currentDomain != null); + + var minMemSize:uint = domainClass.MIN_DOMAIN_MEMORY_LENGTH; + Assert.expectEq("minMemSize >= 8", true, minMemSize >= 8); + + Assert.expectEq("currentDomain.domainMemory == null", true, currentDomain.domainMemory == null); + + + var ba:Object; + + var emptyByteArrayOk:Boolean = false; + + ba = new byteArrayClass(); + try + { + currentDomain.domainMemory = ba; + emptyByteArrayOk = true; + } + catch(e:*) {} + + Assert.expectEq("Empty byte array ok", false, emptyByteArrayOk); + + var smallByteArrayOk:Boolean = false; + + ba = new byteArrayClass(); + ba.length = domainClass.MIN_DOMAIN_MEMORY_LENGTH - 1; + + try + { + currentDomain.domainMemory = ba; + smallByteArrayOk = true; + } + catch(e:*) {} + + Assert.expectEq("Small byte array ok", false, smallByteArrayOk); + + var wrongObj1Ok:Boolean = false; + + try + { + currentDomain.domainMemory = []; + wrongObj1Ok = true; + } + catch(e:*) {} + + Assert.expectEq("Wrong obj (Array) ok", false, wrongObj1Ok); + + var wrongObj2Ok:Boolean = false; + + try + { + currentDomain.domainMemory = {}; + wrongObj2Ok = true; + } + catch(e:*) {} + + Assert.expectEq("Wrong obj (Object) ok", false, wrongObj2Ok); + + var wrongObj3Ok:Boolean = false; + + try + { + currentDomain.domainMemory = function(i:int):int { return i; }; + wrongObj3Ok = true; + } + catch(e:*) {} + + Assert.expectEq("Wrong obj (Function) ok", false, wrongObj3Ok); + + var wrongObj4Ok:Boolean = false; + + class UserClass1 + { + }; + + try + { + currentDomain.domainMemory = new UserClass1; + wrongObj4Ok = true; + } + catch(e:*) {} + + Assert.expectEq("Wrong obj (user) ok", false, wrongObj4Ok); + + var minSizedByteArrayOk:Boolean = false; + + ba = new byteArrayClass(); + ba.length = domainClass.MIN_DOMAIN_MEMORY_LENGTH; + + try + { + currentDomain.domainMemory = ba; + minSizedByteArrayOk = true; + } + catch(e:*) {} + + Assert.expectEq("Min sized byte array ok", true, minSizedByteArrayOk); + + + var longTests:Array = []; + + function readTest(salt:Number, size:int, baWrite:Function, baRead:Function, op:Function) + { + currentDomain.domainMemory.endian = "littleEndian"; + + var len:uint = currentDomain.domainMemory.length - size; + var n:int; + var e:Array = []; + + for(var offs:int = 0; offs < size; offs++) + { + for(n = offs; n <= len; n += size) + { + currentDomain.domainMemory.position = n; + baWrite(n+salt); + currentDomain.domainMemory.position = n; + e[n] = baRead(); + } + for(n = offs; n <= len; n += size) + { + if(op(n) != e[n]) + return false; + } + } + return true; + } + + function readTestByte(salt:int):Boolean + { + return readTest(salt, 1, + currentDomain.domainMemory.writeByte, + currentDomain.domainMemory.readUnsignedByte, + function(addr:int):int { return LI8(addr); } + ); + } + + function readTestByteSX(salt:int):Boolean + { + return readTest(salt, 1, + currentDomain.domainMemory.writeByte, + currentDomain.domainMemory.readByte, + function(addr:int):int { return LIX8(addr); } + ); + } + + + function readTestShort(salt:int):Boolean + { + return readTest(salt, 2, + currentDomain.domainMemory.writeShort, + currentDomain.domainMemory.readUnsignedShort, + function(addr:int):int { return LI16(addr); } + ); + } + + function readTestShortSX(salt:int):Boolean + { + return readTest(salt, 2, + currentDomain.domainMemory.writeShort, + currentDomain.domainMemory.readShort, + function(addr:int):int { return LIX16(addr); } + ); + } + + function readTestInt(salt:int):Boolean + { + return readTest(salt, 4, + currentDomain.domainMemory.writeInt, + currentDomain.domainMemory.readInt, + function(addr:int):int { return LI32(addr); } + ); + } + + function readTestFloat(salt:Number):Boolean + { + return readTest(salt, 4, + currentDomain.domainMemory.writeFloat, + currentDomain.domainMemory.readFloat, + function(addr:int):Number { return LF32(addr); } + ); + } + + function readTestDouble(salt:Number):Boolean + { + return readTest(salt, 8, + currentDomain.domainMemory.writeDouble, + currentDomain.domainMemory.readDouble, + function(addr:int):Number { return LF64(addr); } + ); + } + + + longTests.push(function():void { + Assert.expectEq("Read test byte w/ min sized", true, readTestByte(12)); + Assert.expectEq("Read test byte w/ sign extend w/ min sized", true, readTestByteSX(-21)); + Assert.expectEq("Read test short w/ min sized", true, readTestShort(3456)); + Assert.expectEq("Read test short w/ sign extend w/ min sized", true, readTestShortSX(-6543)); + Assert.expectEq("Read test int w/ min sized", true, readTestInt(567890)); + Assert.expectEq("Read test float w/ min sized", true, readTestFloat(12.34)); + Assert.expectEq("Read test double w/ min sized", true, readTestDouble(34.56)); + }); + + + + function writeTest(salt:Number, size:int, test:Function, baRead:Function, op:Function):Boolean + { + currentDomain.domainMemory.endian = "littleEndian"; + + var len:uint = currentDomain.domainMemory.length - size; + var n:int; + var v:*; + + for(var offs:int = 0; offs < size; offs++) + { + for(n = offs; n <= len; n += size) + { + op(n+salt, n); + } + for(n = offs; n <= len; n += size) + { + currentDomain.domainMemory.position = n; + if(!test(baRead(), n+salt)) + return false; + } + } + return true; + } + + function writeTestByte(salt:int):Boolean + { + return writeTest(salt, 1, + function(a:int, b:int):Boolean { return (a&0xff) == (b&0xff); }, + currentDomain.domainMemory.readUnsignedByte, + function(v:int, n:int):void { SI8(v, n); } + ); + } + + function writeTestShort(salt:int):Boolean + { + return writeTest(salt, 2, + function(a:int, b:int):Boolean { return (a&0xffff) == (b&0xffff); }, + currentDomain.domainMemory.readUnsignedShort, + function(v:int, n:int):void { SI16(v, n); } + ); +} + + function writeTestInt(salt:int):Boolean + { + return writeTest(salt, 4, + function(a:int, b:int):Boolean { return a == b; }, + currentDomain.domainMemory.readInt, + function(v:int, n:int):void { SI32(v, n); } + ); + } + + function writeTestFloat(salt:Number):Boolean + { + return writeTest(salt, 4, + function(a:Number, b:Number):Boolean { return Math.abs(a-b)<0.0001; }, + currentDomain.domainMemory.readFloat, + function(v:Number, n:int):void { SF32(v, n); } + ); + } + + function writeTestDouble(salt:Number):Boolean + { + return writeTest(salt, 8, + function(a:Number, b:Number):Boolean { return Math.abs(a-b)<0.0001; }, + currentDomain.domainMemory.readDouble, + function(v:Number, n:int):void { SF64(v, n); } + ); + } + + longTests.push(function():void { + Assert.expectEq("Write test byte w/ min sized", true, writeTestByte(12)); + Assert.expectEq("Write test short w/ min sized", true, writeTestShort(3456)); + Assert.expectEq("Write test int w/ min sized", true, writeTestInt(567890)); + Assert.expectEq("Write test float w/ min sized", true, writeTestFloat(12.34)); + Assert.expectEq("Write test double w/ min sized", true, writeTestDouble(34.56)); + }); + + function writeBytes(salt:int):void + { + var len:uint = currentDomain.domainMemory ? currentDomain.domainMemory.length : + domainClass.MIN_DOMAIN_MEMORY_LENGTH; + + var n:int; + var v:int; + + // byte test + for(n = 0; n < len; n += 1) + { + v = (n + salt) & 0xff; + + SI8(v, n); + } + } + + function verifyBytes(salt:int):Boolean + { + var len:uint = currentDomain.domainMemory ? currentDomain.domainMemory.length : + domainClass.MIN_DOMAIN_MEMORY_LENGTH; + + var n:int; + var v:int; + + // byte test + for(n = 0; n < len; n += 1) + { + v = (n + salt) & 0xff; + + if(LI8(n) != v) + return false; + } + return true; + } + + longTests.push(function():void { + writeBytes(12); + Assert.expectEq("Write min / verify min", true, verifyBytes(12)); + }); + + longTests.push(function():void { + ba = currentDomain.domainMemory; + currentDomain.domainMemory = null; + Assert.expectEq("Write min / verify scratch", false, verifyBytes(12)); + }); + + longTests.push(function():void { + writeBytes(34); + Assert.expectEq("Write scratch / verify scratch", true, verifyBytes(34)); + }); + + longTests.push(function():void { + currentDomain.domainMemory = ba; + Assert.expectEq("Write scratch / verify min", false, verifyBytes(34)); + }); + + + function rangeTest(size:int, f:Function):Boolean + { + var len:uint = currentDomain.domainMemory ? currentDomain.domainMemory.length : + domainClass.MIN_DOMAIN_MEMORY_LENGTH; + + var n:int; + var v:int; + var fails:Array = []; + + for(n = -10000; n < len + 10000; n += 1) + { + try + { + f(n); + } + catch(e:*) + { + fails.push(n); + } + } + if(fails.length == 20000 + size - 1) + { + for(n = 0; n < 10000; n++) + if(fails[n] != -10000 + n) + return false; + for(n = 0; n < 10000 + size - 1; n++) + if(fails[n + 10000] != len + n - (size - 1)) + { + print("fails[n + 10000]: " + fails[n + 10000]); + print("len:" + len); + print("size:" + size); + print("n:" + n); + return false; + } + return true; + } + return false; + } + + function rangeReadTestByte():Boolean + { + return rangeTest(1, function(n:int):void { LI8(n); } ); + } + + function rangeOffsReadTestByte():Boolean + { + return rangeTest(1, function(n:int):void { var k:int = n - 4; LI8(ADD_I(k, 4)); }) && + rangeTest(1, function(n:int):void { var k:int = n + 4; LI8(SUBTRACT_I(k, 4)); }) && + rangeTest(1, function(n:int):void { var k:int = n + 4; LI8(ADD_I(k, -4)); }) && + rangeTest(1, function(n:int):void { var k:int = n - 4; LI8(SUBTRACT_I(k, -4)); }); + } + + + function rangeReadTestShort():Boolean + { + return rangeTest(2, function(n:int):void { LI16(n); } ); + } + + function rangeOffsReadTestShort():Boolean + { + return rangeTest(2, function(n:int):void { var k:int = n - 4; LI16(ADD_I(k, 4)); }) && + rangeTest(2, function(n:int):void { var k:int = n + 4; LI16(SUBTRACT_I(k, 4)); }) && + rangeTest(2, function(n:int):void { var k:int = n + 4; LI16(ADD_I(k, -4)); }) && + rangeTest(2, function(n:int):void { var k:int = n - 4; LI16(SUBTRACT_I(k, -4)); }); + } + + function rangeReadTestInt():Boolean + { + return rangeTest(4, function(n:int):void { LI32(n); } ); + } + + function rangeOffsReadTestInt():Boolean + { + return rangeTest(4, function(n:int):void { var k:int = n - 4; LI32(ADD_I(k, 4)); }) && + rangeTest(4, function(n:int):void { var k:int = n + 4; LI32(SUBTRACT_I(k, 4)); }) && + rangeTest(4, function(n:int):void { var k:int = n + 4; LI32(ADD_I(k, -4)); }) && + rangeTest(4, function(n:int):void { var k:int = n - 4; LI32(SUBTRACT_I(k, -4)); }); + } + + function rangeReadTestFloat():Boolean + { + return rangeTest(4, function(n:int):void { LF32(n); } ); + } + + function rangeOffsReadTestFloat():Boolean + { + return rangeTest(4, function(n:int):void { var k:int = n - 4; LF32(ADD_I(k, 4)); }) && + rangeTest(4, function(n:int):void { var k:int = n + 4; LF32(SUBTRACT_I(k, 4)); }) && + rangeTest(4, function(n:int):void { var k:int = n + 4; LF32(ADD_I(k, -4)); }) && + rangeTest(4, function(n:int):void { var k:int = n - 4; LF32(SUBTRACT_I(k, -4)); }); + } + + function rangeReadTestDouble():Boolean + { + return rangeTest(8, function(n:int):void { LF64(n); } ); + } + + function rangeOffsReadTestDouble():Boolean + { + return rangeTest(8, function(n:int):void { var k:int = n - 4; LF64(ADD_I(k, 4)); }) && + rangeTest(8, function(n:int):void { var k:int = n + 4; LF64(SUBTRACT_I(k, 4)); }) && + rangeTest(8, function(n:int):void { var k:int = n + 4; LF64(ADD_I(k, -4)); }) && + rangeTest(8, function(n:int):void { var k:int = n - 4; LF64(SUBTRACT_I(k, -4)); }); + } + + longTests.push(function():void { + Assert.expectEq("Range read test byte min", true, rangeReadTestByte()); + Assert.expectEq("Range offs read test byte min", true, rangeOffsReadTestByte()); + Assert.expectEq("Range read test short min", true, rangeReadTestShort()); + Assert.expectEq("Range offs read test short min", true, rangeOffsReadTestShort()); + Assert.expectEq("Range read test int min", true, rangeReadTestInt()); + Assert.expectEq("Range offs read test int min", true, rangeOffsReadTestInt()); + Assert.expectEq("Range read test float min", true, rangeReadTestFloat()); + Assert.expectEq("Range offs read test float min", true, rangeOffsReadTestFloat()); + Assert.expectEq("Range read test double min", true, rangeReadTestDouble()); + Assert.expectEq("Range offs read test double min", true, rangeOffsReadTestDouble()); + }); + + + function rangeReadTestWide():Boolean + { + return rangeTest(2009, function(n:int):void { + var n2:int = n + 1004; + LI8(SUBTRACT_I(n2, 1004)); + LI8(ADD_I(n2, 1004)); + } ); + } + longTests.push(function():void{ + var oldLen:uint = currentDomain.domainMemory.length; + currentDomain.domainMemory.length = 16384; + Assert.expectEq("Range read test wide", true, rangeReadTestWide()); + currentDomain.domainMemory.length = oldLen; + }); + + + function rangeWriteTestByte():Boolean + { + return rangeTest(1, function(n:int):void { SI8(-1, n); } ); + } + + function rangeWriteTestShort():Boolean + { + return rangeTest(2, function(n:int):void { SI16(-1, n); } ); + } + + function rangeWriteTestInt():Boolean + { + return rangeTest(4, function(n:int):void { SI32(-1, n); } ); + } + + function rangeWriteTestFloat():Boolean + { + return rangeTest(4, function(n:int):void { SF32(-1, n); } ); + } + + function rangeWriteTestDouble():Boolean + { + return rangeTest(8, function(n:int):void { SF64(-1, n); } ); + } + + longTests.push(function():void { + Assert.expectEq("Range write test byte min", true, rangeWriteTestByte()); + Assert.expectEq("Range write test short min", true, rangeWriteTestShort()); + Assert.expectEq("Range write test int min", true, rangeWriteTestInt()); + Assert.expectEq("Range write test float min", true, rangeWriteTestFloat()); + Assert.expectEq("Range write test double min", true, rangeWriteTestDouble()); + }); + + + function rangeWriteTestWide():Boolean + { + return rangeTest(2009, function(n:int):void { + var n2:int = n + 1004; + SI8(-1, SUBTRACT_I(n2, 1004)); + SI8(-1, ADD_I(n2, 1004)); + } ); + } + + longTests.push(function():void { + var oldLen:uint = currentDomain.domainMemory.length; + currentDomain.domainMemory.length = 16384; + Assert.expectEq("Range write test wide", true, rangeWriteTestWide()); + currentDomain.domainMemory.length = oldLen; + }); + + + function genRangeTest(min:int, max:int, f:Function):Boolean + { + for(var n:int = min; n < max; n++) + if(!f(n)) + return false; + return true; + } + + function sextTest():Boolean + { + return genRangeTest(0x6000, 0x12000, function(n:int):Boolean + { + var sx16:int = (n << 16) >> 16; + var sx8:int = (n << 24) >> 24; + var sx1:int = (n << 31) >> 31; + + if(sx16 != SXI16(n)) + return false; + if(sx8 != SXI8(n)) + return false; + if(sx1 != SXI1(n)) + return false; + return true; + } + ); + } + + longTests.push(function():void { + Assert.expectEq("Sign extend test", true, sextTest()); + }); + + function readWriteTest(size:int, f:Function):Boolean + { + var len:uint = currentDomain.domainMemory ? currentDomain.domainMemory.length : + domainClass.MIN_DOMAIN_MEMORY_LENGTH; + return genRangeTest(0, len - size + 1, f); + } + + function readWriteTestByte(salt:int):Boolean + { + return readWriteTest(1, function(n:int):Boolean + { + var v:int = (n + salt) & 0xff; + SI8(v, n); + return LI8(n) == v; + } + ); + } + + function readWriteTestShort(salt:int):Boolean + { + return readWriteTest(2, function(n:int):Boolean + { + var v:int = (n + salt) & 0xffff; + SI16(v, n); + return LI16(n) == v; + } + ); + } + + function readWriteTestInt(salt:int):Boolean + { + return readWriteTest(4, function(n:int):Boolean + { + var v:int = (n + salt); + SI32(v, n); + return LI32(n) == v; + } + ); + } + + function readWriteTestFloat(salt:Number):Boolean + { + return readWriteTest(4, function(n:int):Boolean + { + var v:Number = (n + salt); + SF32(v, n); + return Math.abs(LF32(n) - v)<0.0001; + } + ); + } + + function readWriteTestDouble(salt:Number):Boolean + { + return readWriteTest(8, function(n:int):Boolean + { + var v:Number = (n + salt); + SF64(v, n); + return Math.abs(LF64(n) - v)<0.0001; + } + ); + } + + longTests.push(function():void { + Assert.expectEq("Read/write byte min", true, readWriteTestByte(12)); + Assert.expectEq("Read/write short min", true, readWriteTestShort(3456)); + Assert.expectEq("Read/write int min", true, readWriteTestInt(567890)); + Assert.expectEq("Read/write float min", true, readWriteTestFloat(12.34)); + Assert.expectEq("Read/write double min", true, readWriteTestDouble(34.56)); + }); + + longTests.push(function():void { + ba = currentDomain.domainMemory; + currentDomain.domainMemory = null; + + Assert.expectEq("Read/write byte scratch", true, readWriteTestByte(12)); + Assert.expectEq("Read/write short scratch", true, readWriteTestShort(3456)); + Assert.expectEq("Read/write int scratch", true, readWriteTestInt(567890)); + Assert.expectEq("Read/write float scratch", true, readWriteTestFloat(12.34)); + Assert.expectEq("Read/write double scratch", true, readWriteTestDouble(34.56)); + + currentDomain.domainMemory = ba; + }); + + +// +//////////////////////////////////////////////////////////////// + + // longTests.push(test); + var n:int = 0; + for(n = 0; n < longTests.length; n++) + longTests[n](); + +} diff --git a/tests/tests/swfs/from_avmplus/mops/mops_basics/output.txt b/tests/tests/swfs/from_avmplus/mops/mops_basics/output.txt new file mode 100644 index 000000000..a1dd15f66 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/mops_basics/output.txt @@ -0,0 +1,44 @@ +domainClass != null PASSED! +byteArrayClass != null PASSED! +currentDomain != null PASSED! +minMemSize >= 8 PASSED! +currentDomain.domainMemory == null PASSED! +Empty byte array ok PASSED! +Small byte array ok PASSED! +Wrong obj (Array) ok PASSED! +Wrong obj (Object) ok PASSED! +Wrong obj (Function) ok PASSED! +Wrong obj (user) ok PASSED! +Min sized byte array ok PASSED! +Read test byte w/ min sized PASSED! +Read test byte w/ sign extend w/ min sized PASSED! +Read test short w/ min sized PASSED! +Read test short w/ sign extend w/ min sized PASSED! +Read test int w/ min sized PASSED! +Read test float w/ min sized PASSED! +Read test double w/ min sized PASSED! +Write test byte w/ min sized PASSED! +Write test short w/ min sized PASSED! +Write test int w/ min sized PASSED! +Write test float w/ min sized PASSED! +Write test double w/ min sized PASSED! +Write min / verify min PASSED! +Write min / verify scratch PASSED! +Write scratch / verify scratch PASSED! +Write scratch / verify min PASSED! +Range read test byte min PASSED! +Range offs read test byte min PASSED! +Range read test short min PASSED! +Range offs read test short min PASSED! +Range read test int min PASSED! +Range offs read test int min PASSED! +Range read test float min PASSED! +Range offs read test float min PASSED! +Range read test double min PASSED! +Range offs read test double min PASSED! +Range read test wide PASSED! +Range write test byte min PASSED! +Range write test short min PASSED! +Range write test int min PASSED! +Range write test float min PASSED! +Range write test double min PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/mops_basics/test.swf b/tests/tests/swfs/from_avmplus/mops/mops_basics/test.swf new file mode 100644 index 000000000..7d3034822 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/mops_basics/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/mops_basics/test.toml b/tests/tests/swfs/from_avmplus/mops/mops_basics/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/mops_basics/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/sf32/Test.as b/tests/tests/swfs/from_avmplus/mops/sf32/Test.as new file mode 100644 index 000000000..8a3c45be2 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf32/Test.as @@ -0,0 +1,162 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION = "mops"; +// var VERSION = "AS3"; +// var TITLE = "sf32"; + + + Assert.expectError("sf32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ SF32(0x41460200, ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + var idx:int=0; + SI8(0x01, idx+1); + SI8(0x01, idx+2); + + // Test the memory boundaries + clearMemory(); + Assert.expectError("sf32(0x41460200, -1)", Utils.RANGEERROR+1506, function(){ SF32(0x41460200, -1); }); + Assert.expectError("sf32(0x41460200, mem.length)", Utils.RANGEERROR+1506, function(){ SF32(0x41460200, mem.length); }); + Assert.expectError("sf32(0x41460200, mem.length-1)", Utils.RANGEERROR+1506, function(){ SF32(0x41460200, mem.length-1); }); + Assert.expectError("sf32(0x41460200, mem.length-2)", Utils.RANGEERROR+1506, function(){ SF32(0x41460200, mem.length-2); }); + Assert.expectError("sf32(0x41460200, mem.length-3)", Utils.RANGEERROR+1506, function(){ SF32(0x41460200, mem.length-3); }); + + Assert.expectEq("sf32(0x41460200, mem.length-4)", undefined, SF32(0x01010101, mem.length-4)); + + testli8(); + testli16(); + testli32(); + testlf32(); + testreadByte(); + testreadUnsignedByte(); + testreadInt(); + testreadUnsignedInt(); + testreadFloat(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testli8():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + Assert.expectEq("li8 load 1st byte written by sf32(12.37548828125)", uint(0x00), LI8(0)); + Assert.expectEq("li8 load 2nd byte written by sf32(12.37548828125)", uint(0x02), LI8(1)); + Assert.expectEq("li8 load 3rd byte written by sf32(12.37548828125)", uint(0x46), LI8(2)); + Assert.expectEq("li8 load 4th byte written by sf32(12.37548828125)", uint(0x41), LI8(3)); + } + + function testli16():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + Assert.expectEq("li16 load bytes written by sf32()", 0x0200, LI16(0)); + Assert.expectEq("li16 load bytes written by sf32()", 0x4146, LI16(2)); + } + + function testli32():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + Assert.expectEq("li32 load bytes written by sf32()", int(0x41460200), LI32(0)); + } + + function testlf32():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + Assert.expectEq("lf32 load bytes written by sf32()", 12.37548828125, LF32(0)); + + } + + function testreadByte():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + mem.position = 0; + Assert.expectEq("readByte() load bytes written by sf32()", 0x00, mem.readByte()); + Assert.expectEq("readByte() load bytes written by sf32()", 0x02, mem.readByte()); + Assert.expectEq("readByte() load bytes written by sf32()", 0x46, mem.readByte()); + Assert.expectEq("readByte() load bytes written by sf32()", 0x41, mem.readByte()); + } + + function testreadUnsignedByte():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + mem.position = 0; + Assert.expectEq("readUnsignedByte() load bytes written by sf32()", 0x00, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by sf32()", 0x02, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by sf32()", 0x46, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by sf32()", 0x41, mem.readUnsignedByte()); + } + + function testreadInt():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + mem.position = 0; + Assert.expectEq("readInt() load bytes written by sf32()", int(0x41460200), mem.readInt()); + } + + function testreadUnsignedInt():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + mem.position = 0; + Assert.expectEq("readUnsignedInt() load bytes written by sf32()", uint(0x41460200), mem.readUnsignedInt()); + } + + function testreadFloat():void + { + clearMemory(); + // 0x41460200 == 12.37548828125 + SF32(12.37548828125, 0); + mem.position = 0; + Assert.expectEq("readFloat() load bytes written by sf32()", 12.37548828125, mem.readFloat()); + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/sf32/output.txt b/tests/tests/swfs/from_avmplus/mops/sf32/output.txt new file mode 100644 index 000000000..f9bee52b8 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf32/output.txt @@ -0,0 +1,26 @@ +sf32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +sf32(0x41460200, -1) PASSED! +sf32(0x41460200, mem.length) PASSED! +sf32(0x41460200, mem.length-1) PASSED! +sf32(0x41460200, mem.length-2) PASSED! +sf32(0x41460200, mem.length-3) PASSED! +sf32(0x41460200, mem.length-4) PASSED! +li8 load 1st byte written by sf32(12.37548828125) PASSED! +li8 load 2nd byte written by sf32(12.37548828125) PASSED! +li8 load 3rd byte written by sf32(12.37548828125) PASSED! +li8 load 4th byte written by sf32(12.37548828125) PASSED! +li16 load bytes written by sf32() PASSED! +li16 load bytes written by sf32() PASSED! +li32 load bytes written by sf32() PASSED! +lf32 load bytes written by sf32() PASSED! +readByte() load bytes written by sf32() PASSED! +readByte() load bytes written by sf32() PASSED! +readByte() load bytes written by sf32() PASSED! +readByte() load bytes written by sf32() PASSED! +readUnsignedByte() load bytes written by sf32() PASSED! +readUnsignedByte() load bytes written by sf32() PASSED! +readUnsignedByte() load bytes written by sf32() PASSED! +readUnsignedByte() load bytes written by sf32() PASSED! +readInt() load bytes written by sf32() PASSED! +readUnsignedInt() load bytes written by sf32() PASSED! +readFloat() load bytes written by sf32() PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/sf32/test.swf b/tests/tests/swfs/from_avmplus/mops/sf32/test.swf new file mode 100644 index 000000000..685325728 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/sf32/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/sf32/test.toml b/tests/tests/swfs/from_avmplus/mops/sf32/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf32/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/sf64/Test.as b/tests/tests/swfs/from_avmplus/mops/sf64/Test.as new file mode 100644 index 000000000..71fc1300c --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf64/Test.as @@ -0,0 +1,200 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION = "mops"; +// var VERSION = "AS3"; +// var TITLE = "sf64"; + + + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + Assert.expectError("sf64(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ SF64(2.8846085099489688873291015625E6, ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + // Test the memory boundaries + clearMemory(); + Assert.expectError("sf64(0x4146020041460200, -1)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, -1); }); + Assert.expectError("sf64(0x4146020041460200, mem.length)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-1)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-1); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-2)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-2); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-3)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-3); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-4)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-4); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-5)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-5); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-6)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-6); }); + Assert.expectError("sf64(0x4146020041460200, mem.length-7)", Utils.RANGEERROR+1506, function(){ SF64(2.8846085099489688873291015625E6, mem.length-7); }); + + Assert.expectEq("sf64(0x4146020041460200, mem.length-8)", undefined, SF64(0x4146020041460200, mem.length-8)); + + testli8(); + testli16(); + testli32(); + testlf32(); + testlf64(); + testreadByte(); + testreadUnsignedByte(); + testreadInt(); + testreadUnsignedInt(); + testreadFloat(); + testreadDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testli8():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("li8 load 1st byte written by sf64()", uint(0x00), LI8(0)); + Assert.expectEq("li8 load 2nd byte written by sf64()", uint(0x02), LI8(1)); + Assert.expectEq("li8 load 3rd byte written by sf64()", uint(0x46), LI8(2)); + Assert.expectEq("li8 load 4th byte written by sf64()", uint(0x41), LI8(3)); + Assert.expectEq("li8 load 5th byte written by sf64()", uint(0x00), LI8(4)); + Assert.expectEq("li8 load 6th byte written by sf64()", uint(0x02), LI8(5)); + Assert.expectEq("li8 load 7th byte written by sf64()", uint(0x46), LI8(6)); + Assert.expectEq("li8 load 8th byte written by sf64()", uint(0x41), LI8(7)); + } + + function testli16():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("li16 load bytes written by sf64()", 0x0200, LI16(0)); + Assert.expectEq("li16 load bytes written by sf64()", 0x4146, LI16(2)); + Assert.expectEq("li16 load bytes written by sf64()", 0x0200, LI16(4)); + Assert.expectEq("li16 load bytes written by sf64()", 0x4146, LI16(6)); + } + + function testli32():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("li32 load bytes written by sf64()", int(0x41460200), LI32(0)); + Assert.expectEq("li32 load bytes written by sf64()", int(0x41460200), LI32(4)); + } + + function testlf32():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("lf32 load bytes written by sf64()", 12.37548828125, LF32(0)); + Assert.expectEq("lf32 load bytes written by sf64()", 12.37548828125, LF32(4)); + } + + function testlf64():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + Assert.expectEq("lf64 load bytes written by sf64()", 2.8846085099489688873291015625E6, LF64(0)); + } + + function testreadByte():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readByte() load 1st byte written by sf64()", 0x00, mem.readByte()); + Assert.expectEq("readByte() load 2nd byte written by sf64()", 0x02, mem.readByte()); + Assert.expectEq("readByte() load 3rd byte written by sf64()", 0x46, mem.readByte()); + Assert.expectEq("readByte() load 4th byte written by sf64()", 0x41, mem.readByte()); + Assert.expectEq("readByte() load 5th byte written by sf64()", 0x00, mem.readByte()); + Assert.expectEq("readByte() load 6th byte written by sf64()", 0x02, mem.readByte()); + Assert.expectEq("readByte() load 7th byte written by sf64()", 0x46, mem.readByte()); + Assert.expectEq("readByte() load 8th byte written by sf64()", 0x41, mem.readByte()); + } + + function testreadUnsignedByte():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readUnsignedByte() load 1st byte written by sf64()", 0x00, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 2nd byte written by sf64()", 0x02, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 3rd byte written by sf64()", 0x46, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 4th byte written by sf64()", 0x41, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 5th byte written by sf64()", 0x00, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 6th byte written by sf64()", 0x02, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 7th byte written by sf64()", 0x46, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load 8th byte written by sf64()", 0x41, mem.readUnsignedByte()); + } + + function testreadInt():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readInt() load bytes written by sf64()", int(0x41460200), mem.readInt()); + Assert.expectEq("readInt() load bytes written by sf64()", int(0x41460200), mem.readInt()); + } + + function testreadUnsignedInt():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readUnsignedInt() load bytes written by sf64()", uint(0x41460200), mem.readUnsignedInt()); + Assert.expectEq("readUnsignedInt() load bytes written by sf64()", uint(0x41460200), mem.readUnsignedInt()); + } + + function testreadFloat():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readFloat() load bytes written by sf64()", 12.37548828125, mem.readFloat()); + Assert.expectEq("readFloat() load bytes written by sf64()", 12.37548828125, mem.readFloat()); + } + + function testreadDouble():void + { + clearMemory(); + // 0x4146020041460200 == 2.8846085099489688873291015625E6 + SF64(2.8846085099489688873291015625E6, 0); + mem.position = 0; + Assert.expectEq("readDouble() load bytes written by sf64()", 2.8846085099489688873291015625E6, mem.readDouble()); + } + +} diff --git a/tests/tests/swfs/from_avmplus/mops/sf64/output.txt b/tests/tests/swfs/from_avmplus/mops/sf64/output.txt new file mode 100644 index 000000000..7c2234191 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf64/output.txt @@ -0,0 +1,51 @@ +sf64(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +sf64(0x4146020041460200, -1) PASSED! +sf64(0x4146020041460200, mem.length) PASSED! +sf64(0x4146020041460200, mem.length-1) PASSED! +sf64(0x4146020041460200, mem.length-2) PASSED! +sf64(0x4146020041460200, mem.length-3) PASSED! +sf64(0x4146020041460200, mem.length-4) PASSED! +sf64(0x4146020041460200, mem.length-5) PASSED! +sf64(0x4146020041460200, mem.length-6) PASSED! +sf64(0x4146020041460200, mem.length-7) PASSED! +sf64(0x4146020041460200, mem.length-8) PASSED! +li8 load 1st byte written by sf64() PASSED! +li8 load 2nd byte written by sf64() PASSED! +li8 load 3rd byte written by sf64() PASSED! +li8 load 4th byte written by sf64() PASSED! +li8 load 5th byte written by sf64() PASSED! +li8 load 6th byte written by sf64() PASSED! +li8 load 7th byte written by sf64() PASSED! +li8 load 8th byte written by sf64() PASSED! +li16 load bytes written by sf64() PASSED! +li16 load bytes written by sf64() PASSED! +li16 load bytes written by sf64() PASSED! +li16 load bytes written by sf64() PASSED! +li32 load bytes written by sf64() PASSED! +li32 load bytes written by sf64() PASSED! +lf32 load bytes written by sf64() PASSED! +lf32 load bytes written by sf64() PASSED! +lf64 load bytes written by sf64() PASSED! +readByte() load 1st byte written by sf64() PASSED! +readByte() load 2nd byte written by sf64() PASSED! +readByte() load 3rd byte written by sf64() PASSED! +readByte() load 4th byte written by sf64() PASSED! +readByte() load 5th byte written by sf64() PASSED! +readByte() load 6th byte written by sf64() PASSED! +readByte() load 7th byte written by sf64() PASSED! +readByte() load 8th byte written by sf64() PASSED! +readUnsignedByte() load 1st byte written by sf64() PASSED! +readUnsignedByte() load 2nd byte written by sf64() PASSED! +readUnsignedByte() load 3rd byte written by sf64() PASSED! +readUnsignedByte() load 4th byte written by sf64() PASSED! +readUnsignedByte() load 5th byte written by sf64() PASSED! +readUnsignedByte() load 6th byte written by sf64() PASSED! +readUnsignedByte() load 7th byte written by sf64() PASSED! +readUnsignedByte() load 8th byte written by sf64() PASSED! +readInt() load bytes written by sf64() PASSED! +readInt() load bytes written by sf64() PASSED! +readUnsignedInt() load bytes written by sf64() PASSED! +readUnsignedInt() load bytes written by sf64() PASSED! +readFloat() load bytes written by sf64() PASSED! +readFloat() load bytes written by sf64() PASSED! +readDouble() load bytes written by sf64() PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/sf64/test.swf b/tests/tests/swfs/from_avmplus/mops/sf64/test.swf new file mode 100644 index 000000000..d27085fcb Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/sf64/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/sf64/test.toml b/tests/tests/swfs/from_avmplus/mops/sf64/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/sf64/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/si16/Test.as b/tests/tests/swfs/from_avmplus/mops/si16/Test.as new file mode 100644 index 000000000..6c984624d --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si16/Test.as @@ -0,0 +1,245 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION = "mops"; +// var VERSION = "AS3"; +// var TITLE = "si16"; + + + Assert.expectError("si16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ SI16(0x0111, ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + /** + * Test that ONLY the lowest 16 bits are stored + */ + clearMemory(); + SI16(0x7F5A32, 0); // should only store 0x5A32 + // li16(1) should load 0x005A since memory is zereod + Assert.expectEq("si16() only stores the least significant 16 bits", 0x005A, LI16(1)); + + // Test the memory boundaries + clearMemory(); + Assert.expectError("si16(0x0101, -1)", Utils.RANGEERROR+1506, function(){ SI16(0x0101, -1); }); + Assert.expectError("si16(0x0101, mem.length)", Utils.RANGEERROR+1506, function(){ SI16(0x0101, mem.length); }); + Assert.expectError("si16(0x0101, mem.length-1)", Utils.RANGEERROR+1506, function(){ SI16(0x0101, mem.length-1); }); + Assert.expectEq("si16(0x0101, mem.length-2)", undefined, SI16(0x0101, mem.length-2)); + Assert.expectEq("si16(0x0101FE, mem.length-2), should only store 16 bits so no overrun", undefined, SI16(0x0101FE, mem.length-2)); + Assert.expectEq("si16(0x0101FE, mem.length-2), should only store 16 bits so no overrun confirm", 0x01FE, LI16(mem.length-2)); + + testli8(); + testli16(); + testli32(); + testlf32(); + testlf64(); + testreadByte(); + testreadUnsignedByte(); + testreadBoolean(); + testreadInt(); + testreadUnsignedInt(); + testreadFloat(); + testreadDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testli8():void + { + clearMemory(); + SI16(0x807F, 0); + Assert.expectEq("li8 load 1st byte written by si16(0x807F)", 0x7F, LI8(0)); + Assert.expectEq("li8 load 2nd byte written by si16(0x807F)", uint(0x80), LI8(1)); + } + + function testli16():void + { + clearMemory(); + SI16(0x80DE, 0); + Assert.expectEq("li16 load bytes written by si16()", 0x80DE, LI16(0)); + } + + function testli32():void + { + clearMemory(); + SI16(0x80DE, 2); + SI16(0x32F1, 0); + Assert.expectEq("li32 load bytes written by si16()", int(0x80DE32F1), LI32(0)); + } + + function testlf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI16(0x4146, 2); + SI16(0x0000, 0); + Assert.expectEq("lf32 load bytes written by si16()", 12.375, LF32(0)); + + } + + function testlf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI16(0x43E1, 6); + SI16(0xC3ED, 4); + SI16(0xA52E, 2); + SI16(0x0C09, 0); + Assert.expectEq("lf64 load bytes written by si16()", 1.0241024102410242048E19, LF64(0)); + } + + function testreadByte():void + { + clearMemory(); + SI16(0x007F, 0); + SI16(0x80FF, 2); + + mem.position = 0; + Assert.expectEq("readByte() load bytes written by si16(0x007F)", 0x7F, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si16(0x007F)", 0, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si16(0x80FF)", -1, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si16(0x80FF)", -128, mem.readByte()); + } + + function testreadUnsignedByte():void + { + clearMemory(); + SI16(0x007F, 0); + SI16(0x80FF, 2); + + mem.position = 0; + Assert.expectEq("readUnsignedByte() load bytes written by si16(0x007F)", 127, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si16(0x007F)", 0, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si16(0x80FF)", 255, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si16(0x80FF)", 128, mem.readUnsignedByte()); + } + + + function testreadBoolean():void + { + clearMemory(); + SI16(0x0100, 0); + mem.position = 0; + Assert.expectEq("readBoolean() load bytes written by si16(0x0100)", false, mem.readBoolean()); + Assert.expectEq("readBoolean() load bytes written by si16(0x0100)", true, mem.readBoolean()); + } + + function testreadInt():void + { + clearMemory(); + SI16(0x80DE, 2); + SI16(0x32F1, 0); + + mem.position = 0; + Assert.expectEq("readInt() load bytes written by si16()", int(0x80DE32F1), mem.readInt()); + } + + function testreadUnsignedInt():void + { + clearMemory(); + SI16(0x80DE, 2); + SI16(0x32F1, 0); + + mem.position = 0; + Assert.expectEq("readUnsignedInt() load bytes written by si16()", uint(0x80DE32F1), mem.readUnsignedInt()); + } + + function testreadFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI16(0x4146, 2); + SI16(0x0000, 0); + + mem.position = 0; + Assert.expectEq("readFloat() load bytes written by si16()", 12.375, mem.readFloat()); + } + + function testreadDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI16(0x43E1, 6); + SI16(0xC3ED, 4); + SI16(0xA52E, 2); + SI16(0x0C09, 0); + + mem.position = 0; + Assert.expectEq("readDouble() load bytes written by si16()", 1.0241024102410242048E19, mem.readDouble()); + } +} diff --git a/tests/tests/swfs/from_avmplus/mops/si16/output.txt b/tests/tests/swfs/from_avmplus/mops/si16/output.txt new file mode 100644 index 000000000..3eab5ec69 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si16/output.txt @@ -0,0 +1,28 @@ +si16(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +si16() only stores the least significant 16 bits PASSED! +si16(0x0101, -1) PASSED! +si16(0x0101, mem.length) PASSED! +si16(0x0101, mem.length-1) PASSED! +si16(0x0101, mem.length-2) PASSED! +si16(0x0101FE, mem.length-2), should only store 16 bits so no overrun PASSED! +si16(0x0101FE, mem.length-2), should only store 16 bits so no overrun confirm PASSED! +li8 load 1st byte written by si16(0x807F) PASSED! +li8 load 2nd byte written by si16(0x807F) PASSED! +li16 load bytes written by si16() PASSED! +li32 load bytes written by si16() PASSED! +lf32 load bytes written by si16() PASSED! +lf64 load bytes written by si16() PASSED! +readByte() load bytes written by si16(0x007F) PASSED! +readByte() load bytes written by si16(0x007F) PASSED! +readByte() load bytes written by si16(0x80FF) PASSED! +readByte() load bytes written by si16(0x80FF) PASSED! +readUnsignedByte() load bytes written by si16(0x007F) PASSED! +readUnsignedByte() load bytes written by si16(0x007F) PASSED! +readUnsignedByte() load bytes written by si16(0x80FF) PASSED! +readUnsignedByte() load bytes written by si16(0x80FF) PASSED! +readBoolean() load bytes written by si16(0x0100) PASSED! +readBoolean() load bytes written by si16(0x0100) PASSED! +readInt() load bytes written by si16() PASSED! +readUnsignedInt() load bytes written by si16() PASSED! +readFloat() load bytes written by si16() PASSED! +readDouble() load bytes written by si16() PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/si16/test.swf b/tests/tests/swfs/from_avmplus/mops/si16/test.swf new file mode 100644 index 000000000..d6eee9e02 Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/si16/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/si16/test.toml b/tests/tests/swfs/from_avmplus/mops/si16/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si16/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/si32/Test.as b/tests/tests/swfs/from_avmplus/mops/si32/Test.as new file mode 100644 index 000000000..0291f2ccf --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si32/Test.as @@ -0,0 +1,236 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION = "mops"; +// var VERSION = "AS3"; +// var TITLE = "si32"; + + + Assert.expectError("si32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ SI32(0x01110101, ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + /** + * Test that ONLY the lowest 32 bits are stored + */ + clearMemory(); + SI32(0x7F5A325601, 0); // should only store 0x5A325601 + // li32(1) should load 0x005A3256 since memory is zereod + Assert.expectEq("si32() only stores the least significant 32 bits", 0x005A3256, LI32(1)); + + // Test the memory boundaries + clearMemory(); + Assert.expectError("si32(0x01010101, -1)", Utils.RANGEERROR+1506, function(){ SI32(0x01010101, -1); }); + Assert.expectError("si32(0x01010101, mem.length)", Utils.RANGEERROR+1506, function(){ SI32(0x01010101, mem.length); }); + Assert.expectError("si32(0x01010101, mem.length-1)", Utils.RANGEERROR+1506, function(){ SI32(0x01010101, mem.length-1); }); + Assert.expectError("si32(0x01010101, mem.length-2)", Utils.RANGEERROR+1506, function(){ SI32(0x01010101, mem.length-2); }); + Assert.expectError("si32(0x01010101, mem.length-3)", Utils.RANGEERROR+1506, function(){ SI32(0x01010101, mem.length-3); }); + + Assert.expectEq("si32(0x01010101, mem.length-4)", undefined, SI32(0x01010101, mem.length-4)); + Assert.expectEq("si32(0x7F5A325601, mem.length-4), should only store 32 bits so no overrun", undefined, SI32(0x7F5A325601, mem.length-4)); + Assert.expectEq("si32(0x7F5A325601, mem.length-4), should only store 32 bits so no overrun confirm", 0x5A325601, LI32(mem.length-4)); + + testli8(); + testli16(); + testli32(); + testlf32(); + testlf64(); + testreadByte(); + testreadUnsignedByte(); + testreadBoolean(); + testreadInt(); + testreadUnsignedInt(); + testreadFloat(); + testreadDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testli8():void + { + clearMemory(); + SI32(0x807FDEF5, 0); + Assert.expectEq("li8 load 1st byte written by si32(0x807FDEF5)", uint(0xF5), LI8(0)); + Assert.expectEq("li8 load 2nd byte written by si32(0x807FDEF5)", uint(0xDE), LI8(1)); + Assert.expectEq("li8 load 3rd byte written by si32(0x807FDEF5)", uint(0x7F), LI8(2)); + Assert.expectEq("li8 load 4th byte written by si32(0x807FDEF5)", uint(0x80), LI8(3)); + } + + function testli16():void + { + clearMemory(); + SI32(0x80DE7F5A, 0); + Assert.expectEq("li16 load bytes written by si32()", 0x7F5A, LI16(0)); + Assert.expectEq("li16 load bytes written by si32()", 0x80DE, LI16(2)); + } + + function testli32():void + { + clearMemory(); + SI32(0x80DE32F1, 0); + Assert.expectEq("li32 load bytes written by si32()", int(0x80DE32F1), LI32(0)); + } + + function testlf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI32(0x41460000, 0); + Assert.expectEq("lf32 load bytes written by si32()", 12.375, LF32(0)); + + } + + function testlf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI32(0x43E1C3ED, 4); + SI32(0xA52E0C09, 0); + Assert.expectEq("lf64 load bytes written by si32()", 1.0241024102410242048E19, LF64(0)); + } + + function testreadByte():void + { + clearMemory(); + SI32(0x80FF007F, 0); + mem.position = 0; + Assert.expectEq("readByte() load bytes written by si32(0x80FF007F)", 0x7F, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si32(0x80FF007F)", 0, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si32(0x80FF007F)", -1, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si32(0x80FF007F)", -128, mem.readByte()); + } + + function testreadUnsignedByte():void + { + clearMemory(); + SI32(0x80FF007F, 0); + + mem.position = 0; + Assert.expectEq("readUnsignedByte() load bytes written by si32(0x80FF007F)", 127, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si32(0x80FF007F)", 0, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si32(0x80FF007F)", 255, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si32(0x80FF007F)", 128, mem.readUnsignedByte()); + } + + + function testreadBoolean():void + { + clearMemory(); + SI32(0x01000100, 0); + mem.position = 0; + Assert.expectEq("readBoolean() load bytes written by si32(0x01000100)", false, mem.readBoolean()); + Assert.expectEq("readBoolean() load bytes written by si32(0x01000100)", true, mem.readBoolean()); + } + + function testreadInt():void + { + clearMemory(); + SI32(0x80DE32F1, 0); + mem.position = 0; + Assert.expectEq("readInt() load bytes written by si32()", int(0x80DE32F1), mem.readInt()); + } + + function testreadUnsignedInt():void + { + clearMemory(); + SI32(0x80DE32F1, 0); + mem.position = 0; + Assert.expectEq("readUnsignedInt() load bytes written by si32()", uint(0x80DE32F1), mem.readUnsignedInt()); + } + + function testreadFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI32(0x41460000, 0); + mem.position = 0; + Assert.expectEq("readFloat() load bytes written by si32()", 12.375, mem.readFloat()); + } + + function testreadDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI32(0x43E1C3ED, 4); + SI32(0xA52E0C09, 0); + + mem.position = 0; + Assert.expectEq("readDouble() load bytes written by si32()", 1.0241024102410242048E19, mem.readDouble()); + } +} diff --git a/tests/tests/swfs/from_avmplus/mops/si32/output.txt b/tests/tests/swfs/from_avmplus/mops/si32/output.txt new file mode 100644 index 000000000..102682e75 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si32/output.txt @@ -0,0 +1,33 @@ +si32(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +si32() only stores the least significant 32 bits PASSED! +si32(0x01010101, -1) PASSED! +si32(0x01010101, mem.length) PASSED! +si32(0x01010101, mem.length-1) PASSED! +si32(0x01010101, mem.length-2) PASSED! +si32(0x01010101, mem.length-3) PASSED! +si32(0x01010101, mem.length-4) PASSED! +si32(0x7F5A325601, mem.length-4), should only store 32 bits so no overrun PASSED! +si32(0x7F5A325601, mem.length-4), should only store 32 bits so no overrun confirm PASSED! +li8 load 1st byte written by si32(0x807FDEF5) PASSED! +li8 load 2nd byte written by si32(0x807FDEF5) PASSED! +li8 load 3rd byte written by si32(0x807FDEF5) PASSED! +li8 load 4th byte written by si32(0x807FDEF5) PASSED! +li16 load bytes written by si32() PASSED! +li16 load bytes written by si32() PASSED! +li32 load bytes written by si32() PASSED! +lf32 load bytes written by si32() PASSED! +lf64 load bytes written by si32() PASSED! +readByte() load bytes written by si32(0x80FF007F) PASSED! +readByte() load bytes written by si32(0x80FF007F) PASSED! +readByte() load bytes written by si32(0x80FF007F) PASSED! +readByte() load bytes written by si32(0x80FF007F) PASSED! +readUnsignedByte() load bytes written by si32(0x80FF007F) PASSED! +readUnsignedByte() load bytes written by si32(0x80FF007F) PASSED! +readUnsignedByte() load bytes written by si32(0x80FF007F) PASSED! +readUnsignedByte() load bytes written by si32(0x80FF007F) PASSED! +readBoolean() load bytes written by si32(0x01000100) PASSED! +readBoolean() load bytes written by si32(0x01000100) PASSED! +readInt() load bytes written by si32() PASSED! +readUnsignedInt() load bytes written by si32() PASSED! +readFloat() load bytes written by si32() PASSED! +readDouble() load bytes written by si32() PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/si32/test.swf b/tests/tests/swfs/from_avmplus/mops/si32/test.swf new file mode 100644 index 000000000..275dfc3cd Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/si32/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/si32/test.toml b/tests/tests/swfs/from_avmplus/mops/si32/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si32/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true diff --git a/tests/tests/swfs/from_avmplus/mops/si8/Test.as b/tests/tests/swfs/from_avmplus/mops/si8/Test.as new file mode 100644 index 000000000..5724684e7 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si8/Test.as @@ -0,0 +1,276 @@ +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Test indirect memory access instructions. + +package { + + import flash.utils.ByteArray; + import flash.utils.Endian; + import flash.system.ApplicationDomain; +import com.adobe.test.Assert; +import com.adobe.test.Utils; + + +// var SECTION:String = "mops"; +// var VERSION:String = "AS3"; +// var TITLE:String = "si8"; + + + Assert.expectError("si8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory()", + Utils.RANGEERROR+1506, + function(){ SI8(0x01, ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH); }); + + initMemory(); + // Get a handle to the domainMemory after it is initialized + var mem:ByteArray = ApplicationDomain.currentDomain.domainMemory; + + /** + * Test that ONLY the lowest 8 bits are stored + */ + clearMemory(); + SI8(0x7F5A, 1); // should only store 0x5A + SI8(0x62, 0); + // li16(0) should load 0x5062 + Assert.expectEq("si8() only stores the least significant 8 bits", 0x5A62, LI16(0)); + // li8(2) should load 0x00, 0x7F should not have spilled + Assert.expectEq("si8() only stores the least significant 8 bits", 0x00, LI8(2)); + + // Test the memory boundaries + clearMemory(); + Assert.expectError("si8(0x01, -1)", Utils.RANGEERROR+1506, function(){ SI8(0x01, -1); }); + Assert.expectError("si8(0x01, mem.length)", Utils.RANGEERROR+1506, function(){ SI8(0x01, mem.length); }); + Assert.expectEq("si8(0x01, mem.length-1)", undefined, SI8(0x01, mem.length-1)); + Assert.expectEq("si8(0x01FE, mem.length-1), should only store 8 bits so no overrun", undefined, SI8(0x01FE, mem.length-1)); + Assert.expectEq("si8(0x01FE, mem.length-1), should only store 8 bits so no overrun confirm", 0xFE, LI8(mem.length-1)); + + + testli8(); + testli16(); + testli32(); + testlf32(); + testlf64(); + testreadByte(); + testreadUnsignedByte(); + testreadBoolean(); + testreadInt(); + testreadUnsignedInt(); + testreadFloat(); + testreadDouble(); + + + function initMemory(bytes:int = 0):void + { + var min:int = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH; + var memory:ByteArray = new ByteArray(); + // memory opcodes use native endianness, but ByteArray defaults to BigEndian + memory.endian = Endian.LITTLE_ENDIAN; + memory.length = bytes > min ? bytes : min; + ApplicationDomain.currentDomain.domainMemory = memory; + } + + function clearMemory():void + { + var i:int; + var len:int = ApplicationDomain.currentDomain.domainMemory.length; + for ( i=0; i < len; i++) + SI8(0x00, i); + } + + function testli8():void + { + clearMemory(); + SI8(0x7F, 0); + SI8(0x80, 1); + Assert.expectEq("li8 load byte written by si8(0x7F)", 0x7F, LI8(0)); + Assert.expectEq("li8 load byte written by si8(0x80)", 0x80, LI8(1)); + } + + function testli16():void + { + clearMemory(); + SI8(0xDE, 0); + SI8(0x80, 1); + Assert.expectEq("li16 load bytes written by si8()", 0x80DE, LI16(0)); + } + + function testli32():void + { + clearMemory(); + SI8(0x80, 3); + SI8(0xDE, 2); + SI8(0x32, 1); + SI8(0xF1, 0); + Assert.expectEq("li32 load bytes written by si8()", int(0x80DE32F1), LI32(0)); + } + + function testlf32():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI8(0x41, 3); + SI8(0x46, 2); + SI8(0x00, 1); + SI8(0x00, 0); + Assert.expectEq("lf32 load bytes written by si8()", 12.375, LF32(0)); + + } + + function testlf64():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI8(0x43, 7); + SI8(0xE1, 6); + SI8(0xC3, 5); + SI8(0xED, 4); + SI8(0xA5, 3); + SI8(0x2E, 2); + SI8(0x0C, 1); + SI8(0x09, 0); + Assert.expectEq("lf64 load bytes written by si8()", 1.0241024102410242048E19, LF64(0)); + } + + function testreadByte():void + { + clearMemory(); + SI8(0x00, 0); + SI8(0x7F, 1); + SI8(0x80, 2); + SI8(0xFF, 3); + + mem.position = 0; + Assert.expectEq("readByte() load bytes written by si8(0x00)", 0, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si8(0x7F)", 127, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si8(0x80)", -128, mem.readByte()); + Assert.expectEq("readByte() load bytes written by si8(0xFF)", -1, mem.readByte()); + } + + function testreadUnsignedByte():void + { + clearMemory(); + SI8(0x00, 0); + SI8(0x7F, 1); + SI8(0x80, 2); + SI8(0xFF, 3); + + mem.position = 0; + Assert.expectEq("readUnsignedByte() load bytes written by si8(0x00)", 0, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si8(0x7F)", 127, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si8(0x80)", 128, mem.readUnsignedByte()); + Assert.expectEq("readUnsignedByte() load bytes written by si8(0xFF)", 255, mem.readUnsignedByte()); + } + + + function testreadBoolean():void + { + clearMemory(); + SI8(0x00, 0); + SI8(0x01, 1); + + mem.position = 0; + Assert.expectEq("readBoolean() load bytes written by si8(0x00)", false, mem.readBoolean()); + Assert.expectEq("readBoolean() load bytes written by si8(0x01)", true, mem.readBoolean()); + } + + function testreadInt():void + { + clearMemory(); + SI8(0x80, 3); + SI8(0xDE, 2); + SI8(0x32, 1); + SI8(0xF1, 0); + + mem.position = 0; + Assert.expectEq("readInt() load bytes written by si8()", int(0x80DE32F1), mem.readInt()); + } + + function testreadUnsignedInt():void + { + clearMemory(); + SI8(0x80, 3); + SI8(0xDE, 2); + SI8(0x32, 1); + SI8(0xF1, 0); + + mem.position = 0; + Assert.expectEq("readUnsignedInt() load bytes written by si8()", uint(0x80DE32F1), mem.readUnsignedInt()); + } + + function testreadFloat():void + { + /****************************************** + * 12.375f + * (12.375)10 = + * (12)10 + (0.375)10 = + * (1100)2 + (0.011)2 = + * (1100.011)2 = + * (1.100011)2 x2^3 + * sign = 0 + * exponent = 130 (127 biased, 127 +3, binary 1000 0010) + * fraction = 100011 + * 0-10000010-10001100000000000000000 + * 01000001 01000110 00000000 00000000 -> int 1095106560 -> 0x41460000 + *****************************************/ + clearMemory(); + SI8(0x41, 3); + SI8(0x46, 2); + SI8(0x00, 1); + SI8(0x00, 0); + + mem.position = 0; + Assert.expectEq("readFloat() load bytes written by si8()", 12.375, mem.readFloat()); + } + + function testreadDouble():void + { + /****************************************** + * 10241024102410241024 + * 0x43E1C3EDA52E0C09 + * sign = 0 + * exponent = 10000111110 + * mantissa = 0001110000111110110110100101001011100000110000001001 + * 0x43E1C3EDA52E0C09 = + * 01000011 11100001 11000011 11101101 + * 10100101 00101110 00001100 00001001 + *****************************************/ + clearMemory(); + SI8(0x43, 7); + SI8(0xE1, 6); + SI8(0xC3, 5); + SI8(0xED, 4); + SI8(0xA5, 3); + SI8(0x2E, 2); + SI8(0x0C, 1); + SI8(0x09, 0); + + mem.position = 0; + Assert.expectEq("readDouble() load bytes written by si8()", 1.0241024102410242048E19, mem.readDouble()); + } + + +} diff --git a/tests/tests/swfs/from_avmplus/mops/si8/output.txt b/tests/tests/swfs/from_avmplus/mops/si8/output.txt new file mode 100644 index 000000000..2f5ae4700 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si8/output.txt @@ -0,0 +1,28 @@ +si8(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) prior to initMemory() PASSED! +si8() only stores the least significant 8 bits PASSED! +si8() only stores the least significant 8 bits PASSED! +si8(0x01, -1) PASSED! +si8(0x01, mem.length) PASSED! +si8(0x01, mem.length-1) PASSED! +si8(0x01FE, mem.length-1), should only store 8 bits so no overrun PASSED! +si8(0x01FE, mem.length-1), should only store 8 bits so no overrun confirm PASSED! +li8 load byte written by si8(0x7F) PASSED! +li8 load byte written by si8(0x80) PASSED! +li16 load bytes written by si8() PASSED! +li32 load bytes written by si8() PASSED! +lf32 load bytes written by si8() PASSED! +lf64 load bytes written by si8() PASSED! +readByte() load bytes written by si8(0x00) PASSED! +readByte() load bytes written by si8(0x7F) PASSED! +readByte() load bytes written by si8(0x80) PASSED! +readByte() load bytes written by si8(0xFF) PASSED! +readUnsignedByte() load bytes written by si8(0x00) PASSED! +readUnsignedByte() load bytes written by si8(0x7F) PASSED! +readUnsignedByte() load bytes written by si8(0x80) PASSED! +readUnsignedByte() load bytes written by si8(0xFF) PASSED! +readBoolean() load bytes written by si8(0x00) PASSED! +readBoolean() load bytes written by si8(0x01) PASSED! +readInt() load bytes written by si8() PASSED! +readUnsignedInt() load bytes written by si8() PASSED! +readFloat() load bytes written by si8() PASSED! +readDouble() load bytes written by si8() PASSED! diff --git a/tests/tests/swfs/from_avmplus/mops/si8/test.swf b/tests/tests/swfs/from_avmplus/mops/si8/test.swf new file mode 100644 index 000000000..6e40dfd3f Binary files /dev/null and b/tests/tests/swfs/from_avmplus/mops/si8/test.swf differ diff --git a/tests/tests/swfs/from_avmplus/mops/si8/test.toml b/tests/tests/swfs/from_avmplus/mops/si8/test.toml new file mode 100644 index 000000000..29f3cef79 --- /dev/null +++ b/tests/tests/swfs/from_avmplus/mops/si8/test.toml @@ -0,0 +1,2 @@ +num_ticks = 1 +known_failure = true