summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/host_cmd/src/battery_display_soc.c
blob: 029551a49ba8f489baa69a20865e65129492241c (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
/* 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/ztest.h>

#include "battery.h"
#include "charge_state.h"
#include "host_command.h"
#include "test/drivers/test_state.h"

ZTEST_USER(battery_display_soc, happy_path)
{
	const uint32_t full_charge_as_tenths =
		CONFIG_BATT_HOST_FULL_FACTOR * 10;
	const uint32_t host_shutdown_charge_as_tenths =
		CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE * 10;
	struct ec_response_display_soc response;
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_RESPONSE(EC_CMD_DISPLAY_SOC, 0, response);

	zassert_ok(host_command_process(&args));

	zassert_equal(args.response_size, sizeof(response));
	zassert_equal(response.display_soc, charge_get_display_charge());
	zassert_equal(response.full_factor, full_charge_as_tenths);
	zassert_equal(response.shutdown_soc, host_shutdown_charge_as_tenths);
}

ZTEST_SUITE(battery_display_soc, drivers_predicate_post_main, NULL, NULL, NULL,
	    NULL);