1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #include "mozilla/CmdLineAndEnvUtils.h"
8 #include "mozilla/TimeStamp.h"
10 #include "nsWindowsHelpers.h"
15 static wchar_t kChildArg
[] = L
"--child";
17 static nsReturnRef
<HANDLE
> CreateProcessWrapper(const wchar_t* aPath
) {
20 const wchar_t* childArgv
[] = {aPath
, kChildArg
};
21 mozilla::UniquePtr
<wchar_t[]> cmdLine(
22 mozilla::MakeCommandLine(mozilla::ArrayLength(childArgv
), childArgv
));
24 STARTUPINFOW si
= {sizeof(si
)};
25 PROCESS_INFORMATION pi
;
26 BOOL ok
= ::CreateProcessW(aPath
, cmdLine
.get(), nullptr, nullptr, FALSE
, 0,
27 nullptr, nullptr, &si
, &pi
);
30 "TEST-FAILED | TimeStampWin | "
31 "CreateProcess failed - %08lx\n",
36 nsAutoHandle
proc(pi
.hProcess
);
37 nsAutoHandle
thd(pi
.hThread
);
43 // Make sure a process creation timestamp is always not bigger than
44 // the current timestamp.
45 auto t0
= mozilla::TimeStamp::ProcessCreation();
46 auto t1
= mozilla::TimeStamp::Now();
49 "TEST-FAILED | TimeStampWin | "
50 "Process creation timestamp is bigger than the current "
57 int wmain(int argc
, wchar_t* argv
[]) {
58 if (argc
== 2 && wcscmp(argv
[1], kChildArg
) == 0) {
64 "TEST-FAILED | TimeStampWin | "
69 // Start a child process successively, checking any of them terminates with
70 // a non-zero value which means an error.
71 for (int i
= 0; i
< 20; ++i
) {
72 nsAutoHandle
childProc(CreateProcessWrapper(argv
[0]));
74 if (::WaitForSingleObject(childProc
, 60000) != WAIT_OBJECT_0
) {
76 "TEST-FAILED | TimeStampWin | "
77 "Unexpected result from WaitForSingleObject\n");
82 if (!::GetExitCodeProcess(childProc
.get(), &childExitCode
)) {
84 "TEST-FAILED | TimeStampWin | "
85 "GetExitCodeProcess failed - %08lx\n",
90 if (childExitCode
!= 0) {