2 * Copyright (c) 2017 Ngie Cooper <ngie@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 get_cam_test_device(const atf_tc_t *tc)
39 const char *cam_test_device;
41 cam_test_device = atf_tc_get_config_var(tc, "cam_test_device");
43 return (cam_test_device);
50 strcpy(cam_errbuf, "");
57 return (strlen(cam_errbuf) != 0);
60 ATF_TC(cam_open_device_negative_test_O_RDONLY);
61 ATF_TC_HEAD(cam_open_device_negative_test_O_RDONLY, tc)
64 atf_tc_set_md_var(tc, "descr",
65 "test that cam_open_device(`cam_device`, O_RDONLY) fails to open "
66 "the underlying pass(4) device (bug 217649)");
67 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
68 atf_tc_set_md_var(tc, "require.user", "root");
71 ATF_TC_BODY(cam_open_device_negative_test_O_RDONLY, tc)
73 const char *cam_test_device;
75 cam_test_device = get_cam_test_device(tc);
78 ATF_CHECK(cam_open_device(cam_test_device, O_RDONLY) == NULL);
79 ATF_REQUIRE(cam_has_error());
82 ATF_TC(cam_open_device_negative_test_nonexistent);
83 ATF_TC_HEAD(cam_open_device_negative_test_nonexistent, tc)
86 atf_tc_set_md_var(tc, "require.user", "root");
89 ATF_TC_BODY(cam_open_device_negative_test_nonexistent, tc)
93 ATF_REQUIRE(cam_open_device("/nonexistent", O_RDWR) == NULL);
94 ATF_REQUIRE(cam_has_error());
97 ATF_TC(cam_open_device_negative_test_unprivileged);
98 ATF_TC_HEAD(cam_open_device_negative_test_unprivileged, tc)
101 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
102 atf_tc_set_md_var(tc, "require.user", "unprivileged");
105 ATF_TC_BODY(cam_open_device_negative_test_unprivileged, tc)
107 const char *cam_test_device;
109 cam_test_device = get_cam_test_device(tc);
112 ATF_CHECK(cam_open_device(cam_test_device, O_RDONLY) == NULL);
113 ATF_REQUIRE(cam_has_error());
116 ATF_CHECK(cam_open_device(cam_test_device, O_RDWR) == NULL);
117 ATF_REQUIRE(cam_has_error());
120 ATF_TC(cam_open_device_positive_test);
121 ATF_TC_HEAD(cam_open_device_positive_test, tc)
124 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
125 atf_tc_set_md_var(tc, "require.user", "root");
128 ATF_TC_BODY(cam_open_device_positive_test, tc)
130 struct cam_device *cam_dev;
131 const char *cam_test_device;
133 cam_test_device = get_cam_test_device(tc);
136 cam_dev = cam_open_device(cam_test_device, O_RDWR);
137 ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
139 ATF_REQUIRE(!cam_has_error());
140 cam_close_device(cam_dev);
143 ATF_TC(cam_close_device_negative_test_NULL);
144 ATF_TC_HEAD(cam_close_device_negative_test_NULL, tc)
147 atf_tc_set_md_var(tc, "descr",
148 "test that cam_close_device(NULL) succeeds without error");
149 atf_tc_set_md_var(tc, "require.user", "root");
152 ATF_TC_BODY(cam_close_device_negative_test_NULL, tc)
156 cam_close_device(NULL);
157 ATF_REQUIRE(!cam_has_error());
160 ATF_TC(cam_getccb_positive_test);
161 ATF_TC_HEAD(cam_getccb_positive_test, tc)
164 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
165 atf_tc_set_md_var(tc, "require.user", "root");
168 ATF_TC_BODY(cam_getccb_positive_test, tc)
171 struct cam_device *cam_dev;
172 const char *cam_test_device;
174 cam_test_device = get_cam_test_device(tc);
177 cam_dev = cam_open_device(cam_test_device, O_RDWR);
178 ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
180 ATF_REQUIRE(!cam_has_error());
181 cam_ccb = cam_getccb(cam_dev);
182 ATF_CHECK_MSG(cam_ccb != NULL, "get_camccb failed: %s", cam_errbuf);
183 ATF_REQUIRE(!cam_has_error());
184 cam_freeccb(cam_ccb);
185 cam_close_device(cam_dev);
188 ATF_TC(cam_freeccb_negative_test_NULL);
189 ATF_TC_HEAD(cam_freeccb_negative_test_NULL, tc)
192 atf_tc_set_md_var(tc, "descr",
193 "test that cam_freeccb(NULL) succeeds without error");
194 atf_tc_set_md_var(tc, "require.user", "root");
197 ATF_TC_BODY(cam_freeccb_negative_test_NULL, tc)
202 ATF_REQUIRE(!cam_has_error());
208 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_O_RDONLY);
209 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_nonexistent);
210 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_unprivileged);
211 ATF_TP_ADD_TC(tp, cam_open_device_positive_test);
212 ATF_TP_ADD_TC(tp, cam_close_device_negative_test_NULL);
213 ATF_TP_ADD_TC(tp, cam_getccb_positive_test);
214 ATF_TP_ADD_TC(tp, cam_freeccb_negative_test_NULL);
216 return (atf_no_error());