aboutsummaryrefslogtreecommitdiffstats
path: root/tests/libosmo-gtlv/gtlv_test.c
blob: 87110630a436389de4466b50df13fec48d1c0249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*
 * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved.
 *
 * Author: Neels Janosch Hofmeyr <nhofmeyr@sysmocom.de>
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdio.h>
#include <errno.h>

#include <osmocom/core/application.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>

#include <osmocom/gtlv/gtlv.h>

void *ctx;

struct ie {
	struct osmo_gtlv_tag_inst ti;
	const char *val;
};

/* write all IEs to a msgb */
struct msgb *test_tlv_enc(const struct osmo_gtlv_cfg *cfg, const struct ie *ies)
{
	const struct ie *ie;
	struct osmo_gtlv_put gtlv = {
		.cfg = cfg,
		.dst = msgb_alloc(1024, __func__),
	};

	for (ie = ies; ie->val; ie++) {
		/* put header without knowing length yet */
		OSMO_ASSERT(osmo_gtlv_put_tli(&gtlv, &ie->ti, 0) == 0);
		/* put value data, as much as desired */
		msgb_put(gtlv.dst, osmo_hexparse(ie->val, gtlv.dst->tail, msgb_tailroom(gtlv.dst)));
		/* update header len from amount of written data */
		OSMO_ASSERT(osmo_gtlv_put_update_tl(&gtlv) == 0);
	}

	printf("- encoded: %s.\n", osmo_hexdump(gtlv.dst->data, gtlv.dst->len));
	return gtlv.dst;
}

/* read all IEs from the msgb, and verify that it matches the given list of IEs */
void test_tlv_dec(const struct osmo_gtlv_cfg *cfg, const struct ie *ies, struct msgb *msg)
{
	const struct ie *ie;
	struct osmo_gtlv_load gtlv = {
		.cfg = cfg,
		.src = { msg->data, msg->len },
	};

	printf("- decoding:\n");
	osmo_gtlv_load_start(&gtlv);

	for (ie = ies; ie->val; ie++) {
		int rc = osmo_gtlv_load_next(&gtlv);
		if (rc) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next() rc = %d\n", rc);
			exit(1);
		}
		/* end of TLV structure? */
		if (!gtlv.val)
			break;
		printf("  T=%s L=%zu", osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL), gtlv.len);
		printf(" v=%s\n", osmo_hexdump_nospc(gtlv.val, gtlv.len));
		if (gtlv.ti.tag != ie->ti.tag) {
			printf("  ERROR loading TLV structure: expected tag %u, got tag %u\n", ie->ti.tag, gtlv.ti.tag);
			exit(1);
		}
		if (strcmp(ie->val, osmo_hexdump_nospc(gtlv.val, gtlv.len))) {
			printf("  ERROR loading TLV structure: expected val %s, got val %s\n", ie->val,
			       osmo_hexdump_nospc(gtlv.val, gtlv.len));
			exit(1);
		}
	}
}

void test_tlv_peek(const struct osmo_gtlv_cfg *cfg, const struct ie *ies, struct msgb *msg)
{
	const struct ie *ie;
	struct osmo_gtlv_load gtlv = {
		.cfg = cfg,
		.src = { msg->data, msg->len },
	};

	printf("- peeking:\n");
	osmo_gtlv_load_start(&gtlv);

	ie = ies;
	while (1) {
		int rc;
		struct osmo_gtlv_tag_inst next_tag;
		rc = osmo_gtlv_load_peek_tag(&gtlv, &next_tag);
		if (rc == -ENOENT) {
			printf("  peek rc=-ENOENT\n");
		} else {
			printf("  peek T=%s", osmo_gtlv_tag_inst_to_str_c(ctx, &next_tag, NULL));
			printf("\n");
		}

		if (ie->val && osmo_gtlv_tag_inst_cmp(&next_tag, &ie->ti)) {
			printf("  ERROR peeking tag: expected tag %s, got tag %s\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL),
			       osmo_gtlv_tag_inst_to_str_c(ctx, &next_tag, NULL));
			exit(1);
		}
		if (!ie->val && rc != -ENOENT) {
			printf("  ERROR peeking tag: expected -ENOENT, got rc=%d, tag %s\n", rc,
			       osmo_gtlv_tag_inst_to_str_c(ctx, &next_tag, NULL));
			exit(1);
		}

		if (rc == -ENOENT)
			break;

		/* go to the next TLV */
		rc = osmo_gtlv_load_next(&gtlv);
		if (rc) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next() rc = %d\n", rc);
			exit(1);
		}
		if (ie->val)
			ie++;
	}
}

/* Decode TLV in random order, each time searching for a tag in the raw data */
void test_tlv_dec_by_tag(const struct osmo_gtlv_cfg *cfg, const struct ie *ies, struct msgb *msg)
{
	const struct ie *last_ie;
	const struct ie *ie;
	int rc;
	struct osmo_gtlv_load gtlv = {
		.cfg = cfg,
		.src = { msg->data, msg->len },
	};

	printf("- decoding in reverse order:\n");

	last_ie = ies;
	while (last_ie->val) last_ie++;
	last_ie--;

	for (ie = last_ie; ie >= ies; ie--) {
		/* each time, look from the beginning */
		osmo_gtlv_load_start(&gtlv);
		rc = osmo_gtlv_load_next_by_tag_inst(&gtlv, &ie->ti);
		if (rc) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next_by_tag_inst(%s) rc = %d\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL), rc);
			exit(1);
		}
		if (!gtlv.val) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next_by_tag_inst(%s) returned NULL val\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL));
			exit(1);
		}
		if (osmo_gtlv_tag_inst_cmp(&gtlv.ti, &ie->ti)) {
			printf("  ERROR loading TLV structure: expected tag %s, got tag %s\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL),
			       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL));
			exit(1);
		}
		if (strcmp(ie->val, osmo_hexdump_nospc(gtlv.val, gtlv.len))) {
			while (1) {
				printf("   (mismatch: T=%s L=%zu v=%s, checking for another occurrence of T=%s)\n",
				       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL),
				       gtlv.len,
				       osmo_hexdump_nospc(gtlv.val, gtlv.len),
				       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL));

				rc = osmo_gtlv_load_next_by_tag_inst(&gtlv, &ie->ti);
				if (rc || !gtlv.val) {
					printf("  ERROR val not found\n");
					exit(1);
				}
				if (strcmp(ie->val, osmo_hexdump_nospc(gtlv.val, gtlv.len)) == 0) {
					break;
				}
			}
		}
		printf("  T=%s L=%zu v=%s\n",
		       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL),
		       gtlv.len, osmo_hexdump_nospc(gtlv.val, gtlv.len));
	}

	printf("- decoding every second tag:\n");

	osmo_gtlv_load_start(&gtlv);
	for (ie = ies; ie->val; ie++) {
		/* skip one tag */
		ie++;
		if (!ie->val)
			break;

		rc = osmo_gtlv_load_next_by_tag_inst(&gtlv, &ie->ti);
		if (rc) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next_by_tag_inst(%s) rc = %d\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL), rc);
			exit(1);
		}
		if (!gtlv.val) {
			printf("  ERROR loading TLV structure: osmo_gtlv_load_next_by_tag_inst(%s) returned NULL val\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL));
			exit(1);
		}
		if (osmo_gtlv_tag_inst_cmp(&gtlv.ti, &ie->ti)) {
			printf("  ERROR loading TLV structure: expected tag %s, got tag %s\n",
			       osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL),
			       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL));
			exit(1);
		}
		if (strcmp(ie->val, osmo_hexdump_nospc(gtlv.val, gtlv.len))) {
			while (1) {
				printf("   (mismatch: T=%s L=%zu v=%s, checking for another occurrence of T=%s)\n",
				       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL),
				       gtlv.len,
				       osmo_hexdump_nospc(gtlv.val, gtlv.len),
				       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL));

				rc = osmo_gtlv_load_next_by_tag_inst(&gtlv, &ie->ti);
				if (rc || !gtlv.val) {
					printf("  ERROR val not found\n");
					exit(1);
				}
				if (strcmp(ie->val, osmo_hexdump_nospc(gtlv.val, gtlv.len)) == 0) {
					break;
				}
			}
		}
		printf("  T=%s L=%zu v=%s\n",
		       osmo_gtlv_tag_inst_to_str_c(ctx, &gtlv.ti, NULL),
		       gtlv.len, osmo_hexdump_nospc(gtlv.val, gtlv.len));
	}

	printf("- enforcing order: without restart, a past tag is not parsed again:\n");
	/* Try to read the first tag, expect that it isn't found because we're already halfway in the message data */
	ie = ies;
	rc = osmo_gtlv_load_next_by_tag_inst(&gtlv, &ie->ti);
	printf("  osmo_gtlv_load_next_by_tag_inst(%s) rc=", osmo_gtlv_tag_inst_to_str_c(ctx, &ie->ti, NULL));
	if (rc == -ENOENT) {
		printf("-ENOENT\n");
	} else {
		printf("%d\n", rc);
		printf("  ERROR: expected -ENOENT\n");
		exit(1);
	}
}

void test_tlv(const char *label, struct ie *tests[], size_t tests_len, const struct osmo_gtlv_cfg *cfg)
{
	int i;
	for (i = 0; i < tests_len; i++) {
		const struct ie *ies = tests[i];
		struct msgb *msg;
		printf("\n=== start: %s[%d]\n", label, i);

		msg = test_tlv_enc(cfg, ies);
		test_tlv_dec(cfg, ies, msg);
		test_tlv_peek(cfg, ies, msg);
		test_tlv_dec_by_tag(cfg, ies, msg);

		msgb_free(msg);

		printf("=== end: %s[%d]\n", label, i);
	}
}

struct ie t8l8v_test1[] = {
	/* smallest T */
	{ {}, "2342" },
	/* largest T */
	{ {255}, "2342" },

	/* smallest V (no V data) */
	{ {1}, "" },
	/* largest V, 255 bytes is the largest that an 8bit size length can express. */
	{ {123}, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	       "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
	},

	/* arbitrary test data */
	{ {101}, "11" },
	{ {102}, "2222" },
	{ {103}, "333333" },
	{}
};

struct ie t8l8v_test_multi[] = {
	{ {42}, "42" },
	{ {2}, "0101" },
	{ {2}, "2222" },
	{ {3}, "11" },
	{ {3}, "2222" },
	{ {3}, "333333" },
	{ {23}, "23" },
	{ {42}, "666f72747974776f" },
	{ {23}, "7477656e74797468726565" },
	{}
};

struct ie *t8l8v_tests[] = {
	t8l8v_test1,
	t8l8v_test_multi,
};

void test_t8l8v(void)
{
	test_tlv(__func__, t8l8v_tests, ARRAY_SIZE(t8l8v_tests), &osmo_t8l8v_cfg);
}

struct ie t16l16v_test1[] = {
	/* smallest T */
	{ {}, "2342" },
	/* largest T */
	{ {65535}, "2342" },

	/* smallest V (no V data) */
	{ {1}, "" },
	/* 256 bytes is one more than an 8bit size length can express. */
	{ {123}, "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	},

	/* arbitrary test data */
	{ {1001}, "11" },
	{ {1002}, "2222" },
	{ {1003}, "333333" },
	{}
};

struct ie t16l16v_test_multi[] = {
	{ {1042}, "42" },
	{ {102}, "0101" },
	{ {102}, "2222" },
	{ {103}, "11" },
	{ {103}, "2222" },
	{ {103}, "333333" },
	{ {1023}, "23" },
	{ {1042}, "666f72747974776f" },
	{ {1023}, "7477656e74797468726565" },
	{}
};

struct ie *t16l16v_tests[] = {
	t16l16v_test1,
	t16l16v_test_multi,
};

void test_t16l16v(void)
{
	test_tlv(__func__, t16l16v_tests, ARRAY_SIZE(t16l16v_tests), &osmo_t16l16v_cfg);
}

struct ie txlxv_test1[] = {
	/* smallest T */
	{ {}, "2342" },
	/* largest T that still fits in one encoded octet (highest bit serves as flag) */
	{ {0x7f}, "2342" },
	/* smallest T that needs two octets to be encoded (first octet = 0x80 flag + 0, second octet = 0x1) */
	{ {0x80}, "2342" },
	/* largest T that can be encoded in 16bit - one flag bit. */
	{ {0x7fff}, "2342" },

	/* smallest V (no V data) */
	{ {1}, "" },
	/* 256 bytes is one more than an 8bit size length can express. */
	{ {123}, "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	       "0000000000000000000000000000000000000000000000000000000000000000"
	},

	/* arbitrary test data */
	{ {1002}, "2222" },
	{ {1003}, "333333" },
	{}
};

struct ie txlxv_test_multi[] = {
	{ {1042}, "42" },
	{ {1002}, "0101" },
	{ {1002}, "2222" },
	{ {103}, "11" },
	{ {103}, "2222" },
	{ {103}, "333333" },
	{ {1023}, "23" },
	{ {1042}, "666f72747974776f" },
	{ {1023}, "7477656e74797468726565" },
	{}
};

struct ie *txlxv_tests[] = {
	txlxv_test1,
	txlxv_test_multi,
};

/* Example of defining a variable TL, where size of T and L depend on the actual tag and length values: load. */
int txlxv_load_tl(struct osmo_gtlv_load *gtlv, const uint8_t *src_data, size_t src_data_len)
{
	const uint8_t *pos = src_data;
	const uint8_t *end = src_data + src_data_len;
	if (pos[0] & 0x80) {
		if (pos + 2 > end)
			return -EINVAL;
		gtlv->ti.tag = (((int)pos[1]) << 7) + (pos[0] & 0x7f);
		pos += 2;
	} else {
		gtlv->ti.tag = pos[0];
		pos++;
	}

	switch (gtlv->ti.tag) {
	case 1002:
		/* fixed-length IE */
		gtlv->len = 2;
		break;
	case 123:
		/* 16bit length IE */
		if (pos + 2 > end)
			return -EINVAL;
		gtlv->len = osmo_load16be(pos);
		pos += 2;
		break;
	default:
		/* 8bit length IE */
		if (pos + 1 > end)
			return -EINVAL;
		gtlv->len = *pos;
		pos++;
		break;
	}
	gtlv->val = pos;
	return 0;
}

/* Example of defining a variable TL, where size of T and L depend on the actual tag and length values: store. */
int txlxv_store_tl(uint8_t *dst_data, size_t dst_data_avail, const struct osmo_gtlv_tag_inst *ti, size_t len,
		   struct osmo_gtlv_put *gtlv)
{
	uint8_t *pos = dst_data;
	uint8_t *end = dst_data + dst_data_avail;
	unsigned int tag = ti->tag;
	if (tag < 0x80) {
		if (pos + 1 > end)
			return -ENOSPC;
		pos[0] = tag;
		pos++;
	} else {
		if (pos + 2 > end)
			return -ENOSPC;
		pos[0] = 0x80 + (tag & 0x7f);
		pos[1] = tag >> 7;
		pos += 2;
	}

	switch (tag) {
	case 1002:
		/* fixed-length IE, write no len */
		break;
	case 123:
		/* 16bit length IE */
		if (len > UINT16_MAX)
			return -ERANGE;
		if (pos + 2 > end)
			return -ENOSPC;
		osmo_store16be(len, pos);
		pos += 2;
		break;
	default:
		/* 8bit length IE */
		if (len > UINT8_MAX)
			return -ERANGE;
		if (pos + 1 > end)
			return -ENOSPC;
		pos[0] = len;
		pos++;
		break;
	}
	return pos - dst_data;
}

const struct osmo_gtlv_cfg txlxv_cfg = {
	.tl_min_size = 1,
	.load_tl = txlxv_load_tl,
	.store_tl = txlxv_store_tl,
};

void test_txlxv(void)
{
	test_tlv(__func__, txlxv_tests, ARRAY_SIZE(txlxv_tests), &txlxv_cfg);
}

/* Example of defining a TLI, with an instance indicator */
static int tliv_load_tl(struct osmo_gtlv_load *gtlv, const uint8_t *src_data, size_t src_data_len)
{
	/* already validated in next_tl_valid(): src_data_len >= cfg->tl_min_size == 2. */
	gtlv->ti.tag = src_data[0];
	gtlv->len = src_data[1];

	switch (gtlv->ti.tag) {
	/* All tags that are TLIV go here */
	case 5:
	case 7:
	case 9:
		if (src_data_len < 3)
			return -ENOSPC;
		gtlv->ti.instance_present = true;
		gtlv->ti.instance = src_data[2];
		gtlv->val = src_data + 3;
		return 0;
	default:
		gtlv->val = src_data + 2;
		return 0;
	}
}

static int tliv_store_tl(uint8_t *dst_data, size_t dst_data_avail, const struct osmo_gtlv_tag_inst *ti, size_t len,
			 struct osmo_gtlv_put *gtlv)
{
	if (ti->tag > UINT8_MAX)
		return -EINVAL;
	if (len > UINT8_MAX)
		return -EMSGSIZE;
	if (dst_data_avail < 2)
		return -ENOSPC;

	dst_data[0] = ti->tag;
	dst_data[1] = len;

	switch (ti->tag) {
	/* All tags that are TLIV go here */
	case 5:
	case 7:
	case 9:
		if (dst_data_avail < 3)
			return -ENOSPC;
		if (!ti->instance_present)
			return -EINVAL;
		if (ti->instance > UINT8_MAX)
			return -EINVAL;
		dst_data[2] = ti->instance;
		return 3;
	default:
		return 2;
	}
}

const struct osmo_gtlv_cfg osmo_tliv_cfg = {
	.tl_min_size = 2,
	.load_tl = tliv_load_tl,
	.store_tl = tliv_store_tl,
};

struct ie tliv_test1[] = {
	/* TLV */
	{ {1}, "0002" },
	/* TLIV */
	{ {5, true, 1}, "0017" },
	/* TLIV */
	{ {5, true, 2}, "0018" },
	/* TLIV */
	{ {5, true, 3}, "0019" },
	/* TLV */
	{ {6}, "001a" },
	/* TLIV */
	{ {7, true, 1}, "001b" },
	/* TLIV */
	{ {9, true, 1}, "001c" },
	{}
};

struct ie *tliv_tests[] = {
	tliv_test1,
};

void test_tliv(void)
{
	test_tlv(__func__, tliv_tests, ARRAY_SIZE(tliv_tests), &osmo_tliv_cfg);
}

int main(int argc, char **argv)
{
	ctx = talloc_named_const(NULL, 0, "gtlv_test");
	msgb_talloc_ctx_init(ctx, 0);

	test_t8l8v();
	test_t16l16v();
	test_txlxv();
	test_tliv();

	talloc_free(ctx);
	return 0;
}