aboutsummaryrefslogtreecommitdiff
path: root/test/dm/sm.c
blob: 7ebb0c9c85ed437ae3ec64d479a9109493042d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2023 SberDevices, Inc.
 *
 * Author: Alexey Romanov <avromanov@salutedevices.com>
 */

#include <common.h>
#include <dm.h>
#include <sm.h>
#include <sandbox-sm.h>
#include <asm/ptrace.h>
#include <dm/device-internal.h>
#include <dm/test.h>
#include <test/ut.h>
#include <linux/sizes.h>

static int dm_test_sm(struct unit_test_state *uts)
{
	struct udevice *dev;
	struct pt_regs regs;
	char buffer[128] = { 0 };
	char test_string[] = "secure-monitor";
	int ret, val;

	ut_assertok(uclass_get_device_by_name(UCLASS_SM,
		"secure-monitor", &dev));

	ret = sm_call(dev, SANDBOX_SMC_CMD_COUNT, NULL, &regs);
	ut_asserteq(ret, -EINVAL);

	ret = sm_call(dev, SANDBOX_SMC_CMD_COMMON, &val, &regs);
	ut_asserteq(ret, 0);
	ut_asserteq(val, 0);

	ret = sm_call_write(dev, buffer, sizeof(buffer),
		SANDBOX_SMC_CMD_COUNT, &regs);
	ut_asserteq(ret, -EINVAL);

	ret = sm_call_write(dev, buffer, SZ_4K + 1,
		SANDBOX_SMC_CMD_WRITE_MEM, &regs);
	ut_asserteq(ret, -EINVAL);

	ret = sm_call_write(dev, buffer, sizeof(buffer),
		SANDBOX_SMC_CMD_COUNT, &regs);
	ut_asserteq(ret, -EINVAL);

	ret = sm_call_write(dev, buffer, SZ_4K + 1,
		SANDBOX_SMC_CMD_READ_MEM, &regs);
	ut_asserteq(ret, -EINVAL);

	ret = sm_call_write(dev, test_string, sizeof(test_string),
		SANDBOX_SMC_CMD_WRITE_MEM, &regs);
	ut_asserteq(ret, sizeof(test_string));

	ret = sm_call_read(dev, buffer, sizeof(buffer),
		SANDBOX_SMC_CMD_READ_MEM, &regs);
	ut_asserteq(ret, sizeof(buffer));

	ut_asserteq_str(buffer, test_string);

	return 0;
}

DM_TEST(dm_test_sm, UT_TESTF_SCAN_FDT);