summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/panes.zig4
-rw-r--r--test/pdf.zig8
-rw-r--r--test/pdf_bench.zig26
-rw-r--r--test/pdf_sections_bench.zig8
4 files changed, 27 insertions, 19 deletions
diff --git a/test/panes.zig b/test/panes.zig
index 1460b355..1b1b3eea 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3421,7 +3421,9 @@ const PdfTests = struct {
test "PDF word probe owns quads and text without a selection object" {
if (comptime !enabled) return;
- var document = try Document.open("docs/design.pdf");
+ const bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "docs/design.pdf", std.testing.allocator, .unlimited);
+ defer std.testing.allocator.free(bytes);
+ var document = try Document.openBytes(bytes);
defer document.deinit();
var found = try document.search(std.testing.allocator, 0, "Pardes");
defer found.deinit(std.testing.allocator);
diff --git a/test/pdf.zig b/test/pdf.zig
index b8a768c8..cc4a258d 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -212,11 +212,13 @@ test "PDF mounted bytes own their source after the caller frees it" {
gpa.free(source);
defer document.deinit();
- var original = try pdf_impl.Document.open("docs/design.pdf");
+ const again = try pardes.filesystem.readFile(gpa, "docs/design.pdf");
+ defer gpa.free(again);
+ var original = try pdf_impl.Document.openBytes(again);
defer original.deinit();
try std.testing.expectEqual(original.pages, document.pages);
try std.testing.expectEqual(try original.pageSize(0), try document.pageSize(0));
- const raster = try document.render(gpa, 0);
+ const raster = try document.render(gpa, 0, .{}, &.{});
defer gpa.free(raster.rgba);
try std.testing.expect(raster.rgba.len > 0);
}
@@ -1249,7 +1251,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
// tint, and tinted as the pane tints.
const plain = try gpa.alloc(u8, shape.len);
defer gpa.free(plain);
- try pv.document.renderIntoAt(0, request, shape, shape.wholePage(), &.{}, plain);
+ try pv.document.renderIntoAtWithPaper(0, request, shape, shape.wholePage(), &.{}, plain, false);
const whole = try gpa.dupe(u8, plain);
defer gpa.free(whole);
try pdf_impl.tintRgba(whole, pv.tint, panes.Pdf.tintColors(p));
diff --git a/test/pdf_bench.zig b/test/pdf_bench.zig
index 23565106..9054698b 100644
--- a/test/pdf_bench.zig
+++ b/test/pdf_bench.zig
@@ -9,9 +9,9 @@
//! ReleaseFast. Timed regions include MuPDF rasterization directly into the
//! allocator-owned RGBA output; tint scenarios additionally include the exact
//! in-place PDF transform used by the core. Checksum/free/reporting stay
-//! outside. "cold" means a fresh Document and MuPDF page cache (the OS
-//! filesystem cache is deliberately uncontrolled), while warm scenarios
-//! retain one Document.
+//! outside. "cold" means a fresh Document and MuPDF page cache, opened from
+//! the file's bytes (read once, untimed, as the view reads a file whole),
+//! while warm scenarios retain one Document.
const std = @import("std");
const bench_util = @import("bench_util.zig");
const nowNs = bench_util.nowNs;
@@ -28,6 +28,8 @@ const checksum_seed: u64 = 0x7061_7264_6573_5044;
const Config = struct {
path: []const u8 = "docs/design.pdf",
+ /// the file at `path`, read whole before anything is timed
+ bytes: []const u8 = "",
page: usize = 0,
reps: usize = default_reps,
warmup: usize = default_warmup,
@@ -140,9 +142,11 @@ const Result = struct {
pub fn main(init: std.process.Init) !void {
const args = try init.minimal.args.toSlice(init.arena.allocator());
- const config = parseArgs(args);
+ var config = parseArgs(args);
+ config.bytes = std.Io.Dir.cwd().readFileAlloc(init.io, config.path, gpa, .unlimited) catch |err|
+ fatal("cannot read {s}: {t}", .{ config.path, err });
- var probe = pdf.Document.open(config.path) catch |err|
+ var probe = pdf.Document.openBytes(config.bytes) catch |err|
fatal("cannot open {s}: {t}", .{ config.path, err });
const document_pages = probe.pages;
probe.deinit();
@@ -239,7 +243,7 @@ fn measure(
if (scenario.lifecycle == .cold_document_page) {
for (0..rounds) |round| {
const timed = try timeCold(
- config.path,
+ config.bytes,
config.page,
profile.request,
scenario.decoration,
@@ -253,7 +257,7 @@ fn measure(
}
}
} else {
- var document = try pdf.Document.open(config.path);
+ var document = try pdf.Document.openBytes(config.bytes);
defer document.deinit();
for (0..rounds) |round| {
const timed = switch (scenario.lifecycle) {
@@ -298,14 +302,14 @@ fn measure(
}
fn timeCold(
- path: []const u8,
+ bytes: []const u8,
page: usize,
request: pdf.RenderRequest,
decoration: Decoration,
tint: pdf.TintMode,
) !Timed {
const started = nowNs();
- var document = try pdf.Document.open(path);
+ var document = try pdf.Document.openBytes(bytes);
errdefer document.deinit();
const rendered = try renderPage(&document, page, request, decoration, tint);
const elapsed = @max(@as(u64, 1), nowNs() -| started);
@@ -364,8 +368,8 @@ fn renderPage(
tint: pdf.TintMode,
) !pdf.Render {
const rendered = switch (decoration) {
- .plain => document.renderAt(gpa, page, request),
- .highlighted => document.renderWithHighlightsAt(gpa, page, request, &highlights),
+ .plain => document.render(gpa, page, request, &.{}),
+ .highlighted => document.render(gpa, page, request, &highlights),
};
const fresh = try rendered;
errdefer gpa.free(fresh.rgba);
diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig
index ee26e83d..ce548924 100644
--- a/test/pdf_sections_bench.zig
+++ b/test/pdf_sections_bench.zig
@@ -72,7 +72,7 @@ pub fn main(init: std.process.Init) !void {
try writeFile(path, fixture);
defer unlink(path);
- var document = try pdf.Document.open(path);
+ var document = try pdf.Document.openBytes(fixture);
defer document.deinit();
var outline = try document.outline(gpa);
defer outline.deinit(gpa);
@@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void {
defer gpa.free(synthetic);
const results = [_]Result{
- try measureOutline(path, config),
+ try measureOutline(fixture, config),
try measureMaterialize(path, outline.entries, config),
try measureCachedControl(path, config),
try measureCachedReopen(path, config),
@@ -112,14 +112,14 @@ fn parseArgs(args: []const []const u8) Config {
return config;
}
-fn measureOutline(path: []const u8, config: Config) !Result {
+fn measureOutline(fixture: []const u8, config: Config) !Result {
const samples = try gpa.alloc(u64, config.reps);
defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
// Document open/close is setup: this row isolates MuPDF outline load,
// bridge flattening, and the Zig-owned two-allocation copy.
- var document = try pdf.Document.open(path);
+ var document = try pdf.Document.openBytes(fixture);
defer document.deinit();
const started = nowNs();
var outline = try document.outline(gpa);