Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/macro-assembler.h"
6 : #include "src/simulator.h"
7 : #include "test/common/assembler-tester.h"
8 : #include "testing/gtest-support.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 :
13 : #define __ tasm.
14 :
15 : // Test the x64 assembler by compiling some simple functions into
16 : // a buffer and executing them. These tests do not initialize the
17 : // V8 library, create a context, or use any V8 objects.
18 :
19 15443 : TEST(TurboAssemblerTest, TestHardAbort) {
20 : auto buffer = AllocateAssemblerBuffer();
21 : TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
22 3 : buffer->CreateView());
23 : __ set_abort_hard(true);
24 :
25 1 : __ Abort(AbortReason::kNoReason);
26 :
27 1 : CodeDesc desc;
28 : tasm.GetCode(nullptr, &desc);
29 1 : buffer->MakeExecutable();
30 1 : auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer->start());
31 :
32 2 : ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason");
33 : }
34 :
35 15443 : TEST(TurboAssemblerTest, TestCheck) {
36 : auto buffer = AllocateAssemblerBuffer();
37 : TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
38 3 : buffer->CreateView());
39 : __ set_abort_hard(true);
40 :
41 : // Fail if the first parameter is 17.
42 : __ movl(rax, Immediate(17));
43 : __ cmpl(rax, arg_reg_1);
44 1 : __ Check(Condition::not_equal, AbortReason::kNoReason);
45 1 : __ ret(0);
46 :
47 1 : CodeDesc desc;
48 : tasm.GetCode(nullptr, &desc);
49 1 : buffer->MakeExecutable();
50 1 : auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer->start());
51 :
52 : f.Call(0);
53 : f.Call(18);
54 2 : ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason");
55 : }
56 :
57 : #undef __
58 :
59 : } // namespace internal
60 9264 : } // namespace v8
|