diff options
Diffstat (limited to 'test/accum.c')
-rw-r--r-- | test/accum.c | 137 |
1 files changed, 88 insertions, 49 deletions
diff --git a/test/accum.c b/test/accum.c index bccfbe7..3658879 100644 --- a/test/accum.c +++ b/test/accum.c @@ -2084,33 +2084,30 @@ error: unsigned test_swmr_write_big(hbool_t newest_format) { + hid_t fid = -1; /* File ID */ hid_t fapl = -1; /* File access property list */ H5F_t * rf = NULL; /* File pointer */ uint8_t *wbuf2 = NULL, *rbuf = NULL; /* Buffers for reading & writing */ uint8_t wbuf[1024]; /* Buffer for reading & writing */ unsigned u; /* Local index variable */ -#ifdef H5_HAVE_UNISTD_H - pid_t pid; /* Process ID */ -#endif /* H5_HAVE_UNISTD_H */ - int status; /* Status returned from child process */ - char * new_argv[] = {NULL}; - char * driver = NULL; /* VFD string (from env variable) */ - hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ + hbool_t process_success = FALSE; + char * driver = NULL; /* VFD string (from env variable) */ + hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ if (newest_format) TESTING("SWMR write of large metadata: with latest format") else TESTING("SWMR write of large metadata: with non-latest-format") -#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)) +#if !defined(H5_HAVE_UNISTD_H) && !defined(H5_HAVE_WIN32_API) + /* Not a Windows or POSIX system */ SKIPPED(); - HDputs(" Test skipped due to fork or waitpid not defined."); + HDputs(" Test skipped: Not a Windows or POSIX system."); return 0; -#else /* defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID) */ - +#else /* Skip this test if SWMR I/O is not supported for the VFD specified * by the environment variable. */ @@ -2219,51 +2216,94 @@ test_swmr_write_big(hbool_t newest_format) if (HDmemcmp(wbuf2, rbuf, (size_t)BIG_BUF_SIZE) != 0) TEST_ERROR; - /* Fork child process to verify that the data at [1024, 2014] does get written to disk */ - if ((pid = HDfork()) < 0) { - HDperror("fork"); - FAIL_STACK_ERROR; - } - else if (0 == pid) { /* Child process */ - /* Run the reader */ - status = HDexecv(SWMR_READER, new_argv); - HDprintf("errno from execv = %s\n", strerror(errno)); - FAIL_STACK_ERROR; - } /* end if */ +#if defined(H5_HAVE_WIN32_API) + { + STARTUPINFO si; + PROCESS_INFORMATION pi; + DWORD exit_code = EXIT_FAILURE; - /* Parent process -- wait for the child process to complete */ - while (pid != HDwaitpid(pid, &status, 0)) - /*void*/; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); - /* Check if child process terminates normally and its return value */ - if (WIFEXITED(status) && !WEXITSTATUS(status)) { - /* Flush the accumulator */ - if (accum_reset(rf) < 0) + if (0 == CreateProcess(NULL, SWMR_READER, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { + HDprintf("CreateProcess failed (%d).\n", GetLastError()); FAIL_STACK_ERROR; + } - /* Close and remove the file */ - if (H5Fclose(fid) < 0) - FAIL_STACK_ERROR; + (void)WaitForSingleObject(pi.hProcess, INFINITE); + + if (FALSE == GetExitCodeProcess(pi.hProcess, &exit_code) || EXIT_FAILURE == exit_code) + process_success = FALSE; + else + process_success = TRUE; - /* Close the property list */ - if (H5Pclose(fapl) < 0) + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } +#else /* defined(H5_HAVE_WIN32_API) */ + { + pid_t pid; /* Process ID */ + int status; /* Status returned from child process */ + + /* Fork child process to verify that the data at [1024, 2014] does get written to disk */ + if ((pid = HDfork()) < 0) { + HDperror("fork"); + FAIL_STACK_ERROR; + } + else if (0 == pid) { /* Child process */ + /* By convention, argv[0] tells the name of program invoked. + * + * execv on NetBSD 8 will actually return EFAULT if there is a + * NULL at argv[0], so we follow the convention unconditionally. + */ + char swmr_reader[] = SWMR_READER; + char *const new_argv[] = {swmr_reader, NULL}; + /* Run the reader */ + status = HDexecv(SWMR_READER, new_argv); + HDprintf("errno from execv = %s\n", HDstrerror(errno)); FAIL_STACK_ERROR; + } /* end if */ - /* Pop API context */ - if (api_ctx_pushed && H5CX_pop() < 0) - FAIL_STACK_ERROR - api_ctx_pushed = FALSE; + /* Parent process -- wait for the child process to complete */ + while (pid != HDwaitpid(pid, &status, 0)) + /*void*/; - HDremove(SWMR_FILENAME); + /* Check if child process terminates normally and its return value */ + if (WIFEXITED(status) && !WEXITSTATUS(status)) + process_success = TRUE; + } +#endif /* defined(H5_HAVE_WIN32_API) */ - /* Release memory */ - if (wbuf2) - HDfree(wbuf2); - if (rbuf) - HDfree(rbuf); - PASSED(); - return 0; - } /* end if */ + /* Check if the process terminated correctly */ + if (!process_success) + FAIL_PUTS_ERROR("child process exited abnormally") + + /* Flush the accumulator */ + if (accum_reset(rf) < 0) + FAIL_STACK_ERROR; + + /* Close and remove the file */ + if (H5Fclose(fid) < 0) + FAIL_STACK_ERROR; + + /* Close the property list */ + if (H5Pclose(fapl) < 0) + FAIL_STACK_ERROR; + + /* Pop API context */ + if (api_ctx_pushed && H5CX_pop() < 0) + FAIL_STACK_ERROR + api_ctx_pushed = FALSE; + + /* Release memory */ + if (wbuf2) + HDfree(wbuf2); + if (rbuf) + HDfree(rbuf); + + PASSED(); + return 0; error: /* Closing and remove the file */ @@ -2273,7 +2313,6 @@ error: H5CX_pop(); H5Pclose(fapl); - HDremove(SWMR_FILENAME); /* Release memory */ if (wbuf2) @@ -2283,7 +2322,7 @@ error: return 1; -#endif +#endif /* !defined(H5_HAVE_UNISTD_H) && !defined(H5_HAVE_WIN32_API) */ } /* end test_swmr_write_big() */ |