In tests, use ASSERT_NO_FATAL_FAILURE() instead of checking

testing::Test::HasFatalFailure() after calling functions that could fail
fatally.

Inspired by
https://codereview.chromium.org/637503006/diff/20001/minidump/minidump_thread_writer_test.cc#newcode437

TEST=client_test, minidump_test, util_test
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/640383002
This commit is contained in:
Mark Mentovai 2014-10-09 15:08:54 -04:00
parent 9c76cc60db
commit 22350bd676
15 changed files with 171 additions and 366 deletions

View File

@ -95,10 +95,7 @@ void TestCaptureContext() {
{
SCOPED_TRACE("context_1");
SanityCheckContext(&context_1);
}
if (testing::Test::HasFatalFailure()) {
return;
ASSERT_NO_FATAL_FAILURE(SanityCheckContext(&context_1));
}
// The program counter reference value is this functions address. The
@ -134,10 +131,7 @@ void TestCaptureContext() {
{
SCOPED_TRACE("context_2");
SanityCheckContext(&context_2);
}
if (testing::Test::HasFatalFailure()) {
return;
ASSERT_NO_FATAL_FAILURE(SanityCheckContext(&context_2));
}
EXPECT_EQ(sp, StackPointerFromContext(&context_2));
@ -145,10 +139,7 @@ void TestCaptureContext() {
}
TEST(CaptureContextMac, CaptureContext) {
TestCaptureContext();
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(TestCaptureContext());
}
} // namespace

View File

@ -39,10 +39,7 @@ TEST(MinidumpFileWriter, Empty) {
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
VerifyMinidumpHeader(header, 0, 0);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0));
}
class TestStream final : public internal::MinidumpStreamWriter {
@ -101,10 +98,7 @@ TEST(MinidumpFileWriter, OneStream) {
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
VerifyMinidumpHeader(header, 1, kTimestamp);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -164,10 +158,7 @@ TEST(MinidumpFileWriter, ThreeStreams) {
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
VerifyMinidumpHeader(header, 3, kTimestamp);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -229,10 +220,7 @@ TEST(MinidumpFileWriter, ZeroLengthStream) {
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_writer.string()[0]);
VerifyMinidumpHeader(header, 1, 0);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(

View File

@ -50,10 +50,7 @@ void GetMemoryListStream(const std::string& file_contents,
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]);
VerifyMinidumpHeader(header, expected_streams, 0);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, expected_streams, 0));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -93,10 +90,8 @@ TEST(MinidumpMemoryWriter, EmptyMemoryList) {
file_writer.string().size());
const MINIDUMP_MEMORY_LIST* memory_list;
GetMemoryListStream(file_writer.string(), &memory_list, 1);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges);
}
@ -118,10 +113,8 @@ TEST(MinidumpMemoryWriter, OneMemoryRegion) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MEMORY_LIST* memory_list;
GetMemoryListStream(file_writer.string(), &memory_list, 1);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
MINIDUMP_MEMORY_DESCRIPTOR expected;
expected.StartOfMemoryRange = kBaseAddress;
@ -159,10 +152,8 @@ TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MEMORY_LIST* memory_list;
GetMemoryListStream(file_writer.string(), &memory_list, 1);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
@ -266,10 +257,8 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MEMORY_LIST* memory_list;
GetMemoryListStream(file_writer.string(), &memory_list, 2);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 2));
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);

View File

@ -45,10 +45,7 @@ void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) {
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]);
VerifyMinidumpHeader(header, 1, 0);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -170,10 +167,7 @@ TEST(MinidumpMiscInfoWriter, Empty) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
@ -194,10 +188,7 @@ TEST(MinidumpMiscInfoWriter, ProcessId) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID;
@ -223,10 +214,7 @@ TEST(MinidumpMiscInfoWriter, ProcessTimes) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES;
@ -259,10 +247,7 @@ TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_2* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_2 expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO;
@ -289,10 +274,7 @@ TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_3* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY;
@ -315,10 +297,7 @@ TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_3* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS;
@ -341,10 +320,7 @@ TEST(MinidumpMiscInfoWriter, ProtectedProcess) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_3* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS;
@ -381,10 +357,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_3* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
@ -446,10 +419,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_3* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
@ -490,10 +460,7 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_4* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
@ -529,10 +496,7 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_4* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
@ -601,10 +565,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
const MINIDUMP_MISC_INFO_4* observed;
GetMiscInfoStream(file_writer.string(), &observed);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 =

View File

@ -43,10 +43,7 @@ void GetModuleListStream(const std::string& file_contents,
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]);
VerifyMinidumpHeader(header, 1, 0);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -78,10 +75,8 @@ TEST(MinidumpModuleWriter, EmptyModuleList) {
file_writer.string().size());
const MINIDUMP_MODULE_LIST* module_list;
GetModuleListStream(file_writer.string(), &module_list);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
EXPECT_EQ(0u, module_list->NumberOfModules);
}
@ -276,24 +271,18 @@ void ExpectModule(const MINIDUMP_MODULE* expected,
string16 expected_module_name_utf16 = base::UTF8ToUTF16(expected_module_name);
EXPECT_EQ(expected_module_name_utf16, observed_module_name_utf16);
ExpectCodeViewRecord(&observed->CvRecord,
file_contents,
expected_pdb_name,
expected_pdb_uuid,
expected_pdb_timestamp,
expected_pdb_age);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectCodeViewRecord(&observed->CvRecord,
file_contents,
expected_pdb_name,
expected_pdb_uuid,
expected_pdb_timestamp,
expected_pdb_age));
ExpectMiscellaneousDebugRecord(&observed->MiscRecord,
file_contents,
expected_debug_name,
expected_debug_type,
expected_debug_utf16);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectMiscellaneousDebugRecord(&observed->MiscRecord,
file_contents,
expected_debug_name,
expected_debug_type,
expected_debug_utf16));
}
TEST(MinidumpModuleWriter, EmptyModule) {
@ -316,28 +305,23 @@ TEST(MinidumpModuleWriter, EmptyModule) {
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list;
GetModuleListStream(file_writer.string(), &module_list);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
MINIDUMP_MODULE expected = {};
ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
NULL,
NULL,
0,
0,
NULL,
0,
false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
NULL,
NULL,
0,
0,
NULL,
0,
false));
}
TEST(MinidumpModuleWriter, OneModule) {
@ -410,10 +394,8 @@ TEST(MinidumpModuleWriter, OneModule) {
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list;
GetModuleListStream(file_writer.string(), &module_list);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
@ -432,20 +414,17 @@ TEST(MinidumpModuleWriter, OneModule) {
expected.VersionInfo.dwFileType = kFileType;
expected.VersionInfo.dwFileSubtype = kFileSubtype;
ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
kPDBName,
&pdb_uuid,
0,
kPDBAge,
kDebugName,
kDebugType,
kDebugUTF16);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
kPDBName,
&pdb_uuid,
0,
kPDBAge,
kDebugName,
kDebugType,
kDebugUTF16));
}
TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) {
@ -488,29 +467,24 @@ TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) {
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list;
GetModuleListStream(file_writer.string(), &module_list);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
MINIDUMP_MODULE expected = {};
ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
kPDBName,
NULL,
kPDBTimestamp,
kPDBAge,
kDebugName,
kDebugType,
kDebugUTF16);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName,
kPDBName,
NULL,
kPDBTimestamp,
kPDBAge,
kDebugName,
kDebugType,
kDebugUTF16));
}
TEST(MinidumpModuleWriter, ThreeModules) {
@ -583,10 +557,8 @@ TEST(MinidumpModuleWriter, ThreeModules) {
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list;
GetModuleListStream(file_writer.string(), &module_list);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
EXPECT_EQ(3u, module_list->NumberOfModules);
@ -598,20 +570,17 @@ TEST(MinidumpModuleWriter, ThreeModules) {
expected.BaseOfImage = kModuleBase1;
expected.SizeOfImage = kModuleSize1;
ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName1,
kPDBName1,
&pdb_uuid_1,
0,
kPDBAge1,
NULL,
0,
false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
kModuleName1,
kPDBName1,
&pdb_uuid_1,
0,
kPDBAge1,
NULL,
0,
false));
}
{
@ -620,20 +589,17 @@ TEST(MinidumpModuleWriter, ThreeModules) {
expected.BaseOfImage = kModuleBase2;
expected.SizeOfImage = kModuleSize2;
ExpectModule(&expected,
&module_list->Modules[1],
file_writer.string(),
kModuleName2,
NULL,
NULL,
0,
0,
NULL,
0,
false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[1],
file_writer.string(),
kModuleName2,
NULL,
NULL,
0,
0,
NULL,
0,
false));
}
{
@ -642,20 +608,17 @@ TEST(MinidumpModuleWriter, ThreeModules) {
expected.BaseOfImage = kModuleBase3;
expected.SizeOfImage = kModuleSize3;
ExpectModule(&expected,
&module_list->Modules[2],
file_writer.string(),
kModuleName3,
kPDBName3,
NULL,
kPDBTimestamp3,
kPDBAge3,
NULL,
0,
false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[2],
file_writer.string(),
kModuleName3,
kPDBName3,
NULL,
kPDBTimestamp3,
kPDBAge3,
NULL,
0,
false));
}
}

View File

@ -51,10 +51,7 @@ void GetSystemInfoStream(const std::string& file_contents,
const MINIDUMP_HEADER* header =
reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]);
VerifyMinidumpHeader(header, 1, 0);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
const MINIDUMP_DIRECTORY* directory =
reinterpret_cast<const MINIDUMP_DIRECTORY*>(
@ -89,10 +86,8 @@ TEST(MinidumpSystemInfoWriter, Empty) {
const MINIDUMP_SYSTEM_INFO* system_info;
const MINIDUMP_STRING* csd_version;
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version));
EXPECT_EQ(kMinidumpCPUArchitectureUnknown,
system_info->ProcessorArchitecture);
@ -162,11 +157,8 @@ TEST(MinidumpSystemInfoWriter, X86_Win) {
const MINIDUMP_SYSTEM_INFO* system_info;
const MINIDUMP_STRING* csd_version;
GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
@ -225,11 +217,8 @@ TEST(MinidumpSystemInfoWriter, X86_64_Mac) {
const MINIDUMP_SYSTEM_INFO* system_info;
const MINIDUMP_STRING* csd_version;
GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
@ -270,10 +259,8 @@ TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) {
const MINIDUMP_SYSTEM_INFO* system_info;
const MINIDUMP_STRING* csd_version;
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(0u, system_info->ProcessorLevel);

View File

@ -41,7 +41,7 @@ namespace {
// Runs /usr/bin/sw_vers with a single argument, |argument|, and places the
// commands standard output into |output| after stripping the trailing newline.
// Fatal gtest assertions report tool failures, which the caller should check
// for with testing::Test::HasFatalFailure().
// for with ASSERT_NO_FATAL_FAILURE() or testing::Test::HasFatalFailure().
void SwVers(NSString* argument, std::string* output) {
@autoreleasepool {
base::scoped_nsobject<NSPipe> pipe([[NSPipe alloc] init]);
@ -90,26 +90,18 @@ TEST(MacUtil, MacOSXVersion) {
}
std::string expected_product_version;
SwVers(@"-productVersion", &expected_product_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
SwVers(@"-productVersion", &expected_product_version));
EXPECT_EQ(expected_product_version, version);
std::string expected_build_version;
SwVers(@"-buildVersion", &expected_build_version);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(SwVers(@"-buildVersion", &expected_build_version));
EXPECT_EQ(expected_build_version, build);
std::string expected_product_name;
SwVers(@"-productName", &expected_product_name);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(SwVers(@"-productName", &expected_product_name));
// Look for a space after the product name in the complete version string.
expected_product_name += ' ';

View File

@ -160,10 +160,8 @@ void ExpectSegmentCommand(const SegmentCommand* expect_segment,
const Section* expect_section = &expect_sections[index];
const process_types::section* actual_section =
actual_segment->GetSectionAtIndex(index, NULL);
ExpectSection(&expect_sections[index], actual_section);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(
ExpectSection(&expect_sections[index], actual_section));
// Make sure that the section is accessible by GetSectionByName as well.
std::string section_name =
@ -247,14 +245,11 @@ void ExpectSegmentCommands(const MachHeader* expect_image,
MachOImageSegmentReader::SegmentNameString(expect_segment->segname);
const MachOImageSegmentReader* actual_segment =
actual_image->GetSegmentByName(segment_name);
ExpectSegmentCommand(expect_segment,
expect_image,
actual_segment,
actual_image,
&section_index);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSegmentCommand(expect_segment,
expect_image,
actual_segment,
actual_image,
&section_index));
}
position += command->cmdsize;
}
@ -306,8 +301,9 @@ void ExpectSegmentCommands(const MachHeader* expect_image,
MachOImageSegmentReader::SectionNameString(section->sectname);
// It should be possible to look up the first section by name.
EXPECT_EQ(section, actual_image->GetSectionByName(
section->segname, section->sectname, NULL));
EXPECT_EQ(section,
actual_image->GetSectionByName(
section->segname, section->sectname, NULL));
}
EXPECT_FALSE(
actual_image->GetSectionByName("NoSuchSegment", test_section, NULL));
@ -376,10 +372,8 @@ void ExpectMachImage(const MachHeader* expect_image,
UUID uuid;
actual_image->UUID(&uuid);
ExpectSegmentCommands(expect_image, actual_image, test_section_index_bounds);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSegmentCommands(
expect_image, actual_image, test_section_index_bounds));
}
// Verifies the symbol whose Nlist structure is |entry| and whose name is |name|
@ -486,10 +480,7 @@ void ExpectSymbolTable(const MachHeader* expect_image,
for (uint32_t index = 0; index < symtab->nsyms; ++index) {
const Nlist* entry = nlist + index;
const char* name = strtab + entry->n_un.n_strx;
ExpectSymbol(entry, name, actual_image);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSymbol(entry, name, actual_image));
}
}
@ -520,14 +511,11 @@ TEST(MachOImageReader, Self_MainExecutable) {
// The main executable has image index 0.
intptr_t image_slide = _dyld_get_image_vmaddr_slide(0);
ExpectMachImage(mh_execute_header,
mh_execute_header_address,
image_slide,
&image_reader,
true);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(mh_execute_header,
mh_execute_header_address,
image_slide,
&image_reader,
true));
// This symbol, __mh_execute_header, is known to exist in all MH_EXECUTE
// Mach-O files.
@ -536,10 +524,7 @@ TEST(MachOImageReader, Self_MainExecutable) {
&symbol_address));
EXPECT_EQ(mh_execute_header_address, symbol_address);
ExpectSymbolTable(mh_execute_header, &image_reader);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mh_execute_header, &image_reader));
}
TEST(MachOImageReader, Self_DyldImages) {
@ -573,16 +558,10 @@ TEST(MachOImageReader, Self_DyldImages) {
}
intptr_t image_slide = _dyld_get_image_vmaddr_slide(index);
ExpectMachImage(
mach_header, image_address, image_slide, &image_reader, false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
mach_header, image_address, image_slide, &image_reader, false));
ExpectSymbolTable(mach_header, &image_reader);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
}
// Now that all of the modules have been verified, make sure that dyld itself
@ -608,16 +587,10 @@ TEST(MachOImageReader, Self_DyldImages) {
EXPECT_EQ(static_cast<uint32_t>(MH_DYLINKER), image_reader.FileType());
// Theres no good API to get dylds slide, so dont bother checking it.
ExpectMachImage(
mach_header, image_address, kSlideUnknown, &image_reader, false);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
mach_header, image_address, kSlideUnknown, &image_reader, false));
ExpectSymbolTable(mach_header, &image_reader);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7

View File

@ -370,10 +370,7 @@ TEST(ProcessReader, SelfSeveralThreads) {
TestThreadPool thread_pool;
const size_t kChildThreads = 16;
thread_pool.StartThreads(kChildThreads);
if (Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(thread_pool.StartThreads(kChildThreads));
// Build a map of all expected threads, keyed by each threads ID. The values
// are addresses that should lie somewhere within each threads stack.
@ -462,10 +459,7 @@ class ProcessReaderThreadedChild final : public MachMultiprocess {
void MachMultiprocessChild() override {
TestThreadPool thread_pool;
thread_pool.StartThreads(thread_count_);
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(thread_pool.StartThreads(thread_count_));
int write_fd = WritePipeFD();

View File

@ -398,12 +398,9 @@ class TestMachMessageServer : public MachMessageServer::Interface,
// process replies before all of the requests are sent, because the
// server wont have sent any replies until all of the requests are in
// its queue.
ChildSendRequest();
ASSERT_NO_FATAL_FAILURE(ChildSendRequest());
} else {
ChildSendRequestAndWaitForReply();
}
if (testing::Test::HasFatalFailure()) {
return;
ASSERT_NO_FATAL_FAILURE(ChildSendRequestAndWaitForReply());
}
}
@ -411,18 +408,12 @@ class TestMachMessageServer : public MachMessageServer::Interface,
options_.child_send_all_requests_before_receiving_any_replies) {
// Now that all of the requests have been sent, let the parent know that
// its safe to begin processing them, and then wait for the replies.
ChildNotifyParentViaPipe();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ChildNotifyParentViaPipe());
for (size_t index = 0;
index < options_.client_send_request_count;
++index) {
ChildWaitForReply();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ChildWaitForReply());
}
}
@ -562,22 +553,16 @@ class TestMachMessageServer : public MachMessageServer::Interface,
// In the child process, sends a request message to the server and then
// receives a reply message.
void ChildSendRequestAndWaitForReply() {
ChildSendRequest();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ChildSendRequest());
if (options_.parent_wait_for_child_pipe &&
!options_.child_send_all_requests_before_receiving_any_replies) {
// The parent is waiting to read a byte to indicate that the message has
// been placed in the queue.
ChildNotifyParentViaPipe();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(ChildNotifyParentViaPipe());
}
ChildWaitForReply();
ASSERT_NO_FATAL_FAILURE(ChildWaitForReply());
}
const Options& options_;

View File

@ -82,10 +82,7 @@ MachMultiprocess::~MachMultiprocess() {
}
void MachMultiprocess::PreFork() {
Multiprocess::PreFork();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork());
// Set up the parent port and register it with the bootstrap server before
// forking, so that its guaranteed to be there when the child attempts to

View File

@ -63,10 +63,7 @@ void Multiprocess::Run() {
scoped_ptr<internal::MultiprocessInfo> info(new internal::MultiprocessInfo);
base::AutoReset<internal::MultiprocessInfo*> reset_info(&info_, info.get());
PreFork();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(PreFork());
pid_t pid = fork();
ASSERT_GE(pid, 0) << ErrnoMessage("fork");

View File

@ -93,10 +93,7 @@ class Multiprocess {
//!
//! \code
//! virtual void PreFork() override {
//! Multiprocess::PreFork();
//! if (testing::Test::HasFatalFailure()) {
//! return;
//! }
//! ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork());
//!
//! // Place subclass-specific pre-fork code here.
//! }

View File

@ -48,10 +48,7 @@ MultiprocessExec::~MultiprocessExec() {
}
void MultiprocessExec::PreFork() {
Multiprocess::PreFork();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork());
ASSERT_FALSE(command_.empty());

View File

@ -217,10 +217,7 @@ class TestMultiprocessClosePipe final : public Multiprocess {
// Multiprocess:
virtual void MultiprocessParent() override {
VerifyInitial();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyInitial());
if (who_closes_ == kParentCloses) {
Close();
@ -230,10 +227,7 @@ class TestMultiprocessClosePipe final : public Multiprocess {
}
virtual void MultiprocessChild() override {
VerifyInitial();
if (testing::Test::HasFatalFailure()) {
return;
}
ASSERT_NO_FATAL_FAILURE(VerifyInitial());
if (who_closes_ == kChildCloses) {
Close();