Index: test/unittests/interpreter/bytecodes-unittest.cc |
diff --git a/test/unittests/interpreter/bytecodes-unittest.cc b/test/unittests/interpreter/bytecodes-unittest.cc |
index 5472927a40630ac98b34345d3da890903c821298..f45781718a343624aa38be4e6fb10e5a2e1a98d4 100644 |
--- a/test/unittests/interpreter/bytecodes-unittest.cc |
+++ b/test/unittests/interpreter/bytecodes-unittest.cc |
@@ -177,6 +177,65 @@ TEST(Bytecodes, DebugBreakExistForEachBytecode) { |
#undef CHECK_DEBUG_BREAK_SIZE |
} |
+TEST(Bytecodes, DecodeBytecodeAndOperands) { |
+ struct BytecodesAndResult { |
+ const uint8_t bytecode[32]; |
+ const size_t length; |
+ int parameter_count; |
+ const char* output; |
+ }; |
+ |
+#define B(Name) static_cast<uint8_t>(Bytecode::k##Name) |
+ const BytecodesAndResult cases[] = { |
+ {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, |
+ {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, |
+ {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, |
+ 6, |
+ 0, |
+ "LdaSmi.ExtraWide [100000]"}, |
+ {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, |
+ {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, |
+ {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, |
+ 6, |
+ 0, |
+ "LdaSmi.ExtraWide [-100000]"}, |
+ {{B(Star), 0xfb}, 2, 0, " Star r5"}, |
+ {{B(Wide), B(Star), 0x78, 0xff}, 4, 0, " Star.Wide r136"}, |
+ {{B(Wide), B(Call), 0x7a, 0xff, 0x79, 0xff, 0x02, 0x00, 0xb1, 0x00}, |
+ 10, |
+ 0, |
+ "Call.Wide r134, r135, #2, [177]"}, |
+ {{B(Ldar), |
+ static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
+ 2, |
+ 3, |
+ " Ldar a1"}, |
+ }; |
+#undef B |
+ |
+ for (size_t i = 0; i < arraysize(cases); ++i) { |
+ // Generate reference string by prepending formatted bytes. |
+ std::stringstream expected_ss; |
+ std::ios ios_fmt(nullptr); |
rmcilroy
2016/03/22 17:15:37
nit - default_format ?
oth
2016/03/23 10:10:06
Done.
|
+ ios_fmt.copyfmt(expected_ss); |
+ expected_ss.fill('0'); |
rmcilroy
2016/03/22 17:15:37
nit - newline, and a comment to explain what this
|
+ expected_ss.flags(std::ios::right | std::ios::hex); |
+ for (size_t b = 0; b < cases[i].length; b++) { |
+ expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b]) |
+ << ' '; |
+ } |
+ expected_ss.copyfmt(ios_fmt); |
+ expected_ss << cases[i].output; |
+ |
+ // Generate decoded byte output. |
+ std::stringstream actual_ss; |
+ Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count); |
+ |
+ // Compare. |
+ CHECK_EQ(actual_ss.str(), expected_ss.str()); |
+ } |
+} |
+ |
TEST(Bytecodes, DebugBreakForPrefixBytecodes) { |
CHECK_EQ(Bytecode::kDebugBreakWide, |
Bytecodes::GetDebugBreak(Bytecode::kWide)); |