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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
38 get_cam_test_device(const atf_tc_t *tc)
40 const char *cam_test_device;
42 cam_test_device = atf_tc_get_config_var(tc, "cam_test_device");
44 return (cam_test_device);
51 strcpy(cam_errbuf, "");
58 return (strlen(cam_errbuf) != 0);
61 ATF_TC(cam_open_device_negative_test_O_RDONLY);
62 ATF_TC_HEAD(cam_open_device_negative_test_O_RDONLY, tc)
65 atf_tc_set_md_var(tc, "descr",
66 "test that cam_open_device(`cam_device`, O_RDONLY) fails to open "
67 "the underlying pass(4) device (bug 217649)");
68 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
69 atf_tc_set_md_var(tc, "require.user", "root");
72 ATF_TC_BODY(cam_open_device_negative_test_O_RDONLY, tc)
74 const char *cam_test_device;
76 cam_test_device = get_cam_test_device(tc);
79 ATF_CHECK(cam_open_device(cam_test_device, O_RDONLY) == NULL);
80 ATF_REQUIRE(cam_has_error());
83 ATF_TC(cam_open_device_negative_test_nonexistent);
84 ATF_TC_HEAD(cam_open_device_negative_test_nonexistent, tc)
87 atf_tc_set_md_var(tc, "require.user", "root");
90 ATF_TC_BODY(cam_open_device_negative_test_nonexistent, tc)
94 ATF_REQUIRE(cam_open_device("/nonexistent", O_RDWR) == NULL);
95 ATF_REQUIRE(cam_has_error());
98 ATF_TC(cam_open_device_negative_test_unprivileged);
99 ATF_TC_HEAD(cam_open_device_negative_test_unprivileged, tc)
102 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
103 atf_tc_set_md_var(tc, "require.user", "unprivileged");
106 ATF_TC_BODY(cam_open_device_negative_test_unprivileged, tc)
108 const char *cam_test_device;
110 cam_test_device = get_cam_test_device(tc);
113 ATF_CHECK(cam_open_device(cam_test_device, O_RDONLY) == NULL);
114 ATF_REQUIRE(cam_has_error());
117 ATF_CHECK(cam_open_device(cam_test_device, O_RDWR) == NULL);
118 ATF_REQUIRE(cam_has_error());
121 ATF_TC(cam_open_device_positive_test);
122 ATF_TC_HEAD(cam_open_device_positive_test, tc)
125 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
126 atf_tc_set_md_var(tc, "require.user", "root");
129 ATF_TC_BODY(cam_open_device_positive_test, tc)
131 struct cam_device *cam_dev;
132 const char *cam_test_device;
134 cam_test_device = get_cam_test_device(tc);
137 cam_dev = cam_open_device(cam_test_device, O_RDWR);
138 ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
140 ATF_REQUIRE(!cam_has_error());
141 cam_close_device(cam_dev);
144 ATF_TC(cam_close_device_negative_test_NULL);
145 ATF_TC_HEAD(cam_close_device_negative_test_NULL, tc)
148 atf_tc_set_md_var(tc, "descr",
149 "test that cam_close_device(NULL) succeeds without error");
150 atf_tc_set_md_var(tc, "require.user", "root");
153 ATF_TC_BODY(cam_close_device_negative_test_NULL, tc)
157 cam_close_device(NULL);
158 ATF_REQUIRE(!cam_has_error());
161 ATF_TC(cam_getccb_positive_test);
162 ATF_TC_HEAD(cam_getccb_positive_test, tc)
165 atf_tc_set_md_var(tc, "require.config", "cam_test_device");
166 atf_tc_set_md_var(tc, "require.user", "root");
169 ATF_TC_BODY(cam_getccb_positive_test, tc)
172 struct cam_device *cam_dev;
173 const char *cam_test_device;
175 cam_test_device = get_cam_test_device(tc);
178 cam_dev = cam_open_device(cam_test_device, O_RDWR);
179 ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
181 ATF_REQUIRE(!cam_has_error());
182 cam_ccb = cam_getccb(cam_dev);
183 ATF_CHECK_MSG(cam_ccb != NULL, "get_camccb failed: %s", cam_errbuf);
184 ATF_REQUIRE(!cam_has_error());
185 cam_freeccb(cam_ccb);
186 cam_close_device(cam_dev);
189 ATF_TC(cam_freeccb_negative_test_NULL);
190 ATF_TC_HEAD(cam_freeccb_negative_test_NULL, tc)
193 atf_tc_set_md_var(tc, "descr",
194 "test that cam_freeccb(NULL) succeeds without error");
195 atf_tc_set_md_var(tc, "require.user", "root");
198 ATF_TC_BODY(cam_freeccb_negative_test_NULL, tc)
203 ATF_REQUIRE(!cam_has_error());
209 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_O_RDONLY);
210 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_nonexistent);
211 ATF_TP_ADD_TC(tp, cam_open_device_negative_test_unprivileged);
212 ATF_TP_ADD_TC(tp, cam_open_device_positive_test);
213 ATF_TP_ADD_TC(tp, cam_close_device_negative_test_NULL);
214 ATF_TP_ADD_TC(tp, cam_getccb_positive_test);
215 ATF_TP_ADD_TC(tp, cam_freeccb_negative_test_NULL);
217 return (atf_no_error());