summaryrefslogtreecommitdiff
path: root/tests/utility_tests.c
blob: 5e22339f383407ff7fa90b811086323b2f6de2ab (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
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Tests for utility functions
 */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "test_common.h"
#include "utility.h"
#include "vboot_common.h"

/* Test utility.h and sysincludes.h macros */
static void MacrosTest(void)
{
	int64_t a = -10, b = -20;
	uint64_t u = (0xABCD00000000ULL);
	uint64_t v = (0xABCD000000ULL);

	TEST_EQ(Min(1, 2), 1, "Min 1");
	TEST_EQ(Min(4, 3), 3, "Min 2");
	TEST_EQ(Min(5, 5), 5, "Min 5");
	TEST_EQ(Min(a, b), b, "Min uint64 1");
	TEST_EQ(Min(b, a), b, "Min uint64 2");
	TEST_EQ(Min(b, b), b, "Min uint64 same");

	TEST_EQ(u >> 8, v, "uint64_t >> 8");
	TEST_EQ(u >> 0, u, "uint64_t >> 0");
	TEST_EQ(u >> 36, (uint64_t)0xABC, "uint64_t >> 36");

	TEST_EQ(v * (uint32_t)0, 0, "uint64_t * uint32_t 0");
	TEST_EQ(v * (uint32_t)1, v, "uint64_t * uint32_t 1");
	TEST_EQ(v * (uint32_t)256, u, "uint64_t * uint32_t 256");
}

int main(int argc, char* argv[])
{
	int error_code = 0;

	MacrosTest();

	if (!gTestSuccess)
		error_code = 255;

	return error_code;
}