Benjamin Gaignard | a550b54 | 2018-11-27 13:49:50 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
| 4 | */ |
| 5 | |
Benjamin Gaignard | a550b54 | 2018-11-27 13:49:50 +0100 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <hwspinlock.h> |
| 8 | #include <asm/state.h> |
| 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Benjamin Gaignard | a550b54 | 2018-11-27 13:49:50 +0100 | [diff] [blame] | 12 | #include <test/ut.h> |
| 13 | |
| 14 | /* Test that hwspinlock driver functions are called */ |
| 15 | static int dm_test_hwspinlock_base(struct unit_test_state *uts) |
| 16 | { |
| 17 | struct sandbox_state *state = state_get_current(); |
| 18 | struct hwspinlock hws; |
| 19 | |
| 20 | ut_assertok(uclass_get_device(UCLASS_HWSPINLOCK, 0, &hws.dev)); |
| 21 | ut_assertnonnull(hws.dev); |
| 22 | ut_asserteq(false, state->hwspinlock); |
| 23 | |
| 24 | hws.id = 0; |
| 25 | ut_assertok(hwspinlock_lock_timeout(&hws, 1)); |
| 26 | ut_asserteq(true, state->hwspinlock); |
| 27 | |
| 28 | ut_assertok(hwspinlock_unlock(&hws)); |
| 29 | ut_asserteq(false, state->hwspinlock); |
| 30 | |
| 31 | ut_assertok(hwspinlock_lock_timeout(&hws, 1)); |
| 32 | ut_assertok(!hwspinlock_lock_timeout(&hws, 1)); |
| 33 | |
| 34 | ut_assertok(hwspinlock_unlock(&hws)); |
| 35 | ut_assertok(!hwspinlock_unlock(&hws)); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 40 | DM_TEST(dm_test_hwspinlock_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |