28#include <gtest/gtest.h>
38class TestTarget :
public Extensible<TestTarget>
42class IntegerExtension :
public Extension<TestTarget, IntegerExtension>
45 explicit IntegerExtension(uint32_t
data)
48 std::unique_ptr<gem5::ExtensionBase> clone()
const override
50 return std::unique_ptr<IntegerExtension>(
new IntegerExtension(data_));
53 uint32_t getData()
const {
return data_; }
59class BoolExtension :
public Extension<TestTarget, BoolExtension>
62 explicit BoolExtension(
bool data)
65 std::unique_ptr<gem5::ExtensionBase> clone()
const override
67 return std::unique_ptr<BoolExtension>(
new BoolExtension(data_));
70 bool getData()
const {
return data_; }
78TEST(ExtensibleTest, ExtensionID)
80 std::shared_ptr<IntegerExtension> ext1(
new IntegerExtension(0xabcd));
81 EXPECT_EQ(0, ext1->getExtensionID());
83 std::shared_ptr<BoolExtension> ext2(
new BoolExtension(
true));
84 EXPECT_EQ(1, ext2->getExtensionID());
87TEST(ExtensibleTest, SetAndRemoveExtension)
89 const uint32_t
data = 0xbeef;
90 std::shared_ptr<IntegerExtension>
ext(
new IntegerExtension(
data));
91 std::unique_ptr<TestTarget> target(
new TestTarget);
92 target->setExtension(
ext);
93 EXPECT_EQ(
data, target->getExtension<IntegerExtension>()->getData());
95 target->removeExtension<IntegerExtension>();
96 EXPECT_EQ(
nullptr, target->getExtension<IntegerExtension>());
99TEST(ExtensibleTest, ReplaceExtension)
101 const uint32_t
data = 0xbeef;
102 std::shared_ptr<IntegerExtension>
ext(
new IntegerExtension(
data));
103 std::unique_ptr<TestTarget> target(
new TestTarget);
104 target->setExtension(
ext);
105 EXPECT_EQ(
data, target->getExtension<IntegerExtension>()->getData());
107 const uint32_t new_data = 0xa5a5;
108 std::shared_ptr<IntegerExtension> new_ext(
new IntegerExtension(new_data));
109 target->setExtension(new_ext);
110 EXPECT_EQ(new_data, target->getExtension<IntegerExtension>()->getData());
This is the extension for carrying additional information.
TEST(ExtensibleTest, ExtensionID)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.