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 : mmap.c
21 *
22 * VARIATIONS : 18
23 *
24 * EVENTS TESTED: DM_EVENT_READ
25 * DM_EVENT_WRITE
26 */
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <pthread.h>
32 #include <unistd.h>
33 #include <sys/mount.h>
34 #include <sys/mman.h>
35 #include <fcntl.h>
36 #include "dm_test.h"
37
38 #define TMP_FILELEN 50000
39 #define MMAPFILE_EXE "mmapfile"
40
41 pthread_t tid;
42 dm_sessid_t sid;
43 char dmMsgBuf[4096];
44 char command[4096];
45 char *mountPt;
46 char *deviceNm;
47 char DummyFile[FILENAME_MAX];
48 char DummyTmp[FILENAME_MAX];
49
50 /* Variables for thread communications */
51 dm_eventtype_t eventExpected;
52 dm_eventtype_t eventReceived;
53 dm_response_t eventResponse;
54 void *hanp1;
55 size_t hlen1;
56 dm_off_t offset;
57 dm_size_t length;
58
59 void *Thread(void *);
60
main(int argc,char ** argv)61 int main(int argc, char **argv)
62 {
63
64 char *varstr;
65 int rc;
66 int i;
67 char *szSessionInfo = "dm_test session info";
68 dm_eventset_t events;
69
70 DMOPT_PARSE(argc, argv);
71 DMLOG_START();
72
73 DMEV_ZERO(events);
74 DMEV_SET(DM_EVENT_MOUNT, events);
75
76 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
77 if ((rc = dm_init_service(&varstr)) != 0) {
78 DMLOG_PRINT(DMLVL_ERR,
79 "dm_init_service failed! (rc = %d, errno = %d)\n",
80 rc, errno);
81 DM_EXIT();
82 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
83 == -1) {
84 DMLOG_PRINT(DMLVL_ERR,
85 "dm_create_session failed! (rc = %d, errno = %d)\n",
86 rc, errno);
87 DM_EXIT();
88 } else
89 if ((rc =
90 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
91 &events, DM_EVENT_MAX)) == -1) {
92 DMLOG_PRINT(DMLVL_ERR,
93 "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
94 errno);
95 dm_destroy_session(sid);
96 DM_EXIT();
97 } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
98 DMLOG_PRINT(DMLVL_ERR,
99 "pthread_create failed! (rc = %d, errno = %d)\n",
100 rc, errno);
101 dm_destroy_session(sid);
102 DM_EXIT();
103 } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
104 DMLOG_PRINT(DMLVL_ERR,
105 "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
106 errno);
107 dm_destroy_session(sid);
108 DM_EXIT();
109 } else {
110 int fd;
111
112 sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
113 sprintf(DummyTmp, "%s/%s", mountPt, DUMMY_TMP);
114
115 remove(DummyFile);
116
117 EVENT_DELIVERY_DELAY;
118 fd = open(DummyTmp, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
119 if (fd != -1) {
120 for (i = 0; i < TMP_FILELEN / DUMMY_STRLEN; i++) {
121 if (write(fd, DUMMY_STRING, DUMMY_STRLEN) !=
122 DUMMY_STRLEN) {
123 rc = -1;
124 break;
125 }
126 }
127 } else {
128 rc = -1;
129 }
130 if (rc != -1) {
131 rc = fsync(fd);
132 }
133 if (rc != -1) {
134 rc = close(fd);
135 }
136 if (rc == -1) {
137 DMLOG_PRINT(DMLVL_ERR,
138 "creating dummy file failed! (rc = %d, errno = %d)\n",
139 rc, errno);
140 dm_destroy_session(sid);
141 DM_EXIT();
142 }
143 }
144
145 DMLOG_PRINT(DMLVL_DEBUG,
146 "Starting DMAPI memory mapped file synchronous event data tests\n");
147
148 /*
149 * TEST : mmap - no regions
150 * EXPECTED: no event
151 */
152 if (DMVAR_EXEC(MMAP_READ_BASE + 1)) {
153 int fd;
154 void *hanp;
155 size_t hlen;
156 off_t inoff = 0;
157 size_t inlen = DUMMY_STRLEN;
158
159 /* Variation set up */
160 eventExpected = DM_EVENT_INVALID;
161 eventReceived = DM_EVENT_INVALID;
162 eventResponse = DM_RESP_INVALID;
163
164 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
165 if ((rc = system(command)) == -1) {
166 /* No clean up */
167 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
168 remove(DummyFile);
169 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
170 close(fd);
171 remove(DummyFile);
172 } else if ((rc = close(fd)) == -1) {
173 dm_handle_free(hanp, hlen);
174 remove(DummyFile);
175 }
176 if (rc == -1) {
177 DMLOG_PRINT(DMLVL_DEBUG,
178 "Unable to set up variation! (errno = %d)\n",
179 errno);
180 DMVAR_SKIP();
181 } else {
182 /* Variation */
183 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
184 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
185 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
186 rc = system(command);
187 EVENT_DELIVERY_DELAY;
188 DMVAR_END(DMVAR_CHKPASSEXP
189 (0, rc, eventExpected, eventReceived));
190
191 /* Variation clean up */
192 rc = remove(DummyFile);
193 if (rc == -1) {
194 DMLOG_PRINT(DMLVL_DEBUG,
195 "Unable to clean up variation! (errno = %d)\n",
196 errno);
197 }
198 dm_handle_free(hanp, hlen);
199 }
200 }
201
202 /*
203 * TEST : mmap - one region, DM_REGION_WRITE
204 * EXPECTED: no event
205 */
206 if (DMVAR_EXEC(MMAP_READ_BASE + 2)) {
207 int fd;
208 void *hanp;
209 size_t hlen;
210 off_t inoff = 0;
211 size_t inlen = DUMMY_STRLEN;
212 dm_boolean_t exactflag;
213 int numRegions;
214 dm_region_t Regions[1];
215
216 /* Variation set up */
217 eventExpected = DM_EVENT_INVALID;
218 eventReceived = DM_EVENT_INVALID;
219 eventResponse = DM_RESP_INVALID;
220 numRegions = 1;
221 Regions[0].rg_offset = 0;
222 Regions[0].rg_size = 0;
223 Regions[0].rg_flags = DM_REGION_WRITE;
224
225 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
226 if ((rc = system(command)) == -1) {
227 /* No clean up */
228 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
229 remove(DummyFile);
230 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
231 close(fd);
232 remove(DummyFile);
233 } else
234 if (((rc =
235 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
236 numRegions, Regions, &exactflag)) == -1)
237 || ((rc = close(fd)) == -1)) {
238 dm_handle_free(hanp, hlen);
239 remove(DummyFile);
240 }
241 if (rc == -1) {
242 DMLOG_PRINT(DMLVL_DEBUG,
243 "Unable to set up variation! (errno = %d)\n",
244 errno);
245 DMVAR_SKIP();
246 } else {
247 /* Variation */
248 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
249 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
250 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
251 rc = system(command);
252 EVENT_DELIVERY_DELAY;
253 DMVAR_END(DMVAR_CHKPASSEXP
254 (0, rc, eventExpected, eventReceived));
255
256 /* Variation clean up */
257 rc = remove(DummyFile);
258 if (rc == -1) {
259 DMLOG_PRINT(DMLVL_DEBUG,
260 "Unable to clean up variation! (errno = %d)\n",
261 errno);
262 }
263 dm_handle_free(hanp, hlen);
264 }
265 }
266
267 /*
268 * TEST : mmap - one region, DM_REGION_TRUNCATE
269 * EXPECTED: no event
270 */
271 if (DMVAR_EXEC(MMAP_READ_BASE + 3)) {
272 int fd;
273 void *hanp;
274 size_t hlen;
275 off_t inoff = 0;
276 size_t inlen = DUMMY_STRLEN;
277 dm_boolean_t exactflag;
278 int numRegions;
279 dm_region_t Regions[1];
280
281 /* Variation set up */
282 eventExpected = DM_EVENT_INVALID;
283 eventReceived = DM_EVENT_INVALID;
284 eventResponse = DM_RESP_INVALID;
285 numRegions = 1;
286 Regions[0].rg_offset = 0;
287 Regions[0].rg_size = 0;
288 Regions[0].rg_flags = DM_REGION_TRUNCATE;
289
290 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
291 if ((rc = system(command)) == -1) {
292 /* No clean up */
293 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
294 remove(DummyFile);
295 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
296 close(fd);
297 remove(DummyFile);
298 } else
299 if (((rc =
300 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
301 numRegions, Regions, &exactflag)) == -1)
302 || ((rc = close(fd)) == -1)) {
303 dm_handle_free(hanp, hlen);
304 remove(DummyFile);
305 }
306 if (rc == -1) {
307 DMLOG_PRINT(DMLVL_DEBUG,
308 "Unable to set up variation! (errno = %d)\n",
309 errno);
310 DMVAR_SKIP();
311 } else {
312 /* Variation */
313 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
314 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
315 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
316 rc = system(command);
317 EVENT_DELIVERY_DELAY;
318 DMVAR_END(DMVAR_CHKPASSEXP
319 (0, rc, eventExpected, eventReceived));
320
321 /* Variation clean up */
322 rc = remove(DummyFile);
323 if (rc == -1) {
324 DMLOG_PRINT(DMLVL_DEBUG,
325 "Unable to clean up variation! (errno = %d)\n",
326 errno);
327 }
328 dm_handle_free(hanp, hlen);
329 }
330 }
331
332 /*
333 * TEST : mmap - one region, DM_EVENT_READ, DM_RESP_CONTINUE
334 * EXPECTED: DM_EVENT_READ
335 *
336 * This variation uncovered XFS BUG #33 (entire file returned instead
337 * of mapped region only)
338 */
339 if (DMVAR_EXEC(MMAP_READ_BASE + 4)) {
340 int fd;
341 void *hanp;
342 size_t hlen;
343 off_t inoff = PAGEALIGN(0);
344 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
345 dm_boolean_t exactflag;
346 int varStatus;
347 int numRegions;
348 dm_region_t Regions[1];
349
350 /* Variation set up */
351 eventExpected = DM_EVENT_READ;
352 eventReceived = DM_EVENT_INVALID;
353 eventResponse = DM_RESP_CONTINUE;
354 numRegions = 1;
355 Regions[0].rg_offset = 0;
356 Regions[0].rg_size = 0;
357 Regions[0].rg_flags = DM_REGION_READ;
358
359 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
360 if ((rc = system(command)) == -1) {
361 /* No clean up */
362 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
363 remove(DummyFile);
364 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
365 close(fd);
366 remove(DummyFile);
367 } else
368 if (((rc =
369 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
370 numRegions, Regions, &exactflag)) == -1)
371 || ((rc = close(fd)) == -1)) {
372 dm_handle_free(hanp, hlen);
373 remove(DummyFile);
374 }
375 if (rc == -1) {
376 DMLOG_PRINT(DMLVL_DEBUG,
377 "Unable to set up variation! (errno = %d)\n",
378 errno);
379 DMVAR_SKIP();
380 } else {
381 /* Variation */
382 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
383 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
384 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
385 rc = system(command);
386 EVENT_DELIVERY_DELAY;
387 if ((varStatus =
388 DMVAR_CHKPASSEXP(0, rc, eventExpected,
389 eventReceived)) == DMSTAT_PASS) {
390 if (inoff != offset) {
391 DMLOG_PRINT(DMLVL_ERR,
392 "Offset NOT correct! (%d vs %d)\n",
393 inoff, offset);
394 varStatus = DMSTAT_FAIL;
395 } else if (inlen != length) {
396 DMLOG_PRINT(DMLVL_ERR,
397 "Length NOT correct! (%d vs %d)\n",
398 inlen, length);
399 varStatus = DMSTAT_FAIL;
400 }
401 }
402 DMVAR_END(varStatus);
403
404 /* Variation clean up */
405 rc = remove(DummyFile);
406 if (rc == -1) {
407 DMLOG_PRINT(DMLVL_DEBUG,
408 "Unable to clean up variation! (errno = %d)\n",
409 errno);
410 }
411 dm_handle_free(hanp, hlen);
412 }
413 }
414
415 /*
416 * TEST : mmap - one region, DM_EVENT_READ, DM_RESP_ABORT
417 * EXPECTED: DM_EVENT_READ
418 */
419 if (DMVAR_EXEC(MMAP_READ_BASE + 5)) {
420 int fd;
421 void *hanp;
422 size_t hlen;
423 off_t inoff = PAGEALIGN(0);
424 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
425 dm_boolean_t exactflag;
426 int varStatus;
427 int numRegions;
428 dm_region_t Regions[1];
429
430 /* Variation set up */
431 eventExpected = DM_EVENT_READ;
432 eventReceived = DM_EVENT_INVALID;
433 eventResponse = DM_RESP_ABORT;
434 numRegions = 1;
435 Regions[0].rg_offset = 0;
436 Regions[0].rg_size = 0;
437 Regions[0].rg_flags = DM_REGION_READ;
438
439 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
440 if ((rc = system(command)) == -1) {
441 /* No clean up */
442 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
443 remove(DummyFile);
444 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
445 close(fd);
446 remove(DummyFile);
447 } else
448 if (((rc =
449 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
450 numRegions, Regions, &exactflag)) == -1)
451 || ((rc = close(fd)) == -1)) {
452 dm_handle_free(hanp, hlen);
453 remove(DummyFile);
454 }
455 if (rc == -1) {
456 DMLOG_PRINT(DMLVL_DEBUG,
457 "Unable to set up variation! (errno = %d)\n",
458 errno);
459 DMVAR_SKIP();
460 } else {
461 /* Variation */
462 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
463 DummyFile, O_RDONLY, inoff, (long)inlen, 0);
464 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
465 rc = system(command);
466 EVENT_DELIVERY_DELAY;
467 if ((varStatus =
468 DMVAR_CHKPASSEXP(0, rc, eventExpected,
469 eventReceived)) == DMSTAT_PASS) {
470 if (inoff != offset) {
471 DMLOG_PRINT(DMLVL_ERR,
472 "Offset NOT correct! (%d vs %d)\n",
473 inoff, offset);
474 varStatus = DMSTAT_FAIL;
475 } else if (inlen != length) {
476 DMLOG_PRINT(DMLVL_ERR,
477 "Length NOT correct! (%d vs %d)\n",
478 inlen, length);
479 varStatus = DMSTAT_FAIL;
480 }
481 }
482 DMVAR_END(varStatus);
483
484 /* Variation clean up */
485 rc = remove(DummyFile);
486 if (rc == -1) {
487 DMLOG_PRINT(DMLVL_DEBUG,
488 "Unable to clean up variation! (errno = %d)\n",
489 errno);
490 }
491 dm_handle_free(hanp, hlen);
492 }
493 }
494
495 /*
496 * TEST : mmap - one region, DM_EVENT_READ
497 * EXPECTED: no event
498 */
499 if (DMVAR_EXEC(MMAP_READ_BASE + 6)) {
500 int fd;
501 void *hanp;
502 size_t hlen;
503 off_t inoff = PAGEALIGN(0);
504 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
505 dm_boolean_t exactflag;
506 int numRegions;
507 dm_region_t Regions[1];
508
509 /* Variation set up */
510 eventExpected = DM_EVENT_INVALID;
511 eventReceived = DM_EVENT_INVALID;
512 eventResponse = DM_RESP_CONTINUE;
513 numRegions = 1;
514 Regions[0].rg_offset = TMP_FILELEN / 2;
515 Regions[0].rg_size = 0;
516 Regions[0].rg_flags = DM_REGION_READ;
517
518 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
519 if ((rc = system(command)) == -1) {
520 /* No clean up */
521 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
522 remove(DummyFile);
523 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
524 close(fd);
525 remove(DummyFile);
526 } else
527 if (((rc =
528 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
529 numRegions, Regions, &exactflag)) == -1)
530 || ((rc = close(fd)) == -1)) {
531 dm_handle_free(hanp, hlen);
532 remove(DummyFile);
533 }
534 if (rc == -1) {
535 DMLOG_PRINT(DMLVL_DEBUG,
536 "Unable to set up variation! (errno = %d)\n",
537 errno);
538 DMVAR_SKIP();
539 } else {
540 /* Variation */
541 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
542 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
543 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
544 rc = system(command);
545 EVENT_DELIVERY_DELAY;
546 DMVAR_END(DMVAR_CHKPASSEXP
547 (0, rc, eventExpected, eventReceived));
548
549 /* Variation clean up */
550 rc = remove(DummyFile);
551 if (rc == -1) {
552 DMLOG_PRINT(DMLVL_DEBUG,
553 "Unable to clean up variation! (errno = %d)\n",
554 errno);
555 }
556 dm_handle_free(hanp, hlen);
557 }
558 }
559
560 /*
561 * TEST : mmap - one region, DM_EVENT_READ
562 * EXPECTED: no event
563 */
564 if (DMVAR_EXEC(MMAP_READ_BASE + 7)) {
565 int fd;
566 void *hanp;
567 size_t hlen;
568 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
569 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
570 dm_boolean_t exactflag;
571 int numRegions;
572 dm_region_t Regions[1];
573
574 /* Variation set up */
575 eventExpected = DM_EVENT_INVALID;
576 eventReceived = DM_EVENT_INVALID;
577 eventResponse = DM_RESP_CONTINUE;
578 numRegions = 1;
579 Regions[0].rg_offset = TMP_FILELEN / 2;
580 Regions[0].rg_size = 0;
581 Regions[0].rg_flags = DM_REGION_READ;
582
583 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
584 if ((rc = system(command)) == -1) {
585 /* No clean up */
586 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
587 remove(DummyFile);
588 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
589 close(fd);
590 remove(DummyFile);
591 } else
592 if (((rc =
593 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
594 numRegions, Regions, &exactflag)) == -1)
595 || ((rc = close(fd)) == -1)) {
596 dm_handle_free(hanp, hlen);
597 remove(DummyFile);
598 }
599 if (rc == -1) {
600 DMLOG_PRINT(DMLVL_DEBUG,
601 "Unable to set up variation! (errno = %d)\n",
602 errno);
603 DMVAR_SKIP();
604 } else {
605 /* Variation */
606 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
607 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
608 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
609 rc = system(command);
610 EVENT_DELIVERY_DELAY;
611 DMVAR_END(DMVAR_CHKPASSEXP
612 (0, rc, eventExpected, eventReceived));
613
614 /* Variation clean up */
615 rc = remove(DummyFile);
616 if (rc == -1) {
617 DMLOG_PRINT(DMLVL_DEBUG,
618 "Unable to clean up variation! (errno = %d)\n",
619 errno);
620 }
621 dm_handle_free(hanp, hlen);
622 }
623 }
624
625 /*
626 * TEST : mmap - one region, DM_EVENT_READ
627 * EXPECTED: DM_EVENT_READ
628 */
629 if (DMVAR_EXEC(MMAP_READ_BASE + 8)) {
630 int fd;
631 void *hanp;
632 size_t hlen;
633 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
634 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
635 dm_boolean_t exactflag;
636 int varStatus;
637 int numRegions;
638 dm_region_t Regions[1];
639
640 /* Variation set up */
641 eventExpected = DM_EVENT_READ;
642 eventReceived = DM_EVENT_INVALID;
643 eventResponse = DM_RESP_CONTINUE;
644 numRegions = 1;
645 Regions[0].rg_offset = TMP_FILELEN / 4;
646 Regions[0].rg_size = 0;
647 Regions[0].rg_flags = DM_REGION_READ;
648
649 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
650 if ((rc = system(command)) == -1) {
651 /* No clean up */
652 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
653 remove(DummyFile);
654 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
655 close(fd);
656 remove(DummyFile);
657 } else
658 if (((rc =
659 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
660 numRegions, Regions, &exactflag)) == -1)
661 || ((rc = close(fd)) == -1)) {
662 dm_handle_free(hanp, hlen);
663 remove(DummyFile);
664 }
665 if (rc == -1) {
666 DMLOG_PRINT(DMLVL_DEBUG,
667 "Unable to set up variation! (errno = %d)\n",
668 errno);
669 DMVAR_SKIP();
670 } else {
671 /* Variation */
672 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
673 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
674 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
675 rc = system(command);
676 EVENT_DELIVERY_DELAY;
677 if ((varStatus =
678 DMVAR_CHKPASSEXP(0, rc, eventExpected,
679 eventReceived)) == DMSTAT_PASS) {
680 if (inoff != offset) {
681 DMLOG_PRINT(DMLVL_ERR,
682 "Offset NOT correct! (%d vs %d)\n",
683 inoff, offset);
684 varStatus = DMSTAT_FAIL;
685 } else if (inlen != length) {
686 DMLOG_PRINT(DMLVL_ERR,
687 "Length NOT correct! (%d vs %d)\n",
688 inlen, length);
689 varStatus = DMSTAT_FAIL;
690 }
691 }
692 DMVAR_END(varStatus);
693
694 /* Variation clean up */
695 rc = remove(DummyFile);
696 if (rc == -1) {
697 DMLOG_PRINT(DMLVL_DEBUG,
698 "Unable to clean up variation! (errno = %d)\n",
699 errno);
700 }
701 dm_handle_free(hanp, hlen);
702 }
703 }
704
705 /*
706 * TEST : mmap - one region, DM_EVENT_READ
707 * EXPECTED: no event
708 */
709 if (DMVAR_EXEC(MMAP_READ_BASE + 9)) {
710 int fd;
711 void *hanp;
712 size_t hlen;
713 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
714 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
715 dm_boolean_t exactflag;
716 int numRegions;
717 dm_region_t Regions[1];
718
719 /* Variation set up */
720 eventExpected = DM_EVENT_INVALID;
721 eventReceived = DM_EVENT_INVALID;
722 eventResponse = DM_RESP_CONTINUE;
723 numRegions = 1;
724 Regions[0].rg_offset = 0;
725 Regions[0].rg_size = DUMMY_STRLEN;
726 Regions[0].rg_flags = DM_REGION_READ;
727
728 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
729 if ((rc = system(command)) == -1) {
730 /* No clean up */
731 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
732 remove(DummyFile);
733 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
734 close(fd);
735 remove(DummyFile);
736 } else
737 if (((rc =
738 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
739 numRegions, Regions, &exactflag)) == -1)
740 || ((rc = close(fd)) == -1)) {
741 dm_handle_free(hanp, hlen);
742 remove(DummyFile);
743 }
744 if (rc == -1) {
745 DMLOG_PRINT(DMLVL_DEBUG,
746 "Unable to set up variation! (errno = %d)\n",
747 errno);
748 DMVAR_SKIP();
749 } else {
750 /* Variation */
751 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
752 DummyFile, O_RDONLY, inoff, (long)inlen, 1);
753 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
754 rc = system(command);
755 EVENT_DELIVERY_DELAY;
756 DMVAR_END(DMVAR_CHKPASSEXP
757 (0, rc, eventExpected, eventReceived));
758
759 /* Variation clean up */
760 rc = remove(DummyFile);
761 if (rc == -1) {
762 DMLOG_PRINT(DMLVL_DEBUG,
763 "Unable to clean up variation! (errno = %d)\n",
764 errno);
765 }
766 dm_handle_free(hanp, hlen);
767 }
768 }
769
770 /*
771 * TEST : mmap - no regions
772 * EXPECTED: no event
773 */
774 if (DMVAR_EXEC(MMAP_WRITE_BASE + 1)) {
775 int fd;
776 void *hanp;
777 size_t hlen;
778 off_t inoff = 0;
779 size_t inlen = DUMMY_STRLEN;
780
781 /* Variation set up */
782 eventExpected = DM_EVENT_INVALID;
783 eventReceived = DM_EVENT_INVALID;
784 eventResponse = DM_RESP_INVALID;
785
786 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
787 if ((rc = system(command)) == -1) {
788 /* No clean up */
789 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
790 remove(DummyFile);
791 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
792 close(fd);
793 remove(DummyFile);
794 } else if ((rc = close(fd)) == -1) {
795 dm_handle_free(hanp, hlen);
796 remove(DummyFile);
797 }
798 if (rc == -1) {
799 DMLOG_PRINT(DMLVL_DEBUG,
800 "Unable to set up variation! (errno = %d)\n",
801 errno);
802 DMVAR_SKIP();
803 } else {
804 /* Variation */
805 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
806 DummyFile, O_RDWR, inoff, (long)inlen, 1);
807 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
808 rc = system(command);
809 EVENT_DELIVERY_DELAY;
810 DMVAR_END(DMVAR_CHKPASSEXP
811 (0, rc, eventExpected, eventReceived));
812
813 /* Variation clean up */
814 rc = remove(DummyFile);
815 if (rc == -1) {
816 DMLOG_PRINT(DMLVL_DEBUG,
817 "Unable to clean up variation! (errno = %d)\n",
818 errno);
819 }
820 dm_handle_free(hanp, hlen);
821 }
822 }
823
824 /*
825 * TEST : mmap - one region, DM_REGION_READ
826 * EXPECTED: no event
827 */
828 if (DMVAR_EXEC(MMAP_WRITE_BASE + 2)) {
829 int fd;
830 void *hanp;
831 size_t hlen;
832 off_t inoff = 0;
833 size_t inlen = DUMMY_STRLEN;
834 dm_boolean_t exactflag;
835 int numRegions;
836 dm_region_t Regions[1];
837
838 /* Variation set up */
839 eventExpected = DM_EVENT_INVALID;
840 eventReceived = DM_EVENT_INVALID;
841 eventResponse = DM_RESP_INVALID;
842 numRegions = 1;
843 Regions[0].rg_offset = 0;
844 Regions[0].rg_size = 0;
845 Regions[0].rg_flags = DM_REGION_READ;
846
847 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
848 if ((rc = system(command)) == -1) {
849 /* No clean up */
850 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
851 remove(DummyFile);
852 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
853 close(fd);
854 remove(DummyFile);
855 } else
856 if (((rc =
857 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
858 numRegions, Regions, &exactflag)) == -1)
859 || ((rc = close(fd)) == -1)) {
860 dm_handle_free(hanp, hlen);
861 remove(DummyFile);
862 }
863 if (rc == -1) {
864 DMLOG_PRINT(DMLVL_DEBUG,
865 "Unable to set up variation! (errno = %d)\n",
866 errno);
867 DMVAR_SKIP();
868 } else {
869 /* Variation */
870 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
871 DummyFile, O_RDWR, inoff, (long)inlen, 1);
872 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
873 rc = system(command);
874 EVENT_DELIVERY_DELAY;
875 DMVAR_END(DMVAR_CHKPASSEXP
876 (0, rc, eventExpected, eventReceived));
877
878 /* Variation clean up */
879 rc = remove(DummyFile);
880 if (rc == -1) {
881 DMLOG_PRINT(DMLVL_DEBUG,
882 "Unable to clean up variation! (errno = %d)\n",
883 errno);
884 }
885 dm_handle_free(hanp, hlen);
886 }
887 }
888
889 /*
890 * TEST : mmap - one region, DM_REGION_TRUNCATE
891 * EXPECTED: no event
892 */
893 if (DMVAR_EXEC(MMAP_WRITE_BASE + 3)) {
894 int fd;
895 void *hanp;
896 size_t hlen;
897 off_t inoff = 0;
898 size_t inlen = DUMMY_STRLEN;
899 dm_boolean_t exactflag;
900 int numRegions;
901 dm_region_t Regions[1];
902
903 /* Variation set up */
904 eventExpected = DM_EVENT_INVALID;
905 eventReceived = DM_EVENT_INVALID;
906 eventResponse = DM_RESP_INVALID;
907 numRegions = 1;
908 Regions[0].rg_offset = 0;
909 Regions[0].rg_size = 0;
910 Regions[0].rg_flags = DM_REGION_TRUNCATE;
911
912 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
913 if ((rc = system(command)) == -1) {
914 /* No clean up */
915 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
916 remove(DummyFile);
917 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
918 close(fd);
919 remove(DummyFile);
920 } else
921 if (((rc =
922 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
923 numRegions, Regions, &exactflag)) == -1)
924 || ((rc = close(fd)) == -1)) {
925 dm_handle_free(hanp, hlen);
926 remove(DummyFile);
927 }
928 if (rc == -1) {
929 DMLOG_PRINT(DMLVL_DEBUG,
930 "Unable to set up variation! (errno = %d)\n",
931 errno);
932 DMVAR_SKIP();
933 } else {
934 /* Variation */
935 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
936 DummyFile, O_RDWR, inoff, (long)inlen, 1);
937 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
938 rc = system(command);
939 EVENT_DELIVERY_DELAY;
940 DMVAR_END(DMVAR_CHKPASSEXP
941 (0, rc, eventExpected, eventReceived));
942
943 /* Variation clean up */
944 rc = remove(DummyFile);
945 if (rc == -1) {
946 DMLOG_PRINT(DMLVL_DEBUG,
947 "Unable to clean up variation! (errno = %d)\n",
948 errno);
949 }
950 dm_handle_free(hanp, hlen);
951 }
952 }
953
954 /*
955 * TEST : mmap - one region, DM_EVENT_WRITE, DM_RESP_CONTINUE
956 * EXPECTED: DM_EVENT_WRITE
957 */
958 if (DMVAR_EXEC(MMAP_WRITE_BASE + 4)) {
959 int fd;
960 void *hanp;
961 size_t hlen;
962 off_t inoff = PAGEALIGN(0);
963 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
964 dm_boolean_t exactflag;
965 int varStatus;
966 int numRegions;
967 dm_region_t Regions[1];
968
969 /* Variation set up */
970 eventExpected = DM_EVENT_WRITE;
971 eventReceived = DM_EVENT_INVALID;
972 eventResponse = DM_RESP_CONTINUE;
973 numRegions = 1;
974 Regions[0].rg_offset = 0;
975 Regions[0].rg_size = 0;
976 Regions[0].rg_flags = DM_REGION_WRITE;
977
978 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
979 if ((rc = system(command)) == -1) {
980 /* No clean up */
981 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
982 remove(DummyFile);
983 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
984 close(fd);
985 remove(DummyFile);
986 } else
987 if (((rc =
988 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
989 numRegions, Regions, &exactflag)) == -1)
990 || ((rc = close(fd)) == -1)) {
991 dm_handle_free(hanp, hlen);
992 remove(DummyFile);
993 }
994 if (rc == -1) {
995 DMLOG_PRINT(DMLVL_DEBUG,
996 "Unable to set up variation! (errno = %d)\n",
997 errno);
998 DMVAR_SKIP();
999 } else {
1000 /* Variation */
1001 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1002 DummyFile, O_RDWR, inoff, (long)inlen, 1);
1003 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1004 rc = system(command);
1005 EVENT_DELIVERY_DELAY;
1006 if ((varStatus =
1007 DMVAR_CHKPASSEXP(0, rc, eventExpected,
1008 eventReceived)) == DMSTAT_PASS) {
1009 if (inoff != offset) {
1010 DMLOG_PRINT(DMLVL_ERR,
1011 "Offset NOT correct! (%d vs %d)\n",
1012 inoff, offset);
1013 varStatus = DMSTAT_FAIL;
1014 } else if (inlen != length) {
1015 DMLOG_PRINT(DMLVL_ERR,
1016 "Length NOT correct! (%d vs %d)\n",
1017 inlen, length);
1018 varStatus = DMSTAT_FAIL;
1019 }
1020 }
1021 DMVAR_END(varStatus);
1022
1023 /* Variation clean up */
1024 rc = remove(DummyFile);
1025 if (rc == -1) {
1026 DMLOG_PRINT(DMLVL_DEBUG,
1027 "Unable to clean up variation! (errno = %d)\n",
1028 errno);
1029 }
1030 dm_handle_free(hanp, hlen);
1031 }
1032 }
1033
1034 /*
1035 * TEST : mmap - one region, DM_EVENT_WRITE, DM_RESP_ABORT
1036 * EXPECTED: DM_EVENT_WRITE
1037 */
1038 if (DMVAR_EXEC(MMAP_WRITE_BASE + 5)) {
1039 int fd;
1040 void *hanp;
1041 size_t hlen;
1042 off_t inoff = PAGEALIGN(0);
1043 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
1044 dm_boolean_t exactflag;
1045 int varStatus;
1046 int numRegions;
1047 dm_region_t Regions[1];
1048
1049 /* Variation set up */
1050 eventExpected = DM_EVENT_WRITE;
1051 eventReceived = DM_EVENT_INVALID;
1052 eventResponse = DM_RESP_ABORT;
1053 numRegions = 1;
1054 Regions[0].rg_offset = 0;
1055 Regions[0].rg_size = 0;
1056 Regions[0].rg_flags = DM_REGION_WRITE;
1057
1058 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1059 if ((rc = system(command)) == -1) {
1060 /* No clean up */
1061 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
1062 remove(DummyFile);
1063 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1064 close(fd);
1065 remove(DummyFile);
1066 } else
1067 if (((rc =
1068 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1069 numRegions, Regions, &exactflag)) == -1)
1070 || ((rc = close(fd)) == -1)) {
1071 dm_handle_free(hanp, hlen);
1072 remove(DummyFile);
1073 }
1074 if (rc == -1) {
1075 DMLOG_PRINT(DMLVL_DEBUG,
1076 "Unable to set up variation! (errno = %d)\n",
1077 errno);
1078 DMVAR_SKIP();
1079 } else {
1080 /* Variation */
1081 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1082 DummyFile, O_RDWR, inoff, (long)inlen, 0);
1083 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1084 rc = system(command);
1085 EVENT_DELIVERY_DELAY;
1086 if ((varStatus =
1087 DMVAR_CHKPASSEXP(0, rc, eventExpected,
1088 eventReceived)) == DMSTAT_PASS) {
1089 if (inoff != offset) {
1090 DMLOG_PRINT(DMLVL_ERR,
1091 "Offset NOT correct! (%d vs %d)\n",
1092 inoff, offset);
1093 varStatus = DMSTAT_FAIL;
1094 } else if (inlen != length) {
1095 DMLOG_PRINT(DMLVL_ERR,
1096 "Length NOT correct! (%d vs %d)\n",
1097 inlen, length);
1098 varStatus = DMSTAT_FAIL;
1099 }
1100 }
1101 DMVAR_END(varStatus);
1102
1103 /* Variation clean up */
1104 rc = remove(DummyFile);
1105 if (rc == -1) {
1106 DMLOG_PRINT(DMLVL_DEBUG,
1107 "Unable to clean up variation! (errno = %d)\n",
1108 errno);
1109 }
1110 dm_handle_free(hanp, hlen);
1111 }
1112 }
1113
1114 /*
1115 * TEST : mmap - one region, DM_EVENT_WRITE
1116 * EXPECTED: no event
1117 */
1118 if (DMVAR_EXEC(MMAP_WRITE_BASE + 6)) {
1119 int fd;
1120 void *hanp;
1121 size_t hlen;
1122 off_t inoff = PAGEALIGN(0);
1123 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
1124 dm_boolean_t exactflag;
1125 int numRegions;
1126 dm_region_t Regions[1];
1127
1128 /* Variation set up */
1129 eventExpected = DM_EVENT_INVALID;
1130 eventReceived = DM_EVENT_INVALID;
1131 eventResponse = DM_RESP_CONTINUE;
1132 numRegions = 1;
1133 Regions[0].rg_offset = TMP_FILELEN / 2;
1134 Regions[0].rg_size = 0;
1135 Regions[0].rg_flags = DM_REGION_WRITE;
1136
1137 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1138 if ((rc = system(command)) == -1) {
1139 /* No clean up */
1140 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
1141 remove(DummyFile);
1142 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1143 close(fd);
1144 remove(DummyFile);
1145 } else
1146 if (((rc =
1147 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1148 numRegions, Regions, &exactflag)) == -1)
1149 || ((rc = close(fd)) == -1)) {
1150 dm_handle_free(hanp, hlen);
1151 remove(DummyFile);
1152 }
1153 if (rc == -1) {
1154 DMLOG_PRINT(DMLVL_DEBUG,
1155 "Unable to set up variation! (errno = %d)\n",
1156 errno);
1157 DMVAR_SKIP();
1158 } else {
1159 /* Variation */
1160 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1161 DummyFile, O_RDWR, inoff, (long)inlen, 1);
1162 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1163 rc = system(command);
1164 EVENT_DELIVERY_DELAY;
1165 DMVAR_END(DMVAR_CHKPASSEXP
1166 (0, rc, eventExpected, eventReceived));
1167
1168 /* Variation clean up */
1169 rc = remove(DummyFile);
1170 if (rc == -1) {
1171 DMLOG_PRINT(DMLVL_DEBUG,
1172 "Unable to clean up variation! (errno = %d)\n",
1173 errno);
1174 }
1175 dm_handle_free(hanp, hlen);
1176 }
1177 }
1178
1179 /*
1180 * TEST : mmap - one region, DM_EVENT_WRITE
1181 * EXPECTED: no event
1182 */
1183 if (DMVAR_EXEC(MMAP_WRITE_BASE + 7)) {
1184 int fd;
1185 void *hanp;
1186 size_t hlen;
1187 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
1188 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
1189 dm_boolean_t exactflag;
1190 int numRegions;
1191 dm_region_t Regions[1];
1192
1193 /* Variation set up */
1194 eventExpected = DM_EVENT_INVALID;
1195 eventReceived = DM_EVENT_INVALID;
1196 eventResponse = DM_RESP_CONTINUE;
1197 numRegions = 1;
1198 Regions[0].rg_offset = TMP_FILELEN / 2;
1199 Regions[0].rg_size = 0;
1200 Regions[0].rg_flags = DM_REGION_WRITE;
1201
1202 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1203 if ((rc = system(command)) == -1) {
1204 /* No clean up */
1205 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
1206 remove(DummyFile);
1207 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1208 close(fd);
1209 remove(DummyFile);
1210 } else
1211 if (((rc =
1212 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1213 numRegions, Regions, &exactflag)) == -1)
1214 || ((rc = close(fd)) == -1)) {
1215 dm_handle_free(hanp, hlen);
1216 remove(DummyFile);
1217 }
1218 if (rc == -1) {
1219 DMLOG_PRINT(DMLVL_DEBUG,
1220 "Unable to set up variation! (errno = %d)\n",
1221 errno);
1222 DMVAR_SKIP();
1223 } else {
1224 /* Variation */
1225 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1226 DummyFile, O_RDWR, inoff, (long)inlen, 1);
1227 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1228 rc = system(command);
1229 EVENT_DELIVERY_DELAY;
1230 DMVAR_END(DMVAR_CHKPASSEXP
1231 (0, rc, eventExpected, eventReceived));
1232
1233 /* Variation clean up */
1234 rc = remove(DummyFile);
1235 if (rc == -1) {
1236 DMLOG_PRINT(DMLVL_DEBUG,
1237 "Unable to clean up variation! (errno = %d)\n",
1238 errno);
1239 }
1240 dm_handle_free(hanp, hlen);
1241 }
1242 }
1243
1244 /*
1245 * TEST : mmap - one region, DM_EVENT_WRITE
1246 * EXPECTED: DM_EVENT_WRITE
1247 */
1248 if (DMVAR_EXEC(MMAP_WRITE_BASE + 8)) {
1249 int fd;
1250 void *hanp;
1251 size_t hlen;
1252 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
1253 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
1254 dm_boolean_t exactflag;
1255 int varStatus;
1256 int numRegions;
1257 dm_region_t Regions[1];
1258
1259 /* Variation set up */
1260 eventExpected = DM_EVENT_WRITE;
1261 eventReceived = DM_EVENT_INVALID;
1262 eventResponse = DM_RESP_CONTINUE;
1263 numRegions = 1;
1264 Regions[0].rg_offset = TMP_FILELEN / 4;
1265 Regions[0].rg_size = 0;
1266 Regions[0].rg_flags = DM_REGION_WRITE;
1267
1268 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1269 if ((rc = system(command)) == -1) {
1270 /* No clean up */
1271 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
1272 remove(DummyFile);
1273 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1274 close(fd);
1275 remove(DummyFile);
1276 } else
1277 if (((rc =
1278 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1279 numRegions, Regions, &exactflag)) == -1)
1280 || ((rc = close(fd)) == -1)) {
1281 dm_handle_free(hanp, hlen);
1282 remove(DummyFile);
1283 }
1284 if (rc == -1) {
1285 DMLOG_PRINT(DMLVL_DEBUG,
1286 "Unable to set up variation! (errno = %d)\n",
1287 errno);
1288 DMVAR_SKIP();
1289 } else {
1290 /* Variation */
1291 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1292 DummyFile, O_RDWR, inoff, (long)inlen, 1);
1293 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1294 rc = system(command);
1295 EVENT_DELIVERY_DELAY;
1296 if ((varStatus =
1297 DMVAR_CHKPASSEXP(0, rc, eventExpected,
1298 eventReceived)) == DMSTAT_PASS) {
1299 if (inoff != offset) {
1300 DMLOG_PRINT(DMLVL_ERR,
1301 "Offset NOT correct! (%d vs %d)\n",
1302 inoff, offset);
1303 varStatus = DMSTAT_FAIL;
1304 } else if (inlen != length) {
1305 DMLOG_PRINT(DMLVL_ERR,
1306 "Length NOT correct! (%d vs %d)\n",
1307 inlen, length);
1308 varStatus = DMSTAT_FAIL;
1309 }
1310 }
1311 DMVAR_END(varStatus);
1312
1313 /* Variation clean up */
1314 rc = remove(DummyFile);
1315 if (rc == -1) {
1316 DMLOG_PRINT(DMLVL_DEBUG,
1317 "Unable to clean up variation! (errno = %d)\n",
1318 errno);
1319 }
1320 dm_handle_free(hanp, hlen);
1321 }
1322 }
1323
1324 /*
1325 * TEST : mmap - one region, DM_EVENT_WRITE
1326 * EXPECTED: no event
1327 */
1328 if (DMVAR_EXEC(MMAP_WRITE_BASE + 9)) {
1329 int fd;
1330 void *hanp;
1331 size_t hlen;
1332 off_t inoff = PAGEALIGN(TMP_FILELEN / 4);
1333 size_t inlen = PAGEALIGN(DUMMY_STRLEN);
1334 dm_boolean_t exactflag;
1335 int numRegions;
1336 dm_region_t Regions[1];
1337
1338 /* Variation set up */
1339 eventExpected = DM_EVENT_INVALID;
1340 eventReceived = DM_EVENT_INVALID;
1341 eventResponse = DM_RESP_CONTINUE;
1342 numRegions = 1;
1343 Regions[0].rg_offset = 0;
1344 Regions[0].rg_size = DUMMY_STRLEN;
1345 Regions[0].rg_flags = DM_REGION_WRITE;
1346
1347 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1348 if ((rc = system(command)) == -1) {
1349 /* No clean up */
1350 } else if ((fd = open(DummyFile, O_RDONLY)) == -1) {
1351 remove(DummyFile);
1352 } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1353 close(fd);
1354 remove(DummyFile);
1355 } else
1356 if (((rc =
1357 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1358 numRegions, Regions, &exactflag)) == -1)
1359 || ((rc = close(fd)) == -1)) {
1360 dm_handle_free(hanp, hlen);
1361 remove(DummyFile);
1362 }
1363 if (rc == -1) {
1364 DMLOG_PRINT(DMLVL_DEBUG,
1365 "Unable to set up variation! (errno = %d)\n",
1366 errno);
1367 DMVAR_SKIP();
1368 } else {
1369 /* Variation */
1370 sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE,
1371 DummyFile, O_RDWR, inoff, (long)inlen, 1);
1372 DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command);
1373 rc = system(command);
1374 EVENT_DELIVERY_DELAY;
1375 DMVAR_END(DMVAR_CHKPASSEXP
1376 (0, rc, eventExpected, eventReceived));
1377
1378 /* Variation clean up */
1379 rc = remove(DummyFile);
1380 if (rc == -1) {
1381 DMLOG_PRINT(DMLVL_DEBUG,
1382 "Unable to clean up variation! (errno = %d)\n",
1383 errno);
1384 }
1385 dm_handle_free(hanp, hlen);
1386 }
1387 }
1388
1389 remove(DummyFile);
1390 remove(DummyTmp);
1391
1392 rc = umount(mountPt);
1393 if (rc == -1) {
1394 DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
1395 rc, errno);
1396 }
1397
1398 pthread_join(tid, NULL);
1399
1400 rc = dm_destroy_session(sid);
1401 if (rc == -1) {
1402 DMLOG_PRINT(DMLVL_ERR,
1403 "dm_destroy_session failed! (rc = %d, errno = %d)\n",
1404 rc, errno);
1405 }
1406
1407 DMLOG_STOP();
1408
1409 tst_exit();
1410 }
1411
Thread(void * parm)1412 void *Thread(void *parm)
1413 {
1414 int rc;
1415 size_t dmMsgBufLen;
1416 dm_eventmsg_t *dmMsg;
1417 int bMounted = DM_FALSE;
1418 dm_eventtype_t type;
1419 dm_token_t token;
1420 dm_eventset_t events;
1421 dm_response_t response;
1422
1423 do {
1424 /* Loop until message received (wait could be interrupted) */
1425 do {
1426 DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
1427 dmMsgBufLen = 0;
1428
1429 rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
1430 dmMsgBuf, &dmMsgBufLen);
1431 DMLOG_PRINT(DMLVL_DEBUG,
1432 "... dm_get_events returned %d (errno %d)\n",
1433 rc, errno);
1434 } while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
1435
1436 if (rc) {
1437 DMLOG_PRINT(DMLVL_ERR,
1438 "dm_get_events failed with rc = %d, errno = %d\n",
1439 rc, errno);
1440 dm_destroy_session(sid);
1441 DM_EXIT();
1442 } else {
1443 dmMsg = (dm_eventmsg_t *) dmMsgBuf;
1444 token = dmMsg->ev_token;
1445 type = dmMsg->ev_type;
1446
1447 DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
1448 }
1449
1450 if (type == DM_EVENT_MOUNT) {
1451 /* SPECIAL CASE: need to set disposition, events and response */
1452 dm_mount_event_t *me =
1453 DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
1454 void *lhanp = DM_GET_VALUE(me, me_handle1, void *);
1455 size_t lhlen = DM_GET_LEN(me, me_handle1);
1456
1457 DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
1458 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", me->me_mode);
1459 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
1460 lhanp);
1461 DMLOG_PRINT(DMLVL_DEBUG,
1462 " File system handle length: %d\n", lhlen);
1463 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint handle: %p\n",
1464 DM_GET_VALUE(me, me_handle2, void *));
1465 DMLOG_PRINT(DMLVL_DEBUG,
1466 " Mountpoint handle length: %d\n",
1467 DM_GET_LEN(me, me_handle2));
1468 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint path: %s\n",
1469 DM_GET_VALUE(me, me_name1, char *));
1470 DMLOG_PRINT(DMLVL_DEBUG, " Media designator: %s\n",
1471 DM_GET_VALUE(me, me_name2, char *));
1472 DMLOG_PRINT(DMLVL_DEBUG, " Root handle: %p\n",
1473 DM_GET_VALUE(me, me_roothandle, void *));
1474 DMLOG_PRINT(DMLVL_DEBUG, " Root handle length: %d\n",
1475 DM_GET_LEN(me, me_roothandle));
1476
1477 bMounted = dm_handle_is_valid(lhanp, lhlen);
1478
1479 rc = dm_request_right(sid, lhanp, lhlen, token,
1480 DM_RR_WAIT, DM_RIGHT_EXCL);
1481 if (rc == -1) {
1482 DMLOG_PRINT(DMLVL_ERR,
1483 "dm_request_right failed! (rc = %d, errno = %d)\n",
1484 rc, errno);
1485 dm_destroy_session(sid);
1486 DM_EXIT();
1487 }
1488
1489 DMEV_ZERO(events);
1490 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
1491 DMEV_SET(DM_EVENT_UNMOUNT, events);
1492 DMEV_SET(DM_EVENT_READ, events);
1493 DMEV_SET(DM_EVENT_WRITE, events);
1494 rc = dm_set_disp(sid, lhanp, lhlen, token, &events,
1495 DM_EVENT_MAX);
1496 if (rc == -1) {
1497 DMLOG_PRINT(DMLVL_ERR,
1498 "dm_set_disp failed! (rc = %d, errno = %d)\n",
1499 rc, errno);
1500 dm_destroy_session(sid);
1501 DM_EXIT();
1502 }
1503
1504 DMEV_ZERO(events);
1505 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
1506 DMEV_SET(DM_EVENT_UNMOUNT, events);
1507 rc = dm_set_eventlist(sid, lhanp, lhlen, token, &events,
1508 DM_EVENT_MAX);
1509 if (rc == -1) {
1510 DMLOG_PRINT(DMLVL_ERR,
1511 "dm_set_eventlist failed! (rc = %d, errno = %d)\n",
1512 rc, errno);
1513 dm_destroy_session(sid);
1514 DM_EXIT();
1515 }
1516
1517 rc = dm_release_right(sid, lhanp, lhlen, token);
1518 if (rc == -1) {
1519 DMLOG_PRINT(DMLVL_ERR,
1520 "dm_request_right failed! (rc = %d, errno = %d)\n",
1521 rc, errno);
1522 dm_destroy_session(sid);
1523 DM_EXIT();
1524 }
1525
1526 response = DM_RESP_CONTINUE;
1527 } else if (type == DM_EVENT_UNMOUNT) {
1528 dm_namesp_event_t *nse =
1529 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
1530 if (nse->ne_retcode == 0) {
1531 bMounted = DM_FALSE;
1532 }
1533
1534 response = DM_RESP_CONTINUE;
1535 } else {
1536 eventReceived = type;
1537
1538 switch (type) {
1539 case DM_EVENT_PREUNMOUNT:
1540 response = DM_RESP_CONTINUE;
1541 break;
1542
1543 case DM_EVENT_READ:
1544 {
1545 dm_data_event_t *de =
1546 DM_GET_VALUE(dmMsg, ev_data,
1547 dm_data_event_t *);
1548 hanp1 =
1549 DM_GET_VALUE(de, de_handle, void *);
1550 hlen1 = DM_GET_LEN(de, de_handle);
1551 offset = de->de_offset;
1552 length = de->de_length;
1553
1554 DMLOG_PRINT(DMLVL_DEBUG,
1555 "Message is DM_EVENT_READ\n");
1556 DMLOG_PRINT(DMLVL_DEBUG,
1557 " Handle: %p\n", hanp1);
1558 DMLOG_PRINT(DMLVL_DEBUG,
1559 " Handle length: %d\n",
1560 hlen1);
1561 DMLOG_PRINT(DMLVL_DEBUG,
1562 " Offset: %d\n", offset);
1563 DMLOG_PRINT(DMLVL_DEBUG,
1564 " Length: %d\n", length);
1565
1566 response = eventResponse;
1567 break;
1568 }
1569
1570 case DM_EVENT_WRITE:
1571 {
1572 dm_data_event_t *de =
1573 DM_GET_VALUE(dmMsg, ev_data,
1574 dm_data_event_t *);
1575 hanp1 =
1576 DM_GET_VALUE(de, de_handle, void *);
1577 hlen1 = DM_GET_LEN(de, de_handle);
1578 offset = de->de_offset;
1579 length = de->de_length;
1580
1581 DMLOG_PRINT(DMLVL_DEBUG,
1582 "Message is DM_EVENT_WRITE\n");
1583 DMLOG_PRINT(DMLVL_DEBUG,
1584 " Handle: %p\n", hanp1);
1585 DMLOG_PRINT(DMLVL_DEBUG,
1586 " Handle length: %d\n",
1587 hlen1);
1588 DMLOG_PRINT(DMLVL_DEBUG,
1589 " Offset: %d\n", offset);
1590 DMLOG_PRINT(DMLVL_DEBUG,
1591 " Length: %d\n", length);
1592
1593 response = eventResponse;
1594 break;
1595 }
1596
1597 default:
1598 {
1599 DMLOG_PRINT(DMLVL_ERR,
1600 "Message is unexpected!\n");
1601 response = DM_RESP_ABORT;
1602 break;
1603 }
1604 }
1605 }
1606
1607 if (response != DM_RESP_INVALID) {
1608 DMLOG_PRINT(DMLVL_DEBUG,
1609 "Responding to message %d with %d\n", type,
1610 response);
1611 rc = dm_respond_event(sid, token, response,
1612 response ==
1613 DM_RESP_ABORT ? ABORT_ERRNO : 0,
1614 0, NULL);
1615 }
1616 } while (bMounted);
1617
1618 pthread_exit(0);
1619 }
1620