Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libs/rtemodel/include/RteDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
/******************************************************************************/
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -1132,24 +1132,24 @@ class RteDeviceItem : public RteDeviceElement
* @brief collect effective properties for a supplied tag (e.g. "debug") and processor (e.g. "core_one")
* @param tag property tag
* @param properties reference to list of pointers to RteDeviceProperty to fill
* @param pName processor name, empty to collect properties for all processors
* @param pName processor name; if empty, collects only common properties (without Pname)
* @param bRecursive flag to collect properties recursively from RteDeviceItem parent chain
*/
void CollectEffectiveProperties(const std::string& tag, std::list<RteDeviceProperty*>& properties, const std::string& pName = EMPTY_STRING, bool bRecursive = true) const;

/**
* @brief collect all effective properties for given processor name
* @param properties reference to RteDevicePropertyMap to fill
* @param pName processor name, empty to collect properties for all processors
* @param pName processor name; if empty, collects only common properties (without Pname)
*/
void CollectEffectiveProperties(RteDevicePropertyMap& properties, const std::string& pName = EMPTY_STRING) const;


/**
* @brief fill m_effectiveProperties member by calling via CollectEffectiveProperties(RteDevicePropertyMap&, const std::string&)
* @param pName processor name, empty to collect properties for all processors
* @param pName processor name; if empty, collects only common properties (without Pname)
*/
void CollectEffectiveProperties(const std::string& pName = EMPTY_STRING);
const RteDevicePropertyMap& CollectEffectiveProperties(const std::string& pName = EMPTY_STRING);

protected:
std::map<std::string, RteDeviceProperty*> m_processors; // processor properties
Expand Down
6 changes: 3 additions & 3 deletions libs/rtemodel/include/RteTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
/******************************************************************************/
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -897,7 +897,7 @@ class RteTarget : public RteItem

/**
* @brief getter for list of boards compatible with target's device
* @param boards collection of RteBoad to fill
* @param boards collection of RteBoard to fill
*/
void GetBoards(std::vector<RteBoard*>& boards) const;

Expand Down Expand Up @@ -1042,7 +1042,7 @@ class RteTarget : public RteItem

void CollectPreIncludeStrings(RteComponent* c, int count);

void AddBoadProperties(RteDeviceItem* device, const std::string& processorName);
void AddBoardProperties(RteDeviceItem* device, const std::string& processorName);
void AddAlgorithm(RteItem* algo, RteItem* holder);

std::string NormalizeIncPath(const std::string& path) const;
Expand Down
47 changes: 18 additions & 29 deletions libs/rtemodel/src/RteDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
/******************************************************************************/
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -709,7 +709,7 @@ void RteDeviceItem::CollectEffectiveProperties(const string& tag, list<RteDevice
RteDeviceProperty* p = dynamic_cast<RteDeviceProperty*>(child);
if (p) {
const string& propPname = p->GetProcessorName();
if (pName.empty() || propPname.empty() || propPname == pName) {
if (propPname.empty() || propPname == pName) {
const string& id = p->GetID();
RteDeviceProperty* pInserted = RteDeviceProperty::GetPropertyFromList(id, properties);
if (p == pInserted)
Expand All @@ -736,8 +736,7 @@ void RteDeviceItem::CollectEffectiveProperties(const string& tag, list<RteDevice
// more complicated - gets all available properties
void RteDeviceItem::CollectEffectiveProperties(RteDevicePropertyMap& properties, const string& pName) const
{
RteDevicePropertyMap::iterator dstIt;
for (auto [tag, props] : m_properties) {
for (const auto& [tag, props] : m_properties) {
auto dstIt = properties.find(tag);
// add top containers if not yet exist
if (dstIt == properties.end()) {
Expand All @@ -754,17 +753,18 @@ void RteDeviceItem::CollectEffectiveProperties(RteDevicePropertyMap& properties,
}


void RteDeviceItem::CollectEffectiveProperties(const string& pName)
const RteDevicePropertyMap& RteDeviceItem::CollectEffectiveProperties(const string& pName)
{
m_effectiveProperties[pName] = RteEffectiveProperties();
auto it = m_effectiveProperties.find(pName);
RteDevicePropertyMap& pmap = it->second.m_propertyMap;
CollectEffectiveProperties(pmap, pName);
for (auto [_, l] : pmap) {
for (const auto& [_, l] : pmap) {
for (auto p : l) {
p->CalculateCachedValues();
}
}
return pmap;
}


Expand All @@ -779,32 +779,21 @@ const list<RteDeviceProperty*>& RteEffectiveProperties::GetProperties(const stri

const RteDevicePropertyMap& RteDeviceItem::GetEffectiveProperties(const string& pName)
{
if (m_effectiveProperties.empty()) {
for (auto [pn, p] : m_processors) {
CollectEffectiveProperties(pn);
if(pName.empty() || contains_key(m_processors, pName)) {
auto itp = m_effectiveProperties.find(pName);
if(itp != m_effectiveProperties.end()) {
return itp->second.m_propertyMap;
}
return CollectEffectiveProperties(pName);
}

auto itp = m_effectiveProperties.find(pName);
if (itp != m_effectiveProperties.end()) {
return itp->second.m_propertyMap;
}

static const RteDevicePropertyMap EMPTY_PROPERTY_MAP;
return EMPTY_PROPERTY_MAP;
}

const list<RteDeviceProperty*>& RteDeviceItem::GetEffectiveProperties(const string& tag, const string& pName)
{
if (m_effectiveProperties.empty()) {
GetEffectiveProperties(pName);
}
auto itp = m_effectiveProperties.find(pName);
if (itp != m_effectiveProperties.end()) {
const RteEffectiveProperties& effectiveProps = itp->second;
return effectiveProps.GetProperties(tag);
}
return EMPTY_PROPERTY_LIST;
const RteDevicePropertyMap& effectivePropMap = GetEffectiveProperties(pName);
return get_or_default_const_ref(effectivePropMap, tag, EMPTY_PROPERTY_LIST);
}

RteDeviceProperty* RteDeviceItem::GetSingleEffectiveProperty(const string& tag, const string& pName)
Expand All @@ -817,11 +806,11 @@ RteDeviceProperty* RteDeviceItem::GetSingleEffectiveProperty(const string& tag,

std::list<RteDeviceProperty*> RteDeviceItem::GetAllEffectiveProperties(const std::string& tag)
{
// Make a copy, simpler to merge with potential processor specific memories
list<RteDeviceProperty*> properties = GetEffectiveProperties(tag, RteUtils::EMPTY_STRING);
// Collect a list of unique properties (by pointer) across all processors for the given tag, without merging/normalizing them
list<RteDeviceProperty*> properties;
// Iterate over processors
for(auto [pname, _] : GetProcessors()) {
// Collect processor - unique memories
for (const auto& [pname, _] : GetProcessors()) {
// Collect processor-specific properties for this tag
const list<RteDeviceProperty*>& procProps = GetEffectiveProperties(tag, pname);
for(auto p : procProps) {
if(std::find(properties.begin(), properties.end(), p) == properties.end()) {
Expand Down Expand Up @@ -1226,7 +1215,7 @@ string RteDeviceItemAggregate::GetSummaryString() const
// Memory (RAM/ROM)
unsigned long long ramSize = 0, romSize = 0;
// Get all memory properties
list<RteDeviceProperty*> mems = item->GetAllEffectiveProperties("memory");
const list<RteDeviceProperty*>& mems = item->GetAllEffectiveProperties("memory");
for (auto memsIt = mems.begin(); memsIt != mems.end(); ++memsIt) {
RteDeviceMemory* mem = dynamic_cast<RteDeviceMemory*>(*memsIt);
if (!mem) {
Expand Down
8 changes: 4 additions & 4 deletions libs/rtemodel/src/RteTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void RteTarget::SetBoard(RteBoard* board) {
if (project)
project->SetBoardInfo(GetName(), board);

AddBoadProperties(GetDevice(), GetProcessorName());
AddBoardProperties(GetDevice(), GetProcessorName());
}


Expand Down Expand Up @@ -622,7 +622,7 @@ void RteTarget::ProcessAttributes() // called from SetAttributes(), AddAttribute
AddDeviceProperties(m_device, GetProcessorName());
};

void RteTarget::AddBoadProperties(RteDeviceItem* device, const string& processorName) {
void RteTarget::AddBoardProperties(RteDeviceItem* device, const string& processorName) {

// remove all board algos if any: target can only refer to a single board
for (auto it = m_algos.begin(); it != m_algos.end();) {
Expand Down Expand Up @@ -658,14 +658,14 @@ void RteTarget::AddDeviceProperties(RteDeviceItem* d, const string& processorNam
return;
}

AddBoadProperties(d, processorName);
AddBoardProperties(d, processorName);

string packagePath = RteUtils::ExtractFilePath(package->GetPackageFileName(), true);
// get properties for given processor:
const RteDevicePropertyMap& propMap = d->GetEffectiveProperties(processorName);

for (auto itpm = propMap.begin(); itpm != propMap.end(); ++itpm) {
const string& propType = itpm->first; // processor, feature, mamory, etc.
const string& propType = itpm->first; // processor, feature, memory, etc.
const list<RteDeviceProperty*>& props = itpm->second;
for (auto itp = props.begin(); itp != props.end(); ++itp) {
RteDeviceProperty *p = *itp;
Expand Down
23 changes: 23 additions & 0 deletions libs/rtemodel/test/src/RteModelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ TEST(RteModelTest, LoadPacks) {
// test recommended memory attributes: name and access
summary = da->GetSummaryString();
EXPECT_EQ(summary, "ARM Cortex-M4, 10 MHz, 128 KiB RAM, 256 KiB ROM");
auto di = da->GetDeviceItem();
EXPECT_EQ(di->GetProcessorCount(), 1);
EXPECT_TRUE(di->GetEffectiveProperties("foo").empty());
const auto& m4Properties = di->GetEffectiveProperties("");
EXPECT_FALSE(m4Properties.empty());

da = rteModel->GetDeviceAggregate("RteTest_ARMCM0_Dual", "ARM:82");
ASSERT_NE(da, nullptr);
// test recommended memory attributes: name and access
summary = da->GetSummaryString();
EXPECT_EQ(summary, "ARM Cortex-M0, 10 MHz, ARM Cortex-M0, 10 MHz, 256 KiB RAM, 768 KiB ROM");
di = da->GetDeviceItem();
ASSERT_NE(di, nullptr);
EXPECT_EQ(di->GetProcessorCount(), 2);
const auto& commonProperties = di->GetEffectiveProperties("");
const auto& core0Properties = di->GetEffectiveProperties("cm0_core0");
const auto& core1Properties = di->GetEffectiveProperties("cm0_core1");

EXPECT_TRUE(RteModelTestConfig::IsSubset(commonProperties, core0Properties));
EXPECT_TRUE(RteModelTestConfig::IsSubset(commonProperties, core1Properties));
EXPECT_FALSE(RteModelTestConfig::IsSubset(core0Properties, commonProperties));
EXPECT_FALSE(RteModelTestConfig::IsSubset(core1Properties, commonProperties));
EXPECT_FALSE(RteModelTestConfig::IsSubset(core0Properties, core1Properties));

RteBoard* board = rteModel->FindBoard("RteTest board listing (Rev.C)");
ASSERT_NE(board, nullptr);
Expand Down
23 changes: 23 additions & 0 deletions libs/rtemodel/test/src/RteModelTestConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <iostream>
#include <fstream>
#include <unordered_set>

using namespace std;

Expand Down Expand Up @@ -60,6 +61,28 @@ void RteModelTestConfig::TearDown()
RteFsUtils::DeleteTree(localPacks);
}



bool RteModelTestConfig::IsSubset( const RteDevicePropertyMap& subset, const RteDevicePropertyMap& superset)
{
for(const auto& [key, subsetList] : subset) {
auto it = superset.find(key);
if(it == superset.end()) {
return false;
}
std::unordered_set<RteDeviceProperty*> supersetListAsSet(it->second.begin(), it->second.end());

for(auto* ptr : subsetList) {
if(supersetListAsSet.find(ptr) == supersetListAsSet.end()) {
return false;
}
}
}
return true;
}



void RteModelTestConfig::compareFile(const string& newFile, const string& refFile,
const std::unordered_map<string, string>& expectedChangedFlags, const string& toolchain) const {
ifstream streamNewFile, streamRefFile;
Expand Down
4 changes: 4 additions & 0 deletions libs/rtemodel/test/src/RteModelTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <string>
#include <unordered_map>

#include "RteDevice.h"

class RteModelTestConfig : public ::testing::Test
{
public:
Expand All @@ -26,6 +28,8 @@ class RteModelTestConfig : public ::testing::Test
void compareFile(const std::string& newFile, const std::string& refFile,
const std::unordered_map<std::string, std::string>& expectedChangedFlags, const std::string& toolchain) const;

static bool IsSubset(const RteDevicePropertyMap& subset, const RteDevicePropertyMap& superset);

protected:
void SetUp() override;
void TearDown() override;
Expand Down
Loading
Loading