This source file includes following definitions.
- MULTIPROCESS_TEST_MAIN
- TEST_F
#include <windows.h>
#include <string>
#include "base/command_line.h"
#include "base/test/multiprocess_test.h"
#include "base/win/scoped_handle.h"
#include "base/win/scoped_process_information.h"
#include "base/win/startup_information.h"
#include "base/win/windows_version.h"
#include "testing/multiprocess_func_list.h"
const wchar_t kSectionName[] = L"EventTestSection";
const size_t kSectionSize = 4096;
MULTIPROCESS_TEST_MAIN(FireInheritedEvents) {
HANDLE section = ::OpenFileMappingW(PAGE_READWRITE, false, kSectionName);
HANDLE* events = reinterpret_cast<HANDLE*>(::MapViewOfFile(section,
PAGE_READWRITE, 0, 0, kSectionSize));
if (::SetEvent(events[1]))
return -1;
if (!::SetEvent(events[0]))
return -1;
return 0;
}
class StartupInformationTest : public base::MultiProcessTest {};
TEST_F(StartupInformationTest, InheritStdOut) {
if (base::win::GetVersion() < base::win::VERSION_VISTA)
return;
base::win::StartupInformation startup_info;
HANDLE section = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, 0, kSectionSize,
kSectionName);
ASSERT_TRUE(section);
HANDLE* events = reinterpret_cast<HANDLE*>(::MapViewOfFile(section,
FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, kSectionSize));
SECURITY_ATTRIBUTES security_attributes = { sizeof(security_attributes),
NULL, true };
events[0] = ::CreateEvent(&security_attributes, false, false, NULL);
ASSERT_TRUE(events[0]);
events[1] = ::CreateEvent(&security_attributes, false, false, NULL);
ASSERT_TRUE(events[1]);
ASSERT_TRUE(startup_info.InitializeProcThreadAttributeList(1));
ASSERT_TRUE(startup_info.UpdateProcThreadAttribute(
PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &events[0],
sizeof(events[0])));
std::wstring cmd_line =
MakeCmdLine("FireInheritedEvents").GetCommandLineString();
PROCESS_INFORMATION temp_process_info = {};
ASSERT_TRUE(::CreateProcess(NULL, const_cast<wchar_t*>(cmd_line.c_str()),
NULL, NULL, true, EXTENDED_STARTUPINFO_PRESENT,
NULL, NULL, startup_info.startup_info(),
&temp_process_info)) << ::GetLastError();
base::win::ScopedProcessInformation process_info(temp_process_info);
EXPECT_EQ(WAIT_OBJECT_0, ::WaitForMultipleObjects(2, events, false,
4000));
}