addr_range.test.cc revision 13465
113465Sgabeblack@google.com/* 213465Sgabeblack@google.com * Copyright (c) 2018 ARM Limited 313465Sgabeblack@google.com * All rights reserved 413465Sgabeblack@google.com * 513465Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613465Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713465Sgabeblack@google.com * property including but not limited to intellectual property relating 813465Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913465Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013465Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113465Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213465Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313465Sgabeblack@google.com * 1413465Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1513465Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1613465Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 1713465Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1813465Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1913465Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2013465Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2113465Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2213465Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2313465Sgabeblack@google.com * this software without specific prior written permission. 2413465Sgabeblack@google.com * 2513465Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2613465Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2713465Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2813465Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2913465Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3013465Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3113465Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3213465Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3313465Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3413465Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3513465Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3613465Sgabeblack@google.com * 3713465Sgabeblack@google.com * Authors: Nikos Nikoleris 3813465Sgabeblack@google.com */ 3913465Sgabeblack@google.com 4013465Sgabeblack@google.com#include <gtest/gtest.h> 4113465Sgabeblack@google.com 4213465Sgabeblack@google.com#include "base/addr_range.hh" 4313465Sgabeblack@google.com 4413465Sgabeblack@google.comTEST(AddrRangeComp, AddrRangeIsSubset) 4513465Sgabeblack@google.com{ 4613465Sgabeblack@google.com AddrRange r, r1, r2; 4713465Sgabeblack@google.com 4813465Sgabeblack@google.com // Test non-interleaved ranges 4913465Sgabeblack@google.com r1 = AddrRange(0x0, 0x7f); 5013465Sgabeblack@google.com r2 = AddrRange(0x80, 0xff); 5113465Sgabeblack@google.com 5213465Sgabeblack@google.com r = AddrRange(0x0, 0xf); 5313465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r1)); 5413465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r2)); 5513465Sgabeblack@google.com 5613465Sgabeblack@google.com r = AddrRange(0x80, 0x8f); 5713465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r1)); 5813465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r2)); 5913465Sgabeblack@google.com 6013465Sgabeblack@google.com // Test interleaved ranges 6113465Sgabeblack@google.com r1 = AddrRange(0x0, 0xff, 6, 0, 1, 0); 6213465Sgabeblack@google.com r2 = AddrRange(0x0, 0xff, 6, 0, 1, 1); 6313465Sgabeblack@google.com 6413465Sgabeblack@google.com r = AddrRange(0x0, 0xf); 6513465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r1)); 6613465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r2)); 6713465Sgabeblack@google.com 6813465Sgabeblack@google.com r = AddrRange(0x40, 0x4f); 6913465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r1)); 7013465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r2)); 7113465Sgabeblack@google.com 7213465Sgabeblack@google.com r = AddrRange(0xbf, 0xc0); 7313465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r1)); 7413465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r2)); 7513465Sgabeblack@google.com 7613465Sgabeblack@google.com // Test interleaved ranges with hashing 7713465Sgabeblack@google.com r1 = AddrRange(0x0, 0xff, 6, 7, 1, 0); 7813465Sgabeblack@google.com r2 = AddrRange(0x0, 0xff, 6, 7, 1, 1); 7913465Sgabeblack@google.com 8013465Sgabeblack@google.com r = AddrRange(0x0, 0xf); 8113465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r1)); 8213465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r2)); 8313465Sgabeblack@google.com 8413465Sgabeblack@google.com r = AddrRange(0x40, 0x4f); 8513465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r1)); 8613465Sgabeblack@google.com EXPECT_TRUE(r.isSubset(r2)); 8713465Sgabeblack@google.com 8813465Sgabeblack@google.com r = AddrRange(0xbf, 0xc0); 8913465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r1)); 9013465Sgabeblack@google.com EXPECT_FALSE(r.isSubset(r2)); 9113465Sgabeblack@google.com} 92