File: test-random.c

package info (click to toggle)
ell 0.82-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,388 kB
  • sloc: ansic: 61,555; sh: 5,450; makefile: 575
file content (49 lines) | stat: -rw-r--r-- 870 bytes parent folder | download | duplicates (3)
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
/*
 * Embedded Linux library
 * Copyright (C) 2015  Intel Corporation
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <assert.h>
#include <stdio.h>

#include <ell/ell.h>

static void test_random(const void *data)
{
	uint8_t buf1[128];
	uint8_t buf2[128];
	char *str;

	assert(l_getrandom(buf1, 128));
	str = l_util_hexstring(buf1, 128);
	printf("buf1: %s\n", str);
	l_free(str);

	assert(l_getrandom(buf2, 128));
	str = l_util_hexstring(buf2, 128);
	printf("buf2: %s\n", str);
	l_free(str);

	assert(memcmp(buf1, buf2, 128));
}

static bool getrandom_precheck(const void *data)
{
	return l_getrandom_is_supported();
}

int main(int argc, char *argv[])
{
	l_test_init(&argc, &argv);

	l_test_add_func_precheck("l_getrandom sanity check", test_random,
							getrandom_precheck, 0);

	return l_test_run();
}