Source('bmpwriter.cc')
Source('callback.cc')
Source('cprintf.cc', add_tags='gtest lib')
-GTest('cprintftest', 'cprintftest.cc')
+GTest('cprintftest', 'cprintf.test.cc')
Source('debug.cc')
if env['USE_FENV']:
Source('fenv.c')
if env['USE_PNG']:
Source('pngwriter.cc')
Source('fiber.cc')
-GTest('fibertest', 'fibertest.cc', 'fiber.cc')
-GTest('coroutinetest', 'coroutinetest.cc', 'fiber.cc')
+GTest('fibertest', 'fiber.test.cc', 'fiber.cc')
+GTest('coroutinetest', 'coroutine.test.cc', 'fiber.cc')
Source('framebuffer.cc')
Source('hostinfo.cc')
Source('inet.cc')
Source('inifile.cc')
-GTest('inifiletest', 'inifiletest.cc', 'inifile.cc', 'str.cc')
+GTest('inifiletest', 'inifile.test.cc', 'inifile.cc', 'str.cc')
Source('intmath.cc')
Source('logging.cc')
Source('match.cc')
Source('output.cc')
Source('pixel.cc')
-GTest('pixeltest', 'pixeltest.cc', 'pixel.cc')
+GTest('pixeltest', 'pixel.test.cc', 'pixel.cc')
Source('pollevent.cc')
Source('random.cc')
if env['TARGET_ISA'] != 'null':
Source('str.cc')
Source('time.cc')
Source('trace.cc')
-GTest('trietest', 'trietest.cc')
+GTest('trietest', 'trie.test.cc')
Source('types.cc')
Source('loader/aout_object.cc')
Source('stats/text.cc')
-GTest('addr_range_test', 'addr_range_test.cc')
-GTest('AddrRangeMapTest', 'addr_range_map_test.cc')
-GTest('bituniontest', 'bituniontest.cc')
-GTest('CircleBufTest', 'circlebuftest.cc')
+GTest('addr_range_test', 'addr_range.test.cc')
+GTest('AddrRangeMapTest', 'addr_range_map.test.cc')
+GTest('bituniontest', 'bitunion.test.cc')
+GTest('CircleBufTest', 'circlebuf.test.cc')
DebugFlag('Annotate', "State machine annotation debugging")
DebugFlag('AnnotateQ', "State machine annotation queue debugging")
--- /dev/null
+/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nikos Nikoleris
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/addr_range.hh"
+
+TEST(AddrRangeComp, AddrRangeIsSubset)
+{
+ AddrRange r, r1, r2;
+
+ // Test non-interleaved ranges
+ r1 = AddrRange(0x0, 0x7f);
+ r2 = AddrRange(0x80, 0xff);
+
+ r = AddrRange(0x0, 0xf);
+ EXPECT_TRUE(r.isSubset(r1));
+ EXPECT_FALSE(r.isSubset(r2));
+
+ r = AddrRange(0x80, 0x8f);
+ EXPECT_FALSE(r.isSubset(r1));
+ EXPECT_TRUE(r.isSubset(r2));
+
+ // Test interleaved ranges
+ r1 = AddrRange(0x0, 0xff, 6, 0, 1, 0);
+ r2 = AddrRange(0x0, 0xff, 6, 0, 1, 1);
+
+ r = AddrRange(0x0, 0xf);
+ EXPECT_TRUE(r.isSubset(r1));
+ EXPECT_FALSE(r.isSubset(r2));
+
+ r = AddrRange(0x40, 0x4f);
+ EXPECT_FALSE(r.isSubset(r1));
+ EXPECT_TRUE(r.isSubset(r2));
+
+ r = AddrRange(0xbf, 0xc0);
+ EXPECT_FALSE(r.isSubset(r1));
+ EXPECT_FALSE(r.isSubset(r2));
+
+ // Test interleaved ranges with hashing
+ r1 = AddrRange(0x0, 0xff, 6, 7, 1, 0);
+ r2 = AddrRange(0x0, 0xff, 6, 7, 1, 1);
+
+ r = AddrRange(0x0, 0xf);
+ EXPECT_TRUE(r.isSubset(r1));
+ EXPECT_FALSE(r.isSubset(r2));
+
+ r = AddrRange(0x40, 0x4f);
+ EXPECT_FALSE(r.isSubset(r1));
+ EXPECT_TRUE(r.isSubset(r2));
+
+ r = AddrRange(0xbf, 0xc0);
+ EXPECT_FALSE(r.isSubset(r1));
+ EXPECT_FALSE(r.isSubset(r2));
+}
--- /dev/null
+/*
+ * Copyright (c) 2012, 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Copyright (c) 2006 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Ali Saidi
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/addr_range_map.hh"
+
+// Converted from legacy unit test framework
+TEST(AddrRangeMapTest, LegacyTests)
+{
+ AddrRangeMap<int> r;
+ AddrRangeMap<int>::const_iterator i;
+
+ i = r.insert(RangeIn(10, 40), 5);
+ ASSERT_NE(i, r.end());
+
+ i = r.insert(RangeIn(60, 90), 3);
+ ASSERT_NE(i, r.end());
+
+ EXPECT_NE(r.intersects(RangeIn(20, 30)), r.end());
+ EXPECT_EQ(r.contains(RangeIn(55, 55)), r.end());
+ EXPECT_EQ(r.intersects(RangeIn(55, 55)), r.end());
+
+ i = r.insert(RangeIn(0, 12), 1);
+ EXPECT_EQ(i, r.end());
+
+ i = r.insert(RangeIn(0, 9), 1);
+ ASSERT_NE(i, r.end());
+
+ EXPECT_NE(r.contains(RangeIn(20, 30)), r.end());
+}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2018 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Copyright (c) 2006 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Ali Saidi
- */
-
-#include <gtest/gtest.h>
-
-#include "base/addr_range_map.hh"
-
-// Converted from legacy unit test framework
-TEST(AddrRangeMapTest, LegacyTests)
-{
- AddrRangeMap<int> r;
- AddrRangeMap<int>::const_iterator i;
-
- i = r.insert(RangeIn(10, 40), 5);
- ASSERT_NE(i, r.end());
-
- i = r.insert(RangeIn(60, 90), 3);
- ASSERT_NE(i, r.end());
-
- EXPECT_NE(r.intersects(RangeIn(20, 30)), r.end());
- EXPECT_EQ(r.contains(RangeIn(55, 55)), r.end());
- EXPECT_EQ(r.intersects(RangeIn(55, 55)), r.end());
-
- i = r.insert(RangeIn(0, 12), 1);
- EXPECT_EQ(i, r.end());
-
- i = r.insert(RangeIn(0, 9), 1);
- ASSERT_NE(i, r.end());
-
- EXPECT_NE(r.contains(RangeIn(20, 30)), r.end());
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nikos Nikoleris
- */
-
-#include <gtest/gtest.h>
-
-#include "base/addr_range.hh"
-
-TEST(AddrRangeComp, AddrRangeIsSubset)
-{
- AddrRange r, r1, r2;
-
- // Test non-interleaved ranges
- r1 = AddrRange(0x0, 0x7f);
- r2 = AddrRange(0x80, 0xff);
-
- r = AddrRange(0x0, 0xf);
- EXPECT_TRUE(r.isSubset(r1));
- EXPECT_FALSE(r.isSubset(r2));
-
- r = AddrRange(0x80, 0x8f);
- EXPECT_FALSE(r.isSubset(r1));
- EXPECT_TRUE(r.isSubset(r2));
-
- // Test interleaved ranges
- r1 = AddrRange(0x0, 0xff, 6, 0, 1, 0);
- r2 = AddrRange(0x0, 0xff, 6, 0, 1, 1);
-
- r = AddrRange(0x0, 0xf);
- EXPECT_TRUE(r.isSubset(r1));
- EXPECT_FALSE(r.isSubset(r2));
-
- r = AddrRange(0x40, 0x4f);
- EXPECT_FALSE(r.isSubset(r1));
- EXPECT_TRUE(r.isSubset(r2));
-
- r = AddrRange(0xbf, 0xc0);
- EXPECT_FALSE(r.isSubset(r1));
- EXPECT_FALSE(r.isSubset(r2));
-
- // Test interleaved ranges with hashing
- r1 = AddrRange(0x0, 0xff, 6, 7, 1, 0);
- r2 = AddrRange(0x0, 0xff, 6, 7, 1, 1);
-
- r = AddrRange(0x0, 0xf);
- EXPECT_TRUE(r.isSubset(r1));
- EXPECT_FALSE(r.isSubset(r2));
-
- r = AddrRange(0x40, 0x4f);
- EXPECT_FALSE(r.isSubset(r1));
- EXPECT_TRUE(r.isSubset(r2));
-
- r = AddrRange(0xbf, 0xc0);
- EXPECT_FALSE(r.isSubset(r1));
- EXPECT_FALSE(r.isSubset(r2));
-}
--- /dev/null
+/*
+ * Copyright 2014 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include <gtest/gtest.h>
+
+#include <cassert>
+#include <iostream>
+#include <type_traits>
+
+#include "base/bitunion.hh"
+#include "base/cprintf.hh"
+
+using namespace std;
+
+namespace {
+
+BitUnion64(SixtyFour)
+ Bitfield<39, 32> byte5;
+ Bitfield<2> bit2;
+ BitfieldRO<39, 32> byte5RO;
+ BitfieldWO<39, 32> byte5WO;
+ SubBitUnion(byte6, 47, 40)
+ Bitfield<43, 42> bits43To42;
+ Bitfield<41> bit41;
+ SignedBitfield<41> bit41Signed;
+ EndSubBitUnion(byte6)
+ SignedBitfield<47, 40> byte6Signed;
+ SignedBitfieldRO<47, 40> byte6SignedRO;
+ SignedBitfieldWO<47, 40> byte6SignedWO;
+EndBitUnion(SixtyFour)
+
+BitUnion64(EmptySixtyFour)
+EndBitUnion(EmptySixtyFour)
+
+BitUnion32(EmptyThirtyTwo)
+EndBitUnion(EmptyThirtyTwo)
+
+BitUnion16(EmptySixteen)
+EndBitUnion(EmptySixteen)
+
+BitUnion8(EmptyEight)
+EndBitUnion(EmptyEight)
+
+class SplitField
+{
+ protected:
+ BitUnion64(In)
+ Bitfield<15, 12> high;
+ Bitfield<7, 4> low;
+ EndBitUnion(In)
+
+ BitUnion64(Out)
+ Bitfield<7, 4> high;
+ Bitfield<3, 0> low;
+ EndBitUnion(Out)
+ public:
+ uint64_t
+ getter(const uint64_t &storage) const
+ {
+ Out out = 0;
+ In in = storage;
+ out.high = in.high;
+ out.low = in.low;
+ return out;
+ }
+
+ void
+ setter(uint64_t &storage, uint64_t val)
+ {
+ Out out = val;
+ In in = 0;
+ in.high = out.high;
+ in.low = out.low;
+ storage = in;
+ }
+};
+
+BitUnion64(Split)
+ BitfieldType<SplitField> split;
+EndBitUnion(Split)
+
+struct ContainingStruct
+{
+ BitUnion64(Contained)
+ Bitfield<63, 60> topNibble;
+ EndBitUnion(Contained)
+
+ Contained contained;
+};
+
+uint64_t
+containingFunc(uint64_t init_val, uint64_t fieldVal)
+{
+ BitUnion32(Contained)
+ Bitfield<16, 15> field;
+ EndBitUnion(Contained)
+
+ Contained contained = init_val;
+ contained.field = fieldVal;
+ return contained;
+}
+
+} // anonymous namespace
+
+// Declare these as global so g++ doesn't ignore them. Initialize them in
+// various ways.
+EmptySixtyFour emptySixtyFour = 0;
+EmptyThirtyTwo emptyThirtyTwo;
+EmptySixteen emptySixteen;
+EmptyEight emptyEight(0);
+
+class BitUnionData : public testing::Test {
+ protected:
+ SixtyFour sixtyFour;
+ Split split;
+
+ void SetUp() override { sixtyFour = 0; split = 0; }
+
+ template <typename T>
+ uint64_t templatedFunction(T) { return 0; }
+
+ template <typename T>
+ uint64_t
+ templatedFunction(BitUnionType<T> u)
+ {
+ BitUnionBaseType<T> b = u;
+ return b;
+ }
+};
+
+TEST_F(BitUnionData, NormalBitfield)
+{
+ EXPECT_EQ(sixtyFour.byte5, 0);
+ sixtyFour.byte5 = 0xff;
+ EXPECT_EQ(sixtyFour, 0xff00000000);
+ sixtyFour.byte5 = 0xfff;
+ EXPECT_EQ(sixtyFour, 0xff00000000);
+ EXPECT_EQ(sixtyFour.byte5, 0xff);
+}
+
+TEST_F(BitUnionData, SingleBitfield)
+{
+ EXPECT_EQ(sixtyFour.bit2, 0);
+ sixtyFour.bit2 = 0x1;
+ EXPECT_EQ(sixtyFour, 0x4);
+ EXPECT_EQ(sixtyFour.bit2, 0x1);
+}
+
+TEST_F(BitUnionData, ReadOnlyBitfield)
+{
+ EXPECT_EQ(sixtyFour.byte5RO, 0);
+ sixtyFour.byte5 = 0xff;
+ EXPECT_EQ(sixtyFour.byte5RO, 0xff);
+}
+
+TEST_F(BitUnionData, WriteOnlyBitfield)
+{
+ sixtyFour.byte5WO = 0xff;
+ EXPECT_EQ(sixtyFour, 0xff00000000);
+}
+
+TEST_F(BitUnionData, SubBitUnions)
+{
+ EXPECT_EQ(sixtyFour.byte6.bit41, 0);
+ sixtyFour.byte6 = 0x2;
+ EXPECT_EQ(sixtyFour.byte6.bit41, 1);
+ sixtyFour.byte6.bits43To42 = 0x3;
+ EXPECT_EQ(sixtyFour.byte6, 0xe);
+ sixtyFour.byte6 = 0xff;
+ sixtyFour.byte6.bit41 = 0;
+ EXPECT_EQ(sixtyFour, 0xfd0000000000);
+}
+
+TEST_F(BitUnionData, SignedBitfields)
+{
+ sixtyFour.byte6 = 0xff;
+ EXPECT_EQ(sixtyFour.byte6Signed, -1);
+ EXPECT_EQ(sixtyFour.byte6SignedRO, -1);
+ sixtyFour.byte6SignedWO = 0;
+ EXPECT_EQ(sixtyFour.byte6Signed, 0);
+ EXPECT_EQ(sixtyFour.byte6SignedRO, 0);
+ EXPECT_EQ(sixtyFour.byte6, 0);
+}
+
+TEST_F(BitUnionData, InsideStruct)
+{
+ ContainingStruct containing;
+ containing.contained = 0;
+ containing.contained.topNibble = 0xd;
+ EXPECT_EQ(containing.contained, 0xd000000000000000);
+}
+
+TEST_F(BitUnionData, InsideFunction)
+{
+ EXPECT_EQ(containingFunc(0xfffff, 0), 0xe7fff);
+}
+
+TEST_F(BitUnionData, BitfieldToBitfieldAssignment)
+{
+ SixtyFour otherSixtyFour = 0;
+ sixtyFour.bit2 = 1;
+ otherSixtyFour.byte6.bit41 = sixtyFour.bit2;
+ EXPECT_EQ(otherSixtyFour, 0x20000000000);
+ otherSixtyFour.bit2 = sixtyFour.bit2;
+ EXPECT_EQ(otherSixtyFour, 0x20000000004);
+}
+
+TEST_F(BitUnionData, Operators)
+{
+ SixtyFour otherSixtyFour = 0x4;
+ sixtyFour = otherSixtyFour;
+ EXPECT_EQ(sixtyFour, 0x4);
+ sixtyFour = 0;
+ EXPECT_TRUE(sixtyFour < otherSixtyFour);
+ EXPECT_TRUE(otherSixtyFour > sixtyFour);
+ EXPECT_TRUE(sixtyFour != otherSixtyFour);
+ sixtyFour = otherSixtyFour;
+ EXPECT_TRUE(sixtyFour == otherSixtyFour);
+}
+
+TEST_F(BitUnionData, Custom)
+{
+ EXPECT_EQ(split, 0);
+ split.split = 0xfff;
+ EXPECT_EQ(split, 0xf0f0);
+ EXPECT_EQ((uint64_t)split.split, 0xff);
+}
+
+TEST_F(BitUnionData, Templating)
+{
+ sixtyFour = 0xff;
+ EXPECT_EQ(templatedFunction(sixtyFour), 0xff);
+ EXPECT_EQ(templatedFunction((uint64_t)sixtyFour), 0);
+
+ BitUnion(uint64_t, Dummy64)
+ EndBitUnion(Dummy64);
+
+ BitUnion(uint32_t, Dummy32)
+ EndBitUnion(Dummy32);
+
+ bool is64;
+ is64 = std::is_same<BitUnionBaseType<Dummy64>, uint64_t>::value;
+ EXPECT_TRUE(is64);
+ is64 = std::is_same<BitUnionBaseType<Dummy32>, uint64_t>::value;
+ EXPECT_FALSE(is64);
+}
+
+TEST_F(BitUnionData, Output)
+{
+ sixtyFour = 1234567812345678;
+ std::stringstream ss;
+ ss << sixtyFour;
+ EXPECT_EQ(ss.str(), "1234567812345678");
+ ss.str("");
+
+ EmptyEight eight = 65;
+ ss << eight;
+ EXPECT_EQ(ss.str(), "65");
+ ss.str("");
+}
+++ /dev/null
-/*
- * Copyright 2014 Google, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Gabe Black
- */
-
-#include <gtest/gtest.h>
-
-#include <cassert>
-#include <iostream>
-#include <type_traits>
-
-#include "base/bitunion.hh"
-#include "base/cprintf.hh"
-
-using namespace std;
-
-namespace {
-
-BitUnion64(SixtyFour)
- Bitfield<39, 32> byte5;
- Bitfield<2> bit2;
- BitfieldRO<39, 32> byte5RO;
- BitfieldWO<39, 32> byte5WO;
- SubBitUnion(byte6, 47, 40)
- Bitfield<43, 42> bits43To42;
- Bitfield<41> bit41;
- SignedBitfield<41> bit41Signed;
- EndSubBitUnion(byte6)
- SignedBitfield<47, 40> byte6Signed;
- SignedBitfieldRO<47, 40> byte6SignedRO;
- SignedBitfieldWO<47, 40> byte6SignedWO;
-EndBitUnion(SixtyFour)
-
-BitUnion64(EmptySixtyFour)
-EndBitUnion(EmptySixtyFour)
-
-BitUnion32(EmptyThirtyTwo)
-EndBitUnion(EmptyThirtyTwo)
-
-BitUnion16(EmptySixteen)
-EndBitUnion(EmptySixteen)
-
-BitUnion8(EmptyEight)
-EndBitUnion(EmptyEight)
-
-class SplitField
-{
- protected:
- BitUnion64(In)
- Bitfield<15, 12> high;
- Bitfield<7, 4> low;
- EndBitUnion(In)
-
- BitUnion64(Out)
- Bitfield<7, 4> high;
- Bitfield<3, 0> low;
- EndBitUnion(Out)
- public:
- uint64_t
- getter(const uint64_t &storage) const
- {
- Out out = 0;
- In in = storage;
- out.high = in.high;
- out.low = in.low;
- return out;
- }
-
- void
- setter(uint64_t &storage, uint64_t val)
- {
- Out out = val;
- In in = 0;
- in.high = out.high;
- in.low = out.low;
- storage = in;
- }
-};
-
-BitUnion64(Split)
- BitfieldType<SplitField> split;
-EndBitUnion(Split)
-
-struct ContainingStruct
-{
- BitUnion64(Contained)
- Bitfield<63, 60> topNibble;
- EndBitUnion(Contained)
-
- Contained contained;
-};
-
-uint64_t
-containingFunc(uint64_t init_val, uint64_t fieldVal)
-{
- BitUnion32(Contained)
- Bitfield<16, 15> field;
- EndBitUnion(Contained)
-
- Contained contained = init_val;
- contained.field = fieldVal;
- return contained;
-}
-
-} // anonymous namespace
-
-// Declare these as global so g++ doesn't ignore them. Initialize them in
-// various ways.
-EmptySixtyFour emptySixtyFour = 0;
-EmptyThirtyTwo emptyThirtyTwo;
-EmptySixteen emptySixteen;
-EmptyEight emptyEight(0);
-
-class BitUnionData : public testing::Test {
- protected:
- SixtyFour sixtyFour;
- Split split;
-
- void SetUp() override { sixtyFour = 0; split = 0; }
-
- template <typename T>
- uint64_t templatedFunction(T) { return 0; }
-
- template <typename T>
- uint64_t
- templatedFunction(BitUnionType<T> u)
- {
- BitUnionBaseType<T> b = u;
- return b;
- }
-};
-
-TEST_F(BitUnionData, NormalBitfield)
-{
- EXPECT_EQ(sixtyFour.byte5, 0);
- sixtyFour.byte5 = 0xff;
- EXPECT_EQ(sixtyFour, 0xff00000000);
- sixtyFour.byte5 = 0xfff;
- EXPECT_EQ(sixtyFour, 0xff00000000);
- EXPECT_EQ(sixtyFour.byte5, 0xff);
-}
-
-TEST_F(BitUnionData, SingleBitfield)
-{
- EXPECT_EQ(sixtyFour.bit2, 0);
- sixtyFour.bit2 = 0x1;
- EXPECT_EQ(sixtyFour, 0x4);
- EXPECT_EQ(sixtyFour.bit2, 0x1);
-}
-
-TEST_F(BitUnionData, ReadOnlyBitfield)
-{
- EXPECT_EQ(sixtyFour.byte5RO, 0);
- sixtyFour.byte5 = 0xff;
- EXPECT_EQ(sixtyFour.byte5RO, 0xff);
-}
-
-TEST_F(BitUnionData, WriteOnlyBitfield)
-{
- sixtyFour.byte5WO = 0xff;
- EXPECT_EQ(sixtyFour, 0xff00000000);
-}
-
-TEST_F(BitUnionData, SubBitUnions)
-{
- EXPECT_EQ(sixtyFour.byte6.bit41, 0);
- sixtyFour.byte6 = 0x2;
- EXPECT_EQ(sixtyFour.byte6.bit41, 1);
- sixtyFour.byte6.bits43To42 = 0x3;
- EXPECT_EQ(sixtyFour.byte6, 0xe);
- sixtyFour.byte6 = 0xff;
- sixtyFour.byte6.bit41 = 0;
- EXPECT_EQ(sixtyFour, 0xfd0000000000);
-}
-
-TEST_F(BitUnionData, SignedBitfields)
-{
- sixtyFour.byte6 = 0xff;
- EXPECT_EQ(sixtyFour.byte6Signed, -1);
- EXPECT_EQ(sixtyFour.byte6SignedRO, -1);
- sixtyFour.byte6SignedWO = 0;
- EXPECT_EQ(sixtyFour.byte6Signed, 0);
- EXPECT_EQ(sixtyFour.byte6SignedRO, 0);
- EXPECT_EQ(sixtyFour.byte6, 0);
-}
-
-TEST_F(BitUnionData, InsideStruct)
-{
- ContainingStruct containing;
- containing.contained = 0;
- containing.contained.topNibble = 0xd;
- EXPECT_EQ(containing.contained, 0xd000000000000000);
-}
-
-TEST_F(BitUnionData, InsideFunction)
-{
- EXPECT_EQ(containingFunc(0xfffff, 0), 0xe7fff);
-}
-
-TEST_F(BitUnionData, BitfieldToBitfieldAssignment)
-{
- SixtyFour otherSixtyFour = 0;
- sixtyFour.bit2 = 1;
- otherSixtyFour.byte6.bit41 = sixtyFour.bit2;
- EXPECT_EQ(otherSixtyFour, 0x20000000000);
- otherSixtyFour.bit2 = sixtyFour.bit2;
- EXPECT_EQ(otherSixtyFour, 0x20000000004);
-}
-
-TEST_F(BitUnionData, Operators)
-{
- SixtyFour otherSixtyFour = 0x4;
- sixtyFour = otherSixtyFour;
- EXPECT_EQ(sixtyFour, 0x4);
- sixtyFour = 0;
- EXPECT_TRUE(sixtyFour < otherSixtyFour);
- EXPECT_TRUE(otherSixtyFour > sixtyFour);
- EXPECT_TRUE(sixtyFour != otherSixtyFour);
- sixtyFour = otherSixtyFour;
- EXPECT_TRUE(sixtyFour == otherSixtyFour);
-}
-
-TEST_F(BitUnionData, Custom)
-{
- EXPECT_EQ(split, 0);
- split.split = 0xfff;
- EXPECT_EQ(split, 0xf0f0);
- EXPECT_EQ((uint64_t)split.split, 0xff);
-}
-
-TEST_F(BitUnionData, Templating)
-{
- sixtyFour = 0xff;
- EXPECT_EQ(templatedFunction(sixtyFour), 0xff);
- EXPECT_EQ(templatedFunction((uint64_t)sixtyFour), 0);
-
- BitUnion(uint64_t, Dummy64)
- EndBitUnion(Dummy64);
-
- BitUnion(uint32_t, Dummy32)
- EndBitUnion(Dummy32);
-
- bool is64;
- is64 = std::is_same<BitUnionBaseType<Dummy64>, uint64_t>::value;
- EXPECT_TRUE(is64);
- is64 = std::is_same<BitUnionBaseType<Dummy32>, uint64_t>::value;
- EXPECT_FALSE(is64);
-}
-
-TEST_F(BitUnionData, Output)
-{
- sixtyFour = 1234567812345678;
- std::stringstream ss;
- ss << sixtyFour;
- EXPECT_EQ(ss.str(), "1234567812345678");
- ss.str("");
-
- EmptyEight eight = 65;
- ss << eight;
- EXPECT_EQ(ss.str(), "65");
- ss.str("");
-}
--- /dev/null
+/*
+ * Copyright (c) 2015, 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/circlebuf.hh"
+
+const char data[] = {
+ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
+ 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
+};
+
+// Basic non-overflow functionality
+TEST(CircleBufTest, BasicReadWriteNoOverflow)
+{
+ CircleBuf<char> buf(8);
+ char foo[16];
+
+ // Write empty buffer, no overflow
+ buf.write(data, 8);
+ EXPECT_EQ(buf.size(), 8);
+ buf.peek(foo, 8);
+ EXPECT_EQ(memcmp(foo, data, 8), 0);
+
+ // Read 2
+ buf.read(foo, 2);
+ EXPECT_EQ(memcmp(foo, data, 2), 0);
+ EXPECT_EQ(buf.size(), 6);
+ buf.read(foo, 6);
+ EXPECT_EQ(memcmp(foo, data + 2, 6), 0);
+ EXPECT_EQ(buf.size(), 0);
+}
+
+// Basic single write overflow functionality
+TEST(CircleBufTest, SingleWriteOverflow)
+{
+ CircleBuf<char> buf(8);
+ char foo[16];
+
+ buf.write(data, 16);
+ EXPECT_EQ(buf.size(), 8);
+ buf.peek(foo, 8);
+ EXPECT_EQ(memcmp(data + 8, foo, 8), 0);
+}
+
+
+// Multi-write overflow functionality
+TEST(CircleBufTest, MultiWriteOverflow)
+{
+ CircleBuf<char> buf(8);
+ char foo[16];
+
+ // Write, no overflow, write overflow
+ buf.write(data, 6);
+ buf.write(data + 8, 6);
+ EXPECT_EQ(buf.size(), 8);
+ buf.peek(foo, 8);
+ EXPECT_EQ(memcmp(data + 4, foo, 2), 0);
+ EXPECT_EQ(memcmp(data + 8, foo + 2, 6), 0);
+}
+
+// Pointer wrap around
+TEST(CircleBufTest, PointerWrapAround)
+{
+ CircleBuf<char> buf(8);
+ char foo[16];
+
+ // _start == 0, _stop = 8
+ buf.write(data, 8);
+ // _start == 4, _stop = 8
+ buf.read(foo, 4);
+ // _start == 4, _stop = 12
+ buf.write(data + 8, 4);
+ EXPECT_EQ(buf.size(), 8);
+ // _start == 10, _stop = 12
+ // Normalized: _start == 2, _stop = 4
+ buf.read(foo + 4, 6);
+ EXPECT_EQ(buf.size(), 2);
+ EXPECT_EQ(memcmp(data, foo, 10), 0);
+ // Normalized: _start == 4, _stop = 4
+ buf.read(foo + 10, 2);
+ EXPECT_EQ(buf.size(), 0);
+ EXPECT_EQ(memcmp(data, foo, 12), 0);
+}
+++ /dev/null
-/*
- * Copyright (c) 2015, 2018 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Andreas Sandberg
- */
-
-#include <gtest/gtest.h>
-
-#include "base/circlebuf.hh"
-
-const char data[] = {
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
- 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
-};
-
-// Basic non-overflow functionality
-TEST(CircleBufTest, BasicReadWriteNoOverflow)
-{
- CircleBuf<char> buf(8);
- char foo[16];
-
- // Write empty buffer, no overflow
- buf.write(data, 8);
- EXPECT_EQ(buf.size(), 8);
- buf.peek(foo, 8);
- EXPECT_EQ(memcmp(foo, data, 8), 0);
-
- // Read 2
- buf.read(foo, 2);
- EXPECT_EQ(memcmp(foo, data, 2), 0);
- EXPECT_EQ(buf.size(), 6);
- buf.read(foo, 6);
- EXPECT_EQ(memcmp(foo, data + 2, 6), 0);
- EXPECT_EQ(buf.size(), 0);
-}
-
-// Basic single write overflow functionality
-TEST(CircleBufTest, SingleWriteOverflow)
-{
- CircleBuf<char> buf(8);
- char foo[16];
-
- buf.write(data, 16);
- EXPECT_EQ(buf.size(), 8);
- buf.peek(foo, 8);
- EXPECT_EQ(memcmp(data + 8, foo, 8), 0);
-}
-
-
-// Multi-write overflow functionality
-TEST(CircleBufTest, MultiWriteOverflow)
-{
- CircleBuf<char> buf(8);
- char foo[16];
-
- // Write, no overflow, write overflow
- buf.write(data, 6);
- buf.write(data + 8, 6);
- EXPECT_EQ(buf.size(), 8);
- buf.peek(foo, 8);
- EXPECT_EQ(memcmp(data + 4, foo, 2), 0);
- EXPECT_EQ(memcmp(data + 8, foo + 2, 6), 0);
-}
-
-// Pointer wrap around
-TEST(CircleBufTest, PointerWrapAround)
-{
- CircleBuf<char> buf(8);
- char foo[16];
-
- // _start == 0, _stop = 8
- buf.write(data, 8);
- // _start == 4, _stop = 8
- buf.read(foo, 4);
- // _start == 4, _stop = 12
- buf.write(data + 8, 4);
- EXPECT_EQ(buf.size(), 8);
- // _start == 10, _stop = 12
- // Normalized: _start == 2, _stop = 4
- buf.read(foo + 4, 6);
- EXPECT_EQ(buf.size(), 2);
- EXPECT_EQ(memcmp(data, foo, 10), 0);
- // Normalized: _start == 4, _stop = 4
- buf.read(foo + 10, 2);
- EXPECT_EQ(buf.size(), 0);
- EXPECT_EQ(memcmp(data, foo, 12), 0);
-}
--- /dev/null
+/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Giacomo Travaglini
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/coroutine.hh"
+
+using namespace m5;
+
+/**
+ * This test is checking if the Coroutine, once it yields
+ * back to the caller, it is still marked as not finished.
+ */
+TEST(Coroutine, Unfinished)
+{
+ auto yielding_task =
+ [] (Coroutine<void, void>::CallerType& yield)
+ {
+ yield();
+ };
+
+ Coroutine<void, void> coro(yielding_task);
+ ASSERT_TRUE(coro);
+}
+
+/**
+ * This test is checking the parameter passing interface of a
+ * coroutine which takes an integer as an argument.
+ * Coroutine::operator() and CallerType::get() are the tested
+ * APIS.
+ */
+TEST(Coroutine, Passing)
+{
+ const std::vector<int> input{ 1, 2, 3 };
+ const std::vector<int> expected_values = input;
+
+ auto passing_task =
+ [&expected_values] (Coroutine<int, void>::CallerType& yield)
+ {
+ int argument;
+
+ for (const auto expected : expected_values) {
+ argument = yield.get();
+ ASSERT_EQ(argument, expected);
+ }
+ };
+
+ Coroutine<int, void> coro(passing_task);
+ ASSERT_TRUE(coro);
+
+ for (const auto val : input) {
+ coro(val);
+ }
+}
+
+/**
+ * This test is checking the yielding interface of a coroutine
+ * which takes no argument and returns integers.
+ * Coroutine::get() and CallerType::operator() are the tested
+ * APIS.
+ */
+TEST(Coroutine, Returning)
+{
+ const std::vector<int> output{ 1, 2, 3 };
+ const std::vector<int> expected_values = output;
+
+ auto returning_task =
+ [&output] (Coroutine<void, int>::CallerType& yield)
+ {
+ for (const auto ret : output) {
+ yield(ret);
+ }
+ };
+
+ Coroutine<void, int> coro(returning_task);
+ ASSERT_TRUE(coro);
+
+ for (const auto expected : expected_values) {
+ int returned = coro.get();
+ ASSERT_EQ(returned, expected);
+ }
+}
+
+/**
+ * This test is still supposed to test the returning interface
+ * of the the Coroutine, proving how coroutine can be used
+ * for generators.
+ * The coroutine is computing the first #steps of the fibonacci
+ * sequence and it is yielding back results one number per time.
+ */
+TEST(Coroutine, Fibonacci)
+{
+ const std::vector<int> expected_values{
+ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };
+
+ const int steps = expected_values.size();
+
+ auto fibonacci_task =
+ [steps] (Coroutine<void, int>::CallerType& yield)
+ {
+ int prev = 0;
+ int current = 1;
+
+ for (auto iter = 0; iter < steps; iter++) {
+ int sum = prev + current;
+ yield(sum);
+
+ prev = current;
+ current = sum;
+ }
+ };
+
+ Coroutine<void, int> coro(fibonacci_task);
+ ASSERT_TRUE(coro);
+
+ for (const auto expected : expected_values) {
+ ASSERT_TRUE(coro);
+ int returned = coro.get();
+ ASSERT_EQ(returned, expected);
+ }
+}
+
+/**
+ * This test is using a bi-channel coroutine (accepting and
+ * yielding values) for testing a cooperative task.
+ * The caller and the coroutine have a string each; they are
+ * composing a new string by merging the strings together one
+ * character per time.
+ * The result string is hence passed back and forth between the
+ * coroutine and the caller.
+ */
+TEST(Coroutine, Cooperative)
+{
+ const std::string caller_str("HloWrd");
+ const std::string coro_str("el ol!");
+ const std::string expected("Hello World!");
+
+ auto cooperative_task =
+ [&coro_str] (Coroutine<std::string, std::string>::CallerType& yield)
+ {
+ for (auto& appended_c : coro_str) {
+ auto old_str = yield.get();
+ yield(old_str + appended_c);
+ }
+ };
+
+ Coroutine<std::string, std::string> coro(cooperative_task);
+
+ std::string result;
+ for (auto& c : caller_str) {
+ ASSERT_TRUE(coro);
+ result += c;
+ result = coro(result).get();
+ }
+
+ ASSERT_EQ(result, expected);
+}
+
+/**
+ * This test is testing nested coroutines by using one inner and one
+ * outer coroutine. It basically ensures that yielding from the inner
+ * coroutine returns to the outer coroutine (mid-layer of execution) and
+ * not to the outer caller.
+ */
+TEST(Coroutine, Nested)
+{
+ const std::string wrong("Inner");
+ const std::string expected("Inner + Outer");
+
+ auto inner_task =
+ [] (Coroutine<void, std::string>::CallerType& yield)
+ {
+ std::string inner_string("Inner");
+ yield(inner_string);
+ };
+
+ auto outer_task =
+ [&inner_task] (Coroutine<void, std::string>::CallerType& yield)
+ {
+ Coroutine<void, std::string> coro(inner_task);
+ std::string inner_string = coro.get();
+
+ std::string outer_string("Outer");
+ yield(inner_string + " + " + outer_string);
+ };
+
+
+ Coroutine<void, std::string> coro(outer_task);
+ ASSERT_TRUE(coro);
+
+ std::string result = coro.get();
+
+ ASSERT_NE(result, wrong);
+ ASSERT_EQ(result, expected);
+}
+
+/**
+ * This test is stressing the scenario where two distinct fibers are
+ * calling the same coroutine. First the test instantiates (and runs) a
+ * coroutine, then spawns another one and it passes it a reference to
+ * the first coroutine. Once the new coroutine calls the first coroutine
+ * and the first coroutine yields, we are expecting execution flow to
+ * be yielded to the second caller (the second coroutine) and not the
+ * original caller (the test itself)
+ */
+TEST(Coroutine, TwoCallers)
+{
+ bool valid_return = false;
+
+ Coroutine<void, void> callee{[]
+ (Coroutine<void, void>::CallerType& yield)
+ {
+ yield();
+ yield();
+ }};
+
+ Coroutine<void, void> other_caller{[&callee, &valid_return]
+ (Coroutine<void, void>::CallerType& yield)
+ {
+ callee();
+ valid_return = true;
+ yield();
+ }};
+
+ ASSERT_TRUE(valid_return);
+}
+++ /dev/null
-/*
- * Copyright (c) 2018 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Giacomo Travaglini
- */
-
-#include <gtest/gtest.h>
-
-#include "base/coroutine.hh"
-
-using namespace m5;
-
-/**
- * This test is checking if the Coroutine, once it yields
- * back to the caller, it is still marked as not finished.
- */
-TEST(Coroutine, Unfinished)
-{
- auto yielding_task =
- [] (Coroutine<void, void>::CallerType& yield)
- {
- yield();
- };
-
- Coroutine<void, void> coro(yielding_task);
- ASSERT_TRUE(coro);
-}
-
-/**
- * This test is checking the parameter passing interface of a
- * coroutine which takes an integer as an argument.
- * Coroutine::operator() and CallerType::get() are the tested
- * APIS.
- */
-TEST(Coroutine, Passing)
-{
- const std::vector<int> input{ 1, 2, 3 };
- const std::vector<int> expected_values = input;
-
- auto passing_task =
- [&expected_values] (Coroutine<int, void>::CallerType& yield)
- {
- int argument;
-
- for (const auto expected : expected_values) {
- argument = yield.get();
- ASSERT_EQ(argument, expected);
- }
- };
-
- Coroutine<int, void> coro(passing_task);
- ASSERT_TRUE(coro);
-
- for (const auto val : input) {
- coro(val);
- }
-}
-
-/**
- * This test is checking the yielding interface of a coroutine
- * which takes no argument and returns integers.
- * Coroutine::get() and CallerType::operator() are the tested
- * APIS.
- */
-TEST(Coroutine, Returning)
-{
- const std::vector<int> output{ 1, 2, 3 };
- const std::vector<int> expected_values = output;
-
- auto returning_task =
- [&output] (Coroutine<void, int>::CallerType& yield)
- {
- for (const auto ret : output) {
- yield(ret);
- }
- };
-
- Coroutine<void, int> coro(returning_task);
- ASSERT_TRUE(coro);
-
- for (const auto expected : expected_values) {
- int returned = coro.get();
- ASSERT_EQ(returned, expected);
- }
-}
-
-/**
- * This test is still supposed to test the returning interface
- * of the the Coroutine, proving how coroutine can be used
- * for generators.
- * The coroutine is computing the first #steps of the fibonacci
- * sequence and it is yielding back results one number per time.
- */
-TEST(Coroutine, Fibonacci)
-{
- const std::vector<int> expected_values{
- 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };
-
- const int steps = expected_values.size();
-
- auto fibonacci_task =
- [steps] (Coroutine<void, int>::CallerType& yield)
- {
- int prev = 0;
- int current = 1;
-
- for (auto iter = 0; iter < steps; iter++) {
- int sum = prev + current;
- yield(sum);
-
- prev = current;
- current = sum;
- }
- };
-
- Coroutine<void, int> coro(fibonacci_task);
- ASSERT_TRUE(coro);
-
- for (const auto expected : expected_values) {
- ASSERT_TRUE(coro);
- int returned = coro.get();
- ASSERT_EQ(returned, expected);
- }
-}
-
-/**
- * This test is using a bi-channel coroutine (accepting and
- * yielding values) for testing a cooperative task.
- * The caller and the coroutine have a string each; they are
- * composing a new string by merging the strings together one
- * character per time.
- * The result string is hence passed back and forth between the
- * coroutine and the caller.
- */
-TEST(Coroutine, Cooperative)
-{
- const std::string caller_str("HloWrd");
- const std::string coro_str("el ol!");
- const std::string expected("Hello World!");
-
- auto cooperative_task =
- [&coro_str] (Coroutine<std::string, std::string>::CallerType& yield)
- {
- for (auto& appended_c : coro_str) {
- auto old_str = yield.get();
- yield(old_str + appended_c);
- }
- };
-
- Coroutine<std::string, std::string> coro(cooperative_task);
-
- std::string result;
- for (auto& c : caller_str) {
- ASSERT_TRUE(coro);
- result += c;
- result = coro(result).get();
- }
-
- ASSERT_EQ(result, expected);
-}
-
-/**
- * This test is testing nested coroutines by using one inner and one
- * outer coroutine. It basically ensures that yielding from the inner
- * coroutine returns to the outer coroutine (mid-layer of execution) and
- * not to the outer caller.
- */
-TEST(Coroutine, Nested)
-{
- const std::string wrong("Inner");
- const std::string expected("Inner + Outer");
-
- auto inner_task =
- [] (Coroutine<void, std::string>::CallerType& yield)
- {
- std::string inner_string("Inner");
- yield(inner_string);
- };
-
- auto outer_task =
- [&inner_task] (Coroutine<void, std::string>::CallerType& yield)
- {
- Coroutine<void, std::string> coro(inner_task);
- std::string inner_string = coro.get();
-
- std::string outer_string("Outer");
- yield(inner_string + " + " + outer_string);
- };
-
-
- Coroutine<void, std::string> coro(outer_task);
- ASSERT_TRUE(coro);
-
- std::string result = coro.get();
-
- ASSERT_NE(result, wrong);
- ASSERT_EQ(result, expected);
-}
-
-/**
- * This test is stressing the scenario where two distinct fibers are
- * calling the same coroutine. First the test instantiates (and runs) a
- * coroutine, then spawns another one and it passes it a reference to
- * the first coroutine. Once the new coroutine calls the first coroutine
- * and the first coroutine yields, we are expecting execution flow to
- * be yielded to the second caller (the second coroutine) and not the
- * original caller (the test itself)
- */
-TEST(Coroutine, TwoCallers)
-{
- bool valid_return = false;
-
- Coroutine<void, void> callee{[]
- (Coroutine<void, void>::CallerType& yield)
- {
- yield();
- yield();
- }};
-
- Coroutine<void, void> other_caller{[&callee, &valid_return]
- (Coroutine<void, void>::CallerType& yield)
- {
- callee();
- valid_return = true;
- yield();
- }};
-
- ASSERT_TRUE(valid_return);
-}
--- /dev/null
+/*
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
+ */
+
+#include <gtest/gtest.h>
+
+#include <cstdio>
+#include <sstream>
+#include <string>
+
+#include "base/cprintf.hh"
+
+#define CPRINTF_TEST(...) \
+ do { \
+ std::stringstream ss; \
+ ccprintf(ss, __VA_ARGS__); \
+ int maxlen = ss.str().length() + 3; \
+ char *buf = new char[maxlen]; \
+ buf[maxlen - 1] = '\0'; \
+ snprintf(buf, maxlen - 2, __VA_ARGS__); \
+ EXPECT_EQ(ss.str(), std::string(buf)); \
+ delete [] buf; \
+ } while (0)
+
+TEST(CPrintf, Misc)
+{
+ char foo[] = "foo";
+ CPRINTF_TEST("%s\n", foo);
+
+ CPRINTF_TEST("%d\n", 'A');
+ CPRINTF_TEST("%shits%%s + %smisses%%s\n", "test", "test");
+ CPRINTF_TEST("%%s%-10s %c he went home \'\"%d %#o %#llx %1.5f %1.2E\n",
+ "hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.141592653589,
+ 1.1e10);
+
+ CPRINTF_TEST("another test\n");
+
+ CPRINTF_TEST("%-10s %c he home \'\"%d %#o %#llx %1.5f %1.2E\n",
+ "hello", 'A', 1, 0xff, 0xfffffffffffffULL,
+ 3.14159265, 1.1e10);
+}
+
+TEST(CPrintf, FloatingPoint)
+{
+ double f = 314159.26535897932384;
+
+ CPRINTF_TEST("%1.8f\n", f);
+ CPRINTF_TEST("%2.8f\n", f);
+ CPRINTF_TEST("%3.8f\n", f);
+ CPRINTF_TEST("%4.8f\n", f);
+ CPRINTF_TEST("%5.8f\n", f);
+ CPRINTF_TEST("%6.8f\n", f);
+ CPRINTF_TEST("%12.8f\n", f);
+ CPRINTF_TEST("%1000.8f\n", f);
+ CPRINTF_TEST("%1.0f\n", f);
+ CPRINTF_TEST("%1.1f\n", f);
+ CPRINTF_TEST("%1.2f\n", f);
+ CPRINTF_TEST("%1.3f\n", f);
+ CPRINTF_TEST("%1.4f\n", f);
+ CPRINTF_TEST("%1.5f\n", f);
+ CPRINTF_TEST("%1.6f\n", f);
+ CPRINTF_TEST("%1.7f\n", f);
+ CPRINTF_TEST("%1.8f\n", f);
+ CPRINTF_TEST("%1.9f\n", f);
+ CPRINTF_TEST("%1.10f\n", f);
+ CPRINTF_TEST("%1.11f\n", f);
+ CPRINTF_TEST("%1.12f\n", f);
+ CPRINTF_TEST("%1.13f\n", f);
+ CPRINTF_TEST("%1.14f\n", f);
+ CPRINTF_TEST("%1.15f\n", f);
+ CPRINTF_TEST("%1.16f\n", f);
+ CPRINTF_TEST("%1.17f\n", f);
+ CPRINTF_TEST("%1.18f\n", f);
+
+ f = 0.00000026535897932384;
+ CPRINTF_TEST("%1.8f\n", f);
+ CPRINTF_TEST("%2.8f\n", f);
+ CPRINTF_TEST("%3.8f\n", f);
+ CPRINTF_TEST("%4.8f\n", f);
+ CPRINTF_TEST("%5.8f\n", f);
+ CPRINTF_TEST("%6.8f\n", f);
+ CPRINTF_TEST("%12.8f\n", f);
+ CPRINTF_TEST("%1.0f\n", f);
+ CPRINTF_TEST("%1.1f\n", f);
+ CPRINTF_TEST("%1.2f\n", f);
+ CPRINTF_TEST("%1.3f\n", f);
+ CPRINTF_TEST("%1.4f\n", f);
+ CPRINTF_TEST("%1.5f\n", f);
+ CPRINTF_TEST("%1.6f\n", f);
+ CPRINTF_TEST("%1.7f\n", f);
+ CPRINTF_TEST("%1.8f\n", f);
+ CPRINTF_TEST("%1.9f\n", f);
+ CPRINTF_TEST("%1.10f\n", f);
+ CPRINTF_TEST("%1.11f\n", f);
+ CPRINTF_TEST("%1.12f\n", f);
+ CPRINTF_TEST("%1.13f\n", f);
+ CPRINTF_TEST("%1.14f\n", f);
+ CPRINTF_TEST("%1.15f\n", f);
+ CPRINTF_TEST("%1.16f\n", f);
+ CPRINTF_TEST("%1.17f\n", f);
+ CPRINTF_TEST("%1.18f\n", f);
+
+ f = 0.00000026535897932384;
+ CPRINTF_TEST("%1.8e\n", f);
+ CPRINTF_TEST("%2.8e\n", f);
+ CPRINTF_TEST("%3.8e\n", f);
+ CPRINTF_TEST("%4.8e\n", f);
+ CPRINTF_TEST("%5.8e\n", f);
+ CPRINTF_TEST("%6.8e\n", f);
+ CPRINTF_TEST("%12.8e\n", f);
+ CPRINTF_TEST("%1.0e\n", f);
+ CPRINTF_TEST("%1.1e\n", f);
+ CPRINTF_TEST("%1.2e\n", f);
+ CPRINTF_TEST("%1.3e\n", f);
+ CPRINTF_TEST("%1.4e\n", f);
+ CPRINTF_TEST("%1.5e\n", f);
+ CPRINTF_TEST("%1.6e\n", f);
+ CPRINTF_TEST("%1.7e\n", f);
+ CPRINTF_TEST("%1.8e\n", f);
+ CPRINTF_TEST("%1.9e\n", f);
+ CPRINTF_TEST("%1.10e\n", f);
+ CPRINTF_TEST("%1.11e\n", f);
+ CPRINTF_TEST("%1.12e\n", f);
+ CPRINTF_TEST("%1.13e\n", f);
+ CPRINTF_TEST("%1.14e\n", f);
+ CPRINTF_TEST("%1.15e\n", f);
+ CPRINTF_TEST("%1.16e\n", f);
+ CPRINTF_TEST("%1.17e\n", f);
+ CPRINTF_TEST("%1.18e\n", f);
+}
+
+TEST(CPrintf, Types)
+{
+ std::stringstream ss;
+
+ std::string foo1 = "string test";
+ ccprintf(ss, "%s\n", foo1);
+ EXPECT_EQ(ss.str(), "string test\n");
+ ss.str("");
+
+ std::stringstream foo2;
+ foo2 << "stringstream test";
+ ccprintf(ss, "%s\n", foo2.str());
+ EXPECT_EQ(ss.str(), "stringstream test\n");
+ ss.str("");
+
+ CPRINTF_TEST("%c %c\n", 'c', 65);
+}
+
+TEST(CPrintf, SpecialFormatting)
+{
+ CPRINTF_TEST("%08.4f\n", 99.99);
+ CPRINTF_TEST("%0*.*f\n", 8, 4, 99.99);
+ CPRINTF_TEST("%07.*f\n", 4, 1.234);
+ CPRINTF_TEST("%#0*x\n", 9, 123412);
+}
+++ /dev/null
-/*
- * Copyright (c) 2002-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nathan Binkert
- */
-
-#include <gtest/gtest.h>
-
-#include <cstdio>
-#include <sstream>
-#include <string>
-
-#include "base/cprintf.hh"
-
-#define CPRINTF_TEST(...) \
- do { \
- std::stringstream ss; \
- ccprintf(ss, __VA_ARGS__); \
- int maxlen = ss.str().length() + 3; \
- char *buf = new char[maxlen]; \
- buf[maxlen - 1] = '\0'; \
- snprintf(buf, maxlen - 2, __VA_ARGS__); \
- EXPECT_EQ(ss.str(), std::string(buf)); \
- delete [] buf; \
- } while (0)
-
-TEST(CPrintf, Misc)
-{
- char foo[] = "foo";
- CPRINTF_TEST("%s\n", foo);
-
- CPRINTF_TEST("%d\n", 'A');
- CPRINTF_TEST("%shits%%s + %smisses%%s\n", "test", "test");
- CPRINTF_TEST("%%s%-10s %c he went home \'\"%d %#o %#llx %1.5f %1.2E\n",
- "hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.141592653589,
- 1.1e10);
-
- CPRINTF_TEST("another test\n");
-
- CPRINTF_TEST("%-10s %c he home \'\"%d %#o %#llx %1.5f %1.2E\n",
- "hello", 'A', 1, 0xff, 0xfffffffffffffULL,
- 3.14159265, 1.1e10);
-}
-
-TEST(CPrintf, FloatingPoint)
-{
- double f = 314159.26535897932384;
-
- CPRINTF_TEST("%1.8f\n", f);
- CPRINTF_TEST("%2.8f\n", f);
- CPRINTF_TEST("%3.8f\n", f);
- CPRINTF_TEST("%4.8f\n", f);
- CPRINTF_TEST("%5.8f\n", f);
- CPRINTF_TEST("%6.8f\n", f);
- CPRINTF_TEST("%12.8f\n", f);
- CPRINTF_TEST("%1000.8f\n", f);
- CPRINTF_TEST("%1.0f\n", f);
- CPRINTF_TEST("%1.1f\n", f);
- CPRINTF_TEST("%1.2f\n", f);
- CPRINTF_TEST("%1.3f\n", f);
- CPRINTF_TEST("%1.4f\n", f);
- CPRINTF_TEST("%1.5f\n", f);
- CPRINTF_TEST("%1.6f\n", f);
- CPRINTF_TEST("%1.7f\n", f);
- CPRINTF_TEST("%1.8f\n", f);
- CPRINTF_TEST("%1.9f\n", f);
- CPRINTF_TEST("%1.10f\n", f);
- CPRINTF_TEST("%1.11f\n", f);
- CPRINTF_TEST("%1.12f\n", f);
- CPRINTF_TEST("%1.13f\n", f);
- CPRINTF_TEST("%1.14f\n", f);
- CPRINTF_TEST("%1.15f\n", f);
- CPRINTF_TEST("%1.16f\n", f);
- CPRINTF_TEST("%1.17f\n", f);
- CPRINTF_TEST("%1.18f\n", f);
-
- f = 0.00000026535897932384;
- CPRINTF_TEST("%1.8f\n", f);
- CPRINTF_TEST("%2.8f\n", f);
- CPRINTF_TEST("%3.8f\n", f);
- CPRINTF_TEST("%4.8f\n", f);
- CPRINTF_TEST("%5.8f\n", f);
- CPRINTF_TEST("%6.8f\n", f);
- CPRINTF_TEST("%12.8f\n", f);
- CPRINTF_TEST("%1.0f\n", f);
- CPRINTF_TEST("%1.1f\n", f);
- CPRINTF_TEST("%1.2f\n", f);
- CPRINTF_TEST("%1.3f\n", f);
- CPRINTF_TEST("%1.4f\n", f);
- CPRINTF_TEST("%1.5f\n", f);
- CPRINTF_TEST("%1.6f\n", f);
- CPRINTF_TEST("%1.7f\n", f);
- CPRINTF_TEST("%1.8f\n", f);
- CPRINTF_TEST("%1.9f\n", f);
- CPRINTF_TEST("%1.10f\n", f);
- CPRINTF_TEST("%1.11f\n", f);
- CPRINTF_TEST("%1.12f\n", f);
- CPRINTF_TEST("%1.13f\n", f);
- CPRINTF_TEST("%1.14f\n", f);
- CPRINTF_TEST("%1.15f\n", f);
- CPRINTF_TEST("%1.16f\n", f);
- CPRINTF_TEST("%1.17f\n", f);
- CPRINTF_TEST("%1.18f\n", f);
-
- f = 0.00000026535897932384;
- CPRINTF_TEST("%1.8e\n", f);
- CPRINTF_TEST("%2.8e\n", f);
- CPRINTF_TEST("%3.8e\n", f);
- CPRINTF_TEST("%4.8e\n", f);
- CPRINTF_TEST("%5.8e\n", f);
- CPRINTF_TEST("%6.8e\n", f);
- CPRINTF_TEST("%12.8e\n", f);
- CPRINTF_TEST("%1.0e\n", f);
- CPRINTF_TEST("%1.1e\n", f);
- CPRINTF_TEST("%1.2e\n", f);
- CPRINTF_TEST("%1.3e\n", f);
- CPRINTF_TEST("%1.4e\n", f);
- CPRINTF_TEST("%1.5e\n", f);
- CPRINTF_TEST("%1.6e\n", f);
- CPRINTF_TEST("%1.7e\n", f);
- CPRINTF_TEST("%1.8e\n", f);
- CPRINTF_TEST("%1.9e\n", f);
- CPRINTF_TEST("%1.10e\n", f);
- CPRINTF_TEST("%1.11e\n", f);
- CPRINTF_TEST("%1.12e\n", f);
- CPRINTF_TEST("%1.13e\n", f);
- CPRINTF_TEST("%1.14e\n", f);
- CPRINTF_TEST("%1.15e\n", f);
- CPRINTF_TEST("%1.16e\n", f);
- CPRINTF_TEST("%1.17e\n", f);
- CPRINTF_TEST("%1.18e\n", f);
-}
-
-TEST(CPrintf, Types)
-{
- std::stringstream ss;
-
- std::string foo1 = "string test";
- ccprintf(ss, "%s\n", foo1);
- EXPECT_EQ(ss.str(), "string test\n");
- ss.str("");
-
- std::stringstream foo2;
- foo2 << "stringstream test";
- ccprintf(ss, "%s\n", foo2.str());
- EXPECT_EQ(ss.str(), "stringstream test\n");
- ss.str("");
-
- CPRINTF_TEST("%c %c\n", 'c', 65);
-}
-
-TEST(CPrintf, SpecialFormatting)
-{
- CPRINTF_TEST("%08.4f\n", 99.99);
- CPRINTF_TEST("%0*.*f\n", 8, 4, 99.99);
- CPRINTF_TEST("%07.*f\n", 4, 1.234);
- CPRINTF_TEST("%#0*x\n", 9, 123412);
-}
--- /dev/null
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include <gtest/gtest.h>
+
+#include <initializer_list>
+#include <iostream>
+#include <vector>
+
+#include "base/fiber.hh"
+
+class TestFiber : public Fiber
+{
+ public:
+ const char *name;
+ std::vector<Fiber *> next;
+
+ TestFiber(const char *name, std::initializer_list<Fiber *> l);
+
+ void checkExpected();
+ void main();
+};
+
+extern TestFiber a;
+extern TestFiber b;
+extern TestFiber c;
+
+TestFiber a("A", { &b, &a, Fiber::primaryFiber(), &b, &c });
+TestFiber b("B", { &a, &c });
+TestFiber c("C", { &a, Fiber::primaryFiber(), Fiber::primaryFiber() });
+
+std::vector<TestFiber *>::iterator expectedIt;
+std::vector<TestFiber *> expected({
+ &a, &b, &a, &a, /* main Fiber, */
+ &a, &b, &c, &a, &c,
+ /* main Fiber, */ &c, &c
+});
+
+TestFiber::TestFiber(
+ const char *name, std::initializer_list<Fiber *> l) :
+ name(name), next(l)
+{}
+
+void
+TestFiber::checkExpected()
+{
+ ASSERT_NE(expectedIt, expected.end());
+ TestFiber *e = *expectedIt++;
+ EXPECT_EQ(e, this) << "Expected " << e->name << ", got " << name;
+}
+
+void
+TestFiber::main()
+{
+ checkExpected();
+ for (auto &n : next) {
+ n->run();
+ checkExpected();
+ }
+}
+
+TEST(Fiber, Switching)
+{
+ expectedIt = expected.begin();
+
+ a.run();
+ EXPECT_EQ(expectedIt - expected.begin(), 4);
+
+ a.run();
+ EXPECT_EQ(expectedIt - expected.begin(), 9);
+
+ c.run();
+ EXPECT_EQ(expectedIt - expected.begin(), 10);
+
+ EXPECT_FALSE(a.finished());
+ EXPECT_FALSE(b.finished());
+ EXPECT_FALSE(c.finished());
+
+ c.run();
+ EXPECT_EQ(expected.end(), expectedIt) <<
+ "Didn't exactly use up the expected Fiber sequence";
+
+ EXPECT_TRUE(c.finished());
+}
+
+int currentIndex = 0;
+
+class LinkedFiber : public Fiber
+{
+ public:
+ const int index;
+ LinkedFiber(Fiber *link, int index) : Fiber(link), index(index) {}
+
+ void
+ main()
+ {
+ EXPECT_EQ(currentIndex, index);
+ currentIndex++;
+ }
+};
+
+TEST(Fiber, Linked)
+{
+ currentIndex = 0;
+
+ LinkedFiber lf3(Fiber::primaryFiber(), 3);
+ LinkedFiber lf2(&lf3, 2);
+ LinkedFiber lf1(&lf2, 1);
+ LinkedFiber lf0(&lf1, 0);
+
+ lf0.run();
+
+ EXPECT_EQ(currentIndex, 4);
+}
+++ /dev/null
-/*
- * Copyright 2018 Google, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Gabe Black
- */
-
-#include <gtest/gtest.h>
-
-#include <initializer_list>
-#include <iostream>
-#include <vector>
-
-#include "base/fiber.hh"
-
-class TestFiber : public Fiber
-{
- public:
- const char *name;
- std::vector<Fiber *> next;
-
- TestFiber(const char *name, std::initializer_list<Fiber *> l);
-
- void checkExpected();
- void main();
-};
-
-extern TestFiber a;
-extern TestFiber b;
-extern TestFiber c;
-
-TestFiber a("A", { &b, &a, Fiber::primaryFiber(), &b, &c });
-TestFiber b("B", { &a, &c });
-TestFiber c("C", { &a, Fiber::primaryFiber(), Fiber::primaryFiber() });
-
-std::vector<TestFiber *>::iterator expectedIt;
-std::vector<TestFiber *> expected({
- &a, &b, &a, &a, /* main Fiber, */
- &a, &b, &c, &a, &c,
- /* main Fiber, */ &c, &c
-});
-
-TestFiber::TestFiber(
- const char *name, std::initializer_list<Fiber *> l) :
- name(name), next(l)
-{}
-
-void
-TestFiber::checkExpected()
-{
- ASSERT_NE(expectedIt, expected.end());
- TestFiber *e = *expectedIt++;
- EXPECT_EQ(e, this) << "Expected " << e->name << ", got " << name;
-}
-
-void
-TestFiber::main()
-{
- checkExpected();
- for (auto &n : next) {
- n->run();
- checkExpected();
- }
-}
-
-TEST(Fiber, Switching)
-{
- expectedIt = expected.begin();
-
- a.run();
- EXPECT_EQ(expectedIt - expected.begin(), 4);
-
- a.run();
- EXPECT_EQ(expectedIt - expected.begin(), 9);
-
- c.run();
- EXPECT_EQ(expectedIt - expected.begin(), 10);
-
- EXPECT_FALSE(a.finished());
- EXPECT_FALSE(b.finished());
- EXPECT_FALSE(c.finished());
-
- c.run();
- EXPECT_EQ(expected.end(), expectedIt) <<
- "Didn't exactly use up the expected Fiber sequence";
-
- EXPECT_TRUE(c.finished());
-}
-
-int currentIndex = 0;
-
-class LinkedFiber : public Fiber
-{
- public:
- const int index;
- LinkedFiber(Fiber *link, int index) : Fiber(link), index(index) {}
-
- void
- main()
- {
- EXPECT_EQ(currentIndex, index);
- currentIndex++;
- }
-};
-
-TEST(Fiber, Linked)
-{
- currentIndex = 0;
-
- LinkedFiber lf3(Fiber::primaryFiber(), 3);
- LinkedFiber lf2(&lf3, 2);
- LinkedFiber lf1(&lf2, 1);
- LinkedFiber lf0(&lf1, 0);
-
- lf0.run();
-
- EXPECT_EQ(currentIndex, 4);
-}
--- /dev/null
+/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
+ * Steve Reinhardt
+ */
+
+#include <gtest/gtest.h>
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "base/inifile.hh"
+
+using namespace std;
+
+namespace {
+
+std::istringstream iniFile(R"ini_file(
+[General]
+ Test1=BARasdf
+ Test2=bar
+
+[Junk]
+Test3=yo
+Test4=mama
+
+[Foo]
+Foo1=89
+Foo2=384
+
+[General]
+Test3=89
+
+[Junk]
+Test4+=mia
+)ini_file");
+
+};
+
+TEST(Initest, MatchFound)
+{
+ IniFile simConfigDB;
+ simConfigDB.load(iniFile);
+
+ std::string value;
+
+ auto ret = simConfigDB.find("General", "Test2", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "bar");
+
+ ret = simConfigDB.find("Junk", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "yo");
+
+ ret = simConfigDB.find("Junk", "Test4", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "mama mia");
+
+ ret = simConfigDB.find("General", "Test1", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "BARasdf");
+
+ ret = simConfigDB.find("General", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "89");
+}
+
+TEST(Initest, MatchNotFound)
+{
+ IniFile simConfigDB;
+ simConfigDB.load(iniFile);
+
+ std::string value;
+
+ auto ret = simConfigDB.find("Junk2", "test3", value);
+ ASSERT_FALSE(ret);
+
+ ret = simConfigDB.find("Junk", "test4", value);
+ ASSERT_FALSE(ret);
+}
+++ /dev/null
-/*
- * Copyright (c) 2018 ARM Limited
- * All rights reserved
- *
- * Copyright (c) 2002-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nathan Binkert
- * Steve Reinhardt
- */
-
-#include <gtest/gtest.h>
-
-#include <fstream>
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include "base/inifile.hh"
-
-using namespace std;
-
-namespace {
-
-std::istringstream iniFile(R"ini_file(
-[General]
- Test1=BARasdf
- Test2=bar
-
-[Junk]
-Test3=yo
-Test4=mama
-
-[Foo]
-Foo1=89
-Foo2=384
-
-[General]
-Test3=89
-
-[Junk]
-Test4+=mia
-)ini_file");
-
-};
-
-TEST(Initest, MatchFound)
-{
- IniFile simConfigDB;
- simConfigDB.load(iniFile);
-
- std::string value;
-
- auto ret = simConfigDB.find("General", "Test2", value);
- ASSERT_TRUE(ret);
- ASSERT_STREQ(value.c_str(), "bar");
-
- ret = simConfigDB.find("Junk", "Test3", value);
- ASSERT_TRUE(ret);
- ASSERT_STREQ(value.c_str(), "yo");
-
- ret = simConfigDB.find("Junk", "Test4", value);
- ASSERT_TRUE(ret);
- ASSERT_STREQ(value.c_str(), "mama mia");
-
- ret = simConfigDB.find("General", "Test1", value);
- ASSERT_TRUE(ret);
- ASSERT_STREQ(value.c_str(), "BARasdf");
-
- ret = simConfigDB.find("General", "Test3", value);
- ASSERT_TRUE(ret);
- ASSERT_STREQ(value.c_str(), "89");
-}
-
-TEST(Initest, MatchNotFound)
-{
- IniFile simConfigDB;
- simConfigDB.load(iniFile);
-
- std::string value;
-
- auto ret = simConfigDB.find("Junk2", "test3", value);
- ASSERT_FALSE(ret);
-
- ret = simConfigDB.find("Junk", "test4", value);
- ASSERT_FALSE(ret);
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/pixel.hh"
+
+static Pixel pixel_red(0xff, 0x00, 0x00);
+static Pixel pixel_green(0x00, 0xff, 0x00);
+static Pixel pixel_blue(0x00, 0x00, 0xff);
+
+TEST(FBTest, PixelConversionRGBA8888)
+{
+ EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_red),
+ 0x000000ffU);
+ EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_green),
+ 0x0000ff00U);
+ EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_blue),
+ 0x00ff0000U);
+
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x000000ffU),
+ pixel_red);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x0000ff00U),
+ pixel_green);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x00ff0000U),
+ pixel_blue);
+}
+
+TEST(FBTest, PixelConversionRGB565)
+{
+ EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_red), 0x001fU);
+ EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_green), 0x07e0U);
+ EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_blue), 0xf800U);
+
+ EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x001fU), pixel_red);
+ EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x07e0U), pixel_green);
+ EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0xf800U), pixel_blue);
+}
+
+TEST(FBTest, PixelToMemRGBA8888LE)
+{
+ uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef };
+ PixelConverter::rgba8888_le.fromPixel(data, pixel_red);
+ EXPECT_EQ(data[0], 0xff);
+ EXPECT_EQ(data[1], 0x00);
+ EXPECT_EQ(data[3], 0x00);
+ EXPECT_EQ(data[3], 0x00);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_red);
+
+ PixelConverter::rgba8888_le.fromPixel(data, pixel_green);
+ EXPECT_EQ(data[0], 0x00);
+ EXPECT_EQ(data[1], 0xff);
+ EXPECT_EQ(data[3], 0x00);
+ EXPECT_EQ(data[3], 0x00);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_green);
+
+ PixelConverter::rgba8888_le.fromPixel(data, pixel_blue);
+ EXPECT_EQ(data[0], 0x00);
+ EXPECT_EQ(data[1], 0x00);
+ EXPECT_EQ(data[2], 0xff);
+ EXPECT_EQ(data[3], 0x00);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_blue);
+}
+
+TEST(FBTest, MemToPixelRGBA8888LE)
+{
+ uint8_t red[] = { 0xff, 0x00, 0x00, 0x00 };
+ uint8_t green[] = { 0x00, 0xff, 0x00, 0x00 };
+ uint8_t blue[] = { 0x00, 0x00, 0xff, 0x00 };
+
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(red), pixel_red);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(green), pixel_green);
+ EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(blue), pixel_blue);
+}
+
+TEST(FBTest, MemToPixelRGBA8888BE)
+{
+ uint8_t red[] = { 0x00, 0x00, 0x00, 0xff };
+ uint8_t green[] = { 0x00, 0x00, 0xff, 0x00 };
+ uint8_t blue[] = { 0x00, 0xff, 0x00, 0x00 };
+
+ EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(red), pixel_red);
+ EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(green), pixel_green);
+ EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(blue), pixel_blue);
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Andreas Sandberg
- */
-
-#include <gtest/gtest.h>
-
-#include "base/pixel.hh"
-
-static Pixel pixel_red(0xff, 0x00, 0x00);
-static Pixel pixel_green(0x00, 0xff, 0x00);
-static Pixel pixel_blue(0x00, 0x00, 0xff);
-
-TEST(FBTest, PixelConversionRGBA8888)
-{
- EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_red),
- 0x000000ffU);
- EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_green),
- 0x0000ff00U);
- EXPECT_EQ(PixelConverter::rgba8888_le.fromPixel(pixel_blue),
- 0x00ff0000U);
-
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x000000ffU),
- pixel_red);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x0000ff00U),
- pixel_green);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(0x00ff0000U),
- pixel_blue);
-}
-
-TEST(FBTest, PixelConversionRGB565)
-{
- EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_red), 0x001fU);
- EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_green), 0x07e0U);
- EXPECT_EQ(PixelConverter::rgb565_le.fromPixel(pixel_blue), 0xf800U);
-
- EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x001fU), pixel_red);
- EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0x07e0U), pixel_green);
- EXPECT_EQ(PixelConverter::rgb565_le.toPixel(0xf800U), pixel_blue);
-}
-
-TEST(FBTest, PixelToMemRGBA8888LE)
-{
- uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef };
- PixelConverter::rgba8888_le.fromPixel(data, pixel_red);
- EXPECT_EQ(data[0], 0xff);
- EXPECT_EQ(data[1], 0x00);
- EXPECT_EQ(data[3], 0x00);
- EXPECT_EQ(data[3], 0x00);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_red);
-
- PixelConverter::rgba8888_le.fromPixel(data, pixel_green);
- EXPECT_EQ(data[0], 0x00);
- EXPECT_EQ(data[1], 0xff);
- EXPECT_EQ(data[3], 0x00);
- EXPECT_EQ(data[3], 0x00);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_green);
-
- PixelConverter::rgba8888_le.fromPixel(data, pixel_blue);
- EXPECT_EQ(data[0], 0x00);
- EXPECT_EQ(data[1], 0x00);
- EXPECT_EQ(data[2], 0xff);
- EXPECT_EQ(data[3], 0x00);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(data), pixel_blue);
-}
-
-TEST(FBTest, MemToPixelRGBA8888LE)
-{
- uint8_t red[] = { 0xff, 0x00, 0x00, 0x00 };
- uint8_t green[] = { 0x00, 0xff, 0x00, 0x00 };
- uint8_t blue[] = { 0x00, 0x00, 0xff, 0x00 };
-
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(red), pixel_red);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(green), pixel_green);
- EXPECT_EQ(PixelConverter::rgba8888_le.toPixel(blue), pixel_blue);
-}
-
-TEST(FBTest, MemToPixelRGBA8888BE)
-{
- uint8_t red[] = { 0x00, 0x00, 0x00, 0xff };
- uint8_t green[] = { 0x00, 0x00, 0xff, 0x00 };
- uint8_t blue[] = { 0x00, 0xff, 0x00, 0x00 };
-
- EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(red), pixel_red);
- EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(green), pixel_green);
- EXPECT_EQ(PixelConverter::rgba8888_be.toPixel(blue), pixel_blue);
-}
--- /dev/null
+/*
+ * Copyright (c) 2012 Google
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "base/trie.hh"
+#include "base/types.hh"
+
+namespace {
+
+static inline uint32_t *ptr(uintptr_t val)
+{
+ return (uint32_t *)val;
+}
+
+} // anonymous namespace
+
+class TrieTestData : public testing::Test
+{
+ protected:
+ typedef Trie<Addr, uint32_t> TrieType;
+ TrieType trie;
+
+ std::string
+ dumpTrie()
+ {
+ std::stringstream ss;
+ trie.dump("test trie", ss);
+ return ss.str();
+ }
+};
+
+TEST_F(TrieTestData, Empty)
+{
+ EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
+}
+
+TEST_F(TrieTestData, SingleEntry)
+{
+ trie.insert(0x0123456789abcdef, 40, ptr(1));
+ EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(1)) << dumpTrie();
+}
+
+TEST_F(TrieTestData, TwoOverlappingEntries)
+{
+ trie.insert(0x0123456789abcdef, 40, ptr(1));
+ trie.insert(0x0123456789abcdef, 36, ptr(2));
+ EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
+}
+
+TEST_F(TrieTestData, TwoOverlappingEntriesReversed)
+{
+ trie.insert(0x0123456789abcdef, 36, ptr(2));
+ trie.insert(0x0123456789abcdef, 40, ptr(1));
+ EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
+}
+
+TEST_F(TrieTestData, TwoIndependentEntries)
+{
+ trie.insert(0x0123456789abcdef, 40, ptr(2));
+ trie.insert(0x0123456776543210, 40, ptr(1));
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456776000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
+}
+
+TEST_F(TrieTestData, TwoEntries)
+{
+ trie.insert(0x0123456789000000, 40, ptr(4));
+ trie.insert(0x0123000000000000, 40, ptr(1));
+ trie.insert(0x0123456780000000, 40, ptr(3));
+ trie.insert(0x0123456700000000, 40, ptr(2));
+
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
+}
+
+TEST_F(TrieTestData, RemovingEntries)
+{
+ TrieType::Handle node1, node2;
+ trie.insert(0x0123456789000000, 40, ptr(4));
+ trie.insert(0x0123000000000000, 40, ptr(1));
+ trie.insert(0x0123456780000000, 40, ptr(3));
+ node1 = trie.insert(0x0123456700000000, 40, ptr(2));
+ node2 = trie.insert(0x0123456700000000, 32, ptr(10));
+
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(10)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(10)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(10)) << dumpTrie();
+
+ trie.remove(node2);
+
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
+
+ trie.remove(node1);
+
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
+}
+++ /dev/null
-/*
- * Copyright (c) 2012 Google
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Gabe Black
- */
-
-#include <gtest/gtest.h>
-
-#include <iostream>
-#include <sstream>
-#include <string>
-
-#include "base/trie.hh"
-#include "base/types.hh"
-
-namespace {
-
-static inline uint32_t *ptr(uintptr_t val)
-{
- return (uint32_t *)val;
-}
-
-} // anonymous namespace
-
-class TrieTestData : public testing::Test
-{
- protected:
- typedef Trie<Addr, uint32_t> TrieType;
- TrieType trie;
-
- std::string
- dumpTrie()
- {
- std::stringstream ss;
- trie.dump("test trie", ss);
- return ss.str();
- }
-};
-
-TEST_F(TrieTestData, Empty)
-{
- EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
-}
-
-TEST_F(TrieTestData, SingleEntry)
-{
- trie.insert(0x0123456789abcdef, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(1)) << dumpTrie();
-}
-
-TEST_F(TrieTestData, TwoOverlappingEntries)
-{
- trie.insert(0x0123456789abcdef, 40, ptr(1));
- trie.insert(0x0123456789abcdef, 36, ptr(2));
- EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
-}
-
-TEST_F(TrieTestData, TwoOverlappingEntriesReversed)
-{
- trie.insert(0x0123456789abcdef, 36, ptr(2));
- trie.insert(0x0123456789abcdef, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
-}
-
-TEST_F(TrieTestData, TwoIndependentEntries)
-{
- trie.insert(0x0123456789abcdef, 40, ptr(2));
- trie.insert(0x0123456776543210, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(2)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456776000000), ptr(1)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
-}
-
-TEST_F(TrieTestData, TwoEntries)
-{
- trie.insert(0x0123456789000000, 40, ptr(4));
- trie.insert(0x0123000000000000, 40, ptr(1));
- trie.insert(0x0123456780000000, 40, ptr(3));
- trie.insert(0x0123456700000000, 40, ptr(2));
-
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
-}
-
-TEST_F(TrieTestData, RemovingEntries)
-{
- TrieType::Handle node1, node2;
- trie.insert(0x0123456789000000, 40, ptr(4));
- trie.insert(0x0123000000000000, 40, ptr(1));
- trie.insert(0x0123456780000000, 40, ptr(3));
- node1 = trie.insert(0x0123456700000000, 40, ptr(2));
- node2 = trie.insert(0x0123456700000000, 32, ptr(10));
-
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(10)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(10)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(10)) << dumpTrie();
-
- trie.remove(node2);
-
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
-
- trie.remove(node1);
-
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
-}