gem5  v21.1.0.2
addr_range_map.test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include <gtest/gtest.h>
42 
43 #include <vector>
44 
45 #include "base/addr_range_map.hh"
46 
47 using namespace gem5;
48 
49 // Converted from legacy unit test framework
50 TEST(AddrRangeMapTest, LegacyTests)
51 {
54 
55  i = r.insert(RangeIn(10, 40), 5);
56  ASSERT_NE(i, r.end());
57 
58  i = r.insert(RangeIn(60, 90), 3);
59  ASSERT_NE(i, r.end());
60 
61  EXPECT_NE(r.intersects(RangeIn(20, 30)), r.end());
62  EXPECT_EQ(r.contains(RangeIn(55, 55)), r.end());
63  EXPECT_EQ(r.intersects(RangeIn(55, 55)), r.end());
64 
65  i = r.insert(RangeIn(0, 12), 1);
66  EXPECT_EQ(i, r.end());
67 
68  i = r.insert(RangeIn(0, 9), 1);
69  ASSERT_NE(i, r.end());
70 
71  EXPECT_NE(r.contains(RangeIn(20, 30)), r.end());
72 }
73 
88 TEST(AddrRangeMapTest, InterleavedTest1)
89 {
90  const auto N = 16;
91  const auto masks = std::vector<Addr>{
92  0x40,
93  0x80,
94  0x100,
95  0x200
96  };
97  const Addr start = 0x80000000;
98  const Addr end = 0xc0000000;
99 
102 
103  // populate AddrRangeMap with N-way interleaved address ranges
104  // for all intlvMatch values 0..N-1
105  for (int k=0; k < N; k++) {
106  r.insert(AddrRange(start, end, masks, k), k);
107  }
108  // find AddrRange element containing start address
109  i = r.contains(start);
110  // i must not be the past-the-end iterator
111  ASSERT_NE(i, r.end()) << "start address not found in AddrRangeMap";
112  // intlvMatch = 0 for start = 0x80000000
113  EXPECT_EQ(i->second, 0);
114 }
115 
132 TEST(AddrRangeMapTest, InterleavedTest2)
133 {
134  const auto N = 16;
135  const auto masks = std::vector<Addr>{
136  0x4444444444440,
137  0x8888888888880,
138  0x1111111111100,
139  0x2222222222200
140  };
141  const Addr start = 0x80000000;
142  const Addr end = 0xc0000000;
143 
146 
147  // populate AddrRangeMap with N-way interleaved address ranges
148  // for all intlvMatch values 0..N-1
149  for (int k=0; k < N; k++) {
150  r.insert(AddrRange(start, end, masks, k), k);
151  }
152  // find AddrRange element containing start address
153  i = r.contains(start);
154  // i must not be the past-the-end iterator
155  ASSERT_NE(i, r.end()) << "start address not found in AddrRangeMap";
156  // intlvMatch = 2 for start = 0x80000000
157  EXPECT_EQ(i->second, 2);
158 }
gem5::AddrRangeMap
The AddrRangeMap uses an STL map to implement an interval tree for address decoding.
Definition: addr_range_map.hh:62
std::vector< Addr >
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::RangeIn
AddrRange RangeIn(Addr start, Addr end)
Definition: addr_range.hh:654
gem5::AddrRangeMap::const_iterator
RangeMap::const_iterator const_iterator
Definition: addr_range_map.hh:73
TEST
TEST(AddrRangeMapTest, LegacyTests)
Definition: addr_range_map.test.cc:50
addr_range_map.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::MipsISA::r
r
Definition: pra_constants.hh:98
gem5::MipsISA::k
Bitfield< 23 > k
Definition: dt_constants.hh:81
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:71
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40

Generated on Tue Sep 21 2021 12:24:52 for gem5 by doxygen 1.8.17