static int aio_md_test(void) { int error, fd, i, mdctl_fd, unit; char pathname[PATH_MAX]; struct aio_md_arg arg; struct aio_context ac; struct md_ioctl mdio; mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0); if (mdctl_fd < 0) errx(-1, "FAIL: aio_md_test: open(/dev/%s): %s", MDCTL_NAME, strerror(errno)); bzero(&mdio, sizeof(mdio)); mdio.md_version = MDIOVERSION; mdio.md_type = MD_MALLOC; mdio.md_options = MD_AUTOUNIT | MD_COMPRESS; mdio.md_mediasize = GLOBAL_MAX; mdio.md_sectorsize = 512; arg.ama_mdctl_fd = mdctl_fd; arg.ama_unit = -1; arg.ama_fd = -1; if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) { error = errno; aio_md_cleanup(&arg); errno = error; errx(-1, "FAIL: aio_md_test: MDIOCATTACH: %s", strerror(errno)); } arg.ama_unit = unit = mdio.md_unit; snprintf(pathname, PATH_MAX, "/dev/md%d", unit); fd = open(pathname, O_RDWR); if (fd < 0) { error = errno; aio_md_cleanup(&arg); errno = error; errx(-1, "FAIL: aio_md_test: open(%s): %s", pathname, strerror(errno)); } arg.ama_fd = fd; aio_context_init(&ac, "aio_md_test", fd, fd, MD_LEN, MD_TIMEOUT, aio_md_cleanup, &arg); aio_write_test(&ac); aio_read_test(&ac); aio_md_cleanup(&arg); fprintf(stderr, "PASS: aio_md_test\n"); }
ATF_TC_BODY(aio_md_test, tc) { int error, fd, mdctl_fd, unit; char pathname[PATH_MAX]; struct aio_md_arg arg; struct aio_context ac; struct md_ioctl mdio; ATF_REQUIRE_KERNEL_MODULE("aio"); mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0); ATF_REQUIRE_MSG(mdctl_fd != -1, "opening /dev/%s failed: %s", MDCTL_NAME, strerror(errno)); bzero(&mdio, sizeof(mdio)); mdio.md_version = MDIOVERSION; mdio.md_type = MD_MALLOC; mdio.md_options = MD_AUTOUNIT | MD_COMPRESS; mdio.md_mediasize = GLOBAL_MAX; mdio.md_sectorsize = 512; arg.ama_mdctl_fd = mdctl_fd; arg.ama_unit = -1; arg.ama_fd = -1; if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) { error = errno; aio_md_cleanup(&arg); errno = error; atf_tc_fail("ioctl MDIOCATTACH failed: %s", strerror(errno)); } arg.ama_unit = unit = mdio.md_unit; snprintf(pathname, PATH_MAX, "/dev/md%d", unit); fd = open(pathname, O_RDWR); ATF_REQUIRE_MSG(fd != -1, "opening %s failed: %s", pathname, strerror(errno)); arg.ama_fd = fd; aio_context_init(&ac, fd, fd, MD_LEN, MD_TIMEOUT, aio_md_cleanup, &arg); aio_write_test(&ac); aio_read_test(&ac); aio_md_cleanup(&arg); }