forked from The-OpenROAD-Project/OpenROAD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSaveReport.cpp
More file actions
407 lines (340 loc) · 12.5 KB
/
Copy pathTestSaveReport.cpp
File metadata and controls
407 lines (340 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026, The OpenROAD Authors
#include <unistd.h>
#include <cstddef>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "boost/json/serialize.hpp"
#include "gtest/gtest.h"
#include "odb/db.h"
#include "odb/dbTypes.h"
#include "tile_generator.h"
#include "timing_report.h"
#include "tst/nangate45_fixture.h"
#include "web/web.h"
namespace web {
namespace {
// ─── Fixture ────────────────────────────────────────────────────────────────
class SaveReportTest : public tst::Nangate45Fixture
{
protected:
void SetUp() override
{
block_->setDieArea(odb::Rect(0, 0, 20000, 20000));
// Place several instances to ensure non-empty tiles.
for (int i = 0; i < 10; ++i) {
placeInst("BUF_X16",
("buf" + std::to_string(i)).c_str(),
2000 + i * 1500,
2000 + i * 1500);
}
}
void TearDown() override
{
for (const auto& path : output_files_) {
std::filesystem::remove(path);
}
}
odb::dbInst* placeInst(const char* master_name,
const char* inst_name,
int x,
int y)
{
odb::dbMaster* master = lib_->findMaster(master_name);
EXPECT_NE(master, nullptr) << "Master not found: " << master_name;
odb::dbInst* inst = odb::dbInst::create(block_, master, inst_name);
inst->setLocation(x, y);
inst->setPlacementStatus(odb::dbPlacementStatus::PLACED);
return inst;
}
std::string tempHtml(const std::string& label)
{
std::string path
= std::filesystem::temp_directory_path()
/ ("web_test_" + label + "_" + std::to_string(::getpid()) + ".html");
output_files_.push_back(path);
return path;
}
static std::string readFile(const std::string& path)
{
std::ifstream f(path);
std::ostringstream ss;
ss << f.rdbuf();
return ss.str();
}
// Generate a report (no STA — timing sections will be empty but valid).
void generateReport(const std::string& path,
int max_setup = 0,
int max_hold = 0)
{
WebServer server(getDb(),
/*sta=*/nullptr,
getLogger(),
/*interp=*/nullptr);
server.saveReport(path, max_setup, max_hold);
}
// Count occurrences of a substring in a string.
static int countOccurrences(const std::string& haystack,
const std::string& needle)
{
int count = 0;
size_t pos = 0;
while ((pos = haystack.find(needle, pos)) != std::string::npos) {
++count;
pos += needle.size();
}
return count;
}
// Check if a string contains a substring.
static bool contains(const std::string& haystack, const std::string& needle)
{
return haystack.find(needle) != std::string::npos;
}
std::vector<std::string> output_files_;
};
// ─── HTML Structure ─────────────────────────────────────────────────────────
TEST_F(SaveReportTest, GeneratesFile)
{
const std::string path = tempHtml("generates");
generateReport(path);
ASSERT_TRUE(std::filesystem::exists(path));
EXPECT_GT(std::filesystem::file_size(path), 0u);
}
TEST_F(SaveReportTest, ContainsRequiredHTMLElements)
{
const std::string path = tempHtml("html_elements");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "<html>"));
EXPECT_TRUE(contains(html, "<head>"));
EXPECT_TRUE(contains(html, "<body>"));
EXPECT_TRUE(contains(html, "</html>"));
EXPECT_TRUE(contains(html, "id=\"gl-container\""));
EXPECT_TRUE(contains(html, "id=\"menu-bar\""));
EXPECT_TRUE(contains(html, "id=\"loading-overlay\""));
EXPECT_TRUE(contains(html, "leaflet.css"));
EXPECT_TRUE(contains(html, "goldenlayout-base.css"));
}
TEST_F(SaveReportTest, ContainsStaticCache)
{
const std::string path = tempHtml("static_cache");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "window.__STATIC_CACHE__"));
}
TEST_F(SaveReportTest, ContainsInlinedJS)
{
const std::string path = tempHtml("inlined_js");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "class WebSocketManager"));
EXPECT_TRUE(contains(html, "fromCache"));
EXPECT_TRUE(contains(html, "TimingWidget"));
EXPECT_TRUE(contains(html, "ChartsWidget"));
}
TEST_F(SaveReportTest, GoldenLayoutFromCDN)
{
const std::string path = tempHtml("gl_cdn");
generateReport(path);
const std::string html = readFile(path);
// GoldenLayout loaded via ES module import from CDN.
EXPECT_TRUE(contains(html, "type=\"module\""));
EXPECT_TRUE(contains(html, "esm.sh/golden-layout"));
// No vendored golden-layout bundle in the HTML.
EXPECT_FALSE(contains(html, "goldenlayout.umd"));
}
// ─── Cache JSON Responses ───────────────────────────────────────────────────
TEST_F(SaveReportTest, CachesValidTechResponse)
{
const std::string path = tempHtml("tech");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"tech\":"));
EXPECT_TRUE(contains(html, "\"layers\":"));
EXPECT_TRUE(contains(html, "\"has_liberty\":"));
EXPECT_TRUE(contains(html, "\"dbu_per_micron\":"));
}
TEST_F(SaveReportTest, CachesValidBoundsResponse)
{
const std::string path = tempHtml("bounds");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"bounds\":"));
EXPECT_TRUE(contains(html, "\"shapes_ready\":true"));
EXPECT_TRUE(contains(html, "\"pin_max_size\":"));
}
TEST_F(SaveReportTest, CachesTimingReportJSON)
{
const std::string path = tempHtml("timing");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"timing_report:setup\":"));
EXPECT_TRUE(contains(html, "\"timing_report:hold\":"));
// Both should have paths arrays (even if empty without STA).
EXPECT_GE(countOccurrences(html, "\"paths\":"), 2);
}
TEST_F(SaveReportTest, CachesSlackHistogramJSON)
{
const std::string path = tempHtml("histogram");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"slack_histogram:setup\":"));
EXPECT_TRUE(contains(html, "\"slack_histogram:hold\":"));
}
TEST_F(SaveReportTest, CachesChartFiltersJSON)
{
const std::string path = tempHtml("filters");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"chart_filters\":"));
EXPECT_TRUE(contains(html, "\"path_groups\":"));
EXPECT_TRUE(contains(html, "\"clocks\":"));
}
TEST_F(SaveReportTest, CachesHeatmapsEmpty)
{
const std::string path = tempHtml("heatmaps");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "\"heatmaps\":"));
// Should be an empty stub.
EXPECT_TRUE(contains(html, "\"heatmaps\":[]"));
}
// ─── Tile Cache ─────────────────────────────────────────────────────────────
TEST_F(SaveReportTest, CachesTilesAtCorrectZoom)
{
const std::string path = tempHtml("tile_zoom");
generateReport(path);
const std::string html = readFile(path);
// Tiles should be at zoom 1 (the hardcoded default).
EXPECT_TRUE(contains(html, "zoom: 1"));
// At least some tile with /1/ zoom level should exist.
EXPECT_TRUE(contains(html, "/1/"));
}
TEST_F(SaveReportTest, CachesTiles)
{
const std::string path = tempHtml("tiles");
generateReport(path);
const std::string html = readFile(path);
// At least some tiles should be cached.
EXPECT_TRUE(contains(html, "tiles: {"));
// At least one tile key with zoom 1 should exist.
EXPECT_TRUE(contains(html, "/1/")) << "No tiles at zoom 1 found";
}
TEST_F(SaveReportTest, TilesAreValidBase64)
{
const std::string path = tempHtml("tile_base64");
generateReport(path);
const std::string html = readFile(path);
// Find any tile value: "layer/1/x/y":"base64..."
const std::string marker = "/1/";
auto pos = html.find(marker);
ASSERT_NE(pos, std::string::npos) << "No tile entry found";
// Skip to the value after the key.
pos = html.find("\":\"", pos);
ASSERT_NE(pos, std::string::npos);
pos += 3; // skip ":"
// Check the base64 prefix: iVBOR is the b64 encoding of \x89PNG\r\n.
EXPECT_EQ(html.substr(pos, 4), "iVBO") << "Tile doesn't look like base64 PNG";
}
// ─── Overlays ───────────────────────────────────────────────────────────────
TEST_F(SaveReportTest, OverlayArraysPresent)
{
const std::string path = tempHtml("overlays");
generateReport(path);
const std::string html = readFile(path);
EXPECT_TRUE(contains(html, "setup: ["));
EXPECT_TRUE(contains(html, "hold: ["));
}
// ─── Shared Serialization ───────────────────────────────────────────────────
TEST_F(SaveReportTest, SerializeTimingPathsRoundTrip)
{
TimingPathSummary p;
p.start_clk = "clk1";
p.end_clk = "clk2";
p.slack = -0.5f;
p.arrival = 1.0f;
p.required = 1.5f;
p.skew = 0.1f;
p.path_delay = 0.9f;
p.logic_depth = 3;
p.fanout = 5;
p.start_pin = "a/Z";
p.end_pin = "b/D";
TimingNode node;
node.pin_name = "a/Z";
node.fanout = 2;
node.is_rising = true;
node.is_clock = false;
node.time = 0.5f;
node.delay = 0.1f;
node.slew = 0.02f;
node.load = 0.01f;
p.data_nodes.push_back(std::move(node));
std::vector<TimingPathSummary> paths = {std::move(p)};
const std::string json = boost::json::serialize(serializeTimingPaths(paths));
EXPECT_TRUE(contains(json, "\"clk1\""));
EXPECT_TRUE(contains(json, "\"clk2\""));
EXPECT_TRUE(contains(json, "\"a/Z\""));
EXPECT_TRUE(contains(json, "\"paths\":"));
EXPECT_TRUE(contains(json, "\"data_nodes\":"));
EXPECT_TRUE(contains(json, "\"capture_nodes\":"));
}
TEST_F(SaveReportTest, SerializeSlackHistogramRoundTrip)
{
SlackHistogramResult h;
h.bins.push_back({-1.0f, 0.0f, 10, true});
h.bins.push_back({0.0f, 1.0f, 20, false});
h.unconstrained_count = 5;
h.total_endpoints = 35;
h.time_unit = "ns";
const std::string json = boost::json::serialize(serializeSlackHistogram(h));
EXPECT_TRUE(contains(json, "\"bins\":"));
EXPECT_TRUE(contains(json, "\"unconstrained_count\":5"));
EXPECT_TRUE(contains(json, "\"total_endpoints\":35"));
EXPECT_TRUE(contains(json, "\"time_unit\":\"ns\""));
}
TEST_F(SaveReportTest, SerializeChartFiltersRoundTrip)
{
ChartFilters f;
f.path_groups.emplace_back("default");
f.clocks.emplace_back("clk");
const std::string json = boost::json::serialize(serializeChartFilters(f));
EXPECT_TRUE(contains(json, "\"path_groups\":"));
EXPECT_TRUE(contains(json, "\"default\""));
EXPECT_TRUE(contains(json, "\"clocks\":"));
EXPECT_TRUE(contains(json, "\"clk\""));
}
TEST_F(SaveReportTest, SerializeTechResponse)
{
TileGenerator gen(getDb(), /*sta=*/nullptr, getLogger());
const std::string json = boost::json::serialize(serializeTechResponse(gen));
EXPECT_TRUE(contains(json, "\"layers\":"));
EXPECT_TRUE(contains(json, "\"sites\":"));
EXPECT_TRUE(contains(json, "\"has_liberty\":"));
EXPECT_TRUE(contains(json, "\"dbu_per_micron\":"));
}
TEST_F(SaveReportTest, SerializeBoundsShapesReady)
{
TileGenerator gen(getDb(), /*sta=*/nullptr, getLogger());
const std::string json_true
= boost::json::serialize(serializeBoundsResponse(gen, true));
EXPECT_TRUE(contains(json_true, "\"shapes_ready\":true"));
const std::string json_false
= boost::json::serialize(serializeBoundsResponse(gen, false));
EXPECT_TRUE(contains(json_false, "\"shapes_ready\":false"));
}
// ─── Edge Cases ─────────────────────────────────────────────────────────────
TEST_F(SaveReportTest, ZeroPathsReport)
{
const std::string path = tempHtml("zero_paths");
generateReport(path, 0, 0);
const std::string html = readFile(path);
ASSERT_TRUE(std::filesystem::exists(path));
EXPECT_TRUE(contains(html, "\"paths\":[]"));
}
} // namespace
} // namespace web