1 /*
2  * Copyright (c) 2024 Vestas Wind Systems A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/can.h>
8 #include <zephyr/ztest.h>
9 
10 #include "common.h"
11 
12 /**
13  * @addtogroup t_can_driver
14  * @{
15  * @defgroup t_can_transceiver test_can_transceiver
16  * @}
17  */
18 
19 /**
20  * @brief Test getting CAN transceiver device pointer.
21  */
ZTEST_USER(can_transceiver,test_get_transceiver)22 ZTEST_USER(can_transceiver, test_get_transceiver)
23 {
24 	const struct device *phy = can_get_transceiver(can_dev);
25 
26 	zassert_equal(phy, can_phy, "wrong CAN transceiver device pointer returned");
27 }
28 
can_transceiver_predicate(const void * state)29 static bool can_transceiver_predicate(const void *state)
30 {
31 	ARG_UNUSED(state);
32 
33 	if (!device_is_ready(can_dev)) {
34 		TC_PRINT("CAN device not ready");
35 		return false;
36 	}
37 
38 	if (!device_is_ready(can_phy)) {
39 		TC_PRINT("CAN transceiver device not ready");
40 		return false;
41 	}
42 
43 	return true;
44 }
45 
can_transceiver_setup(void)46 void *can_transceiver_setup(void)
47 {
48 	k_object_access_grant(can_dev, k_current_get());
49 	k_object_access_grant(can_phy, k_current_get());
50 
51 	zassert_true(device_is_ready(can_dev), "CAN device not ready");
52 	zassert_true(device_is_ready(can_phy), "CAN transceiver device not ready");
53 
54 	return NULL;
55 }
56 
57 ZTEST_SUITE(can_transceiver, can_transceiver_predicate, can_transceiver_setup, NULL, NULL, NULL);
58