master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
25# This module contains miscellaneous functions needed in several parts of
26# the test suite.
28package testutil;
30use strict;
31use warnings;
33BEGIN {
34 use base qw(Exporter);
36 our @EXPORT = qw(
37 runclient
38 runclientoutput
39 setlogfunc
40 exerunner
41 subtextfile
42 subchars
43 subfuncs
44 subnewlines
45 subsha256base64file
46 substrippemfile
47 );
49 our @EXPORT_OK = qw(
50 clearlogs
51 logmsg
52 );
53}
55use Digest::SHA qw(sha256);
56use MIME::Base64;
58use globalconfig qw(
59 $torture
60 $verbose
61 $dev_null
62 );
64my $logfunc; # optional reference to function for logging
65my @logmessages; # array holding logged messages
67#######################################################################
68# Log an informational message
69# If a log callback function was set in setlogfunc, it is called. If not,
70# then the log message is buffered until retrieved by clearlogs.
71#
72# logmsg must only be called by one of the runner_* entry points and functions
73# called by them, or else logs risk being lost, since those are the only
74# functions that know about and return buffered logs.
75sub logmsg {
76 if(!scalar(@_)) {
77 return;
78 }
79 if(defined $logfunc) {
80 &$logfunc(@_);
81 return;
82 }
83 push @logmessages, @_;
84}
86#######################################################################
87# Set the function to use for logging
88sub setlogfunc {
89 ($logfunc) = @_;
90}
92#######################################################################
93# Clear the buffered log messages after returning them
94sub clearlogs {
95 my $loglines = join('', @logmessages);
96 undef @logmessages;
97 return $loglines;
98}
100#######################################################################
102sub includefile {
103 my ($f, $text) = @_;
104 open(F, "<", $f);
105 if($text) {
106 binmode F, ':crlf';
107 }
108 my @a = <F>;
109 close(F);
110 return join("", @a);
111}
113sub subtextfile {
114 my ($thing) = @_;
116 my $count = ($$thing =~ s/%includetext ([^%]*)%[\n\r]+/includefile($1, 1)/ge);
118 return $count > 0;
119}
121sub subchars {
122 my ($thing) = @_;
124 $$thing =~ s/%SP/ /g; # space
125 $$thing =~ s/%TAB/\t/g; # horizontal tab
126 $$thing =~ s/%CR/\r/g; # carriage return aka \r aka 0x0d
127 $$thing =~ s/%LT/</g;
128 $$thing =~ s/%GT/>/g;
129 $$thing =~ s/%AMP/&/g;
130}
132sub repeatit {
133 my ($n, $d)=@_;
134 # decode %NN characters
136 $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
137 $n =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
138 return $d x $n;
139}
141sub hexit {
142 my ($d) = @_;
143 $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
144 return $d;
145}
147sub b64it {
148 my ($d) = @_;
149 # encode %NN characters
150 $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
151 my $enc = encode_base64($d, "");
152 # put the result into there
153 return $enc;
154}
156sub daysit {
157 my ($days) = @_;
158 # convert to now + given days in epoch seconds, align to a 60 second
159 # boundary. Then provide two alternatives.
160 my $now = time();
161 my $d = ($days * 24 * 3600) + $now + 30;
162 $d = int($d / 60) * 60;
163 my $d2 = $d + 60;
164 return "%alternatives[$d,$d2]";
165}
167sub subfuncs {
168 my ($thing) = @_;
170 $$thing =~ s/%b64\[(.*?)\]b64%/b64it($1)/eg;
171 $$thing =~ s/%hex\[(.*?)\]hex%/hexit($1)/eg;
172 $$thing =~ s/%repeat\[(\d+) x (.*?)\]%/repeatit($1, $2)/eg;
173 $$thing =~ s/%days\[(.*?)\]/daysit($1)/eg;
174 $$thing =~ s/%include ([^%]*)%[\n\r]+/includefile($1, 0)/ge;
175}
177my $prevupdate; # module scope so it remembers the last value
178sub subnewlines {
179 my ($force, $thing) = @_;
181 if($force) {
182 # enforce CRLF newline
183 $$thing =~ s/\x0d*\x0a/\x0d\x0a/;
184 return;
185 }
187 if(($$thing =~ /^HTTP\/(1.1|1.0|2|3) ([1-5]|9)[^\x0d]*\z/) ||
188 ($$thing =~ /^(GET|HEAD|POST|PUT|DELETE|CONNECT) \S+ HTTP\/\d+(\.\d+)?/) ||
189 ($$thing =~ /^(SETUP|GET_PARAMETER|OPTIONS|ANNOUNCE|DESCRIBE) \S+ RTSP\/\d+(\.\d+)?/) ||
190 (($$thing =~ /^[a-z0-9_-]+: [^\x0d]*\z/i) &&
191 # skip curl error messages
192 ($$thing !~ /^curl: \(\d+\) /))) {
193 # enforce CRLF newline
194 $$thing =~ s/\x0d*\x0a/\x0d\x0a/;
195 $prevupdate = 1;
196 }
197 else {
198 if(($$thing =~ /^\n\z/) && $prevupdate) {
199 # if there is a blank line after a line we update, we hope it is
200 # the empty line following headers
201 $$thing =~ s/\x0a/\x0d\x0a/;
202 }
203 $prevupdate = 0;
204 }
205}
207#######################################################################
208# Run the application under test and return its return code
209#
210sub runclient {
211 my ($cmd) = @_;
212 my $ret = system($cmd);
213 print "CMD ($ret): $cmd\n" if($verbose && !$torture);
214 return $ret;
216# This is one way to test curl on a remote machine
217# my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
218# sleep 2; # time to allow the NFS server to be updated
219# return $out;
220}
222#######################################################################
223# Run the application under test and return its stdout
224#
225sub runclientoutput {
226 my ($cmd) = @_;
227 return qx($cmd 2>$dev_null);
229# This is one way to test curl on a remote machine
230# my @out = qx(ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\');
231# sleep 2; # time to allow the NFS server to be updated
232# return @out;
233}
235#######################################################################
236# Return custom tool (e.g. wine or qemu) to run curl binaries.
237#
238sub exerunner {
239 if($ENV{'CURL_TEST_EXE_RUNNER'}) {
240 return $ENV{'CURL_TEST_EXE_RUNNER'} . ' ';
241 }
242 return '';
243}
245sub get_sha256_base64 {
246 my ($file_path) = @_;
247 return encode_base64(sha256(do { local $/; open(my $fh, '<:raw', $file_path) or die $!; <$fh> }), "");
248}
250sub subsha256base64file {
251 my ($thing) = @_;
253 # SHA-256 base64
254 while($$thing =~ s/%sha256b64file\[(.*?)\]sha256b64file%/%%SHA256B64FILE%%/i) {
255 my $file_path = $1;
256 $file_path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
257 my $hash_b64 = get_sha256_base64($file_path);
258 $$thing =~ s/%%SHA256B64FILE%%/$hash_b64/;
259 }
260}
262sub get_file_content {
263 my ($file_path) = @_;
264 my $content = do { local $/; open(my $fh, '<', $file_path) or die $!; <$fh> };
265 $content =~ s/(^|-----END .*?-----[\r\n]?)(.*?)(-----BEGIN .*?-----|$)/$1$3/gs;
266 $content =~ s/\r\n/\n/g;
267 chomp($content);
268 return $content;
269}
271sub substrippemfile {
272 my ($thing) = @_;
274 # File content substitution
275 while($$thing =~ s/%strippemfile\[(.*?)\]strippemfile%/%%FILE%%/i) {
276 my $file_path = $1;
277 $file_path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
278 my $file_content = get_file_content($file_path);
279 $$thing =~ s/%%FILE%%/$file_content/;
280 }
281}
2821;
Diagnostics4 git calls · 426 ms
CallStatusSizeTime0426 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch 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=419 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.9 KiB419 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2977 git.response.cache=MISS git.response.duration_ms=419 git.fetch.wants=199a44109e73489296a0f1bdcf68bd74c0f7d4f6 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=2977 git.pkt.payload.max=2956 git.sideband.band1.bytes=2955 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
- a5e211b1183ac6f8
- Request
- 93964c75…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format