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 ***************************************************************************/
24#include "unitcheck.h"
25#include "urldata.h"
26#include "bufq.h"
27#include "curl_trc.h"
29static const char *tail_err(struct bufq *q)
30{
31 struct buf_chunk *chunk;
33 if(!q->tail) {
34 return q->head ? "tail is NULL, but head is not" : NULL;
35 }
37 chunk = q->head;
38 while(chunk) {
39 if(chunk == q->tail) {
40 if(chunk->next) {
41 return "tail points to queue, but not at the end";
42 }
43 return NULL;
44 }
45 chunk = chunk->next;
46 }
47 return "tail not part of queue";
48}
50static void dump_bufq(struct bufq *q, const char *msg)
51{
52 struct buf_chunk *chunk;
53 const char *terr;
54 size_t n;
56 curl_mfprintf(stderr, "bufq[chunk_size=%zu, max_chunks=%zu] %s\n",
57 q->chunk_size, q->max_chunks, msg);
58 curl_mfprintf(stderr, "- queue[\n");
59 chunk = q->head;
60 while(chunk) {
61 curl_mfprintf(stderr, " chunk[len=%zu, roff=%zu, woff=%zu]\n",
62 chunk->dlen, chunk->r_offset, chunk->w_offset);
63 chunk = chunk->next;
64 }
65 curl_mfprintf(stderr, " ]\n");
66 terr = tail_err(q);
67 curl_mfprintf(stderr, "- tail: %s\n", terr ? terr : "ok");
68 n = 0;
69 chunk = q->spare;
70 while(chunk) {
71 ++n;
72 chunk = chunk->next;
73 }
74 curl_mfprintf(stderr, "- chunks: %zu\n", q->chunk_count);
75 curl_mfprintf(stderr, "- spares: %zu\n", n);
76}
78static void check_bufq(size_t pool_spares,
79 size_t chunk_size, size_t max_chunks,
80 size_t wsize, size_t rsize, int opts)
81{
82 static unsigned char test_data[32 * 1024];
84 struct bufq q;
85 struct bufc_pool pool;
86 size_t max_len = chunk_size * max_chunks;
87 CURLcode result;
88 ssize_t i;
89 size_t n2;
90 size_t nwritten, nread;
92 if(pool_spares > 0) {
93 Curl_bufcp_init(&pool, chunk_size, pool_spares);
94 Curl_bufq_initp(&q, &pool, max_chunks, opts);
95 }
96 else {
97 Curl_bufq_init2(&q, chunk_size, max_chunks, opts);
98 }
100 fail_unless(q.chunk_size == chunk_size, "chunk_size init wrong");
101 fail_unless(q.max_chunks == max_chunks, "max_chunks init wrong");
102 fail_unless(!q.head, "init: head not NULL");
103 fail_unless(!q.tail, "init: tail not NULL");
104 fail_unless(!q.spare, "init: spare not NULL");
105 fail_unless(Curl_bufq_len(&q) == 0, "init: bufq length != 0");
107 result = Curl_bufq_write(&q, test_data, wsize, &n2);
108 fail_unless(n2 <= wsize, "write: wrong size returned");
109 fail_unless(result == CURLE_OK, "write: wrong result returned");
111 /* write empty bufq full */
112 nwritten = 0;
113 Curl_bufq_reset(&q);
114 while(!Curl_bufq_is_full(&q)) {
115 result = Curl_bufq_write(&q, test_data, wsize, &n2);
116 if(!result) {
117 nwritten += n2;
118 }
119 else if(result != CURLE_AGAIN) {
120 fail_unless(result == CURLE_AGAIN, "write-loop: unexpected result");
121 break;
122 }
123 }
124 if(nwritten != max_len) {
125 curl_mfprintf(stderr, "%zu bytes written, but max_len=%zu\n",
126 nwritten, max_len);
127 dump_bufq(&q, "after writing full");
128 fail_if(TRUE, "write: bufq full but nwritten wrong");
129 }
131 /* read full bufq empty */
132 nread = 0;
133 while(!Curl_bufq_is_empty(&q)) {
134 result = Curl_bufq_read(&q, test_data, rsize, &n2);
135 if(!result) {
136 nread += n2;
137 }
138 else if(result != CURLE_AGAIN) {
139 fail_unless(result == CURLE_AGAIN, "read-loop: unexpected result");
140 break;
141 }
142 }
143 if(nread != max_len) {
144 curl_mfprintf(stderr, "%zu bytes read, but max_len=%zu\n",
145 nwritten, max_len);
146 dump_bufq(&q, "after reading empty");
147 fail_if(TRUE, "read: bufq empty but nread wrong");
148 }
149 if(q.tail) {
150 dump_bufq(&q, "after reading empty");
151 fail_if(TRUE, "read empty, but tail is not NULL");
152 }
154 for(i = 0; i < 1000; ++i) {
155 result = Curl_bufq_write(&q, test_data, wsize, &n2);
156 if(result && result != CURLE_AGAIN) {
157 fail_unless(result == CURLE_AGAIN, "rw-loop: unexpected write result");
158 break;
159 }
160 result = Curl_bufq_read(&q, test_data, rsize, &n2);
161 if(result && result != CURLE_AGAIN) {
162 fail_unless(result == CURLE_AGAIN, "rw-loop: unexpected read result");
163 break;
164 }
165 }
167 /* Test SOFT_LIMIT option */
168 Curl_bufq_free(&q);
169 Curl_bufq_init2(&q, chunk_size, max_chunks, (opts | BUFQ_OPT_SOFT_LIMIT));
170 nwritten = 0;
171 while(!Curl_bufq_is_full(&q)) {
172 result = Curl_bufq_write(&q, test_data, wsize, &n2);
173 if(result || n2 != wsize) {
174 fail_unless(!result && n2 == wsize, "write should be complete");
175 break;
176 }
177 nwritten += n2;
178 }
179 if(nwritten < max_len) {
180 curl_mfprintf(stderr, "%zu bytes written, but max_len=%zu\n",
181 nwritten, max_len);
182 dump_bufq(&q, "after writing full");
183 fail_if(TRUE, "write: bufq full but nwritten wrong");
184 }
185 /* do one more write on a full bufq, should work */
186 result = Curl_bufq_write(&q, test_data, wsize, &n2);
187 fail_unless(!result && n2 == wsize, "write should be complete");
188 nwritten += n2;
189 /* see that we get all out again */
190 nread = 0;
191 while(!Curl_bufq_is_empty(&q)) {
192 result = Curl_bufq_read(&q, test_data, rsize, &n2);
193 if(result) {
194 fail_unless(result, "read-loop: unexpected fail");
195 break;
196 }
197 nread += n2;
198 }
199 fail_unless(nread == nwritten, "did not get the same out as put in");
201 dump_bufq(&q, "at end of test");
202 Curl_bufq_free(&q);
203 if(pool_spares > 0)
204 Curl_bufcp_free(&pool);
205}
207static CURLcode test_unit2601(const char *arg)
208{
209 UNITTEST_BEGIN_SIMPLE
211 struct bufq q;
212 size_t n;
213 CURLcode result;
214 unsigned char buf[16 * 1024];
216 Curl_bufq_init(&q, 8 * 1024, 12);
217 result = Curl_bufq_read(&q, buf, 128, &n);
218 fail_unless(result && result == CURLE_AGAIN, "read empty fail");
219 Curl_bufq_free(&q);
221 check_bufq(0, 1024, 4, 128, 128, BUFQ_OPT_NONE);
222 check_bufq(0, 1024, 4, 129, 127, BUFQ_OPT_NONE);
223 check_bufq(0, 1024, 4, 2000, 16000, BUFQ_OPT_NONE);
224 check_bufq(0, 1024, 4, 16000, 3000, BUFQ_OPT_NONE);
226 check_bufq(0, 8000, 10, 1234, 1234, BUFQ_OPT_NONE);
227 check_bufq(0, 8000, 10, 8 * 1024, 4 * 1024, BUFQ_OPT_NONE);
229 check_bufq(0, 1024, 4, 128, 128, BUFQ_OPT_NO_SPARES);
230 check_bufq(0, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES);
231 check_bufq(0, 1024, 4, 2000, 16000, BUFQ_OPT_NO_SPARES);
232 check_bufq(0, 1024, 4, 16000, 3000, BUFQ_OPT_NO_SPARES);
234 check_bufq(8, 1024, 4, 128, 128, BUFQ_OPT_NONE);
235 check_bufq(8, 8000, 10, 1234, 1234, BUFQ_OPT_NONE);
236 check_bufq(8, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES);
238 UNITTEST_END_SIMPLE
239}
Diagnostics4 git calls · 164 ms
CallStatusSizeTime0164 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 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=3 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.2 KiB158 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=158 git.response.bytes=2236 git.response.cache=MISS git.response.duration_ms=158 git.fetch.wants=21cdb1383604563c39f3b050b9bd2b5515af277a 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=2236 git.pkt.payload.max=2215 git.sideband.band1.bytes=2214 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
- a5e1fef4be61a9c0
- Request
- 8eb917de…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format