MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

common/test/run-features.c:250–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250int main(int argc, char *argv[])
251{
252 u8 *bits;
253 struct feature_set *fset;
254
255 common_setup(argv[0]);
256
257 /* Just some bits to set. */
258 fset = feature_set_for_feature(tmpctx,
259 OPTIONAL_FEATURE(OPT_DATA_LOSS_PROTECT));
260
261 bits = tal_arr(tmpctx, u8, 0);
262 for (size_t i = 0; i < 100; i += 3)
263 set_feature_bit(&bits, i);
264 for (size_t i = 0; i < 100; i++)
265 assert(test_bit(bits, i / 8, i % 8) == ((i % 3) == 0));
266
267 for (size_t i = 0; i < 100; i++)
268 assert(feature_is_set(bits, i) == ((i % 3) == 0));
269
270 /* Simple test: single byte */
271 bits = tal_arr(tmpctx, u8, 1);
272
273 /* Compulsory feature */
274 bits[0] = (1 << 0);
275 assert(feature_offered(bits, 0));
276 assert(!feature_offered(bits, 2));
277 assert(!feature_offered(bits, 8));
278 assert(!feature_offered(bits, 16));
279
280 /* Optional feature */
281 bits[0] = (1 << 1);
282 assert(feature_offered(bits, 0));
283 assert(!feature_offered(bits, 2));
284 assert(!feature_offered(bits, 8));
285 assert(!feature_offered(bits, 16));
286
287 /* Endian-sensitive test: big-endian means we frob last byte here */
288 bits = tal_arrz(tmpctx, u8, 2);
289
290 bits[1] = (1 << 0);
291 assert(feature_offered(bits, 0));
292 assert(!feature_offered(bits, 2));
293 assert(!feature_offered(bits, 8));
294 assert(!feature_offered(bits, 16));
295
296 /* Optional feature */
297 bits[1] = (1 << 1);
298 assert(feature_offered(bits, 0));
299 assert(!feature_offered(bits, 2));
300 assert(!feature_offered(bits, 8));
301 assert(!feature_offered(bits, 16));
302
303 /* We always support no features. */
304 memset(bits, 0, tal_count(bits));
305 assert(features_unsupported(fset, bits, INIT_FEATURE) == -1);
306
307 /* We must support our own features. */

Callers

nothing calls this directly

Calls 12

common_setupFunction · 0.85
feature_set_for_featureFunction · 0.85
set_feature_bitFunction · 0.85
test_bitFunction · 0.85
feature_is_setFunction · 0.85
feature_offeredFunction · 0.85
test_featurebits_orFunction · 0.85
test_feature_set_orFunction · 0.85
test_feature_trimFunction · 0.85
test_feature_set_subFunction · 0.85
common_shutdownFunction · 0.85
features_unsupportedFunction · 0.70

Tested by

no test coverage detected