int do_test (int argc, char *argv[]) { char buf[1000]; char res[1000]; int i; memset (buf, '\0', sizeof (buf)); memset (res, '\xff', sizeof (res)); if (write (fd, buf, sizeof (buf)) != sizeof (buf)) error (EXIT_FAILURE, errno, "during write"); for (i = 100; i < 200; ++i) buf[i] = i; if (PWRITE (fd, buf + 100, 100, 100) != 100) error (EXIT_FAILURE, errno, "during %s", STRINGIFY (PWRITE)); for (i = 450; i < 600; ++i) buf[i] = i; if (PWRITE (fd, buf + 450, 150, 450) != 150) error (EXIT_FAILURE, errno, "during %s", STRINGIFY (PWRITE)); if (PREAD (fd, res, sizeof (buf) - 50, 50) != sizeof (buf) - 50) error (EXIT_FAILURE, errno, "during %s", STRINGIFY (PREAD)); close (fd); unlink (name); return memcmp (buf + 50, res, sizeof (buf) - 50); }
int main(int argc, char **argv) { char buf[BIG_ENOUGH]; /* correct requests */ FPRINTF(STDERR, "TEST SEQUENTIAL READ ONLY CHANNEL\n"); FPRINTF(STDERR, "channel size = %lld\n", MANIFEST->channels[OPEN(SEQRO)].size); ZTEST(MANIFEST->channels[OPEN(SEQRO)].size == 0); ZTEST(PREAD(SEQRO, buf, 0, 0) == 0); ZTEST(PREAD(SEQRO, buf, 0, 1) == 0); ZTEST(PREAD(SEQRO, buf, 1, 0) == 1); ZTEST(PREAD(SEQRO, buf, 1, MANIFEST->channels[OPEN(SEQRO)].size - 1) == 1); ZTEST(PREAD(SEQRO, buf, 0, -1) == 0); /* incorrect requests: NULL buffer */ ZTEST(PREAD(SEQRO, NULL, 0, 0) < 0); ZTEST(PREAD(SEQRO, NULL, 0, 1) < 0); ZTEST(PREAD(SEQRO, NULL, 1, 0) < 0); ZTEST(PREAD(SEQRO, NULL, 1, MANIFEST->channels[OPEN(SEQRO)].size - 1) < 0); ZTEST(PREAD(SEQRO, NULL, 0, -1) < 0); /* incorrect requests: size */ ZTEST(PREAD(SEQRO, buf, -1, 0) < 0); /* incorrect requests: offset */ ZTEST(PREAD(SEQRO, buf, 0, -1) == 0); ZTEST(PREAD(SEQRO, buf, 1, -1) == 1); ZTEST(PREAD(SEQRO, buf, 1, MANIFEST->channels[OPEN(SEQRO)].size) == 1); /* correct requests: writing of 0 bytes attempt */ ZTEST(PWRITE(SEQRO, buf, 0, 0) == 0); /* incorrect requests: write attempt */ ZTEST(PWRITE(SEQRO, buf, 1, 0) < 0); ZTEST(PWRITE(SEQRO, buf, 1, MANIFEST->channels[OPEN(SEQRO)].size) < 0); ZTEST(PWRITE(SEQRO, buf, 1, MANIFEST->channels[OPEN(SEQRO)].size - 1) < 0); /* incorrect requests: exhausted */ ZTEST(PREAD(SEQRO, buf, 30, 0) == 28); ZTEST(PREAD(SEQRO, buf, 10, 0) < 0); /* count errors and exit with it */ ZREPORT; return 0; }
static void io_blk_free(ZDB_IO_BLK *blk) { const char *myname = "io_blk_free"; int ret; if ((blk->flag & BLK_F_DIRTY)) { ZDB_IO *io = blk->io; avl_remove(&io->blk_tree, blk); #ifdef PWRITE ret = PWRITE(IO_HANDLE(io), blk->dat, blk->dlen, blk->off); if (ret != (int) blk->dlen) { acl_msg_error("%s(%d): pwrite to %s error(%s)," " ret(%d) != len(%d), off: " ACL_FMT_I64D, myname, __LINE__, PATH(IO_STREAM(io)), acl_last_serror(), ret, (int) blk->dlen, blk->off); } #else if (acl_vstream_fseek(IO_STREAM(io), blk->off, SEEK_SET) < 0) { acl_msg_error("%s(%d): fseek %s error(%s), off: " ACL_FMT_I64D, myname, __LINE__, IO_PATH(io), acl_last_serror(), blk->off); } else if ((ret = acl_vstream_writen(IO_STREAM(io), blk->dat, blk->dlen)) == ACL_VSTREAM_EOF) { acl_msg_error("%s(%d): readn from %s, ret(%d) != size(%d)," " off(" ACL_FMT_I64D "), error(%s)", myname, __LINE__, IO_PATH(io), ret, (int) blk->dlen, blk->off, acl_last_serror()); } #endif } if (blk->io->dat_slice) acl_slice_free2(blk->io->dat_slice, blk->dat); else acl_myfree(blk->dat); if (blk->io->blk_slice) acl_slice_free2(blk->io->blk_slice, blk); else acl_myfree(blk); __n--; }
int main(int argc, char **argv) { char buf[BIG_ENOUGH]; /* correct requests */ FPRINTF(STDERR, "TEST RANDOM WRITE ONLY CHANNEL\n"); FPRINTF(STDERR, "channel size = %ld\n", MANIFEST->channels[OPEN(RANWO)].size); ZTEST(MANIFEST->channels[OPEN(RANWO)].size == 0); ZTEST(PWRITE(RANWO, buf, 0, 0) == 0); ZTEST(PWRITE(RANWO, buf, 0, 0) == 0); ZTEST(PWRITE(RANWO, buf, 0, 1) == 0); ZTEST(PWRITE(RANWO, buf, 1, 0) == 1); ZTEST(PWRITE(RANWO, buf, 1, MANIFEST->channels[OPEN(RANWO)].limits[PutSizeLimit] - 1) == 1); ZTEST(PWRITE(RANWO, buf, 0, -1) == 0); /* incorrect requests: NULL buffer */ ZTEST(PWRITE(RANWO, NULL, 0, 0) < 0); ZTEST(PWRITE(RANWO, NULL, 0, 1) < 0); ZTEST(PWRITE(RANWO, NULL, 1, 0) < 0); ZTEST(PWRITE(RANWO, NULL, 1, MANIFEST->channels[OPEN(RANWO)].limits[PutSizeLimit] - 1) < 0); ZTEST(PWRITE(RANWO, NULL, 0, -1) < 0); /* incorrect requests: size */ ZTEST(PWRITE(RANWO, buf, -1, 0) < 0); /* incorrect requests: offset */ ZTEST(PWRITE(RANWO, buf, 0, -1) == 0); ZTEST(PWRITE(RANWO, buf, 1, -1) < 0); ZTEST(PWRITE(RANWO, buf, 1, MANIFEST->channels[OPEN(RANWO)].limits[PutSizeLimit]) < 0); /* correct requests: reading of 0 bytes attempt */ ZTEST(PREAD(RANWO, buf, 0, 0) == 0); /* incorrect requests: read attempt */ ZTEST(PREAD(RANWO, buf, 1, 0) < 0); ZTEST(PREAD(RANWO, buf, 1, MANIFEST->channels[OPEN(RANWO)].limits[PutSizeLimit]) < 0); /* incorrect requests: exhausted */ ZTEST(PWRITE(RANWO, buf, 31, 0) == 30); ZTEST(PWRITE(RANWO, buf, 10, 0) < 0); /* count errors and exit with it */ ZREPORT; return 0; }
ssize_t NaClHostDescPWrite(struct NaClHostDesc *d, void const *buf, size_t len, nacl_off64_t offset) { int need_lock; ssize_t retval; NaClHostDescCheckValidity("NaClHostDescPWrite", d); if (NACL_ABI_O_RDONLY == (d->flags & NACL_ABI_O_ACCMODE)) { NaClLog(3, "NaClHostDescPWrite: RDONLY file\n"); return -NACL_ABI_EBADF; } /* * Linux's interpretation of what the POSIX standard requires * differs from OSX. On Linux, pwrite using a descriptor that was * opened with O_APPEND will ignore the supplied offset parameter * and append. On OSX, the supplied offset parameter wins. * * The POSIX specification at * * http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html * * says that pwrite should always pay attention to the supplied offset. * * We standardize on POSIX behavior. */ need_lock = NACL_LINUX && (0 != (d->flags & NACL_ABI_O_APPEND)); if (need_lock) { int orig_flags; /* * Grab lock that all NaCl platform library using applications * will use. NB: if the descriptor is shared with a non-NaCl * platform library-using application, there is a race. */ NaClHostDescExclusiveLock(d->d); /* * Temporarily disable O_APPEND and issue the pwrite. */ orig_flags = fcntl(d->d, F_GETFL, 0); CHECK(orig_flags & O_APPEND); if (-1 == fcntl(d->d, F_SETFL, orig_flags & ~O_APPEND)) { NaClLog(LOG_FATAL, "NaClHostDescPWrite: could not fcntl F_SETFL (~O_APPEND)\n"); } retval = PWRITE(d->d, buf, len, offset); /* * Always re-enable O_APPEND regardless of pwrite success or * failure. */ if (-1 == fcntl(d->d, F_SETFL, orig_flags)) { NaClLog(LOG_FATAL, "NaClHostDescPWrite: could not fcntl F_SETFL (restore)\n"); } NaClHostDescExclusiveUnlock(d->d); if (-1 == retval) { retval = -NaClXlateErrno(errno); } return retval; } return ((-1 == (retval = PWRITE(d->d, buf, len, offset))) ? -NaClXlateErrno(errno) : retval); }
void mpi_pci_attach(struct device *parent, struct device *self, void *aux) { struct mpi_pci_softc *psc = (void *)self; struct mpi_softc *sc = &psc->psc_mpi; struct pci_attach_args *pa = aux; pcireg_t memtype; int r; pci_intr_handle_t ih; const char *intrstr; psc->psc_pc = pa->pa_pc; psc->psc_tag = pa->pa_tag; psc->psc_ih = NULL; sc->sc_dmat = pa->pa_dmat; sc->sc_ios = 0; /* find the appropriate memory base */ for (r = PCI_MAPREG_START; r < PCI_MAPREG_END; r += sizeof(memtype)) { memtype = pci_mapreg_type(psc->psc_pc, psc->psc_tag, r); if ((memtype & PCI_MAPREG_TYPE_MASK) == PCI_MAPREG_TYPE_MEM) break; } if (r >= PCI_MAPREG_END) { printf(": unable to locate system interface registers\n"); return; } if (pci_mapreg_map(pa, r, memtype, 0, &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_ios, 0) != 0) { printf(": unable to map system interface registers\n"); return; } /* disable the expansion rom */ PWRITE(psc, PCI_ROM_REG, PREAD(psc, PCI_ROM_REG) & ~PCI_ROM_ENABLE); /* hook up the interrupt */ if (pci_intr_map(pa, &ih)) { printf(": unable to map interrupt\n"); goto unmap; } intrstr = pci_intr_string(psc->psc_pc, ih); psc->psc_ih = pci_intr_establish(psc->psc_pc, ih, IPL_BIO, mpi_intr, sc, sc->sc_dev.dv_xname); if (psc->psc_ih == NULL) { printf(": unable to map interrupt%s%s\n", intrstr == NULL ? "" : " at ", intrstr == NULL ? "" : intrstr); goto unmap; } printf(": %s", intrstr); if (pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_ID_REG) == PCI_ID_CODE(PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_1030)) sc->sc_flags |= MPI_F_SPI; if (mpi_attach(sc) != 0) { /* error printed by mpi_attach */ goto deintr; } return; deintr: pci_intr_disestablish(psc->psc_pc, psc->psc_ih); psc->psc_ih = NULL; unmap: bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios); sc->sc_ios = 0; }
int main(int argc, char **argv) { int overall_errors = 0; char buf[BIG_ENOUGH]; /* * todo: add more cases for * (un)successfull writes to not empty channel * (un)successfull reads from not empty channel */ /* test (in)valid write cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR WRITE CASES\n"); ZTEST(PWRITE(STDRW_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, -1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, 0) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, -1, 1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDRW_GOAT, buf, 0, -1) == 0); /* accessing of 0 bytes is always ok */ ZTEST(PWRITE(STDRW_GOAT, buf, 1, -1) < 0); /* size = 1, offset invalid */ ZTEST(PWRITE(STDRW_GOAT, buf, 0, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) == 0); ZTEST(PWRITE(STDRW_GOAT, buf, 1, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid reead cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR READ CASES\n"); ZTEST(PREAD(STDRW_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDRW_GOAT, buf, -1, -1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, -1, 0) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, -1, 1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, 0, -1) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDRW_GOAT, buf, 1, -1) < 0); /* valid size, invalid offset = fail */ ZTEST(PREAD(STDRW_GOAT, buf, 0, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); ZTEST(PREAD(STDRW_GOAT, buf, 1, MANIFEST->channels[OPEN(STDRW_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test NULL buffer cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST NULL BUFFER CASES\n"); ZTEST(PWRITE(STDRW_GOAT, NULL, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, NULL, 0, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDRW_GOAT, (void*)0x1, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0xffff, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x10000, -1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000001 - 0x10000, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDRW_GOAT, (void*)0x10000, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PWRITE(STDRW_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDRW_GOAT, (char*)main, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000001, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDRW_GOAT, &data_start, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PREAD(STDRW_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* exit with code */ if(overall_errors > 0) FPRINTF(STDERR, "OVERALL TEST FAILED with %d errors\n", overall_errors); else FPRINTF(STDERR, "OVERALL TEST SUCCEED\n\n"); return overall_errors; }
int main(int argc, char **argv) { int overall_errors = 0; char buf[BIG_ENOUGH]; /* test an empty cdr channel */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST AN EMPTY CDR\n"); initial_put(STDCDR_EMPTY); MSG_OK(STDCDR_EMPTY, "01234"); MSG_OK(STDCDR_EMPTY, "567"); MSG_OK(STDCDR_EMPTY, "89abcdefg"); MSG_OK(STDCDR_EMPTY, "zyx"); MSG_OK(STDCDR_EMPTY, "this is the end"); MSG_ERR(STDCDR_EMPTY, "this write should fail"); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test stubbed cdr channel */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST STUBBED CDR\n"); eofpos = MANIFEST->channels[OPEN(STDCDR_STUBBED)].size; FPRINTF(STDERR, "%s size = %lld\n", MANIFEST->channels[OPEN(STDCDR_STUBBED)].name, eofpos); MSG_OK(STDCDR_STUBBED, "01234"); MSG_OK(STDCDR_STUBBED, "567"); MSG_OK(STDCDR_STUBBED, "89abcdefg"); MSG_OK(STDCDR_STUBBED, "zyx"); MSG_OK(STDCDR_STUBBED, "this is the end"); MSG_ERR(STDCDR_STUBBED, "this write should fail"); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid write cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR WRITE CASES\n"); ZTEST(PWRITE(STDCDR_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, -1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, 0) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, -1, 1) < 0); /* invalid size, offset ignored = fail */ ZTEST(PWRITE(STDCDR_GOAT, buf, 0, -1) == 0); /* accessing of 0 bytes is always ok */ ZTEST(PWRITE(STDCDR_GOAT, buf, 1, -1) == 1); /* size = 1, offset ignored = 1 byte written */ ZTEST(PWRITE(STDCDR_GOAT, buf, 0, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) == 0); ZTEST(PWRITE(STDCDR_GOAT, buf, 1, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test (in)valid read cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST (IN)VALID CDR READ CASES\n"); ZTEST(PREAD(STDCDR_GOAT, buf, 0, 0) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, -1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, 0) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, -1, 1) < 0); /* invalid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, 0, -1) == 0); /* accessing 0 bytes is always ok */ ZTEST(PREAD(STDCDR_GOAT, buf, 1, -1) < 0); /* valid size, invalid offset = fail */ ZTEST(PREAD(STDCDR_GOAT, buf, 0, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) < 0); ZTEST(PREAD(STDCDR_GOAT, buf, 1, MANIFEST->channels[OPEN(STDCDR_GOAT)].limits[PutSizeLimit] + 1) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test NULL buffer cases */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST NULL BUFFER CASES\n"); ZTEST(PWRITE(STDCDR_GOAT, NULL, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, NULL, 0, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x1, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0xffff, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x10000, -1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000001 - 0x10000, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pwrite */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PWRITE\n"); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x10000, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PWRITE(STDCDR_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other invalid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER INVALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDCDR_GOAT, (char*)main, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr, MANIFEST->heap_size + 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000001, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL, 1, 0) < 0); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 0x1000001, 0) < 0); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* test other valid buffer address/size cases for pread */ ERRCOUNT = 0; FPRINTF(STDERR, "TEST OTHER VALID BUFFER/SIZE CASES FOR PREAD\n"); ZTEST(PREAD(STDCDR_GOAT, &data_start, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, MANIFEST->heap_ptr + MANIFEST->heap_size - 1, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1000000, 1, 0) == 1); ZTEST(PREAD(STDCDR_GOAT, (void*)0x100000000LL - 0x1, 1, 0) == 1); overall_errors += ERRCOUNT; FPRINTF(STDERR, ERRCOUNT ? "TEST FAILED\n\n" : "TEST SUCCEED\n\n"); /* exit with code */ if(overall_errors > 0) FPRINTF(STDERR, "OVERALL TEST FAILED with %d errors\n", overall_errors); else FPRINTF(STDERR, "OVERALL TEST SUCCEED\n\n"); return overall_errors; }