Bug 1610790: Part 1 - Use wmain in mozglue/tests. r=handyman

This patch changes the entrypoint of test programs under mozglue/tests so that
a coming test program can handle a command string easily.

Differential Revision: https://phabricator.services.mozilla.com//D62314
This commit is contained in:
Toshihito Kikuchi 2020-02-12 02:23:57 +02:00
parent dc8d92255d
commit 1764f470d6
7 changed files with 42 additions and 16 deletions

View File

@ -6,7 +6,12 @@
#include "mozilla/SSE.h"
#include <stdio.h>
int main() {
#if defined(XP_WIN)
int wmain()
#else
int main()
#endif // defined(XP_WIN)
{
printf("CPUID detection present: %s\n",
#ifdef MOZILLA_SSE_HAVE_CPUID_DETECTION
"yes"

View File

@ -1811,7 +1811,12 @@ void TestProfiler() {
#endif // MOZ_BASE_PROFILER else
int main() {
#if defined(XP_WIN)
int wmain()
#else
int main()
#endif // defined(XP_WIN)
{
// Note that there are two `TestProfiler` functions above, depending on
// whether MOZ_BASE_PROFILER is #defined.
TestProfiler();

View File

@ -50,7 +50,7 @@ MOZ_NEVER_INLINE PVOID SwapThreadLocalStoragePointer(PVOID aNewValue) {
return oldValue;
}
int main(int argc, char* argv[]) {
int wmain(int argc, wchar_t* argv[]) {
UNICODE_STRING normal;
::RtlInitUnicodeString(&normal, kNormal);

View File

@ -151,7 +151,12 @@ static void TestPrintfFormats() {
print_one("7799 9977", "%2$zu %1$zu", (size_t)9977, (size_t)7799));
}
int main() {
#if defined(XP_WIN)
int wmain()
#else
int main()
#endif // defined(XP_WIN)
{
TestPrintfFormats();
TestPrintfTargetPrint();

View File

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "mozilla/CmdLineAndEnvUtils.h"
#include "mozilla/TimeStamp.h"
#include "nsWindowsHelpers.h"
@ -11,14 +12,18 @@
#include <stdio.h>
#include <windows.h>
static char kChildArg[] = "--child";
static wchar_t kChildArg[] = L"--child";
static nsReturnRef<HANDLE> CreateProcessWrapper(const char* aPath) {
static nsReturnRef<HANDLE> CreateProcessWrapper(const wchar_t* aPath) {
nsAutoHandle empty;
STARTUPINFOA si = {sizeof(si)};
const wchar_t* childArgv[] = {aPath, kChildArg};
mozilla::UniquePtr<wchar_t[]> cmdLine(
mozilla::MakeCommandLine(mozilla::ArrayLength(childArgv), childArgv));
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi;
BOOL ok = ::CreateProcessA(aPath, kChildArg, nullptr, nullptr, FALSE, 0,
BOOL ok = ::CreateProcessW(aPath, cmdLine.get(), nullptr, nullptr, FALSE, 0,
nullptr, nullptr, &si, &pi);
if (!ok) {
printf(
@ -50,7 +55,11 @@ int ChildMain() {
return 0;
}
int main(int argc, char* argv[]) {
int wmain(int argc, wchar_t* argv[]) {
if (argc == 2 && wcscmp(argv[1], kChildArg) == 0) {
return ChildMain();
}
if (argc != 1) {
printf(
"TEST-FAILED | TimeStampWin | "
@ -58,10 +67,6 @@ int main(int argc, char* argv[]) {
return 1;
}
if (strcmp(argv[0], kChildArg) == 0) {
return ChildMain();
}
// Start a child process successively, checking any of them terminates with
// a non-zero value which means an error.
for (int i = 0; i < 20; ++i) {

View File

@ -34,3 +34,9 @@ if CONFIG['OS_ARCH'] == 'WINNT':
'ntdll',
'version',
]
if CONFIG['OS_TARGET'] == 'WINNT' and CONFIG['CC_TYPE'] in ('gcc', 'clang'):
# This allows us to use wmain as the entry point on mingw
LDFLAGS += [
'-municode',
]

View File

@ -375,9 +375,9 @@ inline wchar_t* ArgToString(wchar_t* d, const wchar_t* s) {
* @param aArgvExtra Optional array of arguments to be appended to the resulting
* command line after those provided by |argv|.
*/
inline UniquePtr<wchar_t[]> MakeCommandLine(int argc, wchar_t** argv,
int aArgcExtra = 0,
wchar_t** aArgvExtra = nullptr) {
inline UniquePtr<wchar_t[]> MakeCommandLine(
int argc, const wchar_t* const* argv, int aArgcExtra = 0,
const wchar_t* const* aArgvExtra = nullptr) {
int i;
int len = 0;