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 "splay.h"
27static void splayprint(struct Curl_tree *t, int d, char output)
28{
29 struct Curl_tree *node;
30 int i;
31 int count;
32 if(!t)
33 return;
35 splayprint(t->larger, d + 1, output);
36 for(i = 0; i < d; i++)
37 if(output)
38 curl_mprintf(" ");
40 if(output) {
41 curl_mprintf("0.%ld[%d]", (long)t->key, i);
42 }
44 for(count = 0, node = t->same; node; node = node->same, count++)
45 ;
47 if(output) {
48 if(count)
49 curl_mprintf(" [%d more]\n", count);
50 else
51 curl_mprintf("\n");
52 }
54 splayprint(t->smaller, d + 1, output);
55}
57static void test_timeouts_nonzero_usec_base(void)
58{
59 struct Curl_timeouts timeouts;
60 struct Curl_tree node;
61 struct curltime base;
62 struct curltime deadline;
63 struct curltime now;
64 timediff_t original_deadline_offset;
65 timediff_t original_now_offset;
66 timediff_t deadline_offset;
67 timediff_t now_offset;
68 timediff_t expire_offset;
69 uint32_t mid;
70 int timeout_ms;
72 base.tv_sec = 10;
73 base.tv_usec = 750000;
74 deadline.tv_sec = 12;
75 deadline.tv_usec = 250000;
76 now.tv_sec = 11;
77 now.tv_usec = 100000;
79 original_deadline_offset = curlx_ptimediff_us(&deadline, &base);
80 original_now_offset = curlx_ptimediff_us(&now, &base);
82 Curl_timeouts_init(&timeouts, &base);
83 deadline_offset = Curl_timeouts_offset_us(&timeouts, &deadline);
84 now_offset = Curl_timeouts_offset_us(&timeouts, &now);
86 fail_unless(deadline_offset - original_deadline_offset == base.tv_usec,
87 "deadline offset did not shift by the base microseconds");
88 fail_unless(now_offset - original_now_offset == base.tv_usec,
89 "now offset did not shift by the base microseconds");
91 memset(&node, 0, sizeof(node));
92 timeouts.tree = splayinsert(deadline_offset, timeouts.tree, &node, 42);
93 timeout_ms = Curl_timeouts_next_ms(&timeouts, &now, &expire_offset, &mid);
95 fail_unless(timeout_ms == 1150, "timeout changed with whole-second base");
96 fail_unless(expire_offset == deadline_offset, "wrong expiry offset");
97 fail_unless(mid == 42, "wrong timeout id");
98}
100static CURLcode test_unit1309(const char *arg)
101{
102 UNITTEST_BEGIN_SIMPLE
104/* number of nodes to add to the splay tree */
105#define NUM_NODES 50
107 struct Curl_tree *root, *removed;
108 struct Curl_tree nodes[NUM_NODES * 3];
109 int rc;
110 size_t i, j;
111 timediff_t tv_now = 0, timeout_last;
112 root = NULL; /* the empty tree */
114 /* add nodes */
115 for(i = 0; i < NUM_NODES; i++) {
116 timediff_t key;
118 key = (541 * i) % 1023;
119 root = splayinsert(key, root, &nodes[i], (uint32_t)key);
120 fail_unless(nodes[i].registered, "node should have been registered");
121 }
123 puts("Result:");
124 splayprint(root, 0, 1);
126 for(i = 0; i < NUM_NODES; i++) {
127 size_t rem = (i + 7) % NUM_NODES;
128 curl_mprintf("Tree look:\n");
129 splayprint(root, 0, 1);
130 curl_mprintf("remove node %d, payload %u\n", (int)rem,
131 Curl_splayget(&nodes[rem]));
132 rc = splayremove(root, &nodes[rem], &root);
133 if(rc) {
134 /* failed! */
135 curl_mprintf("remove %d failed!\n", (int)rem);
136 fail("remove");
137 }
138 fail_unless(!nodes[rem].registered, "node should not be registered");
139 rc = splayremove(root, &nodes[rem], &root);
140 if(!rc) {
141 /* failed! */
142 curl_mprintf("double remove %d did not fail!\n", (int)rem);
143 fail("double remove");
144 }
145 }
147 fail_unless(!root, "tree not empty after removing all nodes");
149 /* rebuild tree */
150 for(i = 0; i < NUM_NODES; i++) {
151 timediff_t key;
153 key = (541 * i) % 1023;
155 /* add some nodes with the same key */
156 for(j = 0; j <= i % 3; j++) {
157 root = splayinsert(key, root, &nodes[(i * 3) + j],
158 (uint32_t)(key * 10 + j));
159 }
160 }
162 removed = NULL;
163 for(i = 0; i <= 1100; i += 100) {
164 curl_mprintf("Removing nodes not larger than %d\n", (int)i);
165 tv_now = i;
166 root = splaygetbest(tv_now, root, &removed);
167 while(removed) {
168 curl_mprintf("removed payload %u[%u]\n",
169 Curl_splayget(removed) / 10,
170 Curl_splayget(removed) % 10);
171 root = splaygetbest(tv_now, root, &removed);
172 }
173 }
175 fail_unless(!root, "tree not empty when it should be");
177 /* rebuild tree with duplicate values */
178 for(i = 0; i < NUM_NODES; i++) {
179 timediff_t key = (541 * i) % 128;
180 root = splayinsert(key, root, &nodes[i], (uint32_t)i);
181 }
183 removed = NULL;
184 timeout_last = -1;
185 for(i = 0; i <= 128; i += 32) {
186 curl_mprintf("Removing nodes not larger than %d\n", (int)i);
187 root = splaygetbest(i, root, &removed);
188 while(removed) {
189 curl_mprintf("removed payload %u[timeout=%d]\n",
190 Curl_splayget(removed), (int)removed->key);
191 if(removed->key < timeout_last) {
192 /* failed! */
193 curl_mprintf("remove timeout %d is smaller than last %d!\n",
194 (int)removed->key, (int)timeout_last);
195 fail("wrong timeout order");
196 }
197 timeout_last = removed->key;
198 root = splaygetbest(i, root, &removed);
199 }
200 }
202 fail_unless(!root, "tree not empty when it should be");
204 test_timeouts_nonzero_usec_base();
206 UNITTEST_END_SIMPLE
207}
Diagnostics4 git calls · 280 ms
CallStatusSizeTime0280 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=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 · 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=275 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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.1 KiB275 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2180 git.response.cache=MISS git.response.duration_ms=275 git.fetch.wants=95034d6adf22d85be07e104475305568458de50f 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=2180 git.pkt.payload.max=2159 git.sideband.band1.bytes=2158 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
- a5e2eab73b844bc2
- Request
- 9cef0495…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format