1 /*
2 * Copyright (c) International Business Machines Corp., 2004
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /*
20 * TEST CASE : event_us.c
21 *
22 * VARIATIONS : 21
23 *
24 * EVENTS TESTED: DM_EVENT_USER
25 *
26 * API'S TESTED : dm_create_userevent
27 * dm_send_msg
28 * dm_find_eventmsg
29 */
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <pthread.h>
35 #include <unistd.h>
36 #include <sys/mount.h>
37 #include "dm_test.h"
38
39 pthread_t tid;
40 dm_sessid_t sid;
41 char dmMsgBuf[4096];
42 char *mountPt;
43 char *deviceNm;
44 void *fshanp;
45 size_t fshlen;
46 dm_size_t maxMsgDat;
47
48 /* Variables for thread communications */
49 dm_eventtype_t eventExpected;
50 dm_eventtype_t eventReceived;
51 dm_response_t eventResponse;
52 void *hanp2;
53 size_t hlen2;
54 char name1[FILENAME_MAX];
55 dm_token_t tokenReceived;
56 char msgDataReceived[MSG_DATALEN];
57 dm_size_t msgDataLenReceived;
58
59 void *Thread(void *);
60
main(int argc,char ** argv)61 int main(int argc, char **argv)
62 {
63
64 char *szFuncName;
65 char *varstr;
66 int rc;
67 int varStatus;
68 char *szSessionInfo = "dm_test session info";
69 dm_eventset_t events;
70
71 DMOPT_PARSE(argc, argv);
72 DMLOG_START();
73
74 DMEV_ZERO(events);
75 DMEV_SET(DM_EVENT_MOUNT, events);
76
77 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
78 if ((rc = dm_init_service(&varstr)) != 0) {
79 DMLOG_PRINT(DMLVL_ERR,
80 "dm_init_service failed! (rc = %d, errno = %d)\n",
81 rc, errno);
82 DM_EXIT();
83 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
84 == -1) {
85 DMLOG_PRINT(DMLVL_ERR,
86 "dm_create_session failed! (rc = %d, errno = %d)\n",
87 rc, errno);
88 DM_EXIT();
89 } else
90 if ((rc =
91 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
92 &events, DM_EVENT_MAX)) == -1) {
93 DMLOG_PRINT(DMLVL_ERR,
94 "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
95 errno);
96 dm_destroy_session(sid);
97 DM_EXIT();
98 } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
99 DMLOG_PRINT(DMLVL_ERR,
100 "pthread_create failed! (rc = %d, errno = %d)\n",
101 rc, errno);
102 dm_destroy_session(sid);
103 DM_EXIT();
104 } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
105 DMLOG_PRINT(DMLVL_ERR,
106 "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
107 errno);
108 dm_destroy_session(sid);
109 DM_EXIT();
110 } else {
111 rc = dm_get_config(fshanp, fshlen, DM_CONFIG_MAX_MESSAGE_DATA,
112 &maxMsgDat);
113 if (rc == -1) {
114 DMLOG_PRINT(DMLVL_ERR,
115 "dm_get_config failed! (rc = %d, errno = %d)\n",
116 rc, errno);
117 umount(mountPt);
118 dm_destroy_session(sid);
119 DM_EXIT();
120 }
121 }
122
123 DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI user event tests\n");
124
125 szFuncName = "dm_create_userevent";
126
127 /*
128 * TEST : dm_create_uservent - invalid sid
129 * EXPECTED: rc = -1, errno = EINVAL
130 */
131 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 1)) {
132 char buf[MSG_DATALEN];
133 dm_token_t token;
134
135 /* Variation set up */
136
137 /* Variation */
138 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName);
139 rc = dm_create_userevent(INVALID_ADDR, MSG_DATALEN, buf,
140 &token);
141 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
142
143 /* Variation clean up */
144 }
145
146 /*
147 * TEST : dm_create_uservent - invalid msglen
148 * EXPECTED: rc = -1, errno = E2BIG
149 */
150 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 2)) {
151 char buf[MSG_DATALEN];
152 dm_token_t token;
153
154 /* Variation set up */
155
156 /* Variation */
157 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msglen)\n", szFuncName);
158 rc = dm_create_userevent(sid, maxMsgDat + 1, buf, &token);
159 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);
160
161 /* Variation clean up */
162 }
163
164 /*
165 * TEST : dm_create_uservent - invalid msgdatap
166 * EXPECTED: rc = -1, errno = EFAULT
167 */
168 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 3)) {
169 dm_token_t token;
170
171 /* Variation set up */
172
173 /* Variation */
174 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgdatap)\n", szFuncName);
175 rc = dm_create_userevent(sid, MSG_DATALEN, (void *)INVALID_ADDR,
176 &token);
177 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
178
179 /* Variation clean up */
180 }
181
182 /*
183 * TEST : dm_create_uservent - invalid tokenp
184 * EXPECTED: rc = -1, errno = EFAULT
185 *
186 * This variation uncovered XFS BUG #11 (unused tevp left on queue)
187 */
188 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 4)) {
189 char buf[MSG_DATALEN];
190
191 /* Variation set up */
192
193 /* Variation */
194 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid tokenp)\n", szFuncName);
195 rc = dm_create_userevent(sid, MSG_DATALEN, buf,
196 (dm_token_t *) INVALID_ADDR);
197 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
198
199 /* Variation clean up */
200 }
201
202 /*
203 * TEST : dm_create_uservent - valid
204 * EXPECTED: rc = 0
205 */
206 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 5)) {
207 char buf[MSG_DATALEN];
208 dm_token_t token;
209
210 /* Variation set up */
211 memcpy(buf, MSG_DATA, MSG_DATALEN);
212
213 /* Variation */
214 DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName);
215 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
216 DMVAR_ENDPASSEXP(szFuncName, 0, rc);
217
218 /* Variation clean up */
219 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL);
220 if (rc == -1) {
221 DMLOG_PRINT(DMLVL_DEBUG,
222 "Unable to clean up variation! (errno = %d)\n",
223 errno);
224 }
225 }
226
227 /*
228 * TEST : dm_create_uservent - DM_NO_SESSION sid
229 * EXPECTED: rc = -1, errno = EINVAL
230 */
231 if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 6)) {
232 char buf[MSG_DATALEN];
233 dm_token_t token;
234
235 /* Variation set up */
236
237 /* Variation */
238 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName);
239 rc = dm_create_userevent(DM_NO_SESSION, MSG_DATALEN, buf,
240 &token);
241 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
242
243 /* Variation clean up */
244 }
245
246 szFuncName = "dm_send_msg";
247
248 /*
249 * TEST : dm_send_msg - invalid targetsid
250 * EXPECTED: rc = -1, errno = EINVAL
251 */
252 if (DMVAR_EXEC(SEND_MSG_BASE + 1)) {
253 char buf[MSG_DATALEN];
254
255 /* Variation set up */
256
257 /* Variation */
258 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid targetsid)\n", szFuncName);
259 rc = dm_send_msg(INVALID_ADDR, DM_MSGTYPE_SYNC, MSG_DATALEN,
260 buf);
261 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
262
263 /* Variation clean up */
264 }
265
266 /*
267 * TEST : dm_send_msg - invalid msgtype
268 * EXPECTED: rc = -1, errno = EINVAL
269 */
270 if (DMVAR_EXEC(SEND_MSG_BASE + 2)) {
271 char buf[MSG_DATALEN];
272
273 /* Variation set up */
274
275 /* Variation */
276 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgtype)\n", szFuncName);
277 rc = dm_send_msg(sid, INVALID_ADDR, MSG_DATALEN, buf);
278 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
279
280 /* Variation clean up */
281 }
282
283 /*
284 * TEST : dm_send_msg - invalid buflen
285 * EXPECTED: rc = -1, errno = E2BIG
286 */
287 if (DMVAR_EXEC(SEND_MSG_BASE + 3)) {
288 char buf[MSG_DATALEN];
289
290 /* Variation set up */
291
292 /* Variation */
293 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName);
294 rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, maxMsgDat + 1, buf);
295 DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);
296
297 /* Variation clean up */
298 }
299
300 /*
301 * TEST : dm_send_msg - invalid bufp
302 * EXPECTED: rc = -1, errno = EFAULT
303 */
304 if (DMVAR_EXEC(SEND_MSG_BASE + 4)) {
305 /* Variation set up */
306
307 /* Variation */
308 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName);
309 rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN,
310 (void *)INVALID_ADDR);
311 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
312
313 /* Variation clean up */
314 }
315
316 /*
317 * TEST : dm_send_msg - DM_RESP_CONTINUE
318 * EXPECTED: rc = 0
319 */
320 if (DMVAR_EXEC(SEND_MSG_BASE + 5)) {
321 char buf[MSG_DATALEN];
322
323 /* Variation set up */
324 eventExpected = DM_EVENT_USER;
325 eventReceived = DM_EVENT_INVALID;
326 eventResponse = DM_RESP_CONTINUE;
327 memcpy(buf, MSG_DATA, MSG_DATALEN);
328
329 /* Variation */
330 DMLOG_PRINT(DMLVL_DEBUG, "%s(continue response)\n", szFuncName);
331 rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
332 if ((varStatus =
333 DMVAR_CHKPASSEXP(0, rc, eventExpected,
334 eventReceived)) == DMSTAT_PASS) {
335 if (tokenReceived == 0) {
336 DMLOG_PRINT(DMLVL_ERR,
337 "Token NOT correct! (%d vs non-zero)\n",
338 tokenReceived);
339 varStatus = DMSTAT_FAIL;
340 }
341 if (msgDataLenReceived != MSG_DATALEN) {
342 DMLOG_PRINT(DMLVL_ERR,
343 "Message lengths NOT same! (%d vs %d)\n",
344 msgDataLenReceived, MSG_DATALEN);
345 varStatus = DMSTAT_FAIL;
346 } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) !=
347 0) {
348 DMLOG_PRINT(DMLVL_ERR,
349 "Message data NOT same! (%s vs %s)\n",
350 msgDataReceived, buf);
351 varStatus = DMSTAT_FAIL;
352 }
353 }
354 DMVAR_END(varStatus);
355
356 /* Variation clean up */
357 }
358
359 /*
360 * TEST : dm_send_msg - DM_RESP_ABORT
361 * EXPECTED: rc = -1, errno = ABORT_ERRNO
362 *
363 * This variation uncovered XFS BUG #39 (response reterror returned
364 * instead of -1 and errno set to reterror)
365 */
366 if (DMVAR_EXEC(SEND_MSG_BASE + 6)) {
367 char buf[MSG_DATALEN];
368
369 /* Variation set up */
370 eventExpected = DM_EVENT_USER;
371 eventReceived = DM_EVENT_INVALID;
372 eventResponse = DM_RESP_ABORT;
373 memcpy(buf, MSG_DATA, MSG_DATALEN);
374
375 /* Variation */
376 DMLOG_PRINT(DMLVL_DEBUG, "%s(abort response)\n", szFuncName);
377 rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
378 if ((varStatus =
379 DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected,
380 eventReceived)) == DMSTAT_PASS) {
381 if (tokenReceived == 0) {
382 DMLOG_PRINT(DMLVL_ERR,
383 "Token NOT correct! (%d vs non-zero)\n",
384 tokenReceived);
385 varStatus = DMSTAT_FAIL;
386 }
387 if (msgDataLenReceived != MSG_DATALEN) {
388 DMLOG_PRINT(DMLVL_ERR,
389 "Message lengths NOT same! (%d vs %d)\n",
390 msgDataLenReceived, MSG_DATALEN);
391 varStatus = DMSTAT_FAIL;
392 } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) !=
393 0) {
394 DMLOG_PRINT(DMLVL_ERR,
395 "Message data NOT same! (%s vs %s)\n",
396 msgDataReceived, buf);
397 varStatus = DMSTAT_FAIL;
398 }
399 }
400 DMVAR_END(varStatus);
401
402 /* Variation clean up */
403 }
404
405 /*
406 * TEST : dm_send_msg - DM_MSGTYPE_ASYNC
407 * EXPECTED: rc = 0
408 */
409 if (DMVAR_EXEC(SEND_MSG_BASE + 7)) {
410 char buf[MSG_DATALEN];
411
412 /* Variation set up */
413 eventExpected = DM_EVENT_USER;
414 eventReceived = DM_EVENT_INVALID;
415 eventResponse = DM_RESP_CONTINUE;
416 memcpy(buf, MSG_DATA, MSG_DATALEN);
417
418 /* Variation */
419 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_MSGTYPE_ASYNC)\n", szFuncName);
420 rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, MSG_DATALEN, buf);
421 EVENT_DELIVERY_DELAY;
422 if ((varStatus =
423 DMVAR_CHKPASSEXP(0, rc, eventExpected,
424 eventReceived)) == DMSTAT_PASS) {
425 if (tokenReceived != 0) {
426 DMLOG_PRINT(DMLVL_ERR,
427 "Token NOT correct! (%d vs %d)\n",
428 tokenReceived, 0);
429 varStatus = DMSTAT_FAIL;
430 }
431 if (msgDataLenReceived != MSG_DATALEN) {
432 DMLOG_PRINT(DMLVL_ERR,
433 "Message lengths NOT same! (%d vs %d)\n",
434 msgDataLenReceived, MSG_DATALEN);
435 varStatus = DMSTAT_FAIL;
436 } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) !=
437 0) {
438 DMLOG_PRINT(DMLVL_ERR,
439 "Message data NOT same! (%s vs %s)\n",
440 msgDataReceived, buf);
441 varStatus = DMSTAT_FAIL;
442 }
443 }
444 DMVAR_END(varStatus);
445
446 /* Variation clean up */
447 }
448
449 /*
450 * TEST : dm_send_msg - DM_NO_SESSION targetsid
451 * EXPECTED: rc = -1, errno = EINVAL
452 */
453 if (DMVAR_EXEC(SEND_MSG_BASE + 8)) {
454 char buf[MSG_DATALEN];
455
456 /* Variation set up */
457
458 /* Variation */
459 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION targetsid)\n",
460 szFuncName);
461 rc = dm_send_msg(DM_NO_SESSION, DM_MSGTYPE_SYNC, MSG_DATALEN,
462 buf);
463 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
464
465 /* Variation clean up */
466 }
467
468 szFuncName = "dm_find_eventmsg";
469
470 /*
471 * TEST : dm_find_eventmsg - invalid sid
472 * EXPECTED: rc = -1, errno = EINVAL
473 */
474 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 1)) {
475 dm_token_t token;
476 char buf[MSG_DATALEN];
477 size_t rlen;
478
479 /* Variation set up */
480 memcpy(buf, MSG_DATA, MSG_DATALEN);
481 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
482 if (rc == -1) {
483 DMLOG_PRINT(DMLVL_DEBUG,
484 "Unable to initialize variation! (errno = %d)\n",
485 errno);
486 DMVAR_SKIP();
487 } else {
488 /* Variation */
489 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
490 szFuncName);
491 rc = dm_find_eventmsg(INVALID_ADDR, token, MSG_DATALEN,
492 buf, &rlen);
493 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
494
495 /* Variation clean up */
496 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
497 0, NULL);
498 if (rc == -1) {
499 DMLOG_PRINT(DMLVL_DEBUG,
500 "Unable to clean up variation! (errno = %d)\n",
501 errno);
502 }
503 }
504 }
505
506 /*
507 * TEST : dm_find_eventmsg - invalid token
508 * EXPECTED: rc = -1, errno = EINVAL
509 */
510 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 2)) {
511 dm_token_t token;
512 char buf[MSG_DATALEN];
513 size_t rlen;
514
515 /* Variation set up */
516 memcpy(buf, MSG_DATA, MSG_DATALEN);
517 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
518 if (rc == -1) {
519 DMLOG_PRINT(DMLVL_DEBUG,
520 "Unable to initialize variation! (errno = %d)\n",
521 errno);
522 DMVAR_SKIP();
523 } else {
524 /* Variation */
525 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
526 szFuncName);
527 rc = dm_find_eventmsg(sid, INVALID_ADDR, MSG_DATALEN,
528 buf, &rlen);
529 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
530
531 /* Variation clean up */
532 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
533 0, NULL);
534 if (rc == -1) {
535 DMLOG_PRINT(DMLVL_DEBUG,
536 "Unable to clean up variation! (errno = %d)\n",
537 errno);
538 }
539 }
540 }
541
542 /*
543 * TEST : dm_find_eventmsg - invalid buflen
544 * EXPECTED: rc = -1, errno = E2BIG
545 */
546 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 3)) {
547 dm_token_t token;
548 char buf[MSG_DATALEN];
549 size_t rlen;
550
551 /* Variation set up */
552 memcpy(buf, MSG_DATA, MSG_DATALEN);
553 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
554 if (rc == -1) {
555 DMLOG_PRINT(DMLVL_DEBUG,
556 "Unable to initialize variation! (errno = %d)\n",
557 errno);
558 DMVAR_SKIP();
559 } else {
560 /* Variation */
561 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n",
562 szFuncName);
563 rc = dm_find_eventmsg(sid, token, MSG_DATALEN - 1, buf,
564 &rlen);
565 if (rc == -1) {
566 if (errno == E2BIG) {
567 DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n",
568 rlen);
569 if (rlen ==
570 MSG_DATALEN +
571 sizeof(dm_eventmsg_t)) {
572 DMLOG_PRINT(DMLVL_DEBUG,
573 "%s passed with expected rc = %d, expected errno = %d, and expected rlen = %d\n",
574 szFuncName, rc,
575 errno, rlen);
576 DMVAR_PASS();
577 } else {
578 DMLOG_PRINT(DMLVL_ERR,
579 "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n",
580 szFuncName, rc,
581 errno, rlen,
582 MSG_DATALEN);
583 DMVAR_FAIL();
584 }
585 } else {
586 DMLOG_PRINT(DMLVL_ERR,
587 "%s failed with expected rc = %d but unexpected errno = %d\n",
588 szFuncName, rc, errno);
589 DMVAR_FAIL();
590 }
591 } else {
592 DMLOG_PRINT(DMLVL_ERR,
593 "%s failed with unexpected rc = %d\n",
594 szFuncName, rc);
595 DMVAR_FAIL();
596 }
597
598 /* Variation clean up */
599 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
600 0, NULL);
601 if (rc == -1) {
602 DMLOG_PRINT(DMLVL_DEBUG,
603 "Unable to clean up variation! (errno = %d)\n",
604 errno);
605 }
606 }
607 }
608
609 /*
610 * TEST : dm_find_eventmsg - invalid bufp
611 * EXPECTED: rc = -1, errno = EINVAL
612 */
613 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 4)) {
614 dm_token_t token;
615 char buf[MSG_DATALEN];
616 size_t rlen;
617
618 /* Variation set up */
619 memcpy(buf, MSG_DATA, MSG_DATALEN);
620 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
621 if (rc == -1) {
622 DMLOG_PRINT(DMLVL_DEBUG,
623 "Unable to initialize variation! (errno = %d)\n",
624 errno);
625 DMVAR_SKIP();
626 } else {
627 /* Variation */
628 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n",
629 szFuncName);
630 rc = dm_find_eventmsg(sid, token, MSG_DATALEN,
631 (void *)INVALID_ADDR, &rlen);
632 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
633
634 /* Variation clean up */
635 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
636 0, NULL);
637 if (rc == -1) {
638 DMLOG_PRINT(DMLVL_DEBUG,
639 "Unable to clean up variation! (errno = %d)\n",
640 errno);
641 }
642 }
643 }
644
645 /*
646 * TEST : dm_find_eventmsg - invalid rlenp
647 * EXPECTED: rc = -1, errno = EFAULT
648 */
649 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 5)) {
650 dm_token_t token;
651 char buf[MSG_DATALEN];
652
653 /* Variation set up */
654 memcpy(buf, MSG_DATA, MSG_DATALEN);
655 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
656 if (rc == -1) {
657 DMLOG_PRINT(DMLVL_DEBUG,
658 "Unable to initialize variation! (errno = %d)\n",
659 errno);
660 DMVAR_SKIP();
661 } else {
662 /* Variation */
663 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n",
664 szFuncName);
665 rc = dm_find_eventmsg(sid, token, MSG_DATALEN, buf,
666 (size_t *) INVALID_ADDR);
667 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
668
669 /* Variation clean up */
670 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
671 0, NULL);
672 if (rc == -1) {
673 DMLOG_PRINT(DMLVL_DEBUG,
674 "Unable to clean up variation! (errno = %d)\n",
675 errno);
676 }
677 }
678 }
679
680 /*
681 * TEST : dm_find_eventmsg - valid
682 * EXPECTED: rc = 0
683 */
684 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 6)) {
685 dm_token_t token;
686 char bufin[MSG_DATALEN],
687 bufout[MSG_DATALEN + sizeof(dm_eventmsg_t)];
688 size_t rlen;
689
690 /* Variation set up */
691 memcpy(bufin, MSG_DATA, MSG_DATALEN);
692 rc = dm_create_userevent(sid, MSG_DATALEN, bufin, &token);
693 if (rc == -1) {
694 DMLOG_PRINT(DMLVL_DEBUG,
695 "Unable to initialize variation! (errno = %d)\n",
696 errno);
697 DMVAR_SKIP();
698 } else {
699 /* Variation */
700 DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName);
701 rc = dm_find_eventmsg(sid, token, sizeof(bufout),
702 bufout, &rlen);
703 if (rc == 0) {
704 DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
705 if (rlen == MSG_DATALEN + sizeof(dm_eventmsg_t)) {
706 if (memcmp
707 (bufin,
708 bufout + sizeof(dm_eventmsg_t),
709 MSG_DATALEN) == 0) {
710 DMLOG_PRINT(DMLVL_DEBUG,
711 "%s passed with expected rc = %d, expected rlen %d, and expected buffer %s\n",
712 szFuncName, rc,
713 rlen,
714 bufout +
715 sizeof
716 (dm_eventmsg_t));
717 DMVAR_PASS();
718 } else {
719 DMLOG_PRINT(DMLVL_ERR,
720 "%s failed with expected rc = %d and expected rlen %d but expected buffer %s\n",
721 szFuncName, rc,
722 rlen, bufout);
723 DMVAR_FAIL();
724 }
725 } else {
726 DMLOG_PRINT(DMLVL_ERR,
727 "%s passed with expected rc = %d but unexpected rlen %d\n",
728 szFuncName, rc, rlen);
729 DMVAR_FAIL();
730 }
731 } else {
732 DMLOG_PRINT(DMLVL_ERR,
733 "%s failed with unexpected rc = %d (errno = %d)\n",
734 szFuncName, rc, errno);
735 DMVAR_FAIL();
736 }
737
738 /* Variation clean up */
739 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
740 0, NULL);
741 if (rc == -1) {
742 DMLOG_PRINT(DMLVL_DEBUG,
743 "Unable to clean up variation! (errno = %d)\n",
744 errno);
745 }
746 }
747 }
748
749 /*
750 * TEST : dm_find_eventmsg - DM_NO_SESSION sid
751 * EXPECTED: rc = -1, errno = EINVAL
752 */
753 if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 7)) {
754 dm_token_t token;
755 char buf[MSG_DATALEN];
756 size_t rlen;
757
758 /* Variation set up */
759 memcpy(buf, MSG_DATA, MSG_DATALEN);
760 rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
761 if (rc == -1) {
762 DMLOG_PRINT(DMLVL_DEBUG,
763 "Unable to initialize variation! (errno = %d)\n",
764 errno);
765 DMVAR_SKIP();
766 } else {
767 /* Variation */
768 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
769 szFuncName);
770 rc = dm_find_eventmsg(DM_NO_SESSION, token, MSG_DATALEN,
771 buf, &rlen);
772 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
773
774 /* Variation clean up */
775 rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
776 0, NULL);
777 if (rc == -1) {
778 DMLOG_PRINT(DMLVL_DEBUG,
779 "Unable to clean up variation! (errno = %d)\n",
780 errno);
781 }
782 }
783 }
784
785 rc = umount(mountPt);
786 if (rc == -1) {
787 DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
788 rc, errno);
789 }
790
791 EVENT_DELIVERY_DELAY;
792 pthread_join(tid, NULL);
793
794 rc = dm_destroy_session(sid);
795 if (rc == -1) {
796 DMLOG_PRINT(DMLVL_ERR,
797 "dm_destroy_session failed! (rc = %d, errno = %d)\n",
798 rc, errno);
799 }
800
801 DMLOG_STOP();
802
803 tst_exit();
804 }
805
Thread(void * parm)806 void *Thread(void *parm)
807 {
808 int rc;
809 size_t dmMsgBufLen;
810 dm_eventmsg_t *dmMsg;
811 int bMounted = DM_FALSE;
812 int type;
813 dm_token_t token;
814 dm_eventset_t events;
815 dm_response_t response;
816
817 do {
818 /* Loop until message received (wait could be interrupted) */
819 do {
820 DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
821 dmMsgBufLen = 0;
822
823 rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
824 dmMsgBuf, &dmMsgBufLen);
825 DMLOG_PRINT(DMLVL_DEBUG,
826 "... dm_get_events returned %d (errno %d)\n",
827 rc, errno);
828 } while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
829
830 if (rc) {
831 DMLOG_PRINT(DMLVL_ERR,
832 "dm_get_events failed with rc = %d, errno = %d\n",
833 rc, errno);
834 dm_destroy_session(sid);
835 DM_EXIT();
836 } else {
837 dmMsg = (dm_eventmsg_t *) dmMsgBuf;
838 token = dmMsg->ev_token;
839 type = dmMsg->ev_type;
840
841 DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
842 }
843
844 if (type == DM_EVENT_MOUNT) {
845 /* SPECIAL CASE: need to set disposition, events and response */
846 dm_mount_event_t *me =
847 DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
848 fshanp = DM_GET_VALUE(me, me_handle1, void *);
849 fshlen = DM_GET_LEN(me, me_handle1);
850
851 DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
852 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", me->me_mode);
853 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
854 fshanp);
855 DMLOG_PRINT(DMLVL_DEBUG,
856 " File system handle length: %d\n",
857 fshlen);
858 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint handle: %p\n",
859 DM_GET_VALUE(me, me_handle2, void *));
860 DMLOG_PRINT(DMLVL_DEBUG,
861 " Mountpoint handle length: %d\n",
862 DM_GET_LEN(me, me_handle2));
863 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint path: %s\n",
864 DM_GET_VALUE(me, me_name1, char *));
865 DMLOG_PRINT(DMLVL_DEBUG, " Media designator: %s\n",
866 DM_GET_VALUE(me, me_name2, char *));
867 DMLOG_PRINT(DMLVL_DEBUG, " Root handle: %p\n",
868 DM_GET_VALUE(me, me_roothandle, void *));
869 DMLOG_PRINT(DMLVL_DEBUG, " Root handle length: %d\n",
870 DM_GET_LEN(me, me_roothandle));
871
872 bMounted = dm_handle_is_valid(fshanp, fshlen);
873
874 /*rc = dm_request_right(sid, fshanp, fshlen, token, DM_RR_WAIT, DM_RIGHT_EXCL);
875 if (rc == -1) {
876 DMLOG_PRINT(DMLVL_ERR, "dm_request_right failed! (rc = %d, errno = %d)\n", rc, errno);
877 dm_destroy_session(sid);
878 DM_EXIT();
879 } */
880
881 DMEV_ZERO(events);
882 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
883 DMEV_SET(DM_EVENT_UNMOUNT, events);
884 DMEV_SET(DM_EVENT_POSTCREATE, events);
885 DMEV_SET(DM_EVENT_ATTRIBUTE, events);
886 DMEV_SET(DM_EVENT_CLOSE, events);
887 DMEV_SET(DM_EVENT_DESTROY, events);
888 rc = dm_set_disp(sid, fshanp, fshlen, DM_NO_TOKEN,
889 &events, DM_EVENT_MAX);
890 if (rc == -1) {
891 DMLOG_PRINT(DMLVL_ERR,
892 "dm_set_disp failed! (rc = %d, errno = %d)\n",
893 rc, errno);
894 dm_destroy_session(sid);
895 DM_EXIT();
896 }
897
898 rc = dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
899 &events, DM_EVENT_MAX);
900 if (rc == -1) {
901 DMLOG_PRINT(DMLVL_ERR,
902 "dm_set_eventlist failed! (rc = %d, errno = %d)\n",
903 rc, errno);
904 dm_destroy_session(sid);
905 DM_EXIT();
906 }
907
908 /*rc = dm_release_right(sid, fshanp, fshlen, token);
909 if (rc == -1) {
910 DMLOG_PRINT(DMLVL_ERR, "dm_request_right failed! (rc = %d, errno = %d)\n", rc, errno);
911 dm_destroy_session(sid);
912 DM_EXIT();
913 } */
914
915 response = DM_RESP_CONTINUE;
916 } else if (type == DM_EVENT_PREUNMOUNT) {
917 /* SPECIAL CASE: need to set response */
918 dm_namesp_event_t *nse =
919 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
920
921 DMLOG_PRINT(DMLVL_DEBUG,
922 "Message is DM_EVENT_PREUNMOUNT\n");
923 DMLOG_PRINT(DMLVL_DEBUG, " Unmount mode: %x\n",
924 nse->ne_mode);
925 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
926 DM_GET_VALUE(nse, ne_handle1, void *));
927 DMLOG_PRINT(DMLVL_DEBUG,
928 " File system handle length: %d\n",
929 DM_GET_LEN(nse, ne_handle1));
930 DMLOG_PRINT(DMLVL_DEBUG,
931 " Root directory handle: %p\n",
932 DM_GET_VALUE(nse, ne_handle2, void *));
933 DMLOG_PRINT(DMLVL_DEBUG,
934 " Root directory handle length: %d\n",
935 DM_GET_LEN(nse, ne_handle2));
936
937 response = DM_RESP_CONTINUE;
938 } else if (type == DM_EVENT_UNMOUNT) {
939 /* SPECIAL CASE: need to set response and bMounted */
940 dm_namesp_event_t *nse =
941 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
942
943 DMLOG_PRINT(DMLVL_DEBUG,
944 "Message is DM_EVENT_UNMOUNT\n");
945 DMLOG_PRINT(DMLVL_DEBUG, " Unmount mode: %x\n",
946 nse->ne_mode);
947 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
948 DM_GET_VALUE(nse, ne_handle1, void *));
949 DMLOG_PRINT(DMLVL_DEBUG,
950 " File system handle length: %d\n",
951 DM_GET_LEN(nse, ne_handle1));
952 DMLOG_PRINT(DMLVL_DEBUG, " Return code: %x\n",
953 nse->ne_retcode);
954 if (nse->ne_retcode == 0) {
955 bMounted = DM_FALSE;
956 }
957
958 response = DM_RESP_CONTINUE;
959 } else if (type == DM_EVENT_POSTCREATE) {
960 /* SPECIAL CASE: need to save entry info */
961 dm_namesp_event_t *nse =
962 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
963 hanp2 = DM_GET_VALUE(nse, ne_handle2, void *);
964 hlen2 = DM_GET_LEN(nse, ne_handle2);
965 strcpy(name1, DM_GET_VALUE(nse, ne_name1, char *));
966
967 DMLOG_PRINT(DMLVL_DEBUG,
968 "Message is DM_EVENT_POSTCREATE\n");
969 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", nse->ne_mode);
970 DMLOG_PRINT(DMLVL_DEBUG, " Parent handle: %p\n",
971 DM_GET_VALUE(nse, ne_handle1, void *));
972 DMLOG_PRINT(DMLVL_DEBUG, " Parent handle length: %d\n",
973 DM_GET_LEN(nse, ne_handle1));
974 DMLOG_PRINT(DMLVL_DEBUG, " Entry handle: %p\n", hanp2);
975 DMLOG_PRINT(DMLVL_DEBUG, " Entry handle length: %d\n",
976 hlen2);
977 DMLOG_PRINT(DMLVL_DEBUG, " Entry name: %s\n", name1);
978 DMLOG_PRINT(DMLVL_DEBUG, " Return code: %x\n",
979 nse->ne_retcode);
980
981 /* No response needed */
982 response = DM_RESP_INVALID;
983 } else {
984 eventReceived = type;
985 response = eventResponse;
986
987 switch (type) {
988 case DM_EVENT_USER:
989 {
990 memcpy(&tokenReceived, &token,
991 sizeof(dm_token_t));
992 msgDataLenReceived =
993 DM_GET_LEN(dmMsg, ev_data);
994 memcpy(msgDataReceived,
995 DM_GET_VALUE(dmMsg, ev_data,
996 char *),
997 msgDataLenReceived);
998
999 DMLOG_PRINT(DMLVL_DEBUG,
1000 "Message is DM_EVENT_USER\n");
1001 DMLOG_PRINT(DMLVL_DEBUG,
1002 " Message length: %d\n",
1003 msgDataLenReceived);
1004 DMLOG_PRINT(DMLVL_DEBUG,
1005 " Message data: %s\n",
1006 msgDataReceived);
1007
1008 response = eventResponse;
1009 break;
1010 }
1011
1012 default:
1013 {
1014 DMLOG_PRINT(DMLVL_ERR,
1015 "Message is unexpected!\n");
1016 response = DM_RESP_ABORT;
1017 break;
1018 }
1019 }
1020 }
1021
1022 if (response != DM_RESP_INVALID) {
1023 DMLOG_PRINT(DMLVL_DEBUG,
1024 "Responding to message %d with %d\n", type,
1025 response);
1026 rc = dm_respond_event(sid, token, response,
1027 response ==
1028 DM_RESP_ABORT ? ABORT_ERRNO : 0,
1029 0, NULL);
1030 }
1031 } while (bMounted);
1032
1033 pthread_exit(0);
1034 }
1035