1 /*
2  * Copyright (c) 2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/ztest.h>
10 
11 #include <zephyr/drivers/edac.h>
12 
13 /**
14  * EDAC dummy is used for coverage tests for -ENOSYS returns
15  */
16 
17 static DEVICE_API(edac, edac_dummy_api) = { 0 };
18 
19 DEVICE_DEFINE(dummy_edac, "dummy_edac", NULL, NULL,
20 	      NULL, NULL,
21 	      POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
22 	      &edac_dummy_api);
23 
ZTEST(ibecc,test_edac_dummy_api)24 ZTEST(ibecc, test_edac_dummy_api)
25 {
26 	const struct device *dev = device_get_binding("dummy_edac");
27 	uint64_t value;
28 	int ret;
29 
30 	zassert_not_null(dev, "Device not found");
31 
32 	/* Error log API */
33 
34 	ret = edac_ecc_error_log_get(dev, &value);
35 	zassert_equal(ret, -ENOSYS, "dummy api failed");
36 
37 	ret = edac_ecc_error_log_clear(dev);
38 	zassert_equal(ret, -ENOSYS, "dummy api failed");
39 
40 	ret = edac_parity_error_log_get(dev, &value);
41 	zassert_equal(ret, -ENOSYS, "dummy api failed");
42 
43 	ret = edac_parity_error_log_clear(dev);
44 	zassert_equal(ret, -ENOSYS, "dummy api failed");
45 
46 	/* Error stat API */
47 
48 	ret = edac_errors_cor_get(dev);
49 	zassert_equal(ret, -ENOSYS, "dummy api failed");
50 
51 	ret = edac_errors_uc_get(dev);
52 	zassert_equal(ret, -ENOSYS, "dummy api failed");
53 
54 	/* Notification API */
55 
56 	/* It is OK to use NULL as a callback pointer */
57 	ret = edac_notify_callback_set(dev, NULL);
58 	zassert_equal(ret, -ENOSYS, "dummy api failed");
59 
60 	/* Injection API */
61 
62 	ret = edac_inject_set_param1(dev, 0x0);
63 	zassert_equal(ret, -ENOSYS, "dummy api failed");
64 
65 	ret = edac_inject_get_param1(dev, &value);
66 	zassert_equal(ret, -ENOSYS, "dummy api failed");
67 
68 	ret = edac_inject_set_param2(dev, 0x0);
69 	zassert_equal(ret, -ENOSYS, "dummy api failed");
70 
71 	ret = edac_inject_get_param2(dev, &value);
72 	zassert_equal(ret, -ENOSYS, "dummy api failed");
73 
74 	ret = edac_inject_set_error_type(dev, 0x0);
75 	zassert_equal(ret, -ENOSYS, "dummy api failed");
76 
77 	ret = edac_inject_get_error_type(dev, (uint32_t *)&value);
78 	zassert_equal(ret, -ENOSYS, "dummy api failed");
79 
80 	ret = edac_inject_error_trigger(dev);
81 	zassert_equal(ret, -ENOSYS, "dummy api failed");
82 }
83