Skip to content

Commit 41b2f0a

Browse files
alexanderwachtercarlescufi
authored andcommitted
tests: hwinfo: Make the tests depending on HWINFO_HAS_DRIVER
The test checks for a correct implementation if HWINFO_HAS_DRIVER is set, otherwise it checks for -ENOTSUP return value. Signed-off-by: Alexander Wachter <[email protected]>
1 parent 39e4686 commit 41b2f0a

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

tests/drivers/hwinfo/api/src/main.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
#define BUFFER_LENGTH 17
2727
#define BUFFER_CANARY 0xFF
2828

29-
/*
30-
* Function invokes the get_entropy callback in driver
31-
* to get the random data and fill to passed buffer
32-
*/
29+
#ifdef CONFIG_HWINFO_HAS_DRIVER
3330
static void test_device_id_get(void)
3431
{
3532
u8_t buffer_1[BUFFER_LENGTH];
@@ -39,7 +36,8 @@ static void test_device_id_get(void)
3936

4037
length_read_1 = hwinfo_get_device_id(buffer_1, 1);
4138
zassert_not_equal(length_read_1, -ENOTSUP, "Not supported by hardware");
42-
zassert_false((length_read_1 < 0), "Error returned: %d", length_read_1);
39+
zassert_false((length_read_1 < 0),
40+
"Unexpected negative return value: %d", length_read_1);
4341
zassert_not_equal(length_read_1, 0, "Zero bytes read");
4442
zassert_equal(length_read_1, 1, "Length not adhered");
4543

@@ -66,10 +64,34 @@ static void test_device_id_get(void)
6664
"Two consecutively readings don't match");
6765
}
6866
}
67+
#else
68+
static void test_device_id_get(void) {}
69+
#endif /* CONFIG_HWINFO_HAS_DRIVER */
70+
71+
#ifndef CONFIG_HWINFO_HAS_DRIVER
72+
static void test_device_id_enotsup(void)
73+
{
74+
ssize_t ret;
75+
u8_t buffer[1];
76+
77+
ret = hwinfo_get_device_id(buffer, 1);
78+
/* There is no hwinfo driver for this platform, hence the return value
79+
* should be -ENOTSUP
80+
*/
81+
zassert_equal(ret, -ENOTSUP,
82+
"hwinfo_get_device_id returned % instead of %d",
83+
ret, -ENOTSUP);
84+
}
85+
#else
86+
static void test_device_id_enotsup(void) {}
87+
#endif /* CONFIG_HWINFO_HAS_DRIVER not defined*/
6988

7089
void test_main(void)
7190
{
7291
ztest_test_suite(hwinfo_device_id_api,
73-
ztest_unit_test(test_device_id_get));
92+
ztest_unit_test(test_device_id_get),
93+
ztest_unit_test(test_device_id_enotsup)
94+
);
95+
7496
ztest_run_test_suite(hwinfo_device_id_api);
7597
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tests:
22
drivers.device_id:
33
tags: driver
4-
depends_on: hwinfo
4+
filter: CONFIG_HWINFO

0 commit comments

Comments
 (0)