summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/console_cmd/md.c
blob: c8c3e2c13004fa35be1dca65f4f6701c2fe8fe1a (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright 2022 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <zephyr/shell/shell.h>
#include <zephyr/ztest.h>

#include "console.h"
#include "test/drivers/test_state.h"

ZTEST_SUITE(console_cmd_md, drivers_predicate_post_main, NULL, NULL, NULL,
	    NULL);

ZTEST_USER(console_cmd_md, test_too_few_args)
{
	zassert_equal(EC_ERROR_PARAM_COUNT,
		      shell_execute_cmd(get_ec_shell(), "md"), NULL);
}

ZTEST_USER(console_cmd_md, test_error_param1)
{
	zassert_equal(EC_ERROR_PARAM1,
		      shell_execute_cmd(get_ec_shell(), "md .j"), NULL);
}

ZTEST_USER(console_cmd_md, test_error_bad_address)
{
	zassert_equal(EC_ERROR_PARAM1,
		      shell_execute_cmd(get_ec_shell(), "md not_an_address"),
		      NULL);
}

ZTEST_USER(console_cmd_md, test_default_count)
{
	uint8_t memory[] = { 0x01, 0x02, 0x03, 0x04 };
	char cmd[128] = { 0 };

	zassume_true(sprintf(cmd, "md %" PRIuPTR, (uintptr_t)memory) != 0,
		     NULL);
	zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), NULL);
}

ZTEST_USER(console_cmd_md, test_count_arg)
{
	uint8_t memory[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
	char cmd[128] = { 0 };

	zassume_true(sprintf(cmd, "md %" PRIuPTR " 2", (uintptr_t)memory) != 0,
		     NULL);
	zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), NULL);
}

ZTEST_USER(console_cmd_md, test_byte_format)
{
	uint8_t memory[] = { 0x01, 0x02, 0x03, 0x04 };
	char cmd[128] = { 0 };

	zassume_true(sprintf(cmd, "md .b %" PRIuPTR, (uintptr_t)memory) != 0,
		     NULL);
	zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), NULL);
}

ZTEST_USER(console_cmd_md, test_half_format)
{
	uint8_t memory[] = { 0x01, 0x02, 0x03, 0x04 };
	char cmd[128] = { 0 };

	zassume_true(sprintf(cmd, "md .h %" PRIuPTR, (uintptr_t)memory) != 0,
		     NULL);
	zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), NULL);
}

ZTEST_USER(console_cmd_md, test_string_format)
{
	char memory[] = "hello world";
	char cmd[128] = { 0 };

	zassume_true(sprintf(cmd, "md .s %" PRIuPTR " 12", (uintptr_t)memory) !=
			     0,
		     NULL);
	zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), NULL);
}