master
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22# SPDX-License-Identifier: curl
23#
24###########################################################################
26use strict;
27use warnings;
29# If the build is done out-of-source-tree, specify the build root dir as an
30# argument to this script. Necessary to find the generated buildprotos.h
31# header file.
32my $root = "..";
34if($ARGV[0]) {
35 $root = $ARGV[0];
36}
38# return all known test cases
39sub alltests {
40 my @a;
41 if(open(M, "<", "./data/Makefile.am")) {
42 while(<M>) {
43 if(/^ test(\d+)/) {
44 push @a, $1; # just the number
45 }
46 }
47 close(M);
48 }
49 else {
50 print STDERR "cannot open data/Makefile.am\n";
51 }
52 return @a;
53}
55sub libtests {
56 my @a;
57 if(open(M, "<", "./libtest/Makefile.inc")) {
58 while(<M>) {
59 if(/^ *lib(\d+)\.c/) {
60 push @a, $1; # just the number
61 }
62 }
63 close(M);
64 }
65 else {
66 print STDERR "cannot open Makefile.inc\n";
67 }
68 return @a;
69}
71sub tunittests {
72 my @a;
73 if(open(M, "<", "./tunit/Makefile.inc")) {
74 while(<M>) {
75 if(/^ *tool(\d+)\.c/) {
76 push @a, $1; # just the number
77 }
78 }
79 close(M);
80 }
81 else {
82 print STDERR "cannot open Makefile.inc\n";
83 }
84 return @a;
85}
87sub unittests {
88 my @a;
89 if(open(M, "<", "./unit/Makefile.inc")) {
90 while(<M>) {
91 if(/^ *unit(\d+)\.c/) {
92 push @a, $1; # just the number
93 }
94 }
95 close(M);
96 }
97 else {
98 print STDERR "cannot open Makefile.inc\n";
99 }
100 return @a;
101}
103# provided a test number, return the keywords it uses
104sub keywords {
105 my ($num) = @_;
106 if(open(my $fh, "<", "./data/test$num")) {
107 local $/;
108 my $c = <$fh>;
109 close($fh);
111 # Match and extract the <keywords> block
112 if ($c =~ /<keywords>\n(.*?)<\/keywords>/s) {
113 return split(/\n/, $1);
114 }
115 }
116 else {
117 print STDERR "cannot open test$num\n";
118 }
119 return undef;
120}
122# provided a test number, return the <tool> it uses
123sub tool {
124 my ($num) = @_;
125 if(open(my $fh, "<", "./data/test$num")) {
126 local $/;
127 my $c = <$fh>;
128 close($fh);
130 # Match and extract the <tool> block
131 if ($c =~ /<tool>\n(.*?)<\/tool>/s) {
132 return split(/\n/, $1);
133 }
134 }
135 else {
136 print STDERR "cannot open test$num\n";
137 }
138 return undef;
139}
141# return all the function names that are prototyped here, as a hash
142sub unitprotos {
143 my ($num) = @_;
144 my %protos;
145 if(open(my $fh, "<", "$root/lib/unitprotos.h")) {
146 while(<$fh>) {
147 if(/^UNITTEST .*[* ]([a-z0-9_]+)\(/i) {
148 $protos{$1} = 1;
149 }
150 }
151 close($fh);
152 }
153 else {
154 print STDERR "cannot open unitprotos.h\n";
155 }
156 return %protos;
157}
159# check if this unit test actually uses any internal symbols
160sub checkunit {
161 my ($num, $protref) = @_;
162 my $private = 0;
163 if(open(my $fh, "<", "./unit/unit$num.c")) {
164 while(<$fh>) {
165 # check all function calls
166 while(/([a-z0-9_]+)\(/cig) {
167 my $f = $1;
168 #print "Check ($num) $f\n";
169 if($f =~ /^(Curl_|curlx_)/) {
170 $private = 1;
171 last;
172 }
173 elsif($$protref{$f}) {
174 # it uses prototyped one
175 $private = 1;
176 last;
177 }
178 }
179 if(/struct (Curl_|connectdata)/) {
180 $private = 1;
181 last;
182 }
183 elsif(/\bCURLPROTO_(WS|WSS|MQTTS|SOCKS)\b/) {
184 $private = 1;
185 last;
186 }
187 }
188 close($fh);
189 }
190 else {
191 print STDERR "cannot open unit$num.c\n";
192 }
193 if(!$private) {
194 print "Unit test $num uses no private functions or structs\n";
195 }
196 return !$private;
197}
199sub checkxml {
200 my ($num) = @_;
201 my $bad = 0;
202 if(open(my $fh, "<", "./data/test$num")) {
203 my $has_xml = 0;
204 my %tag_count;
205 while(<$fh>) {
206 chomp;
207 ++$tag_count{$1} if /^<([a-z0-9]+)( .+)?>$/;
208 if(/^<\?xml/) {
209 $has_xml = 1;
210 }
211 if(/^(# Server-side|# Client-side|# Verify data after the test has been \"shot\"|# tool is what to use instead of 'curl')/) {
212 print "data/test$num has superfluous comment: '$_'\n";
213 $bad = 1;
214 }
215 }
216 close($fh);
218 if(!$has_xml) {
219 print "data/test$num lacks <xml> tag\n";
220 $bad = 1;
221 }
223 for my $stat (sort { $tag_count{$a} <=> $tag_count{$b} || $a cmp $b } keys %tag_count) {
224 my $max = ($stat =~ /^(dns|file[0-9]*|postcheck)/) ? 2 : 1;
225 if($tag_count{$stat} > $max) {
226 print "data/test$num has too many '<$stat>' tags ($tag_count{$stat} vs. $max maximum)\n";
227 $bad = 1;
228 }
229 }
230 }
231 else {
232 print STDERR "cannot open test$num\n";
233 $bad = 1;
234 }
235 return $bad;
236}
238my $error;
239my @l;
241print "- Tests with source code in libtests/ have 'libtest' as <keyword>\n";
242@l = libtests();
243for my $t (@l) {
244 my $lt = 0;
245 my @k = keywords($t);
246 for my $w (@k) {
247 if($w eq "libtest") {
248 $lt = 1;
249 }
250 }
251 if(!$lt) {
252 print "Test $t in data/test$t lacks the 'libtest' keyword\n";
253 $error++;
254 }
255}
257print "- Tests with source code in tunit/ have 'tunittest' as <keyword>\n";
258@l = tunittests();
259for my $t (@l) {
260 my $lt = 0;
261 my @k = keywords($t);
262 for my $w (@k) {
263 if($w eq "tunittest") {
264 $lt = 1;
265 }
266 elsif($w eq "unittest") {
267 print "Test $t in data/test$t wrongly has the 'unittest' keyword\n";
268 }
269 }
270 if(!$lt) {
271 print "Test $t in data/test$t lacks the 'tunittest' keyword\n";
272 $error++;
273 }
274}
276print "- Tests with source code in unit/ have 'unittest' as <keyword>\n";
277@l = unittests();
278for my $t (@l) {
279 my $lt = 0;
280 my @k = keywords($t);
281 for my $w (@k) {
282 if($w eq "unittest") {
283 $lt = 1;
284 }
285 elsif($w eq "tunittest") {
286 print "Test $t in data/test$t wrongly has the 'tunittest' keyword\n";
287 }
288 }
289 if(!$lt) {
290 print "Test $t in data/test$t lacks the 'unittest' keyword\n";
291 $error++;
292 }
293}
295my @a = alltests();
296print "- Tests that set lib* in <tool> have 'libtest' as <keyword>\n";
297for my $t (@a) {
298 my @k = tool($t);
299 for my $w (@k) {
300 next if(!$w);
301 if($w =~ /lib%TESTNUMBER/) {
302 print "test $t invokes default tool\n";
303 $error++;
304 }
305 elsif($w =~ /lib(\d+)/) {
306 my $num = $1;
307 if($num == $t) {
308 print "test $t invokes default tool\n";
309 $error++;
310 }
311 my $lt = 0;
313 # get the keywords for test $num
314 my @k = keywords($t);
315 for my $w (@k) {
316 if($w eq "libtest") {
317 $lt = 1;
318 }
319 }
320 if(!$lt) {
321 print "Test $t in data/test$t lacks the 'libtest' keyword\n";
322 $error++;
323 }
324 }
325 }
326}
328print "- Tests that set tool* in <tool> have 'tunittest' as <keyword>\n";
329for my $t (@a) {
330 my @k = tool($t);
331 for my $w (@k) {
332 next if(!$w);
333 if($w =~ /tool%TESTNUMBER/) {
334 print "test $t invokes default tool\n";
335 $error++;
336 }
337 elsif($w =~ /tool(\d+)/) {
338 my $num = $1;
339 if($num == $t) {
340 print "test $t invokes default tool\n";
341 $error++;
342 }
343 my $lt = 0;
345 # get the keywords for test $num
346 my @k = keywords($num);
347 for my $w (@k) {
348 if($w eq "tunittest") {
349 $lt = 1;
350 }
351 }
352 if(!$lt) {
353 print "Test $t in data/test$t lacks the 'tunittest' keyword\n";
354 $error++;
355 }
356 }
357 }
358}
360print "- Tests that set unit* in <tool> have 'unittest' as <keyword>\n";
361for my $t (@a) {
362 my @k = tool($t);
363 for my $w (@k) {
364 next if(!$w);
365 if($w =~ /unit%TESTNUMBER/) {
366 print "test $t invokes default tool\n";
367 $error++;
368 }
369 elsif($w =~ /unit(\d+)/) {
370 my $num = $1;
371 if($num == $t) {
372 print "test $t invokes default tool\n";
373 $error++;
374 }
375 my $lt = 0;
377 # get the keywords for test $num
378 my @k = keywords($num);
379 for my $w (@k) {
380 if($w eq "unittest") {
381 $lt = 1;
382 }
383 }
384 if(!$lt) {
385 print "Test $t in data/test$t lacks the 'unittest' keyword\n";
386 $error++;
387 }
388 }
389 }
390}
392print "- Unit tests actually use private symbols\n";
393@l = unittests();
394my %protos = unitprotos();
395for my $t (@l) {
396 $error += checkunit($t, \%protos);
397}
399print "- All tests have <xml> tag on first line\n";
400for my $t (@a) {
401 $error += checkxml($t);
402}
404exit $error;
Diagnostics4 git calls · 43 ms
CallStatusSizeTime043 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.5 KiB · hit36 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=36 git.response.bytes=2606 git.response.cache=HIT git.response.duration_ms=36 git.fetch.wants=c64962cf0c35dcbf89973c663f77d6dd9baaea8b git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2606 git.pkt.payload.max=2585 git.sideband.band1.bytes=2584 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1c369fc2036cd
- Request
- 41bebddf…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format