Commit ca817b0b authored by Ng Zhi An's avatar Ng Zhi An Committed by V8 LUCI CQ

[x64] Add new disassembly tests that verifies output

Currently the main test for disassembly just checks that there is
disassembly support for a assembler function, it doesn't verify the
output is as expected.

Add a new test case that checks the disassembly output against an
expected string.

Right now we only check a single instruction, subsequent patches will
move more instructions into this test case.

Bug: v8:12207
Change-Id: Id183bb2fd625713d82239363ebce3f4c77155acd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3150145Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76828}
parent fba61177
......@@ -27,16 +27,16 @@
#include <stdlib.h>
#include "src/init/v8.h"
#include "src/base/vector.h"
#include "src/codegen/code-factory.h"
#include "src/codegen/macro-assembler.h"
#include "src/debug/debug.h"
#include "src/diagnostics/disasm.h"
#include "src/diagnostics/disassembler.h"
#include "src/execution/frames-inl.h"
#include "src/utils/ostreams.h"
#include "src/init/v8.h"
#include "src/objects/objects-inl.h"
#include "src/utils/ostreams.h"
#include "test/cctest/cctest.h"
namespace v8 {
......@@ -1057,6 +1057,37 @@ TEST(DisasmX64) {
#endif
}
// Tests that compares the checks the disassembly output with an expected
// string.
TEST(DisasmX64CheckOutput) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
v8::internal::byte buffer[8192];
Assembler assm(AssemblerOptions{},
ExternalAssemblerBuffer(buffer, sizeof buffer));
base::EmbeddedVector<char, 128> disasm_buffer;
disasm::NameConverter converter;
disasm::Disassembler disassembler(converter);
std::string actual, expected;
int pcoffset = 0;
// Helper macro to compare the disassembly of an assembler function call with
// the expected disassembly output. We reuse |Assembler|, so we need to keep
// track of the offset into |buffer| which the Assembler has used, and
// disassemble the instruction at that offset.
#define COMPARE(str, ASM) \
assm.ASM; \
disassembler.InstructionDecode(disasm_buffer, buffer + pcoffset); \
pcoffset = assm.pc_offset(); \
actual = std::string{disasm_buffer.begin()}; \
expected = str; \
CHECK_EQ(expected, actual);
COMPARE("48054e61bc00 REX.W add rax,0xbc614e",
addq(rax, Immediate(12345678)));
}
TEST(DisasmX64YMMRegister) {
if (!CpuFeatures::IsSupported(AVX)) return;
CcTest::InitializeVM();
......@@ -1079,7 +1110,8 @@ TEST(DisasmX64YMMRegister) {
base::Vector<const char> expected =
base::StaticCharVector("c5fd6fc1 vmovdqa ymm0,ymm1\0");
CHECK(expected == actual);
CHECK_EQ(expected, actual);
actual.Dispose();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment