summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/host_cmd/src/adc.c
blob: a6e9beb62c65c8cbf969d046bed872fde9cd2bb3 (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
/* 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 "adc.h"
#include "host_command.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"

#include <zephyr/drivers/emul.h>
#include <zephyr/fff.h>
#include <zephyr/ztest.h>

FAKE_VALUE_FUNC(int, adc_read_channel, enum adc_channel);

ZTEST(hc_adc, normal_path)
{
	struct ec_params_adc_read params = {
		.adc_channel = ADC_TEMP_SENSOR_CHARGER,
	};
	struct ec_response_adc_read response;
	uint16_t ret;

	adc_read_channel_fake.return_val = 123;

	ret = ec_cmd_adc_read(NULL, &params, &response);

	zassert_ok(ret, "Host command returned %u", ret);
	zassert_equal(1, adc_read_channel_fake.call_count);
	zassert_equal(123, response.adc_value);
}

ZTEST(hc_adc, bad_ch_number)
{
	struct ec_params_adc_read params = {
		.adc_channel = ADC_CH_COUNT + 1, /* Invalid */
	};
	struct ec_response_adc_read response;
	uint16_t ret;

	ret = ec_cmd_adc_read(NULL, &params, &response);

	zassert_equal(EC_RES_INVALID_PARAM, ret, "Host command returned %u",
		      ret);
}

static void reset(void *data)
{
	ARG_UNUSED(data);

	RESET_FAKE(adc_read_channel);
}

ZTEST_SUITE(hc_adc, drivers_predicate_post_main, NULL, reset, reset, NULL);