-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main, win: create test runner in windows
- Loading branch information
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,76 @@ | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <windows.h> | ||
#include <strsafe.h> | ||
|
||
#include "include/mini/common.h" | ||
|
||
static char executable_path[BUFSIZE]; | ||
|
||
int popen_complete(char* cmd) | ||
{ | ||
STARTUPINFO StartupInfo; | ||
ZeroMemory(&StartupInfo, sizeof(StartupInfo)); | ||
StartupInfo.cb = sizeof(StartupInfo); | ||
|
||
PROCESS_INFORMATION ProcessInformation; | ||
ZeroMemory(&ProcessInformation, sizeof(ProcessInformation)); | ||
|
||
// BOOL WINAPI CreateProcess( | ||
// _In_opt_ LPCTSTR lpApplicationName, | ||
// _Inout_opt_ LPTSTR lpCommandLine, | ||
// _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, | ||
// _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, | ||
// _In_ BOOL bInheritHandles, | ||
// _In_ DWORD dwCreationFlags, | ||
// _In_opt_ LPVOID lpEnvironment, | ||
// _In_opt_ LPCTSTR lpCurrentDirectory, | ||
// _In_ LPSTARTUPINFO lpStartupInfo, | ||
// Out_ LPPROCESS_INFORMATION lpProcessInformation | ||
// ); | ||
BOOL ret = CreateProcess( | ||
NULL, // No module name (use command line) | ||
cmd, // Command line | ||
NULL, // Process handle not inheritable | ||
NULL, // Thread handle not inheritable | ||
FALSE, // Set handle inheritance to FALSE | ||
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, | ||
NULL, // Use parent's environment block | ||
NULL, // Use parent's starting directory | ||
&StartupInfo, // Pointer to STARTUPINFO structure | ||
&ProcessInformation // Pointer to PROCESS_INFORMATION structure | ||
); | ||
CHECK_EQ(ret, TRUE, "CreateProcess failed"); | ||
|
||
// Wait until child process exits. | ||
DWORD wait_ret = WaitForSingleObject(ProcessInformation.hProcess, INFINITE); | ||
CHECK_EQ(wait_ret, WAIT_OBJECT_0, "Process ended strange"); | ||
|
||
// Get exit code (-1 is good) | ||
DWORD lpExitCode = 0; | ||
BOOL exit_ret = GetExitCodeProcess(ProcessInformation.hProcess, &lpExitCode); | ||
|
||
// Close process and thread handles. | ||
CloseHandle(ProcessInformation.hProcess); | ||
CloseHandle(ProcessInformation.hThread); | ||
|
||
return lpExitCode; | ||
} | ||
|
||
|
||
void mini_prepare_runner(const char* main) { | ||
CHECK(0, "implement me"); | ||
TCHAR** lppPart = { NULL }; | ||
GetFullPathName(main, BUFSIZE, executable_path, lppPart); | ||
CHECK_NE(executable_path, NULL, "realpath(argv[0])"); | ||
} | ||
|
||
|
||
int mini_run_single(const char* test) { | ||
CHECK(0, "implement me"); | ||
const char cmd[BUFSIZE]; | ||
int print_len = sprintf_s(cmd, BUFSIZE, "\"%s\" %s", executable_path, test); | ||
CHECK_NE(print_len, -1, "sprintf_s to format cmd failed"); | ||
int err = popen_complete(cmd); | ||
CHECK_NE(err, -1, "popen() failure"); | ||
return 0; | ||
} |