diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-12 19:56:14 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-12 20:00:50 +0900 |
commit | a55277b88966d7449222c21a663b7dd9d3d330bb (patch) | |
tree | a655bc5e730e317f9d69db2240a0285689f6a92d | |
parent | 847f1ea69edc73c6a9235ff45b005691ce1d33c5 (diff) | |
download | systemd-a55277b88966d7449222c21a663b7dd9d3d330bb.tar.gz |
test: add tests for MAC address helper functions
-rw-r--r-- | src/test/test-ether-addr-util.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/test-ether-addr-util.c b/src/test/test-ether-addr-util.c index 909e34d8c7..e708f019d7 100644 --- a/src/test/test-ether-addr-util.c +++ b/src/test/test-ether-addr-util.c @@ -4,6 +4,36 @@ #include "string-util.h" #include "tests.h" +static void test_ether_addr_helpers(void) { + struct ether_addr a; + + log_info("/* %s */", __func__); + + a = ETHER_ADDR_NULL; + assert_se(ether_addr_is_null(&a)); + assert_se(!ether_addr_is_broadcast(&a)); + assert_se(!ether_addr_is_multicast(&a)); + assert_se(ether_addr_is_unicast(&a)); + assert_se(!ether_addr_is_local(&a)); + assert_se(ether_addr_is_global(&a)); + + memset(a.ether_addr_octet, 0xff, sizeof(a)); + assert_se(!ether_addr_is_null(&a)); + assert_se(ether_addr_is_broadcast(&a)); + assert_se(ether_addr_is_multicast(&a)); + assert_se(!ether_addr_is_unicast(&a)); + assert_se(ether_addr_is_local(&a)); + assert_se(!ether_addr_is_global(&a)); + + a = (struct ether_addr) { { 0x01, 0x23, 0x34, 0x56, 0x78, 0x9a } }; + assert_se(!ether_addr_is_null(&a)); + assert_se(!ether_addr_is_broadcast(&a)); + assert_se(ether_addr_is_multicast(&a)); + assert_se(!ether_addr_is_unicast(&a)); + assert_se(!ether_addr_is_local(&a)); + assert_se(ether_addr_is_global(&a)); +} + #define INFINIBAD_ADDR_1 ((const struct hw_addr_data){ .length = 20, .infiniband = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} }) static void test_HW_ADDR_TO_STRING(void) { @@ -138,6 +168,7 @@ static void test_parse_hw_addr(void) { int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); + test_ether_addr_helpers(); test_HW_ADDR_TO_STRING(); test_parse_hw_addr(); return 0; |