int main(int argc, char **argv) { char *varstr; int rc; int i; char *szSessionInfo = "dm_test session info"; dm_eventset_t events; DMOPT_PARSE(argc, argv); DMLOG_START(); DMEV_ZERO(events); DMEV_SET(DM_EVENT_MOUNT, events); /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ if ((rc = dm_init_service(&varstr)) != 0) { DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) { DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else { int fd; sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE); sprintf(DummyTmp, "%s/%s", mountPt, DUMMY_TMP); remove(DummyFile); EVENT_DELIVERY_DELAY; fd = open(DummyTmp, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); if (fd != -1) { for (i = 0; i < TMP_FILELEN/DUMMY_STRLEN; i++) { if (write(fd, DUMMY_STRING, DUMMY_STRLEN) != DUMMY_STRLEN) { rc = -1; break; } } } else { rc = -1; } if (rc != -1) { rc = fsync(fd); } if (rc != -1) { rc = close(fd); } if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "creating dummy file failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI memory mapped file synchronous event data tests\n") ; /* * TEST : mmap - no regions * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 1)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = close(fd)) == -1) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_REGION_WRITE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 2)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_REGION_TRUNCATE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 3)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_TRUNCATE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ, DM_RESP_CONTINUE * EXPECTED: DM_EVENT_READ * * This variation uncovered XFS BUG #33 (entire file returned instead * of mapped region only) */ if (DMVAR_EXEC(MMAP_READ_BASE + 4)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_READ; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ, DM_RESP_ABORT * EXPECTED: DM_EVENT_READ */ if (DMVAR_EXEC(MMAP_READ_BASE + 5)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_READ; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 0); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 6)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/2; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 7)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/2; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ * EXPECTED: DM_EVENT_READ */ if (DMVAR_EXEC(MMAP_READ_BASE + 8)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_READ; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/4; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_READ * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_READ_BASE + 9)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = DUMMY_STRLEN; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDONLY, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - no regions * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 1)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = close(fd)) == -1) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_REGION_READ * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 2)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_READ; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_REGION_TRUNCATE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 3)) { int fd; void *hanp; size_t hlen; off_t inoff = 0; size_t inlen = DUMMY_STRLEN; dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_INVALID; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_TRUNCATE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE, DM_RESP_CONTINUE * EXPECTED: DM_EVENT_WRITE */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 4)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_WRITE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE, DM_RESP_ABORT * EXPECTED: DM_EVENT_WRITE */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 5)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_WRITE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 0); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 6)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(0); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/2; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 7)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/2; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE * EXPECTED: DM_EVENT_WRITE */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 8)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int varStatus; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_WRITE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = TMP_FILELEN/4; Regions[0].rg_size = 0; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (inoff != offset) { DMLOG_PRINT(DMLVL_ERR, "Offset NOT correct! (%d vs %d)\n", inoff, offset); varStatus = DMSTAT_FAIL; } else if (inlen != length) { DMLOG_PRINT(DMLVL_ERR, "Length NOT correct! (%d vs %d)\n", inlen, length); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : mmap - one region, DM_EVENT_WRITE * EXPECTED: no event */ if (DMVAR_EXEC(MMAP_WRITE_BASE + 9)) { int fd; void *hanp; size_t hlen; off_t inoff = PAGEALIGN(TMP_FILELEN/4); size_t inlen = PAGEALIGN(DUMMY_STRLEN); dm_boolean_t exactflag; int numRegions; dm_region_t Regions[1]; /* Variation set up */ eventExpected = DM_EVENT_INVALID; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; numRegions = 1; Regions[0].rg_offset = 0; Regions[0].rg_size = DUMMY_STRLEN; Regions[0].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DummyTmp, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDONLY)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if (((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions, Regions, &exactflag)) == -1) || ((rc = close(fd)) == -1)) { dm_handle_free(hanp, hlen); remove(DummyFile); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ sprintf(command, "./%s %s %d %ld %ld %d", MMAPFILE_EXE, DummyFile, O_RDWR, inoff, (long)inlen, 1); DMLOG_PRINT(DMLVL_DEBUG, "invoking %s\n", command); rc = system(command); EVENT_DELIVERY_DELAY; DMVAR_END(DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)); /* Variation clean up */ rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } remove(DummyFile); remove(DummyTmp); rc = umount(mountPt); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno); } pthread_join(tid, NULL); rc = dm_destroy_session(sid); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno); } DMLOG_STOP(); return 0; }
int main(int argc, char **argv) { char *varstr; int rc; int varStatus; char *szSessionInfo = "dm_test session info"; dm_eventset_t events; DMOPT_PARSE(argc, argv); DMLOG_START(); DMEV_ZERO(events); DMEV_SET(DM_EVENT_MOUNT, events); /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ if ((rc = dm_init_service(&varstr)) != 0) { DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) { DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else { sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE); sprintf(DummyFile2, "%s/%s", mountPt, DUMMY_FILE2); sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR); sprintf(DummySubdir2, "%s/%s", mountPt, DUMMY_SUBDIR2); sprintf(DummyLink, "%s/%s", mountPt, DUMMY_LINK); remove(DummyFile); remove(DummyFile2); unlink(DummyLink); rmdir(DummySubdir); rmdir(DummySubdir2); } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI synchronous namespace event tests\n") ; /* * TEST : mkdir - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_CREATE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 1)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir); rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : mkdir - DM_RESP_ABORT * EXPECTED: DM_EVENT_CREATE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 2)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir); rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : rmdir - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_REMOVE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 3)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir); rc = rmdir(DummySubdir); DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } } /* * TEST : rmdir - DM_RESP_ABORT * EXPECTED: DM_EVENT_REMOVE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 4)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir); rc = rmdir(DummySubdir); DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_RENAME */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 5)) { dm_ino_t ino1, ino2; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummySubdir, DummySubdir2); EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir2); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv - DM_RESP_ABORT * EXPECTED: DM_EVENT_RENAME */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 6)) { dm_ino_t ino1, ino2; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummySubdir, DummySubdir2); EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_SYMLINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 7)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2); rc = symlink(DummySubdir, DummySubdir2); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummySubdir) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = unlink(DummySubdir2); rc |= rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink - DM_RESP_ABORT * EXPECTED: DM_EVENT_SYMLINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 8)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2); rc = symlink(DummySubdir, DummySubdir2); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummySubdir) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : link - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_LINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 9)) { #ifdef DIRECTORY_LINKS dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink); rc = link(DummySubdir, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); rc |= unlink(DummyLink); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } #else DMLOG_PRINT(DMLVL_WARN, "Test case not built with DIRECTORY_LINKS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : link - DM_RESP_ABORT * EXPECTED: DM_EVENT_LINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 10)) { #ifdef DIRECTORY_LINKS dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink); rc = link(DummySubdir, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } #else DMLOG_PRINT(DMLVL_WARN, "Test case not built with DIRECTORY_LINKS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : open * EXPECTED: DM_EVENT_CREATE, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 1)) { int fd; dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile); fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd); rc = (fd == -1) ? -1 : 0; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : open * EXPECTED: DM_EVENT_CREATE, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 2)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile); fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd); if ((varStatus = DMVAR_CHKFAILEXP(-1, fd, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : remove * EXPECTED: DM_EVENT_REMOVE, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 3)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile); rc = remove(DummyFile); DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } } /* * TEST : remove * EXPECTED: DM_EVENT_REMOVE, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 4)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile); rc = remove(DummyFile); DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv * EXPECTED: DM_EVENT_RENAME, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 5)) { dm_ino_t ino1, ino2; int fd; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummyFile, DummyFile2); EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_FILE2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = remove(DummyFile2); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); } } } /* * TEST : mv * EXPECTED: DM_EVENT_RENAME, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 6)) { dm_ino_t ino1, ino2; int fd; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummyFile, DummyFile2); EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc); if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_FILE2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 7)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink); rc = symlink(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummyFile) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = unlink(DummyLink); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 8)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink); rc = symlink(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummyFile) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : link * EXPECTED: DM_EVENT_LINK, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 9)) { dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; int fd; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink); rc = link(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); rc |= remove(DummyLink); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : link * EXPECTED: DM_EVENT_LINK, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 10)) { dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; int fd; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink); rc = link(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } rc = umount(mountPt); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno); } pthread_join(tid, NULL); rc = dm_destroy_session(sid); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno); } DMLOG_STOP(); tst_exit(); }
int main(int argc, char **argv) { char *szFuncName; char *varstr; int rc; int varStatus; char *szSessionInfo = "dm_test session info"; dm_eventset_t events; DMOPT_PARSE(argc, argv); DMLOG_START(); DMEV_ZERO(events); DMEV_SET(DM_EVENT_MOUNT, events); /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ if ((rc = dm_init_service(&varstr)) != 0) { DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) { DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else { rc = dm_get_config(fshanp, fshlen, DM_CONFIG_MAX_MESSAGE_DATA, &maxMsgDat); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_get_config failed! (rc = %d, errno = %d)\n", rc, errno); umount(mountPt); dm_destroy_session(sid); DM_EXIT(); } } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI user event tests\n") ; szFuncName = "dm_create_userevent"; /* * TEST : dm_create_uservent - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 1)) { char buf[MSG_DATALEN]; dm_token_t token; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_create_userevent(INVALID_ADDR, MSG_DATALEN, buf, &token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_create_uservent - invalid msglen * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 2)) { char buf[MSG_DATALEN]; dm_token_t token; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msglen)\n", szFuncName); rc = dm_create_userevent(sid, maxMsgDat+1, buf, &token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); /* Variation clean up */ } /* * TEST : dm_create_uservent - invalid msgdatap * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 3)) { dm_token_t token; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgdatap)\n", szFuncName); rc = dm_create_userevent(sid, MSG_DATALEN, (void *)INVALID_ADDR, &token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_create_uservent - invalid tokenp * EXPECTED: rc = -1, errno = EFAULT * * This variation uncovered XFS BUG #11 (unused tevp left on queue) */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 4)) { char buf[MSG_DATALEN]; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid tokenp)\n", szFuncName); rc = dm_create_userevent(sid, MSG_DATALEN, buf, (dm_token_t *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_create_uservent - valid * EXPECTED: rc = 0 */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 5)) { char buf[MSG_DATALEN]; dm_token_t token; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : dm_create_uservent - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(CREATE_USEREVENT_BASE + 6)) { char buf[MSG_DATALEN]; dm_token_t token; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_create_userevent(DM_NO_SESSION, MSG_DATALEN, buf, &token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } szFuncName = "dm_send_msg"; /* * TEST : dm_send_msg - invalid targetsid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(SEND_MSG_BASE + 1)) { char buf[MSG_DATALEN]; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid targetsid)\n", szFuncName); rc = dm_send_msg(INVALID_ADDR, DM_MSGTYPE_SYNC, MSG_DATALEN, buf); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_send_msg - invalid msgtype * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(SEND_MSG_BASE + 2)) { char buf[MSG_DATALEN]; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid msgtype)\n", szFuncName); rc = dm_send_msg(sid, INVALID_ADDR, MSG_DATALEN, buf); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_send_msg - invalid buflen * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(SEND_MSG_BASE + 3)) { char buf[MSG_DATALEN]; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName); rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, maxMsgDat+1, buf); DMVAR_ENDFAILEXP(szFuncName, -1, rc, E2BIG); /* Variation clean up */ } /* * TEST : dm_send_msg - invalid bufp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(SEND_MSG_BASE + 4)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName); rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, (void *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_send_msg - DM_RESP_CONTINUE * EXPECTED: rc = 0 */ if (DMVAR_EXEC(SEND_MSG_BASE + 5)) { char buf[MSG_DATALEN]; /* Variation set up */ eventExpected = DM_EVENT_USER; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; memcpy(buf, MSG_DATA, MSG_DATALEN); /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(continue response)\n", szFuncName); rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (tokenReceived == 0) { DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs non-zero)\n", tokenReceived); varStatus = DMSTAT_FAIL; } if (msgDataLenReceived != MSG_DATALEN) { DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN); varStatus = DMSTAT_FAIL; } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) { DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : dm_send_msg - DM_RESP_ABORT * EXPECTED: rc = -1, errno = ABORT_ERRNO * * This variation uncovered XFS BUG #39 (response reterror returned * instead of -1 and errno set to reterror) */ if (DMVAR_EXEC(SEND_MSG_BASE + 6)) { char buf[MSG_DATALEN]; /* Variation set up */ eventExpected = DM_EVENT_USER; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; memcpy(buf, MSG_DATA, MSG_DATALEN); /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(abort response)\n", szFuncName); rc = dm_send_msg(sid, DM_MSGTYPE_SYNC, MSG_DATALEN, buf); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { if (tokenReceived == 0) { DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs non-zero)\n", tokenReceived); varStatus = DMSTAT_FAIL; } if (msgDataLenReceived != MSG_DATALEN) { DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN); varStatus = DMSTAT_FAIL; } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) { DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : dm_send_msg - DM_MSGTYPE_ASYNC * EXPECTED: rc = 0 */ if (DMVAR_EXEC(SEND_MSG_BASE + 7)) { char buf[MSG_DATALEN]; /* Variation set up */ eventExpected = DM_EVENT_USER; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; memcpy(buf, MSG_DATA, MSG_DATALEN); /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_MSGTYPE_ASYNC)\n", szFuncName); rc = dm_send_msg(sid, DM_MSGTYPE_ASYNC, MSG_DATALEN, buf); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { if (tokenReceived != 0) { DMLOG_PRINT(DMLVL_ERR, "Token NOT correct! (%d vs %d)\n", tokenReceived, 0); varStatus = DMSTAT_FAIL; } if (msgDataLenReceived != MSG_DATALEN) { DMLOG_PRINT(DMLVL_ERR, "Message lengths NOT same! (%d vs %d)\n", msgDataLenReceived, MSG_DATALEN); varStatus = DMSTAT_FAIL; } else if (memcmp(msgDataReceived, buf, MSG_DATALEN) != 0) { DMLOG_PRINT(DMLVL_ERR, "Message data NOT same! (%s vs %s)\n", msgDataReceived, buf); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : dm_send_msg - DM_NO_SESSION targetsid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(SEND_MSG_BASE + 8)) { char buf[MSG_DATALEN]; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION targetsid)\n", szFuncName); rc = dm_send_msg(DM_NO_SESSION, DM_MSGTYPE_SYNC, MSG_DATALEN, buf); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } szFuncName = "dm_find_eventmsg"; /* * TEST : dm_find_eventmsg - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 1)) { dm_token_t token; char buf[MSG_DATALEN]; size_t rlen; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_find_eventmsg(INVALID_ADDR, token, MSG_DATALEN, buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 2)) { dm_token_t token; char buf[MSG_DATALEN]; size_t rlen; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_find_eventmsg(sid, INVALID_ADDR, MSG_DATALEN, buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - invalid buflen * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 3)) { dm_token_t token; char buf[MSG_DATALEN]; size_t rlen; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName); rc = dm_find_eventmsg(sid, token, MSG_DATALEN-1, buf, &rlen); if (rc == -1) { if (errno == E2BIG) { DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen); if (rlen == MSG_DATALEN+sizeof(dm_eventmsg_t)) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d, expected errno = %d, and expected rlen = %d\n", szFuncName, rc, errno, rlen); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n", szFuncName, rc, errno, rlen, MSG_DATALEN); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, rc, errno); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - invalid bufp * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 4)) { dm_token_t token; char buf[MSG_DATALEN]; size_t rlen; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName); rc = dm_find_eventmsg(sid, token, MSG_DATALEN, (void *)INVALID_ADDR, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - invalid rlenp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 5)) { dm_token_t token; char buf[MSG_DATALEN]; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", szFuncName); rc = dm_find_eventmsg(sid, token, MSG_DATALEN, buf, (size_t *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - valid * EXPECTED: rc = 0 */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 6)) { dm_token_t token; char bufin[MSG_DATALEN], bufout[MSG_DATALEN+sizeof(dm_eventmsg_t)]; size_t rlen; /* Variation set up */ memcpy(bufin, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, bufin, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName); rc = dm_find_eventmsg(sid, token, sizeof(bufout), bufout, &rlen); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen); if (rlen == MSG_DATALEN+sizeof(dm_eventmsg_t)) { if (memcmp(bufin, bufout+sizeof(dm_eventmsg_t), MSG_DATALEN) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d, expected rlen %d, and expected buffer %s\n", szFuncName, rc, rlen, bufout+sizeof(dm_eventmsg_t)); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected rlen %d but expected buffer %s\n", szFuncName, rc, rlen, bufout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s passed with expected rc = %d but unexpected rlen %d\n", szFuncName, rc, rlen); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_find_eventmsg - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(FIND_EVENTMSG_BASE + 7)) { dm_token_t token; char buf[MSG_DATALEN]; size_t rlen; /* Variation set up */ memcpy(buf, MSG_DATA, MSG_DATALEN); rc = dm_create_userevent(sid, MSG_DATALEN, buf, &token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to initialize variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_find_eventmsg(DM_NO_SESSION, token, MSG_DATALEN, buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_respond_event(sid, token, DM_RESP_CONTINUE, 0, 0, NULL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } rc = umount(mountPt); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno); } EVENT_DELIVERY_DELAY; pthread_join(tid, NULL); rc = dm_destroy_session(sid); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno); } DMLOG_STOP(); tst_exit(); }
void DoTest() { int rc; char *szFuncName; DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI persistent managed regions test\n") ; szFuncName = "dm_get_region"; /* * TEST : dm_get_region - persistent, Part II * EXPECTED: rc = 0, nelem = 5 */ if (DMVAR_EXEC(GET_REGION_BASE + 1)) { int fd; void *hanp; size_t hlen; u_int nelem; dm_region_t regbuf[PMR_NUM_REGIONS]; int varStatus; int i; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(persistent, Part II)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, sizeof(regbuf)/sizeof(dm_region_t), regbuf, &nelem); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelem); } varStatus = DMSTAT_PASS; if (rc != 0) { DMLOG_PRINT(DMLVL_ERR, "%s returned unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); varStatus = DMSTAT_FAIL; } else if (nelem != PMR_NUM_REGIONS) { DMLOG_PRINT(DMLVL_ERR, "Number of regions NOT correct! (%d vs %d)\n", nelem, PMR_NUM_REGIONS); varStatus = DMSTAT_FAIL; } else { DMLOG_PRINT(DMLVL_DEBUG, "%s returned expected rc = %d\n", szFuncName, rc, errno); DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", rc, errno); LogRegions(regbuf, nelem); for (i = 0; i < PMR_NUM_REGIONS; i++) { if (regbuf[i].rg_offset != dm_PMR_regbuf[i].rg_offset) { DMLOG_PRINT(DMLVL_ERR, "region %d offset NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_offset, dm_PMR_regbuf[i].rg_offset); varStatus = DMSTAT_FAIL; } if (regbuf[i].rg_size != dm_PMR_regbuf[i].rg_size) { DMLOG_PRINT(DMLVL_ERR, "region %d size NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_size, dm_PMR_regbuf[i].rg_size); varStatus = DMSTAT_FAIL; } if (regbuf[i].rg_flags != dm_PMR_regbuf[i].rg_flags) { DMLOG_PRINT(DMLVL_ERR, "region %d flags NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_flags, dm_PMR_regbuf[i].rg_flags); varStatus = DMSTAT_FAIL; } } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 2)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_get_region(INVALID_ADDR, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 3)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_get_region(sid, (void *)INVALID_ADDR, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_REGION_BASE + 4)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_get_region(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 5)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, INVALID_ADDR, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid regbufp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 6)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid regbufp)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, (dm_region_t *)INVALID_ADDR, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid nelemp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 7)) { int fd; void *hanp; size_t hlen; u_int nelemin; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid nelemp)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, (u_int *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - DM_SO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 8)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_get_region(DM_NO_SESSION, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_REGION_BASE + 9)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_get_region(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, nelemin, ®buf, &nelemout); if (rc == -1 && errno == EBADF) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); } DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - directory handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 10)) { void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - fs handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 11)) { void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 0 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 11)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 0; sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 0)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 1 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 12)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin, regbufout; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®bufin, 0, sizeof(regbufin)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®bufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 1)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®bufout, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { if (memcmp(®bufin, ®bufout, sizeof(dm_region_t)) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected regions\n", szFuncName, 0); DMLOG_PRINT(DMLVL_DEBUG, "Region in:\n"); LogRegions(®bufin, nelemin); DMLOG_PRINT(DMLVL_DEBUG, "Region out:\n"); LogRegions(®bufout, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 2 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 13)) { #ifdef MULTIPLE_REGIONS int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin[2], regbufout[2]; dm_boolean_t exactflag; /* Variation set up */ nelemin = 2; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; regbufin[1].rg_offset = 2000; regbufin[1].rg_size = 1000; regbufin[1].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 2)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufout, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { if (memcmp(®bufin, ®bufout, sizeof(dm_region_t)) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected regions\n", szFuncName, 0); DMLOG_PRINT(DMLVL_DEBUG, "Region in:\n"); LogRegions(regbufin, nelemin); DMLOG_PRINT(DMLVL_DEBUG, "Region out:\n"); LogRegions(regbufout, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } #else DMLOG_PRINT(DMLVL_WARN, "Test case not built with MULTIPLE_REGIONS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : dm_get_region - regbuf too small * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(GET_REGION_BASE + 14)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin[2], regbufout[1]; dm_boolean_t exactflag; /* Variation set up */ #ifdef MULTIPLE_REGIONS nelemin = 2; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; regbufin[1].rg_offset = 2000; regbufin[1].rg_size = 1000; regbufin[1].rg_flags = DM_REGION_WRITE; #else nelemin = 1; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; #endif sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(regbuf too small)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin-1, regbufout, &nelemout); if (rc == -1) { if (errno == E2BIG) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemout == nelemin) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d and expected errno = %d\n", szFuncName, rc, errno); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected nelemp (%d vs %d)\n", szFuncName, rc, errno, nelemout, nelemin); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, rc, errno); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } }