• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.c
21  *
22  * VARIATIONS	: 41
23  *
24  * API'S TESTED	: dm_get_events
25  * 		  dm_respond_event
26  * 		  dm_move_event
27  * 		  dm_pending
28  */
29 #include <string.h>
30 #include <stdio.h>
31 #include <errno.h>
32 #include <pthread.h>
33 #include <unistd.h>
34 #include <sys/stat.h>
35 #include <sys/mount.h>
36 #include <fcntl.h>
37 #include <signal.h>
38 #include "dm_test.h"
39 
40 #define MAX_EVENT (sizeof(dmMsgBuf)/(MSG_DATALEN+sizeof(dm_eventmsg_t)))
41 
42 pthread_t tid;
43 dm_sessid_t sid;
44 char dmMsgBuf[4096];
45 char command[4096];
46 char mountPt[FILENAME_MAX];
47 char deviceNm[FILENAME_MAX];
48 char *szFuncName;
49 
50 /* Variables for thread communications */
51 int expectedNumMsg;
52 u_int eventsFlags;
53 int rcRespond;
54 int errnoRespond;
55 
56 void *Thread(void *);
57 
LogEventMsgs(void * bufp)58 void LogEventMsgs(void *bufp)
59 {
60 	int i = 0;
61 	dm_eventmsg_t *em = (dm_eventmsg_t *) bufp;
62 
63 	while (em != NULL) {
64 		DMLOG_PRINT(DMLVL_DEBUG, "  eventmsg %d:\n", i++);
65 		DMLOG_PRINT(DMLVL_DEBUG, "    ev_type: %d\n", em->ev_type);
66 		DMLOG_PRINT(DMLVL_DEBUG, "    ev_token: %d\n", em->ev_token);
67 		DMLOG_PRINT(DMLVL_DEBUG, "    ev_sequence: %d\n",
68 			    em->ev_sequence);
69 		DMLOG_PRINT(DMLVL_DEBUG, "    ev_data: length %d, value %s\n",
70 			    DM_GET_LEN(em, ev_data), DM_GET_VALUE(em, ev_data,
71 								  dm_eventtype_t));
72 
73 		em = DM_STEP_TO_NEXT(em, dm_eventmsg_t *);
74 	}
75 }
76 
GetSyncEventMsg(void * bufp)77 dm_eventmsg_t *GetSyncEventMsg(void *bufp)
78 {
79 	dm_eventmsg_t *em = (dm_eventmsg_t *) bufp;
80 
81 	while (em != NULL) {
82 		if ((em->ev_type == DM_EVENT_USER)
83 		    && (em->ev_token != DM_INVALID_TOKEN)) {
84 			return em;
85 		}
86 		em = DM_STEP_TO_NEXT(em, dm_eventmsg_t *);
87 	}
88 
89 	return NULL;
90 }
91 
GetNumEventMsg(void * bufp)92 int GetNumEventMsg(void *bufp)
93 {
94 	dm_eventmsg_t *em = (dm_eventmsg_t *) bufp;
95 	int i = 0;
96 
97 	while (em != NULL) {
98 		i++;
99 		em = DM_STEP_TO_NEXT(em, dm_eventmsg_t *);
100 	}
101 	return i;
102 }
103 
main(int argc,char ** argv)104 int main(int argc, char **argv)
105 {
106 
107 	char *varstr;
108 	int rc;
109 	char *szSessionInfo = "dm_test session info";
110 	dm_eventset_t events;
111 
112 	DMOPT_PARSE(argc, argv);
113 	DMLOG_START();
114 
115 	DMEV_ZERO(events);
116 	DMEV_SET(DM_EVENT_MOUNT, events);
117 
118 	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
119 	if ((rc = dm_init_service(&varstr)) != 0) {
120 		DMLOG_PRINT(DMLVL_ERR,
121 			    "dm_init_service failed! (rc = %d, errno = %d)\n",
122 			    rc, errno);
123 		DM_EXIT();
124 	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
125 		   == -1) {
126 		DMLOG_PRINT(DMLVL_ERR,
127 			    "dm_create_session failed! (rc = %d, errno = %d)\n",
128 			    rc, errno);
129 		DM_EXIT();
130 	}
131 
132 	DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI move event tests\n");
133 
134 	szFuncName = "dm_get_events";
135 
136 	/*
137 	 * TEST    : dm_get_events - invalid sid
138 	 * EXPECTED: rc = -1, errno = EINVAL
139 	 */
140 	if (DMVAR_EXEC(GET_EVENTS_BASE + 1)) {
141 		char buf[MSG_DATALEN];
142 		size_t rlen;
143 
144 		/* Variation set up */
145 
146 		/* Variation */
147 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName);
148 		rc = dm_get_events(INVALID_ADDR, 0, 0, sizeof(buf), buf, &rlen);
149 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
150 
151 		/* Variation clean up */
152 	}
153 
154 	/*
155 	 * TEST    : dm_get_events - invalid buflen
156 	 * EXPECTED: rc = -1, errno = E2BIG
157 	 */
158 	if (DMVAR_EXEC(GET_EVENTS_BASE + 2)) {
159 		char buf[MSG_DATALEN];
160 
161 		/* Variation set up */
162 		memcpy(buf, MSG_DATA, MSG_DATALEN);
163 		rc = pthread_create(&tid, NULL, Thread,
164 				    (void *)(GET_EVENTS_BASE + 2));
165 		if (rc == -1) {
166 			DMLOG_PRINT(DMLVL_DEBUG,
167 				    "Unable to set up variation! (errno = %d)\n",
168 				    errno);
169 			DMVAR_SKIP();
170 		} else {
171 			/* Message thread finishes off variation */
172 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
173 			pthread_join(tid, NULL);
174 		}
175 	}
176 
177 	/*
178 	 * TEST    : dm_get_events - invalid bufp
179 	 * EXPECTED: rc = -1, errno = EFAULT
180 	 */
181 	if (DMVAR_EXEC(GET_EVENTS_BASE + 3)) {
182 		char buf[MSG_DATALEN];
183 
184 		/* Variation set up */
185 		memcpy(buf, MSG_DATA, MSG_DATALEN);
186 		rc = pthread_create(&tid, NULL, Thread,
187 				    (void *)(GET_EVENTS_BASE + 3));
188 		if (rc == -1) {
189 			DMLOG_PRINT(DMLVL_DEBUG,
190 				    "Unable to set up variation! (errno = %d)\n",
191 				    errno);
192 			DMVAR_SKIP();
193 		} else {
194 			/* Message thread finishes off variation */
195 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
196 			pthread_join(tid, NULL);
197 		}
198 	}
199 
200 	/*
201 	 * TEST    : dm_get_events - invalid rlenp
202 	 * EXPECTED: rc = -1, errno = EFAULT
203 	 */
204 	if (DMVAR_EXEC(GET_EVENTS_BASE + 4)) {
205 		char buf[MSG_DATALEN];
206 
207 		/* Variation set up */
208 		memcpy(buf, MSG_DATA, MSG_DATALEN);
209 		rc = pthread_create(&tid, NULL, Thread,
210 				    (void *)(GET_EVENTS_BASE + 4));
211 		if (rc == -1) {
212 			DMLOG_PRINT(DMLVL_DEBUG,
213 				    "Unable to set up variation! (errno = %d)\n",
214 				    errno);
215 			DMVAR_SKIP();
216 		} else {
217 			/* Message thread finishes off variation */
218 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
219 			pthread_join(tid, NULL);
220 		}
221 	}
222 
223 	/*
224 	 * TEST    : dm_get_events - !DM_EV_WAIT with no messages
225 	 * EXPECTED: rc = -1, errno = EAGAIN
226 	 */
227 	if (DMVAR_EXEC(GET_EVENTS_BASE + 5)) {
228 
229 		/* Variation set up */
230 		rc = pthread_create(&tid, NULL, Thread,
231 				    (void *)(GET_EVENTS_BASE + 5));
232 		if (rc == -1) {
233 			DMLOG_PRINT(DMLVL_DEBUG,
234 				    "Unable to set up variation! (errno = %d)\n",
235 				    errno);
236 			DMVAR_SKIP();
237 		} else {
238 			pthread_join(tid, NULL);
239 		}
240 	}
241 
242 	/*
243 	 * TEST    : dm_get_events - !DM_EV_WAIT with one message
244 	 * EXPECTED: rc = 0
245 	 */
246 	if (DMVAR_EXEC(GET_EVENTS_BASE + 6)) {
247 		char buf[MSG_DATALEN];
248 
249 		/* Variation set up */
250 		expectedNumMsg = 1;
251 		eventsFlags = 0;
252 		memcpy(buf, MSG_DATA, MSG_DATALEN);
253 		rc = pthread_create(&tid, NULL, Thread,
254 				    (void *)(GET_EVENTS_BASE + 6));
255 		if (rc == -1) {
256 			DMLOG_PRINT(DMLVL_DEBUG,
257 				    "Unable to set up variation! (errno = %d)\n",
258 				    errno);
259 			DMVAR_SKIP();
260 		} else {
261 			/* Message thread finishes off variation */
262 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
263 			pthread_join(tid, NULL);
264 		}
265 	}
266 
267 	/*
268 	 * TEST    : dm_get_events - DM_EV_WAIT with one message
269 	 * EXPECTED: rc = 0
270 	 */
271 	if (DMVAR_EXEC(GET_EVENTS_BASE + 7)) {
272 		char buf[MSG_DATALEN];
273 
274 		/* Variation set up */
275 		expectedNumMsg = 1;
276 		eventsFlags = DM_EV_WAIT;
277 		memcpy(buf, MSG_DATA, MSG_DATALEN);
278 		rc = pthread_create(&tid, NULL, Thread,
279 				    (void *)(GET_EVENTS_BASE + 7));
280 		if (rc == -1) {
281 			DMLOG_PRINT(DMLVL_DEBUG,
282 				    "Unable to set up variation! (errno = %d)\n",
283 				    errno);
284 			DMVAR_SKIP();
285 		} else {
286 			/* Message thread finishes off variation */
287 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
288 			pthread_join(tid, NULL);
289 		}
290 	}
291 
292 	/*
293 	 * TEST    : dm_get_events - !DM_EV_WAIT with two messages
294 	 * EXPECTED: rc = 0
295 	 */
296 	if (DMVAR_EXEC(GET_EVENTS_BASE + 8)) {
297 		char buf[MSG_DATALEN];
298 
299 		/* Variation set up */
300 		expectedNumMsg = 2;
301 		eventsFlags = 0;
302 		memcpy(buf, MSG_DATA, MSG_DATALEN);
303 		rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, MSG_DATALEN, buf);
304 		if (rc != -1) {
305 			rc = pthread_create(&tid, NULL, Thread,
306 					    (void *)(GET_EVENTS_BASE + 8));
307 		}
308 		if (rc == -1) {
309 			DMLOG_PRINT(DMLVL_DEBUG,
310 				    "Unable to set up variation! (errno = %d)\n",
311 				    errno);
312 			DMVAR_SKIP();
313 		} else {
314 			/* Message thread finishes off variation */
315 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
316 			pthread_join(tid, NULL);
317 		}
318 	}
319 
320 	/*
321 	 * TEST    : dm_get_events - DM_EV_WAIT with two messages
322 	 * EXPECTED: rc = 0
323 	 */
324 	if (DMVAR_EXEC(GET_EVENTS_BASE + 9)) {
325 		char buf[MSG_DATALEN];
326 
327 		/* Variation set up */
328 		expectedNumMsg = 2;
329 		eventsFlags = DM_EV_WAIT;
330 		memcpy(buf, MSG_DATA, MSG_DATALEN);
331 		rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, MSG_DATALEN, buf);
332 		if (rc != -1) {
333 			rc = pthread_create(&tid, NULL, Thread,
334 					    (void *)(GET_EVENTS_BASE + 9));
335 		}
336 		if (rc == -1) {
337 			DMLOG_PRINT(DMLVL_DEBUG,
338 				    "Unable to set up variation! (errno = %d)\n",
339 				    errno);
340 			DMVAR_SKIP();
341 		} else {
342 			/* Message thread finishes off variation */
343 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
344 			pthread_join(tid, NULL);
345 		}
346 	}
347 
348 	/*
349 	 * TEST    : dm_get_events - !DM_EV_WAIT with more than MAX_EVENT messages
350 	 * EXPECTED: rc = 0
351 	 */
352 	if (DMVAR_EXEC(GET_EVENTS_BASE + 10)) {
353 		int i, j;
354 		char buf[MSG_DATALEN];
355 
356 		/* Variation set up */
357 		expectedNumMsg = MAX_EVENT;
358 		eventsFlags = 0;
359 		for (i = 0, rc = 0; i < MAX_EVENT + 1 && rc == 0; i++) {
360 			j = sprintf(buf, "Multi event message %d", i);
361 			rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, j + 1, buf);
362 		}
363 		if (rc != -1) {
364 			rc = pthread_create(&tid, NULL, Thread,
365 					    (void *)(GET_EVENTS_BASE + 10));
366 		}
367 		if (rc == -1) {
368 			DMLOG_PRINT(DMLVL_DEBUG,
369 				    "Unable to set up variation! (errno = %d)\n",
370 				    errno);
371 			DMVAR_SKIP();
372 		} else {
373 			/* Message thread finishes off variation */
374 			j = sprintf(buf, "Multi event message %d", i);
375 			dm_send_msg(sid, DM_MSGTYPE_SYNC, j + 1, buf);
376 			pthread_join(tid, NULL);
377 		}
378 	}
379 
380 	szFuncName = "dm_respond_event";
381 
382 	/*
383 	 * TEST    : dm_respond_event - invalid sid
384 	 * EXPECTED: rc = -1, errno = EINVAL
385 	 */
386 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 1)) {
387 		char buf[MSG_DATALEN];
388 		dm_token_t token;
389 
390 		/* Variation set up */
391 		memcpy(buf, MSG_DATA, MSG_DATALEN);
392 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
393 		if (rc == -1) {
394 			DMLOG_PRINT(DMLVL_DEBUG,
395 				    "Unable to set up variation! (errno = %d)\n",
396 				    errno);
397 			DMVAR_SKIP();
398 		} else {
399 			/* Variation */
400 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
401 				    szFuncName);
402 			rc = dm_respond_event(INVALID_ADDR, token,
403 					      DM_RESP_CONTINUE, 0, sizeof(buf),
404 					      buf);
405 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
406 
407 			/* Variation clean up */
408 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
409 					      0, NULL);
410 			if (rc == -1) {
411 				DMLOG_PRINT(DMLVL_DEBUG,
412 					    "Unable to clean up variation! (errno	= %d)\n",
413 					    errno);
414 			}
415 		}
416 	}
417 
418 	/*
419 	 * TEST    : dm_respond_event - DM_NO_SESSION sid
420 	 * EXPECTED: rc = -1, errno = EINVAL
421 	 */
422 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 2)) {
423 		char buf[MSG_DATALEN];
424 		dm_token_t token;
425 
426 		/* Variation set up */
427 		memcpy(buf, MSG_DATA, MSG_DATALEN);
428 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
429 		if (rc == -1) {
430 			DMLOG_PRINT(DMLVL_DEBUG,
431 				    "Unable to set up variation! (errno = %d)\n",
432 				    errno);
433 			DMVAR_SKIP();
434 		} else {
435 			/* Variation */
436 			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
437 				    szFuncName);
438 			rc = dm_respond_event(DM_NO_SESSION, token,
439 					      DM_RESP_CONTINUE, 0, sizeof(buf),
440 					      buf);
441 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
442 
443 			/* Variation clean up */
444 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
445 					      0, NULL);
446 			if (rc == -1) {
447 				DMLOG_PRINT(DMLVL_DEBUG,
448 					    "Unable to clean up variation! (errno	= %d)\n",
449 					    errno);
450 			}
451 		}
452 	}
453 
454 	/*
455 	 * TEST    : dm_respond_event - invalid token
456 	 * EXPECTED: rc = -1, errno = EINVAL
457 	 */
458 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 3)) {
459 		char buf[MSG_DATALEN];
460 
461 		/* Variation set up */
462 		memcpy(buf, MSG_DATA, MSG_DATALEN);
463 
464 		/* Variation */
465 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName);
466 		rc = dm_respond_event(sid, INVALID_ADDR, DM_RESP_CONTINUE, 0,
467 				      sizeof(buf), buf);
468 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
469 
470 		/* Variation clean up */
471 	}
472 
473 	/*
474 	 * TEST    : dm_respond_event - DM_NO_TOKEN token
475 	 * EXPECTED: rc = -1, errno = EINVAL
476 	 */
477 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 4)) {
478 		char buf[MSG_DATALEN];
479 
480 		/* Variation set up */
481 		memcpy(buf, MSG_DATA, MSG_DATALEN);
482 
483 		/* Variation */
484 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN token)\n", szFuncName);
485 		rc = dm_respond_event(sid, DM_NO_TOKEN, DM_RESP_CONTINUE, 0,
486 				      sizeof(buf), buf);
487 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
488 
489 		/* Variation clean up */
490 	}
491 
492 	/*
493 	 * TEST    : dm_respond_event - DM_INVALID_TOKEN token
494 	 * EXPECTED: rc = -1, errno = EINVAL
495 	 */
496 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 5)) {
497 		char buf[MSG_DATALEN];
498 
499 		/* Variation set up */
500 		memcpy(buf, MSG_DATA, MSG_DATALEN);
501 
502 		/* Variation */
503 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_INVALID_TOKEN token)\n",
504 			    szFuncName);
505 		rc = dm_respond_event(sid, DM_INVALID_TOKEN, DM_RESP_CONTINUE,
506 				      0, sizeof(buf), buf);
507 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
508 
509 		/* Variation clean up */
510 	}
511 
512 	/*
513 	 * TEST    : dm_respond_event - invalid response
514 	 * EXPECTED: rc = -1, errno = EINVAL
515 	 */
516 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 6)) {
517 		char buf[MSG_DATALEN];
518 		dm_token_t token;
519 
520 		/* Variation set up */
521 		memcpy(buf, MSG_DATA, MSG_DATALEN);
522 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
523 		if (rc == -1) {
524 			DMLOG_PRINT(DMLVL_DEBUG,
525 				    "Unable to set up variation! (errno = %d)\n",
526 				    errno);
527 			DMVAR_SKIP();
528 		} else {
529 			/* Variation */
530 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid response)\n",
531 				    szFuncName);
532 			rc = dm_respond_event(sid, token, INVALID_ADDR, 0,
533 					      sizeof(buf), buf);
534 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
535 
536 			/* Variation clean up */
537 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
538 					      0, NULL);
539 			if (rc == -1) {
540 				DMLOG_PRINT(DMLVL_DEBUG,
541 					    "Unable to clean up variation! (errno	= %d)\n",
542 					    errno);
543 			}
544 		}
545 	}
546 
547 	/*
548 	 * TEST    : dm_respond_event - invalid buflen
549 	 * EXPECTED: rc = -1, errno = E2BIG
550 	 *
551 	 * This variation uncovered XFS BUG #37 (0 returned instead of -1 and
552 	 * E2BIG)
553 	 */
554 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 7)) {
555 		char buf[MSG_DATALEN];
556 		dm_token_t token;
557 
558 		/* Variation set up */
559 		memcpy(buf, MSG_DATA, MSG_DATALEN);
560 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
561 		if (rc == -1) {
562 			DMLOG_PRINT(DMLVL_DEBUG,
563 				    "Unable to set up variation! (errno = %d)\n",
564 				    errno);
565 			DMVAR_SKIP();
566 		} else {
567 			/* Variation */
568 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid response)\n",
569 				    szFuncName);
570 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
571 					      INVALID_ADDR, buf);
572 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);
573 
574 			/* Variation clean up */
575 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
576 					      0, NULL);
577 			if (rc == -1) {
578 				DMLOG_PRINT(DMLVL_DEBUG,
579 					    "Unable to clean up variation! (errno	= %d)\n",
580 					    errno);
581 			}
582 		}
583 	}
584 
585 	/*
586 	 * TEST    : dm_respond_event - invalidated token
587 	 * EXPECTED: rc = -1, errno = ESRCH
588 	 */
589 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 8)) {
590 		char buf[MSG_DATALEN];
591 		dm_token_t token;
592 
593 		/* Variation set up */
594 		memcpy(buf, MSG_DATA, MSG_DATALEN);
595 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
596 		if (rc != -1) {
597 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
598 					      sizeof(buf), buf);
599 		}
600 		if (rc == -1) {
601 			DMLOG_PRINT(DMLVL_DEBUG,
602 				    "Unable to set up variation! (errno = %d)\n",
603 				    errno);
604 			DMVAR_SKIP();
605 		} else {
606 			/* Variation */
607 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated token)\n",
608 				    szFuncName);
609 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
610 					      sizeof(buf), buf);
611 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, ESRCH);
612 
613 			/* Variation clean up */
614 		}
615 	}
616 
617 	/*
618 	 * TEST    : dm_respond_event - DM_RESP_INVALID
619 	 * EXPECTED: rc = -1, errno = EINVAL
620 	 */
621 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 9)) {
622 		char buf[MSG_DATALEN];
623 
624 		/* Variation set up */
625 		memcpy(buf, MSG_DATA, MSG_DATALEN);
626 		rc = pthread_create(&tid, NULL, Thread,
627 				    (void *)(RESPOND_EVENT_BASE + 9));
628 		if (rc == -1) {
629 			DMLOG_PRINT(DMLVL_DEBUG,
630 				    "Unable to set up variation! (errno = %d)\n",
631 				    errno);
632 			DMVAR_SKIP();
633 		} else {
634 			/* Message thread finishes off variation */
635 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
636 			pthread_join(tid, NULL);
637 		}
638 	}
639 
640 	/*
641 	 * TEST    : dm_respond_event - DM_RESP_CONTINUE with zero reterror
642 	 * EXPECTED: rc = 0
643 	 */
644 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 10)) {
645 		char buf[MSG_DATALEN];
646 
647 		/* Variation set up */
648 		memcpy(buf, MSG_DATA, MSG_DATALEN);
649 		rc = pthread_create(&tid, NULL, Thread,
650 				    (void *)(RESPOND_EVENT_BASE + 10));
651 		if (rc == -1) {
652 			DMLOG_PRINT(DMLVL_DEBUG,
653 				    "Unable to set up variation! (errno = %d)\n",
654 				    errno);
655 			DMVAR_SKIP();
656 		} else {
657 			/* Message thread continues variation */
658 			rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN,
659 					 buf);
660 			if (rcRespond == 0) {
661 				if (rc == 0) {
662 					DMLOG_PRINT(DMLVL_DEBUG,
663 						    "%s passed with expected rc = %d and expected dm_send_msg rc = %d\n",
664 						    szFuncName, rcRespond, rc);
665 					DMVAR_PASS();
666 				} else {
667 					DMLOG_PRINT(DMLVL_ERR,
668 						    "%s failed with expected rc = %d but unexpected dm_send_msg rc = %d and errno %d\n",
669 						    szFuncName, rcRespond, rc,
670 						    errno);
671 					DMVAR_FAIL();
672 				}
673 			} else {
674 				DMLOG_PRINT(DMLVL_ERR,
675 					    "%s failed with unexpected rc = %d (errno = %d)\n",
676 					    szFuncName, rcRespond,
677 					    errnoRespond);
678 				DMVAR_FAIL();
679 			}
680 			pthread_join(tid, NULL);
681 		}
682 	}
683 
684 	/*
685 	 * TEST    : dm_respond_event - DM_RESP_CONTINUE with non-zero reterror
686 	 * EXPECTED: rc = -1, errno = EINVAL
687 	 */
688 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 11)) {
689 		char buf[MSG_DATALEN];
690 
691 		/* Variation set up */
692 		memcpy(buf, MSG_DATA, MSG_DATALEN);
693 		rc = pthread_create(&tid, NULL, Thread,
694 				    (void *)(RESPOND_EVENT_BASE + 11));
695 		if (rc == -1) {
696 			DMLOG_PRINT(DMLVL_DEBUG,
697 				    "Unable to set up variation! (errno = %d)\n",
698 				    errno);
699 			DMVAR_SKIP();
700 		} else {
701 			/* Message thread finishes off variation */
702 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
703 			pthread_join(tid, NULL);
704 		}
705 	}
706 
707 	/*
708 	 * TEST    : dm_respond_event - DM_RESP_ABORT with zero reterror
709 	 * EXPECTED: rc = -1, errno = EINVAL
710 	 */
711 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 12)) {
712 		char buf[MSG_DATALEN];
713 
714 		/* Variation set up */
715 		memcpy(buf, MSG_DATA, MSG_DATALEN);
716 		rc = pthread_create(&tid, NULL, Thread,
717 				    (void *)(RESPOND_EVENT_BASE + 12));
718 		if (rc == -1) {
719 			DMLOG_PRINT(DMLVL_DEBUG,
720 				    "Unable to set up variation! (errno = %d)\n",
721 				    errno);
722 			DMVAR_SKIP();
723 		} else {
724 			/* Message thread finishes off variation */
725 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
726 			pthread_join(tid, NULL);
727 		}
728 	}
729 
730 	/*
731 	 * TEST    : dm_respond_event - DM_RESP_ABORT with non-zero reterror
732 	 * EXPECTED: rc = ABORT_ERRNO
733 	 */
734 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 13)) {
735 		char buf[MSG_DATALEN];
736 
737 		/* Variation set up */
738 		memcpy(buf, MSG_DATA, MSG_DATALEN);
739 		rc = pthread_create(&tid, NULL, Thread,
740 				    (void *)(RESPOND_EVENT_BASE + 13));
741 		if (rc == -1) {
742 			DMLOG_PRINT(DMLVL_DEBUG,
743 				    "Unable to set up variation! (errno = %d)\n",
744 				    errno);
745 			DMVAR_SKIP();
746 		} else {
747 			/* Message thread continues variation */
748 			rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN,
749 					 buf);
750 			if (rcRespond == 0) {
751 				if (rc == -1) {
752 					if (errno == ABORT_ERRNO) {
753 						DMLOG_PRINT(DMLVL_DEBUG,
754 							    "%s passed with expected rc = %d and dm_send_msg rc = %d\n",
755 							    szFuncName,
756 							    rcRespond, rc);
757 						DMVAR_PASS();
758 					} else {
759 						DMLOG_PRINT(DMLVL_ERR,
760 							    "%s failed with expected rc = %d and dm_send_msg rc = %d but unexpected errno (%d vs %d)\n",
761 							    szFuncName,
762 							    rcRespond, rc,
763 							    errno, ABORT_ERRNO);
764 						DMVAR_FAIL();
765 					}
766 				} else {
767 					DMLOG_PRINT(DMLVL_ERR,
768 						    "%s failed with expected rc = %d but unexpected dm_send_msg rc (%d vs %d)\n",
769 						    szFuncName, rcRespond, rc,
770 						    -1);
771 					DMVAR_FAIL();
772 				}
773 			} else {
774 				DMLOG_PRINT(DMLVL_ERR,
775 					    "%s failed with unexpected rc = %d (errno = %d)\n",
776 					    szFuncName, rcRespond,
777 					    errnoRespond);
778 				DMVAR_FAIL();
779 			}
780 			pthread_join(tid, NULL);
781 		}
782 	}
783 
784 	/*
785 	 * TEST    : dm_respond_event - DM_RESP_DONTCARE
786 	 * EXPECTED: rc = -1, errno = EINVAL
787 	 */
788 	if (DMVAR_EXEC(RESPOND_EVENT_BASE + 14)) {
789 		char buf[MSG_DATALEN];
790 
791 		/* Variation set up */
792 		memcpy(buf, MSG_DATA, MSG_DATALEN);
793 		rc = pthread_create(&tid, NULL, Thread,
794 				    (void *)(RESPOND_EVENT_BASE + 14));
795 		if (rc == -1) {
796 			DMLOG_PRINT(DMLVL_DEBUG,
797 				    "Unable to set up variation! (errno = %d)\n",
798 				    errno);
799 			DMVAR_SKIP();
800 		} else {
801 			/* Message thread finishes off variation */
802 			dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf);
803 			pthread_join(tid, NULL);
804 		}
805 	}
806 
807 	szFuncName = "dm_move_event";
808 
809 	/*
810 	 * TEST    : dm_move_event - invalid srcsid
811 	 * EXPECTED: rc = -1, errno = EINVAL
812 	 */
813 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 1)) {
814 		dm_sessid_t targsid;
815 		dm_token_t token, rtoken;
816 		char buf[MSG_DATALEN];
817 
818 		/* Variation set up */
819 		memcpy(buf, MSG_DATA, MSG_DATALEN);
820 		if ((rc =
821 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
822 				       &targsid)) == -1) {
823 			/* No clean up */
824 		} else
825 		    if ((rc =
826 			 dm_create_userevent(sid, MSG_DATALEN, buf,
827 					     &token)) == -1) {
828 			dm_destroy_session(targsid);
829 		}
830 		if (rc == -1) {
831 			DMLOG_PRINT(DMLVL_DEBUG,
832 				    "Unable to set up variation! (errno = %d)\n",
833 				    errno);
834 			DMVAR_SKIP();
835 		} else {
836 			/* Variation */
837 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid srcsid)\n",
838 				    szFuncName);
839 			rc = dm_move_event(INVALID_ADDR, token, targsid,
840 					   &rtoken);
841 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
842 
843 			/* Variation clean up */
844 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
845 					      0, NULL);
846 			rc |= dm_destroy_session(targsid);
847 			if (rc == -1) {
848 				DMLOG_PRINT(DMLVL_DEBUG,
849 					    "Unable to clean up variation! (errno	= %d)\n",
850 					    errno);
851 			}
852 		}
853 	}
854 
855 	/*
856 	 * TEST    : dm_move_event - DM_NO_SESSION srcsid
857 	 * EXPECTED: rc = -1, errno = EINVAL
858 	 */
859 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 2)) {
860 		dm_sessid_t targsid;
861 		dm_token_t token, rtoken;
862 		char buf[MSG_DATALEN];
863 
864 		/* Variation set up */
865 		memcpy(buf, MSG_DATA, MSG_DATALEN);
866 		if ((rc =
867 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
868 				       &targsid)) == -1) {
869 			/* No clean up */
870 		} else
871 		    if ((rc =
872 			 dm_create_userevent(sid, MSG_DATALEN, buf,
873 					     &token)) == -1) {
874 			dm_destroy_session(targsid);
875 		}
876 		if (rc == -1) {
877 			DMLOG_PRINT(DMLVL_DEBUG,
878 				    "Unable to set up variation! (errno = %d)\n",
879 				    errno);
880 			DMVAR_SKIP();
881 		} else {
882 			/* Variation */
883 			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION srcsid)\n",
884 				    szFuncName);
885 			rc = dm_move_event(DM_NO_SESSION, token, targsid,
886 					   &rtoken);
887 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
888 
889 			/* Variation clean up */
890 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
891 					      0, NULL);
892 			rc |= dm_destroy_session(targsid);
893 			if (rc == -1) {
894 				DMLOG_PRINT(DMLVL_DEBUG,
895 					    "Unable to clean up variation! (errno	= %d)\n",
896 					    errno);
897 			}
898 		}
899 	}
900 
901 	/*
902 	 * TEST    : dm_move_event - invalid token
903 	 * EXPECTED: rc = -1, errno = EINVAL
904 	 */
905 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 3)) {
906 		dm_sessid_t targsid;
907 		dm_token_t token, rtoken;
908 		char buf[MSG_DATALEN];
909 
910 		/* Variation set up */
911 		memcpy(buf, MSG_DATA, MSG_DATALEN);
912 		if ((rc =
913 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
914 				       &targsid)) == -1) {
915 			/* No clean up */
916 		} else
917 		    if ((rc =
918 			 dm_create_userevent(sid, MSG_DATALEN, buf,
919 					     &token)) == -1) {
920 			dm_destroy_session(targsid);
921 		}
922 		if (rc == -1) {
923 			DMLOG_PRINT(DMLVL_DEBUG,
924 				    "Unable to set up variation! (errno = %d)\n",
925 				    errno);
926 			DMVAR_SKIP();
927 		} else {
928 			/* Variation */
929 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
930 				    szFuncName);
931 			rc = dm_move_event(sid, INVALID_ADDR, targsid, &rtoken);
932 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
933 
934 			/* Variation clean up */
935 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
936 					      0, NULL);
937 			rc |= dm_destroy_session(targsid);
938 			if (rc == -1) {
939 				DMLOG_PRINT(DMLVL_DEBUG,
940 					    "Unable to clean up variation! (errno	= %d)\n",
941 					    errno);
942 			}
943 		}
944 	}
945 
946 	/*
947 	 * TEST    : dm_move_event - invalid targetsid
948 	 * EXPECTED: rc = -1, errno = EINVAL
949 	 */
950 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 4)) {
951 		dm_sessid_t targsid;
952 		dm_token_t token, rtoken;
953 		char buf[MSG_DATALEN];
954 
955 		/* Variation set up */
956 		memcpy(buf, MSG_DATA, MSG_DATALEN);
957 		if ((rc =
958 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
959 				       &targsid)) == -1) {
960 			/* No clean up */
961 		} else
962 		    if ((rc =
963 			 dm_create_userevent(sid, MSG_DATALEN, buf,
964 					     &token)) == -1) {
965 			dm_destroy_session(targsid);
966 		}
967 		if (rc == -1) {
968 			DMLOG_PRINT(DMLVL_DEBUG,
969 				    "Unable to set up variation! (errno = %d)\n",
970 				    errno);
971 			DMVAR_SKIP();
972 		} else {
973 			/* Variation */
974 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid targetsid)\n",
975 				    szFuncName);
976 			rc = dm_move_event(sid, token, INVALID_ADDR, &rtoken);
977 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
978 
979 			/* Variation clean up */
980 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
981 					      0, NULL);
982 			rc |= dm_destroy_session(targsid);
983 			if (rc == -1) {
984 				DMLOG_PRINT(DMLVL_DEBUG,
985 					    "Unable to clean up variation! (errno	= %d)\n",
986 					    errno);
987 			}
988 		}
989 	}
990 
991 	/*
992 	 * TEST    : dm_move_event - DM_NO_SESSION targetsid
993 	 * EXPECTED: rc = -1, errno = EINVAL
994 	 */
995 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 5)) {
996 		dm_sessid_t targsid;
997 		dm_token_t token, rtoken;
998 		char buf[MSG_DATALEN];
999 
1000 		/* Variation set up */
1001 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1002 		if ((rc =
1003 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
1004 				       &targsid)) == -1) {
1005 			/* No clean up */
1006 		} else
1007 		    if ((rc =
1008 			 dm_create_userevent(sid, MSG_DATALEN, buf,
1009 					     &token)) == -1) {
1010 			dm_destroy_session(targsid);
1011 		}
1012 		if (rc == -1) {
1013 			DMLOG_PRINT(DMLVL_DEBUG,
1014 				    "Unable to set up variation! (errno = %d)\n",
1015 				    errno);
1016 			DMVAR_SKIP();
1017 		} else {
1018 			/* Variation */
1019 			DMLOG_PRINT(DMLVL_DEBUG,
1020 				    "%s(DM_NO_SESSION targetsid)\n",
1021 				    szFuncName);
1022 			rc = dm_move_event(sid, token, DM_NO_SESSION, &rtoken);
1023 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1024 
1025 			/* Variation clean up */
1026 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1027 					      0, NULL);
1028 			rc |= dm_destroy_session(targsid);
1029 			if (rc == -1) {
1030 				DMLOG_PRINT(DMLVL_DEBUG,
1031 					    "Unable to clean up variation! (errno	= %d)\n",
1032 					    errno);
1033 			}
1034 		}
1035 	}
1036 
1037 	/*
1038 	 * TEST    : dm_move_event - invalid rtokenp
1039 	 * EXPECTED: rc = -1, errno = EFAULT
1040 	 *
1041 	 * This variation uncovered XFS BUG #36 (event moved to targetsid
1042 	 * despite failure)
1043 	 */
1044 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 6)) {
1045 		dm_sessid_t targsid;
1046 		dm_token_t token;
1047 		char buf[MSG_DATALEN];
1048 
1049 		/* Variation set up */
1050 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1051 		if ((rc =
1052 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
1053 				       &targsid)) == -1) {
1054 			/* No clean up */
1055 		} else
1056 		    if ((rc =
1057 			 dm_create_userevent(sid, MSG_DATALEN, buf,
1058 					     &token)) == -1) {
1059 			dm_destroy_session(targsid);
1060 		}
1061 		if (rc == -1) {
1062 			DMLOG_PRINT(DMLVL_DEBUG,
1063 				    "Unable to set up variation! (errno = %d)\n",
1064 				    errno);
1065 			DMVAR_SKIP();
1066 		} else {
1067 			/* Variation */
1068 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rtokenp)\n",
1069 				    szFuncName);
1070 			rc = dm_move_event(sid, token, targsid,
1071 					   (dm_token_t *) INVALID_ADDR);
1072 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1073 
1074 			/* Variation clean up */
1075 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1076 					      0, NULL);
1077 			rc |= dm_destroy_session(targsid);
1078 			if (rc == -1) {
1079 				DMLOG_PRINT(DMLVL_DEBUG,
1080 					    "Unable to clean up variation! (errno	= %d)\n",
1081 					    errno);
1082 			}
1083 		}
1084 	}
1085 
1086 	/*
1087 	 * TEST    : dm_move_event - token not in session
1088 	 * EXPECTED: rc = -1, errno = ENOENT
1089 	 *
1090 	 * This variation uncovered XFS BUG #34 (ESRCH returned instead of
1091 	 * ENOENT)
1092 	 */
1093 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 7)) {
1094 		dm_sessid_t targsid;
1095 		dm_token_t token, rtoken;
1096 		char buf[MSG_DATALEN];
1097 
1098 		/* Variation set up */
1099 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1100 		if ((rc =
1101 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
1102 				       &targsid)) == -1) {
1103 			/* No clean up */
1104 		} else
1105 		    if ((rc =
1106 			 dm_create_userevent(sid, MSG_DATALEN, buf,
1107 					     &token)) == -1) {
1108 			dm_destroy_session(targsid);
1109 		}
1110 		if (rc == -1) {
1111 			DMLOG_PRINT(DMLVL_DEBUG,
1112 				    "Unable to set up variation! (errno = %d)\n",
1113 				    errno);
1114 			DMVAR_SKIP();
1115 		} else {
1116 			/* Variation */
1117 			DMLOG_PRINT(DMLVL_DEBUG, "%s(token not in session)\n",
1118 				    szFuncName);
1119 			rc = dm_move_event(targsid, token, sid, &rtoken);
1120 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, ENOENT);
1121 
1122 			/* Variation clean up */
1123 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1124 					      0, NULL);
1125 			rc |= dm_destroy_session(targsid);
1126 			if (rc == -1) {
1127 				DMLOG_PRINT(DMLVL_DEBUG,
1128 					    "Unable to clean up variation! (errno	= %d)\n",
1129 					    errno);
1130 			}
1131 		}
1132 	}
1133 
1134 	/*
1135 	 * TEST    : dm_move_event - srcsid == targetsid
1136 	 * EXPECTED: rc = 0
1137 	 */
1138 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 8)) {
1139 		dm_sessid_t targsid;
1140 		dm_token_t token, rtoken;
1141 		char buf[MSG_DATALEN];
1142 		size_t rlen;
1143 
1144 		/* Variation set up */
1145 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1146 		if ((rc =
1147 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
1148 				       &targsid)) == -1) {
1149 			/* No clean up */
1150 		} else
1151 		    if ((rc =
1152 			 dm_create_userevent(sid, MSG_DATALEN, buf,
1153 					     &token)) == -1) {
1154 			dm_destroy_session(targsid);
1155 		}
1156 		if (rc == -1) {
1157 			DMLOG_PRINT(DMLVL_DEBUG,
1158 				    "Unable to set up variation! (errno = %d)\n",
1159 				    errno);
1160 			DMVAR_SKIP();
1161 		} else {
1162 			/* Variation */
1163 			DMLOG_PRINT(DMLVL_DEBUG, "%s(srcsid == targetsid)\n",
1164 				    szFuncName);
1165 			rc = dm_move_event(sid, token, sid, &rtoken);
1166 			if (rc == 0) {
1167 				DMLOG_PRINT(DMLVL_DEBUG, "rtoken = %d\n",
1168 					    rtoken);
1169 				rc = dm_find_eventmsg(sid, rtoken,
1170 						      sizeof(dmMsgBuf),
1171 						      dmMsgBuf, &rlen);
1172 				if (rc == 0 && rlen > 0) {
1173 					DMLOG_PRINT(DMLVL_DEBUG,
1174 						    "%s passed with expected rc = %d\n",
1175 						    szFuncName, 0);
1176 					DMVAR_PASS();
1177 				} else {
1178 					DMLOG_PRINT(DMLVL_ERR,
1179 						    "%s failed with expected rc = %d but token %d NOT in src/target session %d\n",
1180 						    szFuncName, 0, token, sid);
1181 					DMVAR_FAIL();
1182 				}
1183 			} else {
1184 				DMLOG_PRINT(DMLVL_ERR,
1185 					    "%s failed with unexpected rc = %d (errno = %d)\n",
1186 					    szFuncName, rc, errno);
1187 				DMVAR_FAIL();
1188 			}
1189 
1190 			/* Variation clean up */
1191 			rc = dm_respond_event(sid, rtoken, DM_RESP_CONTINUE, 0,
1192 					      0, NULL);
1193 			rc |= dm_destroy_session(targsid);
1194 			if (rc == -1) {
1195 				DMLOG_PRINT(DMLVL_DEBUG,
1196 					    "Unable to clean up variation! (errno	= %d)\n",
1197 					    errno);
1198 			}
1199 		}
1200 	}
1201 
1202 	/*
1203 	 * TEST    : dm_move_event - srcsid != targetsid
1204 	 * EXPECTED: rc = 0
1205 	 *
1206 	 * This variation uncovered XFS BUG #35 (ESRCH returned instead of
1207 	 * EINVAL)
1208 	 */
1209 	if (DMVAR_EXEC(MOVE_EVENT_BASE + 9)) {
1210 		dm_sessid_t targsid;
1211 		dm_token_t token, rtoken;
1212 		char buf[MSG_DATALEN];
1213 		size_t rlen;
1214 
1215 		/* Variation set up */
1216 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1217 		if ((rc =
1218 		     dm_create_session(DM_NO_SESSION, szSessionInfo,
1219 				       &targsid)) == -1) {
1220 			/* No clean up */
1221 		} else
1222 		    if ((rc =
1223 			 dm_create_userevent(sid, MSG_DATALEN, buf,
1224 					     &token)) == -1) {
1225 			dm_destroy_session(targsid);
1226 		}
1227 		if (rc == -1) {
1228 			DMLOG_PRINT(DMLVL_DEBUG,
1229 				    "Unable to set up variation! (errno = %d)\n",
1230 				    errno);
1231 			DMVAR_SKIP();
1232 		} else {
1233 			/* Variation */
1234 			DMLOG_PRINT(DMLVL_DEBUG, "%s(srcsid != targetsid)\n",
1235 				    szFuncName);
1236 			rc = dm_move_event(sid, token, targsid, &rtoken);
1237 			if (rc == 0) {
1238 				DMLOG_PRINT(DMLVL_DEBUG, "rtoken = %d\n",
1239 					    rtoken);
1240 				rc = dm_find_eventmsg(sid, token,
1241 						      sizeof(dmMsgBuf),
1242 						      dmMsgBuf, &rlen);
1243 				if (rc == -1 && errno == EINVAL) {
1244 					rc = dm_find_eventmsg(targsid, rtoken,
1245 							      sizeof(dmMsgBuf),
1246 							      dmMsgBuf, &rlen);
1247 					if (rc == 0 && rlen > 0) {
1248 						DMLOG_PRINT(DMLVL_DEBUG,
1249 							    "%s passed with expected rc = %d\n",
1250 							    szFuncName, 0);
1251 						DMVAR_PASS();
1252 					} else {
1253 						DMLOG_PRINT(DMLVL_ERR,
1254 							    "%s failed with expected rc = %d but token %d NOT in target session %d\n",
1255 							    szFuncName, 0,
1256 							    token, targsid);
1257 						DMVAR_FAIL();
1258 					}
1259 				} else {
1260 					DMLOG_PRINT(DMLVL_ERR,
1261 						    "%s failed with expected rc = %d but token %d still in source session %d\n",
1262 						    szFuncName, 0, token, sid);
1263 					DMVAR_FAIL();
1264 				}
1265 			} else {
1266 				DMLOG_PRINT(DMLVL_ERR,
1267 					    "%s failed with unexpected rc = %d (errno = %d)\n",
1268 					    szFuncName, rc, errno);
1269 				DMVAR_FAIL();
1270 			}
1271 
1272 			/* Variation clean up */
1273 			rc = dm_respond_event(targsid, rtoken, DM_RESP_CONTINUE,
1274 					      0, 0, NULL);
1275 			rc |= dm_destroy_session(targsid);
1276 			if (rc == -1) {
1277 				DMLOG_PRINT(DMLVL_DEBUG,
1278 					    "Unable to clean up variation! (errno	= %d)\n",
1279 					    errno);
1280 			}
1281 		}
1282 	}
1283 
1284 	szFuncName = "dm_pending";
1285 
1286 	/*
1287 	 * TEST    : dm_pending - invalid sid
1288 	 * EXPECTED: rc = -1, errno = EINVAL
1289 	 */
1290 	if (DMVAR_EXEC(PENDING_BASE + 1)) {
1291 		char buf[MSG_DATALEN];
1292 		dm_token_t token;
1293 		dm_timestruct_t delay;
1294 
1295 		/* Variation set up */
1296 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1297 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
1298 		if (rc == -1) {
1299 			DMLOG_PRINT(DMLVL_DEBUG,
1300 				    "Unable to set up variation! (errno = %d)\n",
1301 				    errno);
1302 			DMVAR_SKIP();
1303 		} else {
1304 			/* Variation */
1305 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
1306 				    szFuncName);
1307 			rc = dm_pending(INVALID_ADDR, token, &delay);
1308 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1309 
1310 			/* Variation clean up */
1311 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1312 					      0, NULL);
1313 			if (rc == -1) {
1314 				DMLOG_PRINT(DMLVL_DEBUG,
1315 					    "Unable to clean up variation! (errno	= %d)\n",
1316 					    errno);
1317 			}
1318 		}
1319 	}
1320 
1321 	/*
1322 	 * TEST    : dm_pending - DM_NO_SESSION sid
1323 	 * EXPECTED: rc = -1, errno = EINVAL
1324 	 */
1325 	if (DMVAR_EXEC(PENDING_BASE + 2)) {
1326 		char buf[MSG_DATALEN];
1327 		dm_token_t token;
1328 		dm_timestruct_t delay;
1329 
1330 		/* Variation set up */
1331 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1332 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
1333 		if (rc == -1) {
1334 			DMLOG_PRINT(DMLVL_DEBUG,
1335 				    "Unable to set up variation! (errno = %d)\n",
1336 				    errno);
1337 			DMVAR_SKIP();
1338 		} else {
1339 			/* Variation */
1340 			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
1341 				    szFuncName);
1342 			rc = dm_pending(DM_NO_SESSION, token, &delay);
1343 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1344 
1345 			/* Variation clean up */
1346 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1347 					      0, NULL);
1348 			if (rc == -1) {
1349 				DMLOG_PRINT(DMLVL_DEBUG,
1350 					    "Unable to clean up variation! (errno	= %d)\n",
1351 					    errno);
1352 			}
1353 		}
1354 	}
1355 
1356 	/*
1357 	 * TEST    : dm_pending - invalid token
1358 	 * EXPECTED: rc = -1, errno = EINVAL
1359 	 */
1360 	if (DMVAR_EXEC(PENDING_BASE + 3)) {
1361 		dm_timestruct_t delay;
1362 
1363 		/* Variation set up */
1364 
1365 		/* Variation */
1366 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName);
1367 		rc = dm_pending(sid, INVALID_ADDR, &delay);
1368 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1369 
1370 		/* Variation clean up */
1371 	}
1372 
1373 	/*
1374 	 * TEST    : dm_pending - DM_NO_TOKEN token
1375 	 * EXPECTED: rc = -1, errno = EINVAL
1376 	 */
1377 	if (DMVAR_EXEC(PENDING_BASE + 4)) {
1378 		dm_timestruct_t delay;
1379 
1380 		/* Variation set up */
1381 
1382 		/* Variation */
1383 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN token)\n", szFuncName);
1384 		rc = dm_pending(sid, DM_NO_TOKEN, &delay);
1385 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1386 
1387 		/* Variation clean up */
1388 	}
1389 
1390 	/*
1391 	 * TEST    : dm_pending - DM_INVALID_TOKEN token
1392 	 * EXPECTED: rc = -1, errno = EINVAL
1393 	 */
1394 	if (DMVAR_EXEC(PENDING_BASE + 5)) {
1395 		dm_timestruct_t delay;
1396 
1397 		/* Variation set up */
1398 
1399 		/* Variation */
1400 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_INVALID_TOKEN token)\n",
1401 			    szFuncName);
1402 		rc = dm_pending(sid, DM_INVALID_TOKEN, &delay);
1403 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1404 
1405 		/* Variation clean up */
1406 	}
1407 
1408 	/*
1409 	 * TEST    : dm_pending - invalid delay
1410 	 * EXPECTED: rc = -1, errno = EFAULT
1411 	 */
1412 	if (DMVAR_EXEC(PENDING_BASE + 6)) {
1413 		char buf[MSG_DATALEN];
1414 		dm_token_t token;
1415 
1416 		/* Variation set up */
1417 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1418 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
1419 		if (rc == -1) {
1420 			DMLOG_PRINT(DMLVL_DEBUG,
1421 				    "Unable to set up variation! (errno = %d)\n",
1422 				    errno);
1423 			DMVAR_SKIP();
1424 		} else {
1425 			/* Variation */
1426 			DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
1427 				    szFuncName);
1428 			rc = dm_pending(sid, token,
1429 					(dm_timestruct_t *) INVALID_ADDR);
1430 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1431 
1432 			/* Variation clean up */
1433 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1434 					      0, NULL);
1435 			if (rc == -1) {
1436 				DMLOG_PRINT(DMLVL_DEBUG,
1437 					    "Unable to clean up variation! (errno	= %d)\n",
1438 					    errno);
1439 			}
1440 		}
1441 	}
1442 
1443 	/*
1444 	 * TEST    : dm_respond_event - invalidated token
1445 	 * EXPECTED: rc = -1, errno = ESRCH
1446 	 */
1447 	if (DMVAR_EXEC(PENDING_BASE + 7)) {
1448 		char buf[MSG_DATALEN];
1449 		dm_token_t token;
1450 		dm_timestruct_t delay;
1451 
1452 		/* Variation set up */
1453 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1454 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
1455 		if (rc != -1) {
1456 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1457 					      sizeof(buf), buf);
1458 		}
1459 		if (rc == -1) {
1460 			DMLOG_PRINT(DMLVL_DEBUG,
1461 				    "Unable to set up variation! (errno = %d)\n",
1462 				    errno);
1463 			DMVAR_SKIP();
1464 		} else {
1465 			/* Variation */
1466 			DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated token)\n",
1467 				    szFuncName);
1468 			rc = dm_pending(sid, token, &delay);
1469 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, ESRCH);
1470 
1471 			/* Variation clean up */
1472 		}
1473 	}
1474 
1475 	/*
1476 	 * TEST    : dm_pending - valid
1477 	 * EXPECTED: rc = 0
1478 	 */
1479 	if (DMVAR_EXEC(PENDING_BASE + 8)) {
1480 		char buf[MSG_DATALEN];
1481 		dm_token_t token;
1482 		dm_timestruct_t delay;
1483 
1484 		/* Variation set up */
1485 		memcpy(buf, MSG_DATA, MSG_DATALEN);
1486 		rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token);
1487 		if (rc == -1) {
1488 			DMLOG_PRINT(DMLVL_DEBUG,
1489 				    "Unable to set up variation! (errno = %d)\n",
1490 				    errno);
1491 			DMVAR_SKIP();
1492 		} else {
1493 			/* Variation */
1494 			DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName);
1495 			rc = dm_pending(sid, token, &delay);
1496 			DMVAR_ENDPASSEXP(szFuncName, 0, rc);
1497 
1498 			/* Variation clean up */
1499 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1500 					      0, NULL);
1501 			if (rc == -1) {
1502 				DMLOG_PRINT(DMLVL_DEBUG,
1503 					    "Unable to clean up variation! (errno	= %d)\n",
1504 					    errno);
1505 			}
1506 		}
1507 	}
1508 
1509 	rc = dm_destroy_session(sid);
1510 	if (rc == -1) {
1511 		DMLOG_PRINT(DMLVL_ERR,
1512 			    "dm_destroy_session failed! (rc = %d, errno = %d)\n",
1513 			    rc, errno);
1514 	}
1515 
1516 	DMLOG_STOP();
1517 
1518 	tst_exit();
1519 }
1520 
Thread(void * parm)1521 void *Thread(void *parm)
1522 {
1523 	int rc;
1524 	dm_token_t token;
1525 	size_t rlen;
1526 	dm_eventmsg_t *dmMsg;
1527 	int numMsg;
1528 
1529 	EVENT_DELIVERY_DELAY;
1530 
1531 	switch ((long)parm) {
1532 	case GET_EVENTS_BASE + 2:
1533 		/* Variation */
1534 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName);
1535 		rc = dm_get_events(sid, MAX_EVENT, 0, 0, dmMsgBuf, &rlen);
1536 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG);
1537 
1538 		/* Variation clean up */
1539 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1540 				   dmMsgBuf, &rlen);
1541 		if (rc == 0) {
1542 			token = ((dm_eventmsg_t *) dmMsgBuf)->ev_token;
1543 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1544 					      0, NULL);
1545 		}
1546 		if (rc == -1) {
1547 			DMLOG_PRINT(DMLVL_DEBUG,
1548 				    "Unable to clean up variation! (errno	= %d)\n",
1549 				    errno);
1550 		}
1551 		break;
1552 
1553 	case GET_EVENTS_BASE + 3:
1554 		/* Variation */
1555 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName);
1556 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1557 				   (void *)INVALID_ADDR, &rlen);
1558 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1559 
1560 		/* Variation clean up */
1561 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1562 				   dmMsgBuf, &rlen);
1563 		if (rc == 0) {
1564 			token = ((dm_eventmsg_t *) dmMsgBuf)->ev_token;
1565 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1566 					      0, NULL);
1567 		}
1568 		if (rc == -1) {
1569 			DMLOG_PRINT(DMLVL_DEBUG,
1570 				    "Unable to clean up variation! (errno	= %d)\n",
1571 				    errno);
1572 		}
1573 		break;
1574 
1575 	case GET_EVENTS_BASE + 4:
1576 		/* Variation */
1577 		DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", szFuncName);
1578 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1579 				   dmMsgBuf, (size_t *) INVALID_ADDR);
1580 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1581 
1582 		/* Variation clean up */
1583 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1584 				   dmMsgBuf, &rlen);
1585 		if (rc == 0) {
1586 			token = ((dm_eventmsg_t *) dmMsgBuf)->ev_token;
1587 			rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0,
1588 					      0, NULL);
1589 		}
1590 		if (rc == -1) {
1591 			DMLOG_PRINT(DMLVL_DEBUG,
1592 				    "Unable to clean up variation! (errno	= %d)\n",
1593 				    errno);
1594 		}
1595 		break;
1596 
1597 	case GET_EVENTS_BASE + 5:
1598 		/* Variation */
1599 		DMLOG_PRINT(DMLVL_DEBUG, "%s(!DM_EV_WAIT with no messages)\n",
1600 			    szFuncName);
1601 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1602 				   dmMsgBuf, &rlen);
1603 		DMVAR_ENDFAILEXP(szFuncName, -1, rc, EAGAIN);
1604 
1605 		/* Variation clean up */
1606 
1607 		break;
1608 
1609 	case GET_EVENTS_BASE + 6:
1610 	case GET_EVENTS_BASE + 7:
1611 	case GET_EVENTS_BASE + 8:
1612 	case GET_EVENTS_BASE + 9:
1613 		/* Variation */
1614 		DMLOG_PRINT(DMLVL_DEBUG, "%s(%s with %d message(s))\n",
1615 			    szFuncName,
1616 			    (eventsFlags & DM_EV_WAIT) ? "DM_EV_WAIT" :
1617 			    "!DM_EV_WAIT", expectedNumMsg);
1618 		do {
1619 			rlen = 0;
1620 			rc = dm_get_events(sid, MAX_EVENT, eventsFlags,
1621 					   sizeof(dmMsgBuf), dmMsgBuf, &rlen);
1622 		} while ((eventsFlags & DM_EV_WAIT) && (rc == -1)
1623 			 && (errno == EINTR) && (rlen == 0));
1624 		if (rc == 0) {
1625 			LogEventMsgs(dmMsgBuf);
1626 			numMsg = GetNumEventMsg(dmMsgBuf);
1627 			dmMsg = GetSyncEventMsg(dmMsgBuf);
1628 			DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
1629 
1630 			if (numMsg == expectedNumMsg) {
1631 				if (dmMsg != NULL) {
1632 					if (dmMsg->ev_type == DM_EVENT_USER) {
1633 						DMLOG_PRINT(DMLVL_DEBUG,
1634 							    "%s passed with expected rc = %d\n",
1635 							    szFuncName, 0);
1636 						DMVAR_PASS();
1637 					} else {
1638 						DMLOG_PRINT(DMLVL_ERR,
1639 							    "%s failed with expected rc = %d but unexpected event (%d vs %d)\n",
1640 							    szFuncName, 0,
1641 							    dmMsg->ev_type,
1642 							    DM_EVENT_USER);
1643 						DMVAR_FAIL();
1644 					}
1645 				} else {
1646 					DMLOG_PRINT(DMLVL_ERR,
1647 						    "%s failed with expected rc = %d but no synchronous event\n",
1648 						    szFuncName, 0);
1649 					DMVAR_FAIL();
1650 				}
1651 			} else {
1652 				DMLOG_PRINT(DMLVL_ERR,
1653 					    "%s failed with expected rc = %d but unexpected number of events (%d vs %d)\n",
1654 					    szFuncName, 0, numMsg,
1655 					    expectedNumMsg);
1656 				DMVAR_FAIL();
1657 			}
1658 		} else {
1659 			dmMsg = NULL;
1660 			DMLOG_PRINT(DMLVL_ERR,
1661 				    "%s failed with unexpected rc = %d (errno = %d)\n",
1662 				    szFuncName, rc, errno);
1663 			DMVAR_FAIL();
1664 		}
1665 
1666 		/* Variation clean up */
1667 		rc = dm_respond_event(sid,
1668 				      dmMsg ? dmMsg->
1669 				      ev_token : DM_INVALID_TOKEN,
1670 				      DM_RESP_CONTINUE, 0, 0, NULL);
1671 		if (rc == -1) {
1672 			DMLOG_PRINT(DMLVL_DEBUG,
1673 				    "Unable to clean up variation! (errno	= %d)\n",
1674 				    errno);
1675 		}
1676 
1677 		break;
1678 
1679 	case GET_EVENTS_BASE + 10:
1680 		/* Variation */
1681 		DMLOG_PRINT(DMLVL_DEBUG, "%s(%s with %d messages)\n",
1682 			    szFuncName,
1683 			    (eventsFlags & DM_EV_WAIT) ? "DM_EV_WAIT" :
1684 			    "!DM_EV_WAIT", expectedNumMsg);
1685 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1686 				   dmMsgBuf, &rlen);
1687 		if (rc == 0) {
1688 			DMLOG_PRINT(DMLVL_DEBUG, "1st call:\n");
1689 			LogEventMsgs(dmMsgBuf);
1690 			numMsg = GetNumEventMsg(dmMsgBuf);
1691 			DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
1692 			rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1693 					   dmMsgBuf, &rlen);
1694 			if (rc == 0) {
1695 				DMLOG_PRINT(DMLVL_DEBUG, "2nd call:\n");
1696 				DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
1697 				LogEventMsgs(dmMsgBuf);
1698 				dmMsg = GetSyncEventMsg(dmMsgBuf);
1699 
1700 				if (numMsg == expectedNumMsg) {
1701 					if (dmMsg != NULL) {
1702 						if (dmMsg->ev_type ==
1703 						    DM_EVENT_USER) {
1704 							DMLOG_PRINT(DMLVL_DEBUG,
1705 								    "%s passed with expected rc = %d\n",
1706 								    szFuncName,
1707 								    0);
1708 							DMVAR_PASS();
1709 						} else {
1710 							DMLOG_PRINT(DMLVL_ERR,
1711 								    "%s failed with expected rc = %d but unexpected event (%d vs %d)\n",
1712 								    szFuncName,
1713 								    0,
1714 								    dmMsg->
1715 								    ev_type,
1716 								    DM_EVENT_USER);
1717 							DMVAR_FAIL();
1718 						}
1719 					} else {
1720 						DMLOG_PRINT(DMLVL_ERR,
1721 							    "%s failed with expected rc = %d but no synchronous event\n",
1722 							    szFuncName, 0);
1723 						DMVAR_FAIL();
1724 					}
1725 				} else {
1726 					DMLOG_PRINT(DMLVL_ERR,
1727 						    "%s failed with expected rc = %d but unexpected number of events (%d vs %d)\n",
1728 						    szFuncName, 0, numMsg,
1729 						    expectedNumMsg);
1730 					DMVAR_FAIL();
1731 				}
1732 			} else {
1733 				dmMsg = NULL;
1734 				DMLOG_PRINT(DMLVL_ERR,
1735 					    "%s 2nd call failed with unexpected rc = %d (errno = %d)\n",
1736 					    szFuncName, rc, errno);
1737 				DMVAR_FAIL();
1738 			}
1739 		} else {
1740 			dmMsg = NULL;
1741 			DMLOG_PRINT(DMLVL_ERR,
1742 				    "%s 1st call failed with unexpected rc = %d (errno = %d)\n",
1743 				    szFuncName, rc, errno);
1744 			DMVAR_FAIL();
1745 		}
1746 
1747 		/* Variation clean up */
1748 		rc = dm_respond_event(sid,
1749 				      dmMsg ? dmMsg->
1750 				      ev_token : DM_INVALID_TOKEN,
1751 				      DM_RESP_CONTINUE, 0, 0, NULL);
1752 		if (rc == -1) {
1753 			DMLOG_PRINT(DMLVL_DEBUG,
1754 				    "Unable to clean up variation! (errno	= %d)\n",
1755 				    errno);
1756 		}
1757 
1758 		break;
1759 
1760 	case RESPOND_EVENT_BASE + 9:
1761 		/* Variation */
1762 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RESP_INVALID)\n", szFuncName);
1763 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1764 				   dmMsgBuf, &rlen);
1765 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1766 			rc = dm_respond_event(sid, dmMsg->ev_token,
1767 					      DM_RESP_INVALID, 0, 0, NULL);
1768 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1769 
1770 			/* Variation clean up */
1771 			rc = dm_respond_event(sid, dmMsg->ev_token,
1772 					      DM_RESP_CONTINUE, 0, 0, NULL);
1773 			if (rc == -1) {
1774 				DMLOG_PRINT(DMLVL_DEBUG,
1775 					    "Unable to clean up variation! (errno	= %d)\n",
1776 					    errno);
1777 			}
1778 		} else {
1779 			DMLOG_PRINT(DMLVL_ERR,
1780 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1781 				    rc, errno);
1782 		}
1783 		break;
1784 
1785 	case RESPOND_EVENT_BASE + 10:
1786 		/* Variation */
1787 		DMLOG_PRINT(DMLVL_DEBUG,
1788 			    "%s(DM_RESP_CONTINUE with zero reterror)\n",
1789 			    szFuncName);
1790 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1791 				   dmMsgBuf, &rlen);
1792 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1793 			rcRespond =
1794 			    dm_respond_event(sid, dmMsg->ev_token,
1795 					     DM_RESP_CONTINUE, 0, 0, NULL);
1796 			errnoRespond = rcRespond == -1 ? errno : 0;
1797 		} else {
1798 			DMLOG_PRINT(DMLVL_ERR,
1799 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1800 				    rc, errno);
1801 		}
1802 		break;
1803 
1804 	case RESPOND_EVENT_BASE + 11:
1805 		/* Variation */
1806 		DMLOG_PRINT(DMLVL_DEBUG,
1807 			    "%s(DM_RESP_CONTINUE with non-zero reterror)\n",
1808 			    szFuncName);
1809 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1810 				   dmMsgBuf, &rlen);
1811 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1812 			rc = dm_respond_event(sid, dmMsg->ev_token,
1813 					      DM_RESP_CONTINUE, ABORT_ERRNO, 0,
1814 					      NULL);
1815 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1816 
1817 			/* Variation clean up */
1818 			rc = dm_respond_event(sid, dmMsg->ev_token,
1819 					      DM_RESP_CONTINUE, 0, 0, NULL);
1820 			if (rc == -1) {
1821 				DMLOG_PRINT(DMLVL_DEBUG,
1822 					    "Unable to clean up variation! (errno	= %d)\n",
1823 					    errno);
1824 			}
1825 		} else {
1826 			DMLOG_PRINT(DMLVL_ERR,
1827 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1828 				    rc, errno);
1829 		}
1830 		break;
1831 
1832 	case RESPOND_EVENT_BASE + 12:
1833 		/* Variation */
1834 		DMLOG_PRINT(DMLVL_DEBUG,
1835 			    "%s(DM_RESP_ABORT with zero reterror)\n",
1836 			    szFuncName);
1837 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1838 				   dmMsgBuf, &rlen);
1839 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1840 			rc = dm_respond_event(sid, dmMsg->ev_token,
1841 					      DM_RESP_ABORT, 0, 0, NULL);
1842 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1843 
1844 			/* Variation clean up */
1845 			rc = dm_respond_event(sid, dmMsg->ev_token,
1846 					      DM_RESP_CONTINUE, 0, 0, NULL);
1847 			if (rc == -1) {
1848 				DMLOG_PRINT(DMLVL_DEBUG,
1849 					    "Unable to clean up variation! (errno	= %d)\n",
1850 					    errno);
1851 			}
1852 		} else {
1853 			DMLOG_PRINT(DMLVL_ERR,
1854 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1855 				    rc, errno);
1856 		}
1857 		break;
1858 
1859 	case RESPOND_EVENT_BASE + 13:
1860 		/* Variation */
1861 		DMLOG_PRINT(DMLVL_DEBUG,
1862 			    "%s(DM_RESP_ABORT with non-zero reterror)\n",
1863 			    szFuncName);
1864 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1865 				   dmMsgBuf, &rlen);
1866 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1867 			rcRespond =
1868 			    dm_respond_event(sid, dmMsg->ev_token,
1869 					     DM_RESP_ABORT, ABORT_ERRNO, 0,
1870 					     NULL);
1871 			errnoRespond = rcRespond == -1 ? errno : 0;
1872 		} else {
1873 			DMLOG_PRINT(DMLVL_ERR,
1874 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1875 				    rc, errno);
1876 		}
1877 		break;
1878 
1879 	case RESPOND_EVENT_BASE + 14:
1880 		/* Variation */
1881 		DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RESP_DONTCARE)\n", szFuncName);
1882 		rc = dm_get_events(sid, MAX_EVENT, 0, sizeof(dmMsgBuf),
1883 				   dmMsgBuf, &rlen);
1884 		if (rc == 0 && ((dmMsg = GetSyncEventMsg(dmMsgBuf)) != NULL)) {
1885 			rc = dm_respond_event(sid, dmMsg->ev_token,
1886 					      DM_RESP_ABORT, 0, 0, NULL);
1887 			DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1888 
1889 			/* Variation clean up */
1890 			rc = dm_respond_event(sid, dmMsg->ev_token,
1891 					      DM_RESP_CONTINUE, 0, 0, NULL);
1892 			if (rc == -1) {
1893 				DMLOG_PRINT(DMLVL_DEBUG,
1894 					    "Unable to clean up variation! (errno	= %d)\n",
1895 					    errno);
1896 			}
1897 		} else {
1898 			DMLOG_PRINT(DMLVL_ERR,
1899 				    "Unable to obtain synchronous event! (rc = %d, errno = %d)\n",
1900 				    rc, errno);
1901 		}
1902 		break;
1903 
1904 	}
1905 
1906 	pthread_exit(0);
1907 }
1908