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

Function main

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

common_setupFunction · 0.85
set_feature_bitFunction · 0.85
test_bitFunction · 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
feature_set_for_featureFunction · 0.50
feature_is_setFunction · 0.50
feature_offeredFunction · 0.50

Tested by

no test coverage detected