summaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/BinaryStreamTest.cpp33
-rw-r--r--unittests/Support/CrashRecoveryTest.cpp6
-rw-r--r--unittests/Support/ScaledNumberTest.cpp6
3 files changed, 42 insertions, 3 deletions
diff --git a/unittests/Support/BinaryStreamTest.cpp b/unittests/Support/BinaryStreamTest.cpp
index ec3b0effc9e9..1ce74cbb722b 100644
--- a/unittests/Support/BinaryStreamTest.cpp
+++ b/unittests/Support/BinaryStreamTest.cpp
@@ -289,6 +289,39 @@ TEST_F(BinaryStreamTest, StreamRefBounds) {
}
}
+TEST_F(BinaryStreamTest, DropOperations) {
+ std::vector<uint8_t> InputData = {1, 2, 3, 4, 5, 4, 3, 2, 1};
+ auto RefData = makeArrayRef(InputData);
+ initializeInput(InputData, 1);
+
+ ArrayRef<uint8_t> Result;
+ BinaryStreamRef Original(InputData, support::little);
+ ASSERT_EQ(InputData.size(), Original.getLength());
+
+ EXPECT_NO_ERROR(Original.readBytes(0, InputData.size(), Result));
+ EXPECT_EQ(RefData, Result);
+
+ auto Dropped = Original.drop_front(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_front(2), Result);
+
+ Dropped = Original.drop_back(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_back(2), Result);
+
+ Dropped = Original.keep_front(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.take_front(2), Result);
+
+ Dropped = Original.keep_back(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.take_back(2), Result);
+
+ Dropped = Original.drop_symmetric(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_front(2).drop_back(2), Result);
+}
+
// Test that we can write to a BinaryStream without a StreamWriter.
TEST_F(BinaryStreamTest, MutableBinaryByteStreamBounds) {
std::vector<uint8_t> InputData = {'T', 'e', 's', 't', '\0'};
diff --git a/unittests/Support/CrashRecoveryTest.cpp b/unittests/Support/CrashRecoveryTest.cpp
index dbb0db576793..33d87a1c0e4a 100644
--- a/unittests/Support/CrashRecoveryTest.cpp
+++ b/unittests/Support/CrashRecoveryTest.cpp
@@ -17,11 +17,15 @@
#include <windows.h>
#endif
+extern "C" const char *__asan_default_options() {
+ return "allow_user_segv_handler=1";
+}
+
using namespace llvm;
using namespace llvm::sys;
static int GlobalInt = 0;
-static void nullDeref() { *(volatile int *)nullptr = 0; }
+static void nullDeref() { *(volatile int *)0x10 = 0; }
static void incrementGlobal() { ++GlobalInt; }
static void llvmTrap() { LLVM_BUILTIN_TRAP; }
diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp
index 2f38b2a40fb8..9e3f6de6bd17 100644
--- a/unittests/Support/ScaledNumberTest.cpp
+++ b/unittests/Support/ScaledNumberTest.cpp
@@ -335,10 +335,12 @@ TEST(ScaledNumberHelpersTest, matchScales) {
EXPECT_EQ(SOut, matchScales(LDx, LSx, RDx, RSx)); \
EXPECT_EQ(LDy, LDx); \
EXPECT_EQ(RDy, RDx); \
- if (LDy) \
+ if (LDy) { \
EXPECT_EQ(Sy, LSx); \
- if (RDy) \
+ } \
+ if (RDy) { \
EXPECT_EQ(Sy, RSx); \
+ } \
} while (false)
MATCH_SCALES(uint32_t, 0, 0, 0, 0, 0, 0, 0);