Index: util/mach/mach_extensions_test.cc |
diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc |
index aefe489d1bf993ad2f96c11fc2210402e7a2db09..9853944cb969875be186042a05e87dbf6badaf14 100644 |
--- a/util/mach/mach_extensions_test.cc |
+++ b/util/mach/mach_extensions_test.cc |
@@ -17,6 +17,7 @@ |
#include "base/mac/scoped_mach_port.h" |
#include "gtest/gtest.h" |
#include "test/mac/mach_errors.h" |
+#include "util/mac/mac_util.h" |
namespace crashpad { |
namespace test { |
@@ -60,6 +61,76 @@ TEST(MachExtensions, NewMachPort_DeadName) { |
EXPECT_EQ(MACH_PORT_TYPE_DEAD_NAME, type); |
} |
+const exception_mask_t kExcMaskBasic = |
+ EXC_MASK_BAD_ACCESS | |
+ EXC_MASK_BAD_INSTRUCTION | |
+ EXC_MASK_ARITHMETIC | |
+ EXC_MASK_EMULATION | |
+ EXC_MASK_SOFTWARE | |
+ EXC_MASK_BREAKPOINT | |
+ EXC_MASK_SYSCALL | |
+ EXC_MASK_MACH_SYSCALL | |
+ EXC_MASK_RPC_ALERT; |
+ |
+TEST(MachExtensions, ExcMaskAll) { |
+ const exception_mask_t exc_mask_all = ExcMaskAll(); |
+ EXPECT_EQ(kExcMaskBasic, exc_mask_all & kExcMaskBasic); |
+ |
+ EXPECT_FALSE(exc_mask_all & EXC_MASK_CRASH); |
+ EXPECT_FALSE(exc_mask_all & EXC_MASK_CORPSE_NOTIFY); |
+ |
+ const int mac_os_x_minor_version = MacOSXMinorVersion(); |
+ if (mac_os_x_minor_version >= 8) { |
+ EXPECT_TRUE(exc_mask_all & EXC_MASK_RESOURCE); |
+ } else { |
+ EXPECT_FALSE(exc_mask_all & EXC_MASK_RESOURCE); |
+ } |
+ |
+ if (mac_os_x_minor_version >= 9) { |
+ EXPECT_TRUE(exc_mask_all & EXC_MASK_GUARD); |
+ } else { |
+ EXPECT_FALSE(exc_mask_all & EXC_MASK_GUARD); |
+ } |
+ |
+ // Bit 0 should not be set. |
+ EXPECT_FALSE(ExcMaskAll() & 1); |
+ |
+ // Every bit set in ExcMaskAll() must also be set in ExcMaskValid(). |
+ EXPECT_EQ(ExcMaskAll(), ExcMaskAll() & ExcMaskValid()); |
+} |
+ |
+TEST(MachExtensions, ExcMaskValid) { |
+ const exception_mask_t exc_mask_valid = ExcMaskValid(); |
+ EXPECT_EQ(kExcMaskBasic, exc_mask_valid & kExcMaskBasic); |
+ |
+ EXPECT_TRUE(exc_mask_valid & EXC_MASK_CRASH); |
+ |
+ const int mac_os_x_minor_version = MacOSXMinorVersion(); |
+ if (mac_os_x_minor_version >= 8) { |
+ EXPECT_TRUE(exc_mask_valid & EXC_MASK_RESOURCE); |
+ } else { |
+ EXPECT_FALSE(exc_mask_valid & EXC_MASK_RESOURCE); |
+ } |
+ |
+ if (mac_os_x_minor_version >= 9) { |
+ EXPECT_TRUE(exc_mask_valid & EXC_MASK_GUARD); |
+ } else { |
+ EXPECT_FALSE(exc_mask_valid & EXC_MASK_GUARD); |
+ } |
+ |
+ if (mac_os_x_minor_version >= 11) { |
+ EXPECT_TRUE(exc_mask_valid & EXC_MASK_CORPSE_NOTIFY); |
+ } else { |
+ EXPECT_FALSE(exc_mask_valid & EXC_MASK_CORPSE_NOTIFY); |
+ } |
+ |
+ // Bit 0 should not be set. |
+ EXPECT_FALSE(ExcMaskValid() & 1); |
+ |
+ // There must be bits set in ExcMaskValid() that are not set in ExcMaskAll(). |
+ EXPECT_TRUE(ExcMaskValid() & ~ExcMaskAll()); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace crashpad |