Simon Glass | 11a075c | 2022-08-30 21:05:36 -0600 | [diff] [blame] | 1 | // 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 */ |
| 15 | static 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 Apalodimas | b6a2fae | 2023-02-18 17:21:22 +0200 | [diff] [blame^] | 28 | /* |
| 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 Glass | 11a075c | 2022-08-30 21:05:36 -0600 | [diff] [blame] | 33 | |
| 34 | ut_assert(tpm_report_state(dev, buf, sizeof(buf))); |
| 35 | ut_asserteq_str("init_done=1", buf); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT); |