leptris 1.9.424.0-arm-linux → 1.9.426.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +47 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/TODO.SOTA.md +40 -5
- data/vendor-src/libleptris/benchmarks/CMakeLists.txt +25 -0
- data/vendor-src/libleptris/benchmarks/dom/bench_zerocopy_text.c +118 -0
- data/vendor-src/libleptris/benchmarks/fixtures/generate_pipeline.rb +120 -0
- data/vendor-src/libleptris/benchmarks/fixtures/pipeline_config.xml +103 -0
- data/vendor-src/libleptris/benchmarks/fixtures/pipeline_feed.xml +166 -0
- data/vendor-src/libleptris/benchmarks/fixtures/pipeline_metanorma.xml +268 -0
- data/vendor-src/libleptris/benchmarks/fixtures/pipeline_records.xml +284 -0
- data/vendor-src/libleptris/benchmarks/workflows/bench_pipeline_shapes.cpp +693 -0
- data/vendor-src/libleptris/docs/MISSION-PLAN.md +5 -0
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +10 -1
- data/vendor-src/libleptris/src/leptris/leptris_internal.h +8 -0
- data/vendor-src/libleptris/src/leptris/xpath/compiler.c +6 -2
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +13 -1
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +8 -2
- data/vendor-src/libleptris/src/leptris/xpath/functions.c +15 -3
- data/vendor-src/libleptris/src/leptris/xpath/parser.c +8 -0
- data/vendor-src/libleptris/src/leptris/xpath/xpath_ast_cache.c +36 -0
- data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +41 -41
- data/vendor-src/libleptris/src/leptris/xpath/xpath_internal.h +7 -0
- data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +58 -6
- data/vendor-src/libleptris/src/leptris/xslt/xslt_internal.h +10 -0
- data/vendor-src/libleptris/src/leptris/xslt/xslt_parse.c +36 -16
- data/vendor-src/libleptris/test/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/test/differential/README.md +7 -7
- data/vendor-src/libleptris/test/differential/corpus/01-namespaces.xml +8 -0
- data/vendor-src/libleptris/test/differential/corpus/02-entities-predef.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/03-entities-numeric.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/04-cdata.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/05-comments-pi.xml +3 -0
- data/vendor-src/libleptris/test/differential/corpus/06-doctype-internal.xml +6 -0
- data/vendor-src/libleptris/test/differential/corpus/07-unicode.xml +2 -0
- data/vendor-src/libleptris/test/differential/corpus/08-deep-nesting.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/09-mixed-content.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/10-big-attrs.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/11-whitespace.xml +6 -0
- data/vendor-src/libleptris/test/differential/corpus/12-dup-xmlns.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/13-custom-dtd-entity.xml +2 -0
- data/vendor-src/libleptris/test/differential/corpus/14-processing-instr-xml-decl.xml +2 -0
- data/vendor-src/libleptris/test/differential/corpus/15-empty-and-selfclose.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/16-attrs-special-chars.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/17-rss-like.xml +2 -0
- data/vendor-src/libleptris/test/differential/corpus/18-soap-like.xml +5 -0
- data/vendor-src/libleptris/test/differential/corpus/19-xinclude.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/20-single-root.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/21-text-only-elems.xml +1 -0
- data/vendor-src/libleptris/test/differential/corpus/22-long-text.xml +1 -0
- data/vendor-src/libleptris/test/differential/package.json +1 -1
- data/vendor-src/libleptris/test/differential/rs-runner/Cargo.lock +217 -0
- data/vendor-src/libleptris/test/differential/rs-runner/Cargo.toml +18 -0
- data/vendor-src/libleptris/test/differential/rs-runner/run.rs +94 -0
- data/vendor-src/libleptris/test/differential/run.mjs +44 -0
- data/vendor-src/libleptris/test/differential/run.py +44 -0
- data/vendor-src/libleptris/test/differential/run.rb +44 -0
- data/vendor-src/libleptris/test/fixtures/differential/01-namespaces.xml +8 -0
- data/vendor-src/libleptris/test/fixtures/differential/02-entities-predef.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/03-entities-numeric.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/04-cdata.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/05-comments-pi.xml +3 -0
- data/vendor-src/libleptris/test/fixtures/differential/06-doctype-internal.xml +6 -0
- data/vendor-src/libleptris/test/fixtures/differential/07-unicode.xml +2 -0
- data/vendor-src/libleptris/test/fixtures/differential/08-deep-nesting.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/09-mixed-content.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/10-big-attrs.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/11-whitespace.xml +6 -0
- data/vendor-src/libleptris/test/fixtures/differential/12-dup-xmlns.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/13-custom-dtd-entity.xml +2 -0
- data/vendor-src/libleptris/test/fixtures/differential/14-processing-instr-xml-decl.xml +2 -0
- data/vendor-src/libleptris/test/fixtures/differential/15-empty-and-selfclose.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/16-attrs-special-chars.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/17-rss-like.xml +2 -0
- data/vendor-src/libleptris/test/fixtures/differential/18-soap-like.xml +5 -0
- data/vendor-src/libleptris/test/fixtures/differential/19-xinclude.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/20-single-root.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/21-text-only-elems.xml +1 -0
- data/vendor-src/libleptris/test/fixtures/differential/22-long-text.xml +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0000.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0001.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0002.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0003.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0004.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0005.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0006.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0007.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0008.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0009.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0010.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0011.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0012.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0013.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0014.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0015.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0016.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0017.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0018.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0019.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0020.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0021.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0022.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0023.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0024.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0025.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0026.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0027.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0028.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0029.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0030.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0031.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0032.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0033.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0034.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0035.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0036.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0037.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0038.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/gen/gen_0039.xsl +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/html_foreign_cdata_short_opener.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/seed1 +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/seed2 +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_fold.bin +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_astcache_uaf_nightly.bin +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_dyncall_nontext_callee_segv.xml +0 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_empty_match_template_leak.xml +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/xslt_union_number_head_segv.xml +0 -0
- data/vendor-src/libleptris/test/fuzz/fuzz_html.c +39 -0
- data/vendor-src/libleptris/test/fuzz/fuzz_xslt.c +36 -0
- data/vendor-src/libleptris/test/fuzz/generators/gen_xslt_seeds.py +152 -0
- data/vendor-src/libleptris/test/html/test_html.cpp +49 -0
- data/vendor-src/libleptris/test/xpath/test_xpath.cpp +62 -0
- data/vendor-src/libleptris/test/xpath/test_xslt.cpp +33 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +107 -2
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
// benchmarks/workflows/bench_pipeline_shapes.cpp — SOTA B3 (#2055):
|
|
2
|
+
// the whole-pipeline scoreboard shapes. Each shape is a fixed input
|
|
3
|
+
// corpus + a fixed operation script (parse → query → mutate →
|
|
4
|
+
// serialize — the real consumer shapes), run with the interleaved-
|
|
5
|
+
// median discipline: leptris and the competitor alternate within
|
|
6
|
+
// every repetition, so cache/thermal ordering cannot favor either
|
|
7
|
+
// side; the reported number is the median of the per-rep samples.
|
|
8
|
+
//
|
|
9
|
+
// Rows are machine-readable (shape=/engine=/median_us=/ratio=) so
|
|
10
|
+
// the Benchmark workflow summary and MISSION-PLAN.md can quote them
|
|
11
|
+
// verbatim.
|
|
12
|
+
//
|
|
13
|
+
// Usage: bench_pipeline_shapes [reps]
|
|
14
|
+
|
|
15
|
+
#include <cstdio>
|
|
16
|
+
#include <cstdlib>
|
|
17
|
+
#include <cstring>
|
|
18
|
+
#include <algorithm>
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <vector>
|
|
21
|
+
#include <sys/time.h>
|
|
22
|
+
|
|
23
|
+
#include <leptris.h>
|
|
24
|
+
|
|
25
|
+
#ifdef HAVE_PUGIXML
|
|
26
|
+
#include <pugixml.hpp>
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#ifdef HAVE_LIBXML2
|
|
30
|
+
#include <libxml/parser.h>
|
|
31
|
+
#include <libxml/xpath.h>
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
namespace {
|
|
35
|
+
|
|
36
|
+
// ------------------------------------------------------------------
|
|
37
|
+
// Timing + interleaved-median discipline
|
|
38
|
+
// ------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
double now_us(void) {
|
|
41
|
+
struct timeval tv;
|
|
42
|
+
gettimeofday(&tv, NULL);
|
|
43
|
+
return (double)tv.tv_sec * 1e6 + (double)tv.tv_usec;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
double median_of(std::vector<double>& v) {
|
|
47
|
+
std::sort(v.begin(), v.end());
|
|
48
|
+
size_t n = v.size();
|
|
49
|
+
if (!n) return 0.0;
|
|
50
|
+
return n % 2 ? v[n / 2] : (v[n / 2 - 1] + v[n / 2]) / 2.0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
std::vector<char> load_corpus(const char* path) {
|
|
54
|
+
FILE* f = fopen(path, "rb");
|
|
55
|
+
if (!f) {
|
|
56
|
+
fprintf(stderr, "cannot open %s — run from build/benchmarks "
|
|
57
|
+
"(the workflow stages fixtures/ there)\n", path);
|
|
58
|
+
exit(2);
|
|
59
|
+
}
|
|
60
|
+
fseek(f, 0, SEEK_END);
|
|
61
|
+
long n = ftell(f);
|
|
62
|
+
fseek(f, 0, SEEK_SET);
|
|
63
|
+
std::vector<char> buf((size_t)n + 1);
|
|
64
|
+
size_t got = fread(buf.data(), 1, (size_t)n, f);
|
|
65
|
+
fclose(f);
|
|
66
|
+
buf[got] = 0;
|
|
67
|
+
return buf;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ------------------------------------------------------------------
|
|
71
|
+
// The four shapes, leptris side. Each returns nonzero on any
|
|
72
|
+
// structural surprise (a query that must hit but doesn't) so a rig
|
|
73
|
+
// bug can't masquerade as a speed number.
|
|
74
|
+
// ------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
int shape_metanorma_leptris(const char* xml, size_t len) {
|
|
77
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
78
|
+
LeptrisDocument doc = leptris_parse_string(xml, len, &st);
|
|
79
|
+
if (!doc) return 1;
|
|
80
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
81
|
+
if (!root) { leptris_document_free(doc); return 1; }
|
|
82
|
+
|
|
83
|
+
LeptrisXPathResult terms =
|
|
84
|
+
leptris_xpath_eval(doc, root, "//standard/clause/terms/term");
|
|
85
|
+
if (!terms) { leptris_document_free(doc); return 1; }
|
|
86
|
+
size_t nterm = leptris_xpath_result_count(terms);
|
|
87
|
+
if (nterm == 0) { leptris_xpath_result_free(terms);
|
|
88
|
+
leptris_document_free(doc); return 1; }
|
|
89
|
+
for (size_t i = 0; i < nterm; i++) {
|
|
90
|
+
LeptrisElement t = leptris_xpath_result_get(terms, i);
|
|
91
|
+
if (!leptris_element_child_value(
|
|
92
|
+
leptris_element_first_child(t, "preferred"))) {
|
|
93
|
+
leptris_xpath_result_free(terms);
|
|
94
|
+
leptris_document_free(doc);
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
leptris_xpath_result_free(terms);
|
|
99
|
+
|
|
100
|
+
// The compile-shape mutation: clause ids + per-term review notes.
|
|
101
|
+
LeptrisXPathResult clauses =
|
|
102
|
+
leptris_xpath_eval(doc, root, "//standard/clause");
|
|
103
|
+
if (!clauses) { leptris_document_free(doc); return 1; }
|
|
104
|
+
size_t ncl = leptris_xpath_result_count(clauses);
|
|
105
|
+
for (size_t i = 0; i < ncl; i++) {
|
|
106
|
+
char idbuf[32];
|
|
107
|
+
snprintf(idbuf, sizeof idbuf, "sec-%zu", i);
|
|
108
|
+
leptris_element_set_attribute(
|
|
109
|
+
leptris_xpath_result_get(clauses, i), "rev-id", idbuf);
|
|
110
|
+
}
|
|
111
|
+
leptris_xpath_result_free(clauses);
|
|
112
|
+
|
|
113
|
+
LeptrisXPathResult terms2 =
|
|
114
|
+
leptris_xpath_eval(doc, root, "//standard/clause/terms/term");
|
|
115
|
+
if (!terms2) { leptris_document_free(doc); return 1; }
|
|
116
|
+
size_t nt2 = leptris_xpath_result_count(terms2);
|
|
117
|
+
for (size_t i = 0; i < nt2; i++)
|
|
118
|
+
leptris_element_create_child(
|
|
119
|
+
leptris_xpath_result_get(terms2, i), "review");
|
|
120
|
+
leptris_xpath_result_free(terms2);
|
|
121
|
+
|
|
122
|
+
char* out = leptris_document_serialize(doc, NULL);
|
|
123
|
+
if (!out) { leptris_document_free(doc); return 1; }
|
|
124
|
+
leptris_free_string(out);
|
|
125
|
+
leptris_document_free(doc);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int shape_config_leptris(const char* xml, size_t len) {
|
|
130
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
131
|
+
LeptrisDocument doc = leptris_parse_string(xml, len, &st);
|
|
132
|
+
if (!doc) return 1;
|
|
133
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
134
|
+
if (!root) { leptris_document_free(doc); return 1; }
|
|
135
|
+
|
|
136
|
+
// The fixed validation assert set. Assert 0 is the sanity gate
|
|
137
|
+
// (the corpus always has hosts); the rest must merely EVALUATE —
|
|
138
|
+
// a zero count ("no service misses @port") is a PASS, not a rig
|
|
139
|
+
// failure.
|
|
140
|
+
static const char* ASSERTS[] = {
|
|
141
|
+
"//service[@host]",
|
|
142
|
+
"count(//service[not(@port)])",
|
|
143
|
+
"count(//service[@tls='true'])",
|
|
144
|
+
"count(//service/route)",
|
|
145
|
+
"boolean(//defaults)",
|
|
146
|
+
};
|
|
147
|
+
for (size_t a = 0; a < sizeof ASSERTS / sizeof ASSERTS[0]; a++) {
|
|
148
|
+
LeptrisXPathResult r =
|
|
149
|
+
leptris_xpath_eval(doc, root, ASSERTS[a]);
|
|
150
|
+
if (!r) { leptris_document_free(doc); return 1; }
|
|
151
|
+
size_t n = leptris_xpath_result_count(r);
|
|
152
|
+
if (a == 0 && n == 0) {
|
|
153
|
+
leptris_xpath_result_free(r);
|
|
154
|
+
leptris_document_free(doc);
|
|
155
|
+
return 1;
|
|
156
|
+
}
|
|
157
|
+
leptris_xpath_result_free(r);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
char* out = leptris_document_serialize(doc, NULL);
|
|
161
|
+
if (!out) { leptris_document_free(doc); return 1; }
|
|
162
|
+
leptris_free_string(out);
|
|
163
|
+
leptris_document_free(doc);
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
int shape_feed_leptris(const char* xml, size_t len) {
|
|
168
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
169
|
+
LeptrisDocument doc = leptris_parse_string(xml, len, &st);
|
|
170
|
+
if (!doc) return 1;
|
|
171
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
172
|
+
if (!root) { leptris_document_free(doc); return 1; }
|
|
173
|
+
|
|
174
|
+
LeptrisXPathResult entries =
|
|
175
|
+
leptris_xpath_eval(doc, root, "//feed/entry");
|
|
176
|
+
if (!entries) { leptris_document_free(doc); return 1; }
|
|
177
|
+
size_t n = leptris_xpath_result_count(entries);
|
|
178
|
+
if (n == 0) { leptris_xpath_result_free(entries);
|
|
179
|
+
leptris_document_free(doc); return 1; }
|
|
180
|
+
for (size_t i = 0; i < n; i++) {
|
|
181
|
+
LeptrisElement e = leptris_xpath_result_get(entries, i);
|
|
182
|
+
if (!leptris_element_child_value(
|
|
183
|
+
leptris_element_first_child(e, NULL))) {
|
|
184
|
+
leptris_xpath_result_free(entries);
|
|
185
|
+
leptris_document_free(doc);
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
leptris_element_set_attribute(e, "normalized", "1");
|
|
189
|
+
leptris_element_create_child(e, "generator");
|
|
190
|
+
}
|
|
191
|
+
leptris_xpath_result_free(entries);
|
|
192
|
+
|
|
193
|
+
char* out = leptris_document_serialize(doc, NULL);
|
|
194
|
+
if (!out) { leptris_document_free(doc); return 1; }
|
|
195
|
+
leptris_free_string(out);
|
|
196
|
+
leptris_document_free(doc);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
int shape_extract_leptris(const char* xml, size_t len) {
|
|
201
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
202
|
+
LeptrisDocument doc = leptris_parse_string(xml, len, &st);
|
|
203
|
+
if (!doc) return 1;
|
|
204
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
205
|
+
if (!root) { leptris_document_free(doc); return 1; }
|
|
206
|
+
|
|
207
|
+
LeptrisXPathResult sel =
|
|
208
|
+
leptris_xpath_eval(doc, root,
|
|
209
|
+
"//records/record[@status='active']");
|
|
210
|
+
if (!sel) { leptris_document_free(doc); return 1; }
|
|
211
|
+
size_t n = leptris_xpath_result_count(sel);
|
|
212
|
+
if (n == 0) { leptris_xpath_result_free(sel);
|
|
213
|
+
leptris_document_free(doc); return 1; }
|
|
214
|
+
|
|
215
|
+
// The build row: a NEW document assembled from the selection.
|
|
216
|
+
LeptrisDocument out_doc = leptris_document_create();
|
|
217
|
+
if (!out_doc) { leptris_xpath_result_free(sel);
|
|
218
|
+
leptris_document_free(doc); return 1; }
|
|
219
|
+
LeptrisElement out_root =
|
|
220
|
+
leptris_element_create(out_doc, "active-records");
|
|
221
|
+
if (!out_root) { leptris_document_free(out_doc);
|
|
222
|
+
leptris_xpath_result_free(sel);
|
|
223
|
+
leptris_document_free(doc); return 1; }
|
|
224
|
+
leptris_document_set_root(out_doc, out_root);
|
|
225
|
+
for (size_t i = 0; i < n; i++) {
|
|
226
|
+
LeptrisElement rec = leptris_xpath_result_get(sel, i);
|
|
227
|
+
char rid[32], ramt[32];
|
|
228
|
+
const char* id = leptris_element_attribute(rec, "id");
|
|
229
|
+
const char* amt = leptris_element_attribute(rec, "amount");
|
|
230
|
+
if (!id || !amt) { leptris_document_free(out_doc);
|
|
231
|
+
leptris_xpath_result_free(sel);
|
|
232
|
+
leptris_document_free(doc); return 1; }
|
|
233
|
+
snprintf(rid, sizeof rid, "%s", id);
|
|
234
|
+
snprintf(ramt, sizeof ramt, "%s", amt);
|
|
235
|
+
LeptrisElement c = leptris_element_create_child(out_root, "r");
|
|
236
|
+
if (!c) { leptris_document_free(out_doc);
|
|
237
|
+
leptris_xpath_result_free(sel);
|
|
238
|
+
leptris_document_free(doc); return 1; }
|
|
239
|
+
leptris_element_set_attribute(c, "id", rid);
|
|
240
|
+
leptris_element_set_attribute(c, "amount", ramt);
|
|
241
|
+
}
|
|
242
|
+
leptris_xpath_result_free(sel);
|
|
243
|
+
|
|
244
|
+
char* out = leptris_document_serialize(out_doc, NULL);
|
|
245
|
+
if (!out) { leptris_document_free(out_doc);
|
|
246
|
+
leptris_document_free(doc); return 1; }
|
|
247
|
+
leptris_free_string(out);
|
|
248
|
+
leptris_document_free(out_doc);
|
|
249
|
+
leptris_document_free(doc);
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ------------------------------------------------------------------
|
|
254
|
+
// Competitor rigs. Same script per shape, competitor API.
|
|
255
|
+
// ------------------------------------------------------------------
|
|
256
|
+
|
|
257
|
+
#ifdef HAVE_LIBXML2
|
|
258
|
+
int shape_metanorma_libxml2(const char* xml, size_t len) {
|
|
259
|
+
xmlDocPtr doc = xmlReadMemory(xml, (int)len, NULL, NULL, 0);
|
|
260
|
+
if (!doc) return 1;
|
|
261
|
+
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
|
|
262
|
+
if (!ctx) { xmlFreeDoc(doc); return 1; }
|
|
263
|
+
xmlXPathObjectPtr terms =
|
|
264
|
+
xmlXPathEvalExpression((const xmlChar*)"//standard/clause/terms/term", ctx);
|
|
265
|
+
if (!terms || terms->nodesetval == NULL ||
|
|
266
|
+
terms->nodesetval->nodeNr == 0) {
|
|
267
|
+
if (terms) xmlXPathFreeObject(terms);
|
|
268
|
+
xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return 1;
|
|
269
|
+
}
|
|
270
|
+
for (int i = 0; i < terms->nodesetval->nodeNr; i++) {
|
|
271
|
+
xmlNodePtr t = terms->nodesetval->nodeTab[i];
|
|
272
|
+
int has_preferred = 0;
|
|
273
|
+
for (xmlNodePtr c = t->children; c; c = c->next)
|
|
274
|
+
if (c->type == XML_ELEMENT_NODE &&
|
|
275
|
+
xmlStrcmp(c->name, (const xmlChar*)"preferred") == 0 &&
|
|
276
|
+
c->children && c->children->content &&
|
|
277
|
+
c->children->content[0])
|
|
278
|
+
has_preferred = 1;
|
|
279
|
+
if (!has_preferred) {
|
|
280
|
+
xmlXPathFreeObject(terms);
|
|
281
|
+
xmlXPathFreeContext(ctx);
|
|
282
|
+
xmlFreeDoc(doc);
|
|
283
|
+
return 1;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
xmlXPathFreeObject(terms);
|
|
287
|
+
xmlXPathObjectPtr clauses =
|
|
288
|
+
xmlXPathEvalExpression((const xmlChar*)"//standard/clause", ctx);
|
|
289
|
+
if (clauses && clauses->nodesetval) {
|
|
290
|
+
for (int i = 0; i < clauses->nodesetval->nodeNr; i++) {
|
|
291
|
+
char idbuf[32];
|
|
292
|
+
snprintf(idbuf, sizeof idbuf, "sec-%d", i);
|
|
293
|
+
xmlSetProp(clauses->nodesetval->nodeTab[i],
|
|
294
|
+
(const xmlChar*)"rev-id", (const xmlChar*)idbuf);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (clauses) xmlXPathFreeObject(clauses);
|
|
298
|
+
xmlXPathObjectPtr terms2 =
|
|
299
|
+
xmlXPathEvalExpression((const xmlChar*)"//standard/clause/terms/term", ctx);
|
|
300
|
+
if (terms2 && terms2->nodesetval) {
|
|
301
|
+
for (int i = 0; i < terms2->nodesetval->nodeNr; i++)
|
|
302
|
+
xmlNewChild(terms2->nodesetval->nodeTab[i], NULL,
|
|
303
|
+
(const xmlChar*)"review", NULL);
|
|
304
|
+
}
|
|
305
|
+
if (terms2) xmlXPathFreeObject(terms2);
|
|
306
|
+
xmlXPathFreeContext(ctx);
|
|
307
|
+
xmlChar* dump = NULL;
|
|
308
|
+
int dump_len = 0;
|
|
309
|
+
xmlDocDumpMemory(doc, &dump, &dump_len);
|
|
310
|
+
int ok = dump && dump_len > 0;
|
|
311
|
+
xmlFree(dump);
|
|
312
|
+
xmlFreeDoc(doc);
|
|
313
|
+
return ok ? 0 : 1;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
int shape_config_libxml2(const char* xml, size_t len) {
|
|
317
|
+
xmlDocPtr doc = xmlReadMemory(xml, (int)len, NULL, NULL, 0);
|
|
318
|
+
if (!doc) return 1;
|
|
319
|
+
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
|
|
320
|
+
if (!ctx) { xmlFreeDoc(doc); return 1; }
|
|
321
|
+
static const char* ASSERTS[] = {
|
|
322
|
+
"//service[@host]",
|
|
323
|
+
"count(//service[not(@port)])",
|
|
324
|
+
"count(//service[@tls='true'])",
|
|
325
|
+
"count(//service/route)",
|
|
326
|
+
"boolean(//defaults)",
|
|
327
|
+
};
|
|
328
|
+
for (size_t a = 0;
|
|
329
|
+
a < sizeof ASSERTS / sizeof ASSERTS[0]; a++) {
|
|
330
|
+
xmlXPathObjectPtr r = xmlXPathEvalExpression(
|
|
331
|
+
(const xmlChar*)ASSERTS[a], ctx);
|
|
332
|
+
if (!r) { xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return 1; }
|
|
333
|
+
if (a == 0 && (!r->nodesetval || r->nodesetval->nodeNr == 0)) {
|
|
334
|
+
xmlXPathFreeObject(r);
|
|
335
|
+
xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return 1;
|
|
336
|
+
}
|
|
337
|
+
xmlXPathFreeObject(r);
|
|
338
|
+
}
|
|
339
|
+
xmlXPathFreeContext(ctx);
|
|
340
|
+
xmlChar* dump = NULL;
|
|
341
|
+
int dump_len = 0;
|
|
342
|
+
xmlDocDumpMemory(doc, &dump, &dump_len);
|
|
343
|
+
int ok = dump && dump_len > 0;
|
|
344
|
+
xmlFree(dump);
|
|
345
|
+
xmlFreeDoc(doc);
|
|
346
|
+
return ok ? 0 : 1;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
int shape_feed_libxml2(const char* xml, size_t len) {
|
|
350
|
+
xmlDocPtr doc = xmlReadMemory(xml, (int)len, NULL, NULL, 0);
|
|
351
|
+
if (!doc) return 1;
|
|
352
|
+
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
|
|
353
|
+
if (!ctx) { xmlFreeDoc(doc); return 1; }
|
|
354
|
+
xmlXPathObjectPtr entries =
|
|
355
|
+
xmlXPathEvalExpression((const xmlChar*)"//feed/entry", ctx);
|
|
356
|
+
if (!entries || !entries->nodesetval ||
|
|
357
|
+
entries->nodesetval->nodeNr == 0) {
|
|
358
|
+
if (entries) xmlXPathFreeObject(entries);
|
|
359
|
+
xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return 1;
|
|
360
|
+
}
|
|
361
|
+
for (int i = 0; i < entries->nodesetval->nodeNr; i++) {
|
|
362
|
+
xmlNodePtr e = entries->nodesetval->nodeTab[i];
|
|
363
|
+
xmlNodePtr title = NULL;
|
|
364
|
+
for (xmlNodePtr c = e->children; c; c = c->next)
|
|
365
|
+
if (c->type == XML_ELEMENT_NODE &&
|
|
366
|
+
xmlStrcmp(c->name, (const xmlChar*)"title") == 0)
|
|
367
|
+
title = c;
|
|
368
|
+
if (!title || !title->children || !title->children->content ||
|
|
369
|
+
!title->children->content[0]) {
|
|
370
|
+
xmlXPathFreeObject(entries);
|
|
371
|
+
xmlXPathFreeContext(ctx);
|
|
372
|
+
xmlFreeDoc(doc);
|
|
373
|
+
return 1;
|
|
374
|
+
}
|
|
375
|
+
xmlSetProp(e, (const xmlChar*)"normalized", (const xmlChar*)"1");
|
|
376
|
+
xmlNewChild(e, NULL, (const xmlChar*)"generator", NULL);
|
|
377
|
+
}
|
|
378
|
+
xmlXPathFreeObject(entries);
|
|
379
|
+
xmlXPathFreeContext(ctx);
|
|
380
|
+
xmlChar* dump = NULL;
|
|
381
|
+
int dump_len = 0;
|
|
382
|
+
xmlDocDumpMemory(doc, &dump, &dump_len);
|
|
383
|
+
int ok = dump && dump_len > 0;
|
|
384
|
+
xmlFree(dump);
|
|
385
|
+
xmlFreeDoc(doc);
|
|
386
|
+
return ok ? 0 : 1;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
int shape_extract_libxml2(const char* xml, size_t len) {
|
|
390
|
+
xmlDocPtr doc = xmlReadMemory(xml, (int)len, NULL, NULL, 0);
|
|
391
|
+
if (!doc) return 1;
|
|
392
|
+
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
|
|
393
|
+
if (!ctx) { xmlFreeDoc(doc); return 1; }
|
|
394
|
+
xmlXPathObjectPtr sel = xmlXPathEvalExpression(
|
|
395
|
+
(const xmlChar*)"//records/record[@status='active']", ctx);
|
|
396
|
+
if (!sel || !sel->nodesetval || sel->nodesetval->nodeNr == 0) {
|
|
397
|
+
if (sel) xmlXPathFreeObject(sel);
|
|
398
|
+
xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return 1;
|
|
399
|
+
}
|
|
400
|
+
xmlXPathFreeObject(sel);
|
|
401
|
+
xmlXPathFreeContext(ctx);
|
|
402
|
+
xmlDocPtr out = xmlNewDoc((const xmlChar*)"1.0");
|
|
403
|
+
xmlNodePtr out_root = xmlNewNode(NULL, (const xmlChar*)"active-records");
|
|
404
|
+
xmlDocSetRootElement(out, out_root);
|
|
405
|
+
// Honest re-run: fresh context, fresh eval, then build.
|
|
406
|
+
ctx = xmlXPathNewContext(doc);
|
|
407
|
+
sel = xmlXPathEvalExpression(
|
|
408
|
+
(const xmlChar*)"//records/record[@status='active']", ctx);
|
|
409
|
+
if (sel && sel->nodesetval) {
|
|
410
|
+
for (int i = 0; i < sel->nodesetval->nodeNr; i++) {
|
|
411
|
+
xmlNodePtr rec = sel->nodesetval->nodeTab[i];
|
|
412
|
+
xmlChar* id = xmlGetProp(rec, (const xmlChar*)"id");
|
|
413
|
+
xmlChar* amt = xmlGetProp(rec, (const xmlChar*)"amount");
|
|
414
|
+
if (!id || !amt) {
|
|
415
|
+
xmlFree(id); xmlFree(amt);
|
|
416
|
+
xmlXPathFreeObject(sel); xmlXPathFreeContext(ctx);
|
|
417
|
+
xmlFreeDoc(out); xmlFreeDoc(doc);
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
420
|
+
xmlNodePtr c = xmlNewChild(out_root, NULL,
|
|
421
|
+
(const xmlChar*)"r", NULL);
|
|
422
|
+
xmlSetProp(c, (const xmlChar*)"id", id);
|
|
423
|
+
xmlSetProp(c, (const xmlChar*)"amount", amt);
|
|
424
|
+
xmlFree(id); xmlFree(amt);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (sel) xmlXPathFreeObject(sel);
|
|
428
|
+
xmlXPathFreeContext(ctx);
|
|
429
|
+
xmlChar* dump = NULL;
|
|
430
|
+
int dump_len = 0;
|
|
431
|
+
xmlDocDumpMemory(out, &dump, &dump_len);
|
|
432
|
+
int ok = dump && dump_len > 0;
|
|
433
|
+
xmlFree(dump);
|
|
434
|
+
xmlFreeDoc(out);
|
|
435
|
+
xmlFreeDoc(doc);
|
|
436
|
+
return ok ? 0 : 1;
|
|
437
|
+
}
|
|
438
|
+
#endif // HAVE_LIBXML2
|
|
439
|
+
|
|
440
|
+
#ifdef HAVE_PUGIXML
|
|
441
|
+
int shape_metanorma_pugixml(const char* xml, size_t len) {
|
|
442
|
+
pugi::xml_document doc;
|
|
443
|
+
if (!doc.load_buffer(xml, len)) return 1;
|
|
444
|
+
pugi::xpath_node_set terms =
|
|
445
|
+
doc.select_nodes("//standard/clause/terms/term");
|
|
446
|
+
if (terms.empty()) return 1;
|
|
447
|
+
pugi::xpath_node_set clauses =
|
|
448
|
+
doc.select_nodes("//standard/clause");
|
|
449
|
+
char idbuf[32];
|
|
450
|
+
for (size_t i = 0; i < clauses.size(); i++) {
|
|
451
|
+
snprintf(idbuf, sizeof idbuf, "sec-%zu", i);
|
|
452
|
+
clauses[i].node().append_attribute("rev-id") = idbuf;
|
|
453
|
+
}
|
|
454
|
+
for (pugi::xpath_node tn : terms)
|
|
455
|
+
tn.node().append_child("review");
|
|
456
|
+
std::string dump;
|
|
457
|
+
struct Sink : pugi::xml_writer {
|
|
458
|
+
std::string s;
|
|
459
|
+
void write(const void* data, size_t n) override {
|
|
460
|
+
s.append((const char*)data, n);
|
|
461
|
+
}
|
|
462
|
+
} sink;
|
|
463
|
+
doc.save(sink, "", pugi::format_raw | pugi::format_no_declaration);
|
|
464
|
+
dump = sink.s;
|
|
465
|
+
return dump.empty() ? 1 : 0;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
int shape_config_pugixml(const char* xml, size_t len) {
|
|
469
|
+
pugi::xml_document doc;
|
|
470
|
+
if (!doc.load_buffer(xml, len)) return 1;
|
|
471
|
+
static const char* ASSERTS[] = {
|
|
472
|
+
"//service[@host]",
|
|
473
|
+
"count(//service[not(@port)])",
|
|
474
|
+
"count(//service[@tls='true'])",
|
|
475
|
+
"count(//service/route)",
|
|
476
|
+
"boolean(//defaults)",
|
|
477
|
+
};
|
|
478
|
+
pugi::xpath_node_set sanity =
|
|
479
|
+
doc.select_nodes(ASSERTS[0]);
|
|
480
|
+
if (sanity.empty()) return 1;
|
|
481
|
+
for (size_t a = 1;
|
|
482
|
+
a < sizeof ASSERTS / sizeof ASSERTS[0]; a++) {
|
|
483
|
+
pugi::xpath_query q(ASSERTS[a]);
|
|
484
|
+
(void)q.evaluate_number(doc); // the value is the PASS/FAIL
|
|
485
|
+
// verdict; the rig only needs
|
|
486
|
+
// the evaluation to run
|
|
487
|
+
}
|
|
488
|
+
std::string dump;
|
|
489
|
+
struct Sink : pugi::xml_writer {
|
|
490
|
+
std::string s;
|
|
491
|
+
void write(const void* data, size_t n) override {
|
|
492
|
+
s.append((const char*)data, n);
|
|
493
|
+
}
|
|
494
|
+
} sink;
|
|
495
|
+
doc.save(sink, "", pugi::format_raw | pugi::format_no_declaration);
|
|
496
|
+
dump = sink.s;
|
|
497
|
+
return dump.empty() ? 1 : 0;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
int shape_feed_pugixml(const char* xml, size_t len) {
|
|
501
|
+
pugi::xml_document doc;
|
|
502
|
+
if (!doc.load_buffer(xml, len)) return 1;
|
|
503
|
+
pugi::xpath_node_set entries = doc.select_nodes("//feed/entry");
|
|
504
|
+
if (entries.empty()) return 1;
|
|
505
|
+
for (pugi::xpath_node en : entries) {
|
|
506
|
+
if (en.node().child("title").text().empty()) return 1;
|
|
507
|
+
en.node().append_attribute("normalized") = "1";
|
|
508
|
+
en.node().append_child("generator");
|
|
509
|
+
}
|
|
510
|
+
struct Sink : pugi::xml_writer {
|
|
511
|
+
std::string s;
|
|
512
|
+
void write(const void* data, size_t n) override {
|
|
513
|
+
s.append((const char*)data, n);
|
|
514
|
+
}
|
|
515
|
+
} sink;
|
|
516
|
+
doc.save(sink, "", pugi::format_raw | pugi::format_no_declaration);
|
|
517
|
+
return sink.s.empty() ? 1 : 0;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
int shape_extract_pugixml(const char* xml, size_t len) {
|
|
521
|
+
pugi::xml_document doc;
|
|
522
|
+
if (!doc.load_buffer(xml, len)) return 1;
|
|
523
|
+
pugi::xpath_node_set sel =
|
|
524
|
+
doc.select_nodes("//records/record[@status='active']");
|
|
525
|
+
if (sel.empty()) return 1;
|
|
526
|
+
pugi::xml_document out;
|
|
527
|
+
pugi::xml_node out_root = out.append_child("active-records");
|
|
528
|
+
for (pugi::xpath_node sn : sel) {
|
|
529
|
+
pugi::xml_attribute id = sn.node().attribute("id");
|
|
530
|
+
pugi::xml_attribute amt = sn.node().attribute("amount");
|
|
531
|
+
if (!id || !amt) return 1;
|
|
532
|
+
pugi::xml_node c = out_root.append_child("r");
|
|
533
|
+
pugi::xml_attribute cid = c.append_attribute("id");
|
|
534
|
+
cid.set_value(id.value());
|
|
535
|
+
pugi::xml_attribute camt = c.append_attribute("amount");
|
|
536
|
+
camt.set_value(amt.value());
|
|
537
|
+
}
|
|
538
|
+
struct Sink : pugi::xml_writer {
|
|
539
|
+
std::string s;
|
|
540
|
+
void write(const void* data, size_t n) override {
|
|
541
|
+
s.append((const char*)data, n);
|
|
542
|
+
}
|
|
543
|
+
} sink;
|
|
544
|
+
out.save(sink, "", pugi::format_raw | pugi::format_no_declaration);
|
|
545
|
+
return sink.s.empty() ? 1 : 0;
|
|
546
|
+
}
|
|
547
|
+
#endif // HAVE_PUGIXML
|
|
548
|
+
|
|
549
|
+
// ------------------------------------------------------------------
|
|
550
|
+
// Shape table + the interleaved driver
|
|
551
|
+
// ------------------------------------------------------------------
|
|
552
|
+
|
|
553
|
+
struct Shape {
|
|
554
|
+
const char* name;
|
|
555
|
+
const char* corpus;
|
|
556
|
+
int (*leptris_fn)(const char*, size_t);
|
|
557
|
+
#ifdef HAVE_LIBXML2
|
|
558
|
+
int (*libxml2_fn)(const char*, size_t);
|
|
559
|
+
#endif
|
|
560
|
+
#ifdef HAVE_PUGIXML
|
|
561
|
+
int (*pugixml_fn)(const char*, size_t);
|
|
562
|
+
#endif
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
const Shape SHAPES[] = {
|
|
566
|
+
{"metanorma-compile", "fixtures/pipeline_metanorma.xml",
|
|
567
|
+
shape_metanorma_leptris,
|
|
568
|
+
#ifdef HAVE_LIBXML2
|
|
569
|
+
shape_metanorma_libxml2,
|
|
570
|
+
#endif
|
|
571
|
+
#ifdef HAVE_PUGIXML
|
|
572
|
+
shape_metanorma_pugixml,
|
|
573
|
+
#endif
|
|
574
|
+
},
|
|
575
|
+
{"config-validation", "fixtures/pipeline_config.xml",
|
|
576
|
+
shape_config_leptris,
|
|
577
|
+
#ifdef HAVE_LIBXML2
|
|
578
|
+
shape_config_libxml2,
|
|
579
|
+
#endif
|
|
580
|
+
#ifdef HAVE_PUGIXML
|
|
581
|
+
shape_config_pugixml,
|
|
582
|
+
#endif
|
|
583
|
+
},
|
|
584
|
+
{"feed-normalization", "fixtures/pipeline_feed.xml",
|
|
585
|
+
shape_feed_leptris,
|
|
586
|
+
#ifdef HAVE_LIBXML2
|
|
587
|
+
shape_feed_libxml2,
|
|
588
|
+
#endif
|
|
589
|
+
#ifdef HAVE_PUGIXML
|
|
590
|
+
shape_feed_pugixml,
|
|
591
|
+
#endif
|
|
592
|
+
},
|
|
593
|
+
{"extract-transform", "fixtures/pipeline_records.xml",
|
|
594
|
+
shape_extract_leptris,
|
|
595
|
+
#ifdef HAVE_LIBXML2
|
|
596
|
+
shape_extract_libxml2,
|
|
597
|
+
#endif
|
|
598
|
+
#ifdef HAVE_PUGIXML
|
|
599
|
+
shape_extract_pugixml,
|
|
600
|
+
#endif
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
} // namespace
|
|
605
|
+
|
|
606
|
+
int main(int argc, char** argv) {
|
|
607
|
+
int reps = argc > 1 ? atoi(argv[1]) : 25;
|
|
608
|
+
if (reps < 5) reps = 5;
|
|
609
|
+
#ifdef HAVE_LIBXML2
|
|
610
|
+
xmlInitParser();
|
|
611
|
+
#endif
|
|
612
|
+
|
|
613
|
+
printf("# pipeline shapes — interleaved-median, %d reps per side\n",
|
|
614
|
+
reps);
|
|
615
|
+
|
|
616
|
+
for (const Shape& s : SHAPES) {
|
|
617
|
+
std::vector<char> xml = load_corpus(s.corpus);
|
|
618
|
+
|
|
619
|
+
// Correctness gate first: a shape that fails the structural
|
|
620
|
+
// checks disqualifies its own rig (exit nonzero) rather than
|
|
621
|
+
// printing a speed number for a broken script.
|
|
622
|
+
if (s.leptris_fn(xml.data(), xml.size() - 1)) {
|
|
623
|
+
printf("shape=%s engine=leptris ERROR rig-failed\n", s.name);
|
|
624
|
+
return 3;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
std::vector<double> lep_samples;
|
|
628
|
+
lep_samples.reserve((size_t)reps);
|
|
629
|
+
for (int r = 0; r < reps; r++) {
|
|
630
|
+
double t0 = now_us();
|
|
631
|
+
if (s.leptris_fn(xml.data(), xml.size() - 1)) {
|
|
632
|
+
printf("shape=%s engine=leptris ERROR rig-failed-mid\n",
|
|
633
|
+
s.name);
|
|
634
|
+
return 3;
|
|
635
|
+
}
|
|
636
|
+
lep_samples.push_back(now_us() - t0);
|
|
637
|
+
}
|
|
638
|
+
double lep_med = median_of(lep_samples);
|
|
639
|
+
printf("shape=%s engine=leptris median_us=%.1f reps=%d\n",
|
|
640
|
+
s.name, lep_med, reps);
|
|
641
|
+
|
|
642
|
+
#ifdef HAVE_LIBXML2
|
|
643
|
+
if (s.libxml2_fn && s.libxml2_fn(xml.data(), xml.size() - 1)) {
|
|
644
|
+
printf("shape=%s engine=libxml2 ERROR rig-failed\n", s.name);
|
|
645
|
+
return 3;
|
|
646
|
+
}
|
|
647
|
+
// Interleave: rerun leptris BETWEEN competitor reps so the
|
|
648
|
+
// ordering alternates (L O L O … / O L O L … by parity).
|
|
649
|
+
std::vector<double> lx_samples;
|
|
650
|
+
lx_samples.reserve((size_t)reps);
|
|
651
|
+
for (int r = 0; r < reps; r++) {
|
|
652
|
+
if (r % 2 == 0) s.leptris_fn(xml.data(), xml.size() - 1);
|
|
653
|
+
double t0 = now_us();
|
|
654
|
+
s.libxml2_fn(xml.data(), xml.size() - 1);
|
|
655
|
+
lx_samples.push_back(now_us() - t0);
|
|
656
|
+
if (r % 2 == 1) s.leptris_fn(xml.data(), xml.size() - 1);
|
|
657
|
+
}
|
|
658
|
+
double lx_med = median_of(lx_samples);
|
|
659
|
+
printf("shape=%s engine=libxml2 median_us=%.1f reps=%d\n",
|
|
660
|
+
s.name, lx_med, reps);
|
|
661
|
+
if (lx_med > 0.0)
|
|
662
|
+
printf("ratio=%s leptris/libxml2=%.3f\n",
|
|
663
|
+
s.name, lep_med / lx_med);
|
|
664
|
+
#endif
|
|
665
|
+
|
|
666
|
+
#ifdef HAVE_PUGIXML
|
|
667
|
+
if (s.pugixml_fn && s.pugixml_fn(xml.data(), xml.size() - 1)) {
|
|
668
|
+
printf("shape=%s engine=pugixml ERROR rig-failed\n", s.name);
|
|
669
|
+
return 3;
|
|
670
|
+
}
|
|
671
|
+
std::vector<double> px_samples;
|
|
672
|
+
px_samples.reserve((size_t)reps);
|
|
673
|
+
for (int r = 0; r < reps; r++) {
|
|
674
|
+
if (r % 2 == 0) s.leptris_fn(xml.data(), xml.size() - 1);
|
|
675
|
+
double t0 = now_us();
|
|
676
|
+
s.pugixml_fn(xml.data(), xml.size() - 1);
|
|
677
|
+
px_samples.push_back(now_us() - t0);
|
|
678
|
+
if (r % 2 == 1) s.leptris_fn(xml.data(), xml.size() - 1);
|
|
679
|
+
}
|
|
680
|
+
double px_med = median_of(px_samples);
|
|
681
|
+
printf("shape=%s engine=pugixml median_us=%.1f reps=%d\n",
|
|
682
|
+
s.name, px_med, reps);
|
|
683
|
+
if (px_med > 0.0)
|
|
684
|
+
printf("ratio=%s leptris/pugixml=%.3f\n",
|
|
685
|
+
s.name, lep_med / px_med);
|
|
686
|
+
#endif
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
#ifdef HAVE_LIBXML2
|
|
690
|
+
xmlCleanupParser();
|
|
691
|
+
#endif
|
|
692
|
+
return 0;
|
|
693
|
+
}
|