blob: 8ee17f6a9bc34950fd3fd3153527fa9cd5c61882 [file] [log] [blame]
Simon Glass11a075c2022-08-30 21:05:36 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <tpm_api.h>
10#include <dm/test.h>
11#include <test/test.h>
12#include <test/ut.h>
13
14/* Basic test of the TPM uclass */
15static int dm_test_tpm(struct unit_test_state *uts)
16{
17 struct udevice *dev;
18 char buf[50];
19
20 /* check probe success */
21 ut_assertok(uclass_first_device_err(UCLASS_TPM, &dev));
22 ut_assert(tpm_is_v2(dev));
23
24 ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
25 ut_asserteq_str("init_done=0", buf);
26
27 ut_assertok(tpm_init(dev));
Ilias Apalodimasb6a2fae2023-02-18 17:21:22 +020028 /*
29 * tpm auto start will rerun tpm_init, but handles the
30 * -EBUSY return code internally.
31 */
32 ut_assertok(tpm_auto_start(dev));
Simon Glass11a075c2022-08-30 21:05:36 -060033
34 ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
35 ut_asserteq_str("init_done=1", buf);
36
37 return 0;
38}
39DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT);