Loading liblog/logger_write.c +8 −0 Original line number Original line Diff line number Diff line Loading @@ -514,6 +514,14 @@ LIBLOG_ABI_PUBLIC void __android_log_assert(const char *cond, const char *tag, strcpy(buf, "Unspecified assertion failed"); strcpy(buf, "Unspecified assertion failed"); } } // Log assertion failures to stderr for the benefit of "adb shell" users // and gtests (http://b/23675822). struct iovec iov[2] = { { buf, strlen(buf) }, { (char*) "\n", 1 }, }; TEMP_FAILURE_RETRY(writev(2, iov, 2)); __android_log_write(ANDROID_LOG_FATAL, tag, buf); __android_log_write(ANDROID_LOG_FATAL, tag, buf); abort(); /* abort so we have a chance to debug the situation */ abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ /* NOTREACHED */ Loading libutils/tests/Vector_test.cpp +4 −18 Original line number Original line Diff line number Diff line Loading @@ -74,12 +74,9 @@ TEST_F(VectorTest, CopyOnWrite_CopyAndAddElements) { EXPECT_EQ(other[3], 5); EXPECT_EQ(other[3], 5); } } // TODO: gtest isn't capable of parsing Abort messages formatted by // Android (fails differently on host and target), so we always need to // use an empty error message for death tests. TEST_F(VectorTest, SetCapacity_Overflow) { TEST_F(VectorTest, SetCapacity_Overflow) { Vector<int> vector; Vector<int> vector; EXPECT_DEATH(vector.setCapacity(SIZE_MAX / sizeof(int) + 1), ""); EXPECT_DEATH(vector.setCapacity(SIZE_MAX / sizeof(int) + 1), "Assertion failed"); } } TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { Loading @@ -95,20 +92,13 @@ TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { ASSERT_EQ(8U, vector.capacity()); ASSERT_EQ(8U, vector.capacity()); } } // NOTE: All of the tests below are useless because of the "TODO" above. // We have no way of knowing *why* the process crashed. Given that we're // inserting a NULL array, we'll fail with a SIGSEGV eventually. We need // the ability to make assertions on the abort message to make sure we're // failing for the right reasons. TEST_F(VectorTest, _grow_OverflowSize) { TEST_F(VectorTest, _grow_OverflowSize) { Vector<int> vector; Vector<int> vector; vector.add(1); vector.add(1); // Checks that the size calculation (not the capacity calculation) doesn't // Checks that the size calculation (not the capacity calculation) doesn't // overflow : the size here will be (1 + SIZE_MAX). // overflow : the size here will be (1 + SIZE_MAX). // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size_overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), ""); } } TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { Loading @@ -116,18 +106,14 @@ TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { // This should fail because the calculated capacity will overflow even though // This should fail because the calculated capacity will overflow even though // the size of the vector doesn't. // the size of the vector doesn't. // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity_overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), ""); } } TEST_F(VectorTest, _grow_OverflowBufferAlloc) { TEST_F(VectorTest, _grow_OverflowBufferAlloc) { Vector<int> vector; Vector<int> vector; // This should fail because the capacity * sizeof(int) overflows, even // This should fail because the capacity * sizeof(int) overflows, even // though the capacity itself doesn't. // though the capacity itself doesn't. // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), ""); } } TEST_F(VectorTest, editArray_Shared) { TEST_F(VectorTest, editArray_Shared) { Loading Loading
liblog/logger_write.c +8 −0 Original line number Original line Diff line number Diff line Loading @@ -514,6 +514,14 @@ LIBLOG_ABI_PUBLIC void __android_log_assert(const char *cond, const char *tag, strcpy(buf, "Unspecified assertion failed"); strcpy(buf, "Unspecified assertion failed"); } } // Log assertion failures to stderr for the benefit of "adb shell" users // and gtests (http://b/23675822). struct iovec iov[2] = { { buf, strlen(buf) }, { (char*) "\n", 1 }, }; TEMP_FAILURE_RETRY(writev(2, iov, 2)); __android_log_write(ANDROID_LOG_FATAL, tag, buf); __android_log_write(ANDROID_LOG_FATAL, tag, buf); abort(); /* abort so we have a chance to debug the situation */ abort(); /* abort so we have a chance to debug the situation */ /* NOTREACHED */ /* NOTREACHED */ Loading
libutils/tests/Vector_test.cpp +4 −18 Original line number Original line Diff line number Diff line Loading @@ -74,12 +74,9 @@ TEST_F(VectorTest, CopyOnWrite_CopyAndAddElements) { EXPECT_EQ(other[3], 5); EXPECT_EQ(other[3], 5); } } // TODO: gtest isn't capable of parsing Abort messages formatted by // Android (fails differently on host and target), so we always need to // use an empty error message for death tests. TEST_F(VectorTest, SetCapacity_Overflow) { TEST_F(VectorTest, SetCapacity_Overflow) { Vector<int> vector; Vector<int> vector; EXPECT_DEATH(vector.setCapacity(SIZE_MAX / sizeof(int) + 1), ""); EXPECT_DEATH(vector.setCapacity(SIZE_MAX / sizeof(int) + 1), "Assertion failed"); } } TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { Loading @@ -95,20 +92,13 @@ TEST_F(VectorTest, SetCapacity_ShrinkBelowSize) { ASSERT_EQ(8U, vector.capacity()); ASSERT_EQ(8U, vector.capacity()); } } // NOTE: All of the tests below are useless because of the "TODO" above. // We have no way of knowing *why* the process crashed. Given that we're // inserting a NULL array, we'll fail with a SIGSEGV eventually. We need // the ability to make assertions on the abort message to make sure we're // failing for the right reasons. TEST_F(VectorTest, _grow_OverflowSize) { TEST_F(VectorTest, _grow_OverflowSize) { Vector<int> vector; Vector<int> vector; vector.add(1); vector.add(1); // Checks that the size calculation (not the capacity calculation) doesn't // Checks that the size calculation (not the capacity calculation) doesn't // overflow : the size here will be (1 + SIZE_MAX). // overflow : the size here will be (1 + SIZE_MAX). // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size_overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), ""); } } TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { Loading @@ -116,18 +106,14 @@ TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { // This should fail because the calculated capacity will overflow even though // This should fail because the calculated capacity will overflow even though // the size of the vector doesn't. // the size of the vector doesn't. // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity_overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), ""); } } TEST_F(VectorTest, _grow_OverflowBufferAlloc) { TEST_F(VectorTest, _grow_OverflowBufferAlloc) { Vector<int> vector; Vector<int> vector; // This should fail because the capacity * sizeof(int) overflows, even // This should fail because the capacity * sizeof(int) overflows, even // though the capacity itself doesn't. // though the capacity itself doesn't. // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); // EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), ""); } } TEST_F(VectorTest, editArray_Shared) { TEST_F(VectorTest, editArray_Shared) { Loading