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 "hash.h"
27static const size_t slots = 3;
29static void t1603_mydtor(void *p)
30{
31 /* Data are statically allocated */
32 (void)p;
33}
35static size_t elem_dtor_calls;
37static void my_elem_dtor(const void *key, size_t key_len, void *p)
38{
39 (void)p;
40 (void)key;
41 (void)key_len;
42 ++elem_dtor_calls;
43}
45static CURLcode t1603_setup(struct Curl_hash *hash_static)
46{
47 Curl_hash_init(hash_static, slots, CURL_HASH_TYPE_BYTES, t1603_mydtor);
48 return CURLE_OK;
49}
51static void t1603_stop(struct Curl_hash *hash_static)
52{
53 Curl_hash_destroy(hash_static);
54}
56static void t1603_test_socket_type(void)
57{
58 struct Curl_hash hash;
59 curl_socket_t key = 1;
60 curl_socket_t collision = (curl_socket_t)(slots + 1);
61 int value = 1;
62 int collision_value = 2;
63 int replacement_value = 3;
64#if SIZEOF_CURL_SOCKET_T > 4
65 curl_socket_t high_key = ((curl_socket_t)1 << 32) + 1;
66 int high_value = 4;
67#endif
69 Curl_hash_init(&hash, slots, CURL_HASH_TYPE_SOCKET, t1603_mydtor);
70 fail_unless(!Curl_hash_add(&hash, &key, sizeof(key) - 1, &value),
71 "invalid socket key length was accepted");
72 fail_unless(!hash.table, "invalid socket key allocated a hash table");
73 fail_unless(!Curl_hash_pick(&hash, &key, sizeof(key) - 1),
74 "invalid socket key lookup succeeded");
75 fail_unless(Curl_hash_delete(&hash, &key, sizeof(key) - 1),
76 "invalid socket key deletion succeeded");
77 fail_unless(Curl_hash_add(&hash, &key, sizeof(key), &value) == &value,
78 "socket key insertion failed");
79 fail_unless(hash.table && hash.table[1],
80 "socket key used the wrong hash slot");
81 fail_unless(Curl_hash_add(&hash, &key, sizeof(key), &replacement_value) ==
82 &replacement_value, "socket key replacement failed");
83 fail_unless(Curl_hash_count(&hash) == 1,
84 "socket key replacement changed the hash count");
85 fail_unless(Curl_hash_pick(&hash, &key, sizeof(key)) == &replacement_value,
86 "socket key replacement lookup failed");
87 fail_unless(Curl_hash_add(&hash, &collision, sizeof(collision),
88 &collision_value) == &collision_value,
89 "colliding socket key insertion failed");
90 fail_unless(Curl_hash_count(&hash) == 2, "wrong socket hash count");
91 fail_unless(Curl_hash_pick(&hash, &collision, sizeof(collision)) ==
92 &collision_value, "colliding socket key lookup failed");
93#if SIZEOF_CURL_SOCKET_T > 4
94 fail_unless(Curl_hash_add(&hash, &high_key, sizeof(high_key), &high_value) ==
95 &high_value, "wide socket key insertion failed");
96 fail_unless(hash.table && hash.table[2],
97 "wide socket key used the wrong hash slot");
98 fail_unless(Curl_hash_count(&hash) == 3, "wrong wide socket hash count");
99 fail_unless(Curl_hash_pick(&hash, &high_key, sizeof(high_key)) ==
100 &high_value, "wide socket key lookup failed");
101#endif
102 fail_unless(!Curl_hash_delete(&hash, &key, sizeof(key)),
103 "socket key deletion failed");
104 fail_unless(!Curl_hash_pick(&hash, &key, sizeof(key)),
105 "deleted socket key was found");
106 fail_unless(Curl_hash_pick(&hash, &collision, sizeof(collision)) ==
107 &collision_value, "collision was lost after deletion");
108 Curl_hash_destroy(&hash);
109}
111static CURLcode test_unit1603(const char *arg)
112{
113 struct Curl_hash hash_static;
115 UNITTEST_BEGIN(t1603_setup(&hash_static))
117 char key1[] = "key1";
118 char key2[] = "key2b";
119 char key3[] = "key3";
120 char key4[] = "key4";
121 char notakey[] = "notakey";
122 const char *nodep;
123 int rc;
125 fail_unless(hash_str_seeded("a", 1, 97, 0x1234) == 95,
126 "seeded hash is not computed as expected");
128 /* Ensure the key hashes are as expected in order to test both hash
129 collisions and a full table. Unfortunately, the hashes can vary
130 between architectures. */
131 if(hash_str(key1, strlen(key1), slots) != 1 ||
132 hash_str(key2, strlen(key2), slots) != 0 ||
133 hash_str(key3, strlen(key3), slots) != 2 ||
134 hash_str(key4, strlen(key4), slots) != 1)
135 curl_mfprintf(stderr,
136 "Warning: hashes are not computed as expected on this "
137 "architecture; test coverage is less comprehensive\n");
139 nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &key1);
140 fail_unless(nodep, "insertion into hash failed");
141 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
142 fail_unless(nodep == key1, "hash retrieval failed");
144 nodep = Curl_hash_add(&hash_static, &key2, strlen(key2), &key2);
145 fail_unless(nodep, "insertion into hash failed");
146 nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
147 fail_unless(nodep == key2, "hash retrieval failed");
149 nodep = Curl_hash_add(&hash_static, &key3, strlen(key3), &key3);
150 fail_unless(nodep, "insertion into hash failed");
151 nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
152 fail_unless(nodep == key3, "hash retrieval failed");
154 /* The fourth element exceeds the number of slots & collides */
155 nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
156 fail_unless(nodep, "insertion into hash failed");
157 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
158 fail_unless(nodep == key4, "hash retrieval failed");
160 /* Make sure all elements are still accessible */
161 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
162 fail_unless(nodep == key1, "hash retrieval failed");
163 nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
164 fail_unless(nodep == key2, "hash retrieval failed");
165 nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
166 fail_unless(nodep == key3, "hash retrieval failed");
167 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
168 fail_unless(nodep == key4, "hash retrieval failed");
170 /* Delete the second of two entries in a bucket */
171 rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
172 fail_unless(rc == 0, "hash delete failed");
173 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
174 fail_unless(nodep == key1, "hash retrieval failed");
175 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
176 fail_unless(!nodep, "hash retrieval should have failed");
178 /* Insert that deleted node again */
179 nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
180 fail_unless(nodep, "insertion into hash failed");
181 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
182 fail_unless(nodep == key4, "hash retrieval failed");
184 /* Delete the first of two entries in a bucket */
185 rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
186 fail_unless(rc == 0, "hash delete failed");
187 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
188 fail_unless(!nodep, "hash retrieval should have failed");
189 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
190 fail_unless(nodep == key4, "hash retrieval failed");
192 /* Delete the remaining one of two entries in a bucket */
193 rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
194 fail_unless(rc == 0, "hash delete failed");
195 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
196 fail_unless(!nodep, "hash retrieval should have failed");
197 nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
198 fail_unless(!nodep, "hash retrieval should have failed");
200 /* Delete an already deleted node */
201 rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
202 fail_unless(rc, "hash delete should have failed");
204 /* Replace an existing node */
205 nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), ¬akey);
206 fail_unless(nodep, "insertion into hash failed");
207 nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
208 fail_unless(nodep == notakey, "hash retrieval failed");
210 /* Make sure all remaining elements are still accessible */
211 nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
212 fail_unless(nodep == key2, "hash retrieval failed");
213 nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
214 fail_unless(nodep == key3, "hash retrieval failed");
216 /* Add element with own destructor */
217 nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
218 my_elem_dtor);
219 fail_unless(nodep, "add2 insertion into hash failed");
220 fail_unless(elem_dtor_calls == 0, "element destructor count should be 0");
221 /* Add it again, should invoke destructor on first */
222 nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
223 my_elem_dtor);
224 fail_unless(nodep, "add2 again, insertion into hash failed");
225 fail_unless(elem_dtor_calls == 1, "element destructor count should be 1");
226 /* remove, should invoke destructor */
227 rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
228 fail_unless(rc == 0, "hash delete failed");
229 fail_unless(elem_dtor_calls == 2, "element destructor count should be 1");
231 /* Clean up */
232 Curl_hash_clean(&hash_static);
234 t1603_test_socket_type();
236 UNITTEST_END(t1603_stop(&hash_static))
237}
Diagnostics4 git calls · 177 ms
CallStatusSizeTime0177 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 · 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 · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=25 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.3 KiB149 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=149 git.response.bytes=2376 git.response.cache=MISS git.response.duration_ms=149 git.fetch.wants=121654f001ea531c29789a395b609cf8df89816f 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=2376 git.pkt.payload.max=2355 git.sideband.band1.bytes=2354 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
- a5e2e691fb78ecfa
- Request
- 77fe2126…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format