|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/drivers/comparator/fake_comp.h> |
| 8 | + |
| 9 | +#ifdef CONFIG_ZTEST |
| 10 | +#include <zephyr/ztest.h> |
| 11 | +#endif |
| 12 | + |
| 13 | +#define DT_DRV_COMPAT zephyr_fake_comp |
| 14 | + |
| 15 | +DEFINE_FAKE_VALUE_FUNC(int, |
| 16 | + comp_fake_comp_get_output, |
| 17 | + const struct device *); |
| 18 | + |
| 19 | +DEFINE_FAKE_VALUE_FUNC(int, |
| 20 | + comp_fake_comp_set_trigger, |
| 21 | + const struct device *, |
| 22 | + enum comparator_trigger); |
| 23 | + |
| 24 | +DEFINE_FAKE_VALUE_FUNC(int, |
| 25 | + comp_fake_comp_set_trigger_callback, |
| 26 | + const struct device *, |
| 27 | + comparator_callback_t, |
| 28 | + void *); |
| 29 | + |
| 30 | +DEFINE_FAKE_VALUE_FUNC(int, |
| 31 | + comp_fake_comp_trigger_is_pending, |
| 32 | + const struct device *); |
| 33 | + |
| 34 | +static const struct comparator_driver_api fake_comp_api = { |
| 35 | + .get_output = comp_fake_comp_get_output, |
| 36 | + .set_trigger = comp_fake_comp_set_trigger, |
| 37 | + .set_trigger_callback = comp_fake_comp_set_trigger_callback, |
| 38 | + .trigger_is_pending = comp_fake_comp_trigger_is_pending, |
| 39 | +}; |
| 40 | + |
| 41 | +#ifdef CONFIG_ZTEST |
| 42 | +static void fake_comp_reset_rule_before(const struct ztest_unit_test *test, void *fixture) |
| 43 | +{ |
| 44 | + ARG_UNUSED(test); |
| 45 | + ARG_UNUSED(fixture); |
| 46 | + |
| 47 | + RESET_FAKE(comp_fake_comp_get_output); |
| 48 | + RESET_FAKE(comp_fake_comp_set_trigger); |
| 49 | + RESET_FAKE(comp_fake_comp_set_trigger_callback); |
| 50 | + RESET_FAKE(comp_fake_comp_trigger_is_pending); |
| 51 | +} |
| 52 | + |
| 53 | +ZTEST_RULE(comp_fake_comp_reset_rule, fake_comp_reset_rule_before, NULL); |
| 54 | +#endif |
| 55 | + |
| 56 | +DEVICE_DT_INST_DEFINE( |
| 57 | + 0, |
| 58 | + NULL, |
| 59 | + NULL, |
| 60 | + NULL, |
| 61 | + NULL, |
| 62 | + POST_KERNEL, |
| 63 | + CONFIG_COMPARATOR_INIT_PRIORITY, |
| 64 | + &fake_comp_api |
| 65 | +); |
0 commit comments