|
| 1 | +#include "node_postmortem_metadata.cc" |
| 2 | + |
| 3 | +#include "gtest/gtest.h" |
| 4 | +#include "node.h" |
| 5 | +#include "node_internals.h" |
| 6 | +#include "node_test_fixture.h" |
| 7 | +#include "req_wrap-inl.h" |
| 8 | +#include "tracing/agent.h" |
| 9 | +#include "v8.h" |
| 10 | + |
| 11 | + |
| 12 | +class DebugSymbolsTest : public EnvironmentTestFixture {}; |
| 13 | + |
| 14 | + |
| 15 | +class TestHandleWrap : public node::HandleWrap { |
| 16 | + public: |
| 17 | + size_t self_size() const override { return sizeof(*this); } |
| 18 | + |
| 19 | + TestHandleWrap(node::Environment* env, |
| 20 | + v8::Local<v8::Object> object, |
| 21 | + uv_tcp_t* handle) |
| 22 | + : node::HandleWrap(env, |
| 23 | + object, |
| 24 | + reinterpret_cast<uv_handle_t*>(handle), |
| 25 | + node::AsyncWrap::PROVIDER_TIMERWRAP) {} |
| 26 | +}; |
| 27 | + |
| 28 | + |
| 29 | +class TestReqWrap : public node::ReqWrap<uv_req_t> { |
| 30 | + public: |
| 31 | + size_t self_size() const override { return sizeof(*this); } |
| 32 | + |
| 33 | + TestReqWrap(node::Environment* env, v8::Local<v8::Object> object) |
| 34 | + : node::ReqWrap<uv_req_t>(env, |
| 35 | + object, |
| 36 | + node::AsyncWrap::PROVIDER_TIMERWRAP) {} |
| 37 | +}; |
| 38 | + |
| 39 | +TEST_F(DebugSymbolsTest, ContextEmbedderDataIndex) { |
| 40 | + int kContextEmbedderDataIndex = node::Environment::kContextEmbedderDataIndex; |
| 41 | + EXPECT_EQ(nodedbg_const_Environment__kContextEmbedderDataIndex__int, |
| 42 | + kContextEmbedderDataIndex); |
| 43 | +} |
| 44 | + |
| 45 | +TEST_F(DebugSymbolsTest, ExternalStringDataOffset) { |
| 46 | + EXPECT_EQ(nodedbg_offset_ExternalString__data__uintptr_t, |
| 47 | + NODE_OFF_EXTSTR_DATA); |
| 48 | +} |
| 49 | + |
| 50 | +TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) { |
| 51 | + const v8::HandleScope handle_scope(isolate_); |
| 52 | + const Argv argv; |
| 53 | + Env env{handle_scope, argv, this}; |
| 54 | + |
| 55 | + v8::Local<v8::Object> object = v8::Object::New(isolate_); |
| 56 | + node::BaseObject obj(*env, object); |
| 57 | + |
| 58 | + auto expected = reinterpret_cast<uintptr_t>(&obj.persistent()); |
| 59 | + auto calculated = reinterpret_cast<uintptr_t>(&obj) + |
| 60 | + nodedbg_offset_BaseObject__persistent_handle___v8_Persistent_v8_Object; |
| 61 | + EXPECT_EQ(expected, calculated); |
| 62 | + |
| 63 | + obj.persistent().Reset(); // ~BaseObject() expects an empty handle. |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +TEST_F(DebugSymbolsTest, EnvironmentHandleWrapQueue) { |
| 68 | + const v8::HandleScope handle_scope(isolate_); |
| 69 | + const Argv argv; |
| 70 | + Env env{handle_scope, argv, this}; |
| 71 | + |
| 72 | + auto expected = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue()); |
| 73 | + auto calculated = reinterpret_cast<uintptr_t>(*env) + |
| 74 | + nodedbg_offset_Environment__handle_wrap_queue___Environment_HandleWrapQueue; // NOLINT(whitespace/line_length) |
| 75 | + EXPECT_EQ(expected, calculated); |
| 76 | +} |
| 77 | + |
| 78 | +TEST_F(DebugSymbolsTest, EnvironmentReqWrapQueue) { |
| 79 | + const v8::HandleScope handle_scope(isolate_); |
| 80 | + const Argv argv; |
| 81 | + Env env{handle_scope, argv, this}; |
| 82 | + |
| 83 | + auto expected = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue()); |
| 84 | + auto calculated = reinterpret_cast<uintptr_t>(*env) + |
| 85 | + nodedbg_offset_Environment__req_wrap_queue___Environment_ReqWrapQueue; |
| 86 | + EXPECT_EQ(expected, calculated); |
| 87 | +} |
| 88 | + |
| 89 | +TEST_F(DebugSymbolsTest, HandleWrapList) { |
| 90 | + const v8::HandleScope handle_scope(isolate_); |
| 91 | + const Argv argv; |
| 92 | + Env env{handle_scope, argv, this}; |
| 93 | + |
| 94 | + uv_tcp_t handle; |
| 95 | + |
| 96 | + auto obj_template = v8::FunctionTemplate::New(isolate_); |
| 97 | + obj_template->InstanceTemplate()->SetInternalFieldCount(1); |
| 98 | + |
| 99 | + v8::Local<v8::Object> object = |
| 100 | + obj_template->GetFunction()->NewInstance(env.context()).ToLocalChecked(); |
| 101 | + TestHandleWrap obj(*env, object, &handle); |
| 102 | + |
| 103 | + auto queue = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue()); |
| 104 | + auto head = queue + |
| 105 | + nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap; |
| 106 | + auto next = |
| 107 | + head + nodedbg_offset_ListNode_HandleWrap__next___uintptr_t; |
| 108 | + next = *reinterpret_cast<uintptr_t*>(next); |
| 109 | + |
| 110 | + auto expected = reinterpret_cast<uintptr_t>(&obj); |
| 111 | + auto calculated = next - |
| 112 | + nodedbg_offset_HandleWrap__handle_wrap_queue___ListNode_HandleWrap; |
| 113 | + EXPECT_EQ(expected, calculated); |
| 114 | + |
| 115 | + obj.persistent().Reset(); // ~HandleWrap() expects an empty handle. |
| 116 | +} |
| 117 | + |
| 118 | +TEST_F(DebugSymbolsTest, ReqWrapList) { |
| 119 | + const v8::HandleScope handle_scope(isolate_); |
| 120 | + const Argv argv; |
| 121 | + Env env{handle_scope, argv, this}; |
| 122 | + |
| 123 | + auto obj_template = v8::FunctionTemplate::New(isolate_); |
| 124 | + obj_template->InstanceTemplate()->SetInternalFieldCount(1); |
| 125 | + |
| 126 | + v8::Local<v8::Object> object = |
| 127 | + obj_template->GetFunction()->NewInstance(env.context()).ToLocalChecked(); |
| 128 | + TestReqWrap obj(*env, object); |
| 129 | + |
| 130 | + // NOTE (mmarchini): Workaround to fix failing tests on ARM64 machines with |
| 131 | + // older GCC. Should be removed once we upgrade the GCC version used on our |
| 132 | + // ARM64 CI machinies. |
| 133 | + for (auto it : *(*env)->req_wrap_queue()) {} |
| 134 | + |
| 135 | + auto queue = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue()); |
| 136 | + auto head = queue + |
| 137 | + nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue; |
| 138 | + auto next = |
| 139 | + head + nodedbg_offset_ListNode_ReqWrap__next___uintptr_t; |
| 140 | + next = *reinterpret_cast<uintptr_t*>(next); |
| 141 | + |
| 142 | + auto expected = reinterpret_cast<uintptr_t>(&obj); |
| 143 | + auto calculated = |
| 144 | + next - nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue; |
| 145 | + EXPECT_EQ(expected, calculated); |
| 146 | + |
| 147 | + obj.Dispatched(); |
| 148 | +} |