summaryrefslogtreecommitdiff
path: root/tests/vboot_api_kernel6_tests.c
blob: 63aff75dd9719469db8abbc77755ccab588eccfe (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
/* Copyright (c) 2013 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 vboot_api_kernel.c
 */

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

#include "2common.h"
#include "rollback_index.h"
#include "test_common.h"
#include "vboot_api.h"

/* Mock data */
static uint32_t virtual_dev_mode_fail;

/**
 * Reset mock data (for use before each test)
 */
static void ResetMocks(void)
{
	virtual_dev_mode_fail = 0;
}

/* Mocks */
vb2_error_t SetVirtualDevMode(int val)
{
	if (virtual_dev_mode_fail)
		return VB2_ERROR_MOCK;
	return VB2_SUCCESS;
}

static void VbUnlockDeviceTest(void)
{
	ResetMocks();
	TEST_EQ(VbUnlockDevice(), 0, "unlock success");

	ResetMocks();
	virtual_dev_mode_fail = 1;
	TEST_EQ(VbUnlockDevice(), VBERROR_TPM_SET_BOOT_MODE_STATE,
		"set dev fail");
}

int main(void)
{
	VbUnlockDeviceTest();

	return gTestSuccess ? 0 : 255;
}