blob: 995759d4d7e2c0ce17dec42436664129f318a1dc [file] [log] [blame]
Benjamin Gaignarda550b542018-11-27 13:49:50 +01001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Benjamin Gaignarda550b542018-11-27 13:49:50 +01007#include <dm.h>
8#include <hwspinlock.h>
9#include <asm/state.h>
10#include <asm/test.h>
11#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060012#include <test/test.h>
Benjamin Gaignarda550b542018-11-27 13:49:50 +010013#include <test/ut.h>
14
15/* Test that hwspinlock driver functions are called */
16static int dm_test_hwspinlock_base(struct unit_test_state *uts)
17{
18 struct sandbox_state *state = state_get_current();
19 struct hwspinlock hws;
20
21 ut_assertok(uclass_get_device(UCLASS_HWSPINLOCK, 0, &hws.dev));
22 ut_assertnonnull(hws.dev);
23 ut_asserteq(false, state->hwspinlock);
24
25 hws.id = 0;
26 ut_assertok(hwspinlock_lock_timeout(&hws, 1));
27 ut_asserteq(true, state->hwspinlock);
28
29 ut_assertok(hwspinlock_unlock(&hws));
30 ut_asserteq(false, state->hwspinlock);
31
32 ut_assertok(hwspinlock_lock_timeout(&hws, 1));
33 ut_assertok(!hwspinlock_lock_timeout(&hws, 1));
34
35 ut_assertok(hwspinlock_unlock(&hws));
36 ut_assertok(!hwspinlock_unlock(&hws));
37
38 return 0;
39}
40
Simon Glass974dccd2020-07-28 19:41:12 -060041DM_TEST(dm_test_hwspinlock_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);