GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../test/cctest/test_node_postmortem_metadata.cc Lines: 95 104 91.3 %
Date: 2019-01-07 12:15:22 Branches: 22 42 52.4 %

Line Branch Exec Source
1
#include "gtest/gtest.h"
2
#include "node.h"
3
#include "node_internals.h"
4
#include "node_test_fixture.h"
5
#include "req_wrap-inl.h"
6
#include "tracing/agent.h"
7
#include "v8.h"
8
#include "v8abbr.h"
9
10
extern "C" {
11
extern uintptr_t
12
    nodedbg_offset_HandleWrap__handle_wrap_queue___ListNode_HandleWrap;
13
extern uintptr_t
14
    nodedbg_offset_Environment__handle_wrap_queue___Environment_HandleWrapQueue;
15
extern int debug_symbols_generated;
16
extern int nodedbg_const_ContextEmbedderIndex__kEnvironment__int;
17
extern uintptr_t
18
    nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap;
19
extern uintptr_t
20
    nodedbg_offset_Environment__req_wrap_queue___Environment_ReqWrapQueue;
21
extern uintptr_t nodedbg_offset_ExternalString__data__uintptr_t;
22
extern uintptr_t nodedbg_offset_ListNode_ReqWrap__next___uintptr_t;
23
extern uintptr_t nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue;
24
extern uintptr_t nodedbg_offset_ListNode_HandleWrap__next___uintptr_t;
25
extern uintptr_t
26
    nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue;
27
extern uintptr_t
28
    nodedbg_offset_BaseObject__persistent_handle___v8_Persistent_v8_Object;
29
}
30
31
32
14
class DebugSymbolsTest : public EnvironmentTestFixture {};
33
34
35
1
class TestHandleWrap : public node::HandleWrap {
36
 public:
37
  SET_NO_MEMORY_INFO()
38
  SET_MEMORY_INFO_NAME(TestHandleWrap)
39
  SET_SELF_SIZE(TestHandleWrap)
40
41
1
  TestHandleWrap(node::Environment* env,
42
                 v8::Local<v8::Object> object,
43
                 uv_tcp_t* handle)
44
      : node::HandleWrap(env,
45
                         object,
46
                         reinterpret_cast<uv_handle_t*>(handle),
47
1
                         node::AsyncWrap::PROVIDER_TCPWRAP) {}
48
};
49
50
51
1
class TestReqWrap : public node::ReqWrap<uv_req_t> {
52
 public:
53
  SET_NO_MEMORY_INFO()
54
  SET_MEMORY_INFO_NAME(TestReqWrap)
55
  SET_SELF_SIZE(TestReqWrap)
56
57
1
  TestReqWrap(node::Environment* env, v8::Local<v8::Object> object)
58
      : node::ReqWrap<uv_req_t>(env,
59
                                object,
60
1
                                node::AsyncWrap::PROVIDER_FSREQCALLBACK) {}
61
};
62
63
5
TEST_F(DebugSymbolsTest, ContextEmbedderEnvironmentIndex) {
64
1
  int kEnvironmentIndex = node::ContextEmbedderIndex::kEnvironment;
65
1
  EXPECT_EQ(nodedbg_const_ContextEmbedderIndex__kEnvironment__int,
66
1
            kEnvironmentIndex);
67
1
}
68
69
5
TEST_F(DebugSymbolsTest, ExternalStringDataOffset) {
70
1
  EXPECT_EQ(nodedbg_offset_ExternalString__data__uintptr_t,
71
1
            NODE_OFF_EXTSTR_DATA);
72
1
}
73
74
1
class DummyBaseObject : public node::BaseObject {
75
 public:
76
1
  DummyBaseObject(node::Environment* env, v8::Local<v8::Object> obj) :
77
1
    BaseObject(env, obj) {}
78
79
  SET_NO_MEMORY_INFO()
80
  SET_MEMORY_INFO_NAME(DummyBaseObject)
81
  SET_SELF_SIZE(DummyBaseObject)
82
};
83
84
5
TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) {
85
1
  const v8::HandleScope handle_scope(isolate_);
86
2
  const Argv argv;
87
2
  Env env{handle_scope, argv};
88
89
1
  v8::Local<v8::ObjectTemplate> obj_templ = v8::ObjectTemplate::New(isolate_);
90
1
  obj_templ->SetInternalFieldCount(1);
91
92
  v8::Local<v8::Object> object =
93
3
      obj_templ->NewInstance(env.context()).ToLocalChecked();
94
2
  DummyBaseObject obj(*env, object);
95
96
1
  auto expected = reinterpret_cast<uintptr_t>(&obj.persistent());
97
1
  auto calculated = reinterpret_cast<uintptr_t>(&obj) +
98
1
      nodedbg_offset_BaseObject__persistent_handle___v8_Persistent_v8_Object;
99
1
  EXPECT_EQ(expected, calculated);
100
101
2
  obj.persistent().Reset();  // ~BaseObject() expects an empty handle.
102
1
}
103
104
105
5
TEST_F(DebugSymbolsTest, EnvironmentHandleWrapQueue) {
106
1
  const v8::HandleScope handle_scope(isolate_);
107
2
  const Argv argv;
108
2
  Env env{handle_scope, argv};
109
110
1
  auto expected = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue());
111
1
  auto calculated = reinterpret_cast<uintptr_t>(*env) +
112
1
      nodedbg_offset_Environment__handle_wrap_queue___Environment_HandleWrapQueue;  // NOLINT(whitespace/line_length)
113
2
  EXPECT_EQ(expected, calculated);
114
1
}
115
116
5
TEST_F(DebugSymbolsTest, EnvironmentReqWrapQueue) {
117
1
  const v8::HandleScope handle_scope(isolate_);
118
2
  const Argv argv;
119
2
  Env env{handle_scope, argv};
120
121
1
  auto expected = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
122
1
  auto calculated = reinterpret_cast<uintptr_t>(*env) +
123
1
      nodedbg_offset_Environment__req_wrap_queue___Environment_ReqWrapQueue;
124
2
  EXPECT_EQ(expected, calculated);
125
1
}
126
127
5
TEST_F(DebugSymbolsTest, HandleWrapList) {
128
1
  const v8::HandleScope handle_scope(isolate_);
129
2
  const Argv argv;
130
2
  Env env{handle_scope, argv};
131
132
  uv_tcp_t handle;
133
134
1
  auto obj_template = v8::FunctionTemplate::New(isolate_);
135
2
  obj_template->InstanceTemplate()->SetInternalFieldCount(1);
136
137
2
  v8::Local<v8::Object> object = obj_template->GetFunction(env.context())
138
2
                                     .ToLocalChecked()
139
4
                                     ->NewInstance(env.context())
140
2
                                     .ToLocalChecked();
141
2
  TestHandleWrap obj(*env, object, &handle);
142
143
1
  auto queue = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue());
144
1
  auto head = queue +
145
1
      nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap;
146
  auto next =
147
1
      head + nodedbg_offset_ListNode_HandleWrap__next___uintptr_t;
148
1
  next = *reinterpret_cast<uintptr_t*>(next);
149
150
1
  auto expected = reinterpret_cast<uintptr_t>(&obj);
151
1
  auto calculated = next -
152
1
      nodedbg_offset_HandleWrap__handle_wrap_queue___ListNode_HandleWrap;
153
1
  EXPECT_EQ(expected, calculated);
154
155
2
  obj.persistent().Reset();  // ~HandleWrap() expects an empty handle.
156
1
}
157
158
5
TEST_F(DebugSymbolsTest, ReqWrapList) {
159
1
  const v8::HandleScope handle_scope(isolate_);
160
2
  const Argv argv;
161
2
  Env env{handle_scope, argv};
162
163
1
  auto obj_template = v8::FunctionTemplate::New(isolate_);
164
2
  obj_template->InstanceTemplate()->SetInternalFieldCount(1);
165
166
2
  v8::Local<v8::Object> object = obj_template->GetFunction(env.context())
167
2
                                     .ToLocalChecked()
168
4
                                     ->NewInstance(env.context())
169
2
                                     .ToLocalChecked();
170
2
  TestReqWrap obj(*env, object);
171
172
  // NOTE (mmarchini): Workaround to fix failing tests on ARM64 machines with
173
  // older GCC. Should be removed once we upgrade the GCC version used on our
174
  // ARM64 CI machinies.
175
1
  for (auto it : *(*env)->req_wrap_queue()) (void) &it;
176
177
1
  auto queue = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
178
1
  auto head = queue +
179
1
      nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue;
180
  auto next =
181
1
      head + nodedbg_offset_ListNode_ReqWrap__next___uintptr_t;
182
1
  next = *reinterpret_cast<uintptr_t*>(next);
183
184
1
  auto expected = reinterpret_cast<uintptr_t>(&obj);
185
  auto calculated =
186
1
      next - nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue;
187
1
  EXPECT_EQ(expected, calculated);
188
189
2
  obj.Dispatched();
190

4
}