File: executor_address_test.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (84 lines) | stat: -rw-r--r-- 2,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//===-- extensible_address_test.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of the ORC runtime.
//
// Note:
//   This unit test was adapted from
//   llvm/unittests/Support/ExecutorAddressTest.cpp
//
//===----------------------------------------------------------------------===//

#include "executor_address.h"
#include "gtest/gtest.h"

using namespace __orc_rt;

TEST(ExecutorAddrTest, DefaultAndNull) {
  // Check that default constructed values and isNull behave as expected.

  ExecutorAddr Default;
  ExecutorAddr Null(0);
  ExecutorAddr NonNull(1);

  EXPECT_TRUE(Null.isNull());
  EXPECT_EQ(Default, Null);

  EXPECT_FALSE(NonNull.isNull());
  EXPECT_NE(Default, NonNull);
}

TEST(ExecutorAddrTest, Ordering) {
  // Check that ordering operations.
  ExecutorAddr A1(1), A2(2);

  EXPECT_LE(A1, A1);
  EXPECT_LT(A1, A2);
  EXPECT_GT(A2, A1);
  EXPECT_GE(A2, A2);
}

TEST(ExecutorAddrTest, PtrConversion) {
  // Test toPtr / fromPtr round-tripping.
  int X = 0;
  auto XAddr = ExecutorAddr::fromPtr(&X);
  int *XPtr = XAddr.toPtr<int *>();

  EXPECT_EQ(XPtr, &X);
}

TEST(ExecutorAddrTest, AddrRanges) {
  ExecutorAddr A0(0), A1(1), A2(2), A3(3);
  ExecutorAddrRange R0(A0, A1), R1(A1, A2), R2(A2, A3), R3(A0, A2), R4(A1, A3);
  //     012
  // R0: #      -- Before R1
  // R1:  #     --
  // R2:   #    -- After R1
  // R3: ##     -- Overlaps R1 start
  // R4:  ##    -- Overlaps R1 end

  EXPECT_EQ(R1, ExecutorAddrRange(A1, A2));
  EXPECT_EQ(R1, ExecutorAddrRange(A1, ExecutorAddrDiff(1)));
  EXPECT_NE(R1, R2);

  EXPECT_TRUE(R1.contains(A1));
  EXPECT_FALSE(R1.contains(A0));
  EXPECT_FALSE(R1.contains(A2));

  EXPECT_FALSE(R1.overlaps(R0));
  EXPECT_FALSE(R1.overlaps(R2));
  EXPECT_TRUE(R1.overlaps(R3));
  EXPECT_TRUE(R1.overlaps(R4));
}

TEST(ExecutorAddrTest, Hashable) {
  uint64_t RawAddr = 0x1234567890ABCDEF;
  ExecutorAddr Addr(RawAddr);

  EXPECT_EQ(std::hash<uint64_t>()(RawAddr), std::hash<ExecutorAddr>()(Addr));
}