2016-07-14 10:31:02 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-05-20 09:15:06 +00:00
|
|
|
#include "src/diagnostics/eh-frame.h"
|
2016-07-14 10:31:02 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
2017-08-31 10:58:29 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2016-07-14 10:31:02 +00:00
|
|
|
// Test enabled only on supported architectures.
|
|
|
|
#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM) || \
|
|
|
|
defined(V8_TARGET_ARCH_ARM64)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class EhFrameIteratorTest : public testing::Test {};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_F(EhFrameIteratorTest, Values) {
|
|
|
|
// Assuming little endian.
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte kEncoded[] = {0xDE, 0xC0, 0xAD, 0xDE, 0xEF, 0xBE, 0xFF};
|
2016-07-14 10:31:02 +00:00
|
|
|
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_EQ(0xDEADC0DE, iterator.GetNextUInt32());
|
|
|
|
EXPECT_EQ(0xBEEF, iterator.GetNextUInt16());
|
|
|
|
EXPECT_EQ(0xFF, iterator.GetNextByte());
|
2016-07-14 10:31:02 +00:00
|
|
|
EXPECT_TRUE(iterator.Done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EhFrameIteratorTest, Skip) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte kEncoded[] = {0xDE, 0xAD, 0xC0, 0xDE};
|
2016-07-14 10:31:02 +00:00
|
|
|
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
|
|
|
|
iterator.Skip(2);
|
|
|
|
EXPECT_EQ(2, iterator.GetCurrentOffset());
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_EQ(0xC0, iterator.GetNextByte());
|
2016-07-14 10:31:02 +00:00
|
|
|
iterator.Skip(1);
|
|
|
|
EXPECT_TRUE(iterator.Done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EhFrameIteratorTest, ULEB128Decoding) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte kEncoded[] = {0xE5, 0x8E, 0x26};
|
2016-07-14 10:31:02 +00:00
|
|
|
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
|
2016-11-11 12:00:34 +00:00
|
|
|
EXPECT_EQ(624485u, iterator.GetNextULeb128());
|
2016-07-14 10:31:02 +00:00
|
|
|
EXPECT_TRUE(iterator.Done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EhFrameIteratorTest, SLEB128DecodingPositive) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte kEncoded[] = {0xE5, 0x8E, 0x26};
|
2016-07-14 10:31:02 +00:00
|
|
|
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
|
|
|
|
EXPECT_EQ(624485, iterator.GetNextSLeb128());
|
|
|
|
EXPECT_TRUE(iterator.Done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(EhFrameIteratorTest, SLEB128DecodingNegative) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte kEncoded[] = {0x9B, 0xF1, 0x59};
|
2016-07-14 10:31:02 +00:00
|
|
|
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
|
|
|
|
EXPECT_EQ(-624485, iterator.GetNextSLeb128());
|
|
|
|
EXPECT_TRUE(iterator.Done());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-08-31 10:58:29 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|