]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/netlink/test_snl_generic.c
netlink: improve snl(3)
[FreeBSD/FreeBSD.git] / tests / sys / netlink / test_snl_generic.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 #include <sys/param.h>
6 #include <sys/module.h>
7
8 #include <netlink/netlink.h>
9 #include "netlink/netlink_snl.h"
10 #include "netlink/netlink_snl_generic.h"
11
12 #include <atf-c.h>
13
14 static void
15 require_netlink(void)
16 {
17         if (modfind("netlink") == -1)
18                 atf_tc_skip("netlink module not loaded");
19 }
20
21 ATF_TC(snl_verify_genl_parsers);
22 ATF_TC_HEAD(snl_verify_genl_parsers, tc)
23 {
24         atf_tc_set_md_var(tc, "descr", "Tests snl(3) generic parsers are correct");
25 }
26
27 ATF_TC_BODY(snl_verify_genl_parsers, tc)
28 {
29         SNL_VERIFY_PARSERS(snl_all_genl_parsers);
30
31 }
32
33 ATF_TC(test_snl_get_genl_family_success);
34 ATF_TC_HEAD(test_snl_get_genl_family_success, tc)
35 {
36         atf_tc_set_md_var(tc, "descr", "Tests successfull resolution of the 'nlctrl' family");
37 }
38
39 ATF_TC_BODY(test_snl_get_genl_family_success, tc)
40 {
41         struct snl_state ss;
42
43         require_netlink();
44
45         if (!snl_init(&ss, NETLINK_GENERIC))
46                 atf_tc_fail("snl_init() failed");
47
48         ATF_CHECK_EQ(snl_get_genl_family(&ss, "nlctrl"), GENL_ID_CTRL);
49 }
50
51 ATF_TC(test_snl_get_genl_family_failure);
52 ATF_TC_HEAD(test_snl_get_genl_family_failure, tc)
53 {
54         atf_tc_set_md_var(tc, "descr", "Tests unsuccessfull resolution of 'no-such-family' family");
55 }
56
57 ATF_TC_BODY(test_snl_get_genl_family_failure, tc)
58 {
59         struct snl_state ss;
60
61         require_netlink();
62
63         if (!snl_init(&ss, NETLINK_GENERIC))
64                 atf_tc_fail("snl_init() failed");
65
66         ATF_CHECK_EQ(snl_get_genl_family(&ss, "no-such-family"), 0);
67 }
68
69 ATF_TP_ADD_TCS(tp)
70 {
71         ATF_TP_ADD_TC(tp, snl_verify_genl_parsers);
72         ATF_TP_ADD_TC(tp, test_snl_get_genl_family_success);
73         ATF_TP_ADD_TC(tp, test_snl_get_genl_family_failure);
74
75         return (atf_no_error());
76 }
77