Simon Glass | 9b306e5 | 2021-01-16 14:52:22 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2021 Google LLC |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <cros_ec.h> |
| 8 | #include <dm.h> |
| 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <test/ut.h> |
| 12 | |
| 13 | static int dm_test_cros_ec_hello(struct unit_test_state *uts) |
| 14 | { |
| 15 | struct udevice *dev; |
| 16 | uint val; |
| 17 | |
| 18 | ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); |
| 19 | |
| 20 | ut_assertok(cros_ec_hello(dev, NULL)); |
| 21 | |
| 22 | val = 0xdead1357; |
| 23 | ut_assertok(cros_ec_hello(dev, &val)); |
| 24 | ut_asserteq(0xdead1357, val); |
| 25 | |
| 26 | sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO); |
| 27 | ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val)); |
| 28 | ut_asserteq(0x12345678, val); |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT); |
Simon Glass | 33909b5 | 2021-01-16 14:52:25 -0700 | [diff] [blame] | 33 | |
| 34 | static int dm_test_cros_ec_sku_id(struct unit_test_state *uts) |
| 35 | { |
| 36 | struct udevice *dev; |
| 37 | |
| 38 | ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); |
| 39 | ut_asserteq(1234, cros_ec_get_sku_id(dev)); |
| 40 | |
| 41 | /* try the command */ |
| 42 | console_record_reset(); |
| 43 | ut_assertok(run_command("crosec sku", 0)); |
| 44 | ut_assert_nextline("1234"); |
| 45 | ut_assert_console_end(); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT); |
Simon Glass | 959e1ce | 2021-01-16 14:52:26 -0700 | [diff] [blame] | 50 | |
| 51 | static int dm_test_cros_ec_features(struct unit_test_state *uts) |
| 52 | { |
| 53 | struct udevice *dev; |
| 54 | u64 feat; |
| 55 | |
| 56 | ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev)); |
| 57 | ut_assertok(cros_ec_get_features(dev, &feat)); |
| 58 | ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C | |
| 59 | 1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH, |
| 60 | feat); |
| 61 | |
| 62 | ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_I2C)); |
| 63 | ut_asserteq(false, cros_ec_check_feature(dev, EC_FEATURE_MOTION_SENSE)); |
| 64 | ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH)); |
| 65 | |
| 66 | /* try the command */ |
| 67 | console_record_reset(); |
| 68 | ut_assertok(run_command("crosec features", 0)); |
| 69 | ut_assert_nextline("flash"); |
| 70 | ut_assert_nextline("i2c"); |
| 71 | ut_assert_nextline("unified_wake_masks"); |
| 72 | ut_assert_nextline("ish"); |
| 73 | ut_assert_console_end(); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT); |