summaryrefslogtreecommitdiff
path: root/zephyr/test/system_common/src/build_info.c
blob: 7983c1f0a4e042f8675a6fcc6938659311d31f5f (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
/* 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/device.h>
#include <zephyr/fff.h>
#include <zephyr/ztest_assert.h>
#include <zephyr/ztest_test_new.h>

#include "host_command.h"
#include "system.h"

ZTEST_SUITE(host_cmd_get_build_info, NULL, NULL, NULL, NULL, NULL);

FAKE_VALUE_FUNC(const char *, system_get_build_info);

ZTEST(host_cmd_get_build_info, test_get_build_info)
{
	int ret;
	char resp[1024];
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_RESPONSE(EC_CMD_GET_BUILD_INFO, 0, resp);

	RESET_FAKE(system_get_build_info);
	system_get_build_info_fake.return_val = "i-am-a-version";

	ret = host_command_process(&args);

	zassert_equal(ret, EC_SUCCESS, "Unexpected return value: %d", ret);
	zassert_equal(strcmp(resp, "i-am-a-version"), 0,
		      "Unexpected response: %s", resp);
	zassert_equal(system_get_build_info_fake.call_count, 1,
		      "Unexpected call count: %d",
		      system_get_build_info_fake.call_count);
}

ZTEST(host_cmd_get_build_info, test_get_build_info_truncated)
{
	int ret;
	char resp[8];
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_RESPONSE(EC_CMD_GET_BUILD_INFO, 0, resp);

	RESET_FAKE(system_get_build_info);
	system_get_build_info_fake.return_val = "i-am-a-long-version";

	ret = host_command_process(&args);

	zassert_equal(ret, EC_SUCCESS, "Unexpected return value: %d", ret);
	zassert_equal(strcmp(resp, "i-am-a-"), 0, "Unexpected response: %s",
		      resp);
	zassert_equal(system_get_build_info_fake.call_count, 1,
		      "Unexpected call count: %d",
		      system_get_build_info_fake.call_count);
}