Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions libs/rtemodel/src/RteKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,7 @@ bool RteKernel::LoadAndInsertPacks(std::list<RtePackage*>& packs, std::list<std:
if(!pack) {
return false;
}
// pack with explicit path must override installed pack
auto loadedPack = RtePackage::GetPackFromList(pack->GetID(), packs);
if(!loadedPack || (loadedPack->GetPackageState() == PS_INSTALLED && pack->GetPackageState() == PS_EXPLICIT_PATH)) {
newPacks.push_back(pack);
}
newPacks.push_back(pack);
}
globalModel->InsertPacks(newPacks);

Expand Down
12 changes: 2 additions & 10 deletions libs/rtemodel/src/RteModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,9 @@ void RteModel::InsertPack(RtePackage* package)
}
auto state = package->GetPackageState();
if(insertedPack->GetPackageState() == state) {
string pdscPath = RteFsUtils::MakePathCanonical(package->GetAbsolutePackagePath());
if(pdscPath.find(m_rtePath) == 0) { // regular installed pack => error
// duplicate, kept it in a temporary collection till validate;
m_packageDuplicates.push_back(package);
return;
}
string insertedPdscPath = RteFsUtils::MakePathCanonical(insertedPack->GetAbsolutePackagePath());
if(insertedPdscPath.find(m_rtePath) == string::npos) { // inserted pack is also from outside => error
m_packageDuplicates.push_back(package);
return;
}
m_packageDuplicates.push_back(package);
return;
} else if(state != PS_EXPLICIT_PATH) {
return; // pack with explicit path must override installed pack
}
Expand Down
2 changes: 1 addition & 1 deletion libs/rtemodel/src/RtePackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ bool RtePackRegistry::PurgePacks() {
set<string> toErase;
// collect packs that no longer exist
for(auto& [pdscFile, pack] : m_loadedPacks) {
if(!pack || !pack->Exists()) {
if(!pack || pack->GetPackageState() == PackageState::PS_EXPLICIT_PATH || !pack->Exists()) {
toErase.insert(pdscFile);
}
Comment thread
edriouk marked this conversation as resolved.
Outdated
}
Expand Down
13 changes: 11 additions & 2 deletions tools/projmgr/src/ProjMgrRpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,17 @@ RpcArgs::SuccessResult RpcHandler::LoadSolution(const string& solution, const st
m_bUseAllPacks = false; // loading solution will first use only listed packs
m_packReferences.clear(); // will be updated
m_solutionLoaded = false; // assume not loaded yet
// clear only projects, global RTE data and packs stay loaded
ProjMgrKernel::Get()->GetGlobalModel()->ClearProjects();
auto globalModel = ProjMgrKernel::Get()->GetGlobalModel();
// remove non-existing and explicit packs
bool purged = globalModel->GetPackRegistry()->PurgePacks();
if(purged) {
// clear project AND global RTE data, packs stay loaded
globalModel->Clear();
} else {
// clear only projects, global RTE data and packs stay loaded
globalModel->ClearProjects();
Comment thread
Copilot marked this conversation as resolved.
}

RpcArgs::SuccessResult result = {false};
const auto csolutionFile = RteFsUtils::MakePathCanonical(solution);
if(!regex_match(csolutionFile, regex(".*\\.csolution\\.(yml|yaml)"))) {
Expand Down
2 changes: 1 addition & 1 deletion tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ bool ProjMgrWorker::LoadAllRelevantPacks() {
return false;
}
// Get installed packs
if (pdscFiles.empty() || (m_loadPacksPolicy == LoadPacksPolicy::ALL) || (m_loadPacksPolicy == LoadPacksPolicy::LATEST)) {
if (m_rpcMode || pdscFiles.empty() || (m_loadPacksPolicy == LoadPacksPolicy::ALL) || (m_loadPacksPolicy == LoadPacksPolicy::LATEST)) {
const bool latest = (m_loadPacksPolicy == LoadPacksPolicy::LATEST) || (m_loadPacksPolicy == LoadPacksPolicy::DEFAULT);
if (!m_kernel->GetEffectivePdscFiles(pdscFiles, latest)) {
ProjMgrLogger::Get().Error("parsing installed packs failed");
Expand Down
165 changes: 98 additions & 67 deletions tools/projmgr/test/src/ProjMgrRpcTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ class ProjMgrRpcTests : public ProjMgr, public ::testing::Test {

string CreateLoadRequests(const string& solution,
const string& activeTarget = RteUtils::EMPTY_STRING,
const vector<string>& contextList = RteUtils::EMPTY_STRING_VECTOR
const vector<string>& contextList = RteUtils::EMPTY_STRING_VECTOR,
bool loadPacks = true
);

string FormatPackInfoRequests(const string& solution, const string& context, bool loadPacks);

vector<json> RunPackInfoRequests(const string& solution, const string& context, bool loadPacks);

bool CompareRpcResponse(const json& response, const string& ref);

int m_id = 0;
};

string ProjMgrRpcTests::FormatRequest(const int id, const string& method, const json& params = json()) {
Expand All @@ -50,12 +57,18 @@ string ProjMgrRpcTests::FormatRequest(const int id, const string& method, const
return request.dump();
}

string ProjMgrRpcTests::CreateLoadRequests(const string& solution, const string& activeTarget, const vector<string>& contextList)
string ProjMgrRpcTests::CreateLoadRequests(const string& solution, const string& activeTarget, const vector<string>& contextList, bool loadPacks)
{
string loadSolutionRequest;

string requests;
if(loadPacks) {
m_id = 0;
requests = FormatRequest(++m_id, "LoadPacks");
}
if(!solution.empty()) {
string loadSolutionRequest;
auto csolutionPath = testinput_folder + solution;
loadSolutionRequest = FormatRequest(2, "LoadSolution", json({{ "solution", csolutionPath }, { "activeTarget", activeTarget }}));
loadSolutionRequest = FormatRequest(++m_id, "LoadSolution", json({{ "solution", csolutionPath }, { "activeTarget", activeTarget }}));
if(!contextList.empty()) {
YAML::Node cbuildset;
cbuildset["cbuild-set"]["generated-by"] = "ProjMrgUnitTests";
Comment thread
Copilot marked this conversation as resolved.
Outdated
Expand All @@ -70,8 +83,24 @@ string ProjMgrRpcTests::CreateLoadRequests(const string& solution, const string&
cbuildsetFile << cbuildset << std::endl;
cbuildsetFile.close();
}
requests += loadSolutionRequest;
}
return FormatRequest(1, "LoadPacks") + loadSolutionRequest;
return requests;
}

string ProjMgrRpcTests::FormatPackInfoRequests(const string& solution, const string& context, bool loadPacks) {
vector<string> contextList = {
context
};
auto requests = CreateLoadRequests(solution, "", contextList, loadPacks);
requests += FormatRequest(++m_id, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(++m_id, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
requests += FormatRequest(++m_id, "GetPacksInfo", json({{ "context", context }, {"all", true}}));
return requests;
}

vector<json> ProjMgrRpcTests::RunPackInfoRequests(const string& solution, const string& context, bool loadPacks = true) {
return RunRpcMethods( FormatPackInfoRequests(solution, context, loadPacks));
}

bool ProjMgrRpcTests::CompareRpcResponse(const json& response, const string& ref) {
Expand All @@ -92,6 +121,7 @@ vector<json> ProjMgrRpcTests::RunRpcMethods(const string& strIn) {
while(getline(iss, line)) {
responses.push_back(json::parse(line));
}
m_id = 0;
return responses;
}

Expand Down Expand Up @@ -1122,7 +1152,7 @@ TEST_F(ProjMgrRpcTests, PackReferenceMissing) {
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
const auto& responses = RunRpcMethods(requests);
EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
auto packs = responses[2]["result"]["packs"];
// Verify missing field for unresolved packs
for(const auto& pack : packs) {
if(!pack.contains("resolvedPack")) {
Expand All @@ -1135,16 +1165,8 @@ TEST_F(ProjMgrRpcTests, PackReferenceMissing) {

TEST_F(ProjMgrRpcTests, RpcGetPacksInfoSimple) {
string context = "selectable+CM0";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
requests += FormatRequest(5, "GetPacksInfo", json({{ "context", context }, {"all", true}}));

const auto& responses = RunRpcMethods(requests);
const auto& responses = RunPackInfoRequests("/Validation/dependencies.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand Down Expand Up @@ -1174,16 +1196,7 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksInfoSimple) {

TEST_F(ProjMgrRpcTests, RpcGetPacksInfo) {
string context = "test1.Release+CM0";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/TestSolution/test_pack_requirements.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
requests += FormatRequest(5, "GetPacksInfo", json({{ "context", context }, {"all", true}}));

const auto& responses = RunRpcMethods(requests);
const auto& responses = RunPackInfoRequests("/TestSolution/test_pack_requirements.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand All @@ -1203,17 +1216,65 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksInfo) {
EXPECT_FALSE(packInfos[7].contains("used"));
}

TEST_F(ProjMgrRpcTests, RpcGetPacksInfoMissing) {
string context = "project+Miss";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/TestSolution/PackMissing/missing_pack.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
TEST_F(ProjMgrRpcTests, RpcGetPacksInfoPackPath) {
string context = "pack_path+CM0";

const auto& responses = RunRpcMethods(requests);
// first solution
auto requests = FormatPackInfoRequests("/TestSolution/pack_path.csolution.yml", context, true);
// second solution, same pack in a different directory
requests += FormatPackInfoRequests("/TestSolution/pack_path1.csolution.yml", context, false);

auto responses = RunRpcMethods(requests);

// first solution
auto expectedPackPath = testinput_folder + "/SolutionSpecificPack";
auto expectedDoc = testinput_folder + "/SolutionSpecificPack" + "/Doc/overview.md";

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
EXPECT_EQ(packs[0]["pack"], "ARM::RteTest_DFP");
EXPECT_EQ(packs[0]["resolvedPack"], "ARM::RteTest_DFP");
EXPECT_EQ(packs[0]["path"], expectedPackPath);
EXPECT_FALSE(packs[0].contains("upgrade"));

EXPECT_TRUE(responses[3]["result"]["success"]); // get pack infos
auto packInfos = responses[3]["result"]["packs"];
EXPECT_EQ(packInfos.size(), 1);
EXPECT_EQ(packInfos[0]["id"], "ARM::RteTest_DFP@0.2.0");
EXPECT_EQ(packInfos[0]["doc"], expectedDoc);
EXPECT_TRUE(packInfos[0]["used"]);

packInfos = responses[4]["result"]["packs"];
EXPECT_EQ(packInfos.size(), 8);

// second solution

expectedPackPath = testinput_folder + "/SolutionSpecificPack1";
expectedDoc = testinput_folder + "/SolutionSpecificPack1" + "/Doc/overview.md";

EXPECT_TRUE(responses[6]["result"]["success"]);
packs = responses[6]["result"]["packs"];
EXPECT_EQ(packs[0]["pack"], "ARM::RteTest_DFP");
EXPECT_EQ(packs[0]["resolvedPack"], "ARM::RteTest_DFP");
EXPECT_EQ(packs[0]["path"], expectedPackPath);
EXPECT_FALSE(packs[0].contains("upgrade"));

EXPECT_TRUE(responses[7]["result"]["success"]); // get pack infos
packInfos = responses[7]["result"]["packs"];
EXPECT_EQ(packInfos.size(), 1);
EXPECT_EQ(packInfos[0]["id"], "ARM::RteTest_DFP@0.2.0");
EXPECT_EQ(packInfos[0]["doc"], expectedDoc);
EXPECT_TRUE(packInfos[0]["used"]);

packInfos = responses[8]["result"]["packs"];
EXPECT_EQ(packInfos.size(), 8);
}


TEST_F(ProjMgrRpcTests, RpcGetPacksInfoMissing) {
string context = "project+Miss";
const auto& responses = RunPackInfoRequests("/TestSolution/PackMissing/missing_pack.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand All @@ -1230,8 +1291,6 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksInfoMissing) {
EXPECT_EQ(packs[3]["pack"], "ARM::RteTest_DFP");
EXPECT_EQ(packs[3]["resolvedPack"], "ARM::RteTest_DFP@0.2.0");



EXPECT_TRUE(responses[3]["result"]["success"]); // get pack infos
auto packInfos = responses[3]["result"]["packs"];
EXPECT_EQ(packInfos.size(), 4);
Expand All @@ -1242,20 +1301,9 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksInfoMissing) {
EXPECT_EQ(packInfos[3]["id"], "ARM::RteTest_DFP@0.2.0");
}



TEST_F(ProjMgrRpcTests, RpcGetPacksNotLatest) {
string context = "test1.DebugOldDfp+CM0";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/TestSolution/test_pack_requirements.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
requests += FormatRequest(5, "GetPacksInfo", json({{ "context", context }, {"all", true}}));

const auto& responses = RunRpcMethods(requests);
const auto& responses = RunPackInfoRequests("/TestSolution/test_pack_requirements.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand Down Expand Up @@ -1293,16 +1341,7 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksNotLatest) {

TEST_F(ProjMgrRpcTests, RpcGetPacksInfoLayer) {
string context = "packs.CompatibleLayers+RteTest_ARMCM3";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/TestLayers/packs.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));
requests += FormatRequest(5, "GetPacksInfo", json({{ "context", context }, {"all", true}}));

const auto& responses = RunRpcMethods(requests);
const auto& responses = RunPackInfoRequests("/TestLayers/packs.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand All @@ -1329,15 +1368,7 @@ TEST_F(ProjMgrRpcTests, RpcGetPacksInfoLayer) {

TEST_F(ProjMgrRpcTests, RpcGetPacksInfoLocal) {
string context = "incompatible.Debug+CM0";
vector<string> contextList = {
context
};

auto requests = CreateLoadRequests("/TestSolution/PackRequirements/incompatible.csolution.yml", "", contextList);
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
requests += FormatRequest(4, "GetPacksInfo", json({{ "context", context }, {"all", false}}));

const auto& responses = RunRpcMethods(requests);
const auto& responses = RunPackInfoRequests("/TestSolution/PackRequirements/incompatible.csolution.yml", context);

EXPECT_TRUE(responses[2]["result"]["success"]);
auto packs = responses[2]["result"]["packs"];
Expand Down
11 changes: 10 additions & 1 deletion tools/projmgr/test/src/ProjMgrTestEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ void ProjMgrTestEnv::SetUp() {
}
RteFsUtils::CreateDirectories(destPackPath);
fs::copy(fs::path(srcPackPath), fs::path(destPackPath), fs::copy_options::recursive, ec);

destPackPath = testinput_folder + "/SolutionSpecificPack1";
if (RteFsUtils::Exists(destPackPath)) {
RteFsUtils::RemoveDir(destPackPath);
}
RteFsUtils::CreateDirectories(destPackPath);
fs::copy(fs::path(srcPackPath), fs::path(destPackPath), fs::copy_options::recursive, ec);


srcPackPath = testcmsispack_folder + "/ARM/RteTest/0.1.0";
destPackPath = testinput_folder + "/SolutionSpecificPack2";
if (RteFsUtils::Exists(destPackPath)) {
Expand Down Expand Up @@ -243,7 +252,7 @@ std::map<std::string, std::string, RtePackageComparator> ProjMgrTestEnv::GetEffe
rteKernel.SetCmsisPackRoot(GetCmsisPackRoot());
std::list<std::string> pdscFiles;
std::list<RtePackage*> packs;
rteKernel.GetEffectivePdscFiles(pdscFiles, bLatestsOnly);
rteKernel.GetEffectivePdscFiles(pdscFiles, bLatestsOnly);
rteKernel.LoadAndInsertPacks(packs, pdscFiles);
for (const auto& pack : packs) {
pdscMap[pack->GetID()] = pack->GetPackageFileName();
Expand Down
Loading