Skip to content

Commit eda99da

Browse files
authored
[csolution-rpc] Tolerate component selection errors
1 parent 697f1ff commit eda99da

File tree

11 files changed

+130
-7
lines changed

11 files changed

+130
-7
lines changed

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,12 @@ class ProjMgrWorker {
704704
*/
705705
void SetUpCommand(bool isSetup);
706706

707+
/**
708+
* @brief set flag when running in rpc mode
709+
* @param boolean rpcMode
710+
*/
711+
void RpcMode(bool rpcMode);
712+
707713
/**
708714
* @brief set yaml emitter
709715
* @param pointer to yaml emitter
@@ -961,6 +967,7 @@ class ProjMgrWorker {
961967
bool m_relativePaths;
962968
bool m_cbuild2cmake;
963969
bool m_isSetupCommand;
970+
bool m_rpcMode = false;
964971
std::set<std::string> m_undefLayerVars;
965972
StrMap m_packMetadata;
966973
std::map<std::string, ExecutesItem> m_executes;

tools/projmgr/src/ProjMgr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ int ProjMgr::ProcessCommands() {
424424
} else if (m_command == "rpc") {
425425
// Launch 'rpc' server over stdin/stdout
426426
ProjMgrLogger::m_silent = true;
427+
m_worker.RpcMode(true);
427428
if (!m_rpcServer.Run()) {
428429
return ErrorCode::ERROR;
429430
}

tools/projmgr/src/ProjMgrRpcServer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ bool ProjMgrRpcServer::Run(void) {
138138

139139
// Send response
140140
if (m_contextLength) {
141-
cout << CONTENT_LENGTH_HEADER << response.size() << std::endl << std::endl;
141+
cout << CONTENT_LENGTH_HEADER << response.size() << std::endl << std::endl << response << std::flush;
142+
} else {
143+
cout << response << std::endl;
142144
}
143-
cout << response << std::flush;
144145

145146
if (m_debug) {
146147
log << response << std::endl;

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ void ProjMgrWorker::SetUpCommand(bool isSetup) {
298298
m_isSetupCommand = isSetup;
299299
}
300300

301+
void ProjMgrWorker::RpcMode(bool rpcMode) {
302+
m_rpcMode = rpcMode;
303+
}
304+
301305
void ProjMgrWorker::SetEmitter(ProjMgrYamlEmitter* emitter) {
302306
m_emitter = emitter;
303307
}
@@ -1919,6 +1923,11 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
19191923
return false;
19201924
}
19211925

1926+
// tolerate component selection errors when in rpc mode
1927+
if (m_rpcMode) {
1928+
error = false;
1929+
}
1930+
19221931
return !error;
19231932
}
19241933

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
5+
components:
6+
- component: Startup
7+
- component: CORE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
5+
compiler: AC6
6+
7+
target-types:
8+
- type: TestHW
9+
device: RteTest_ARMCM4_NOFP
10+
11+
projects:
12+
- project: minimal.cproject.yml
13+
14+
packs:
15+
- pack: ARM::RteTest_DFP
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
5+
components:
6+
- component: Startup
7+
- component: CORE
8+
- component: ARM::UNKNOWN:COMPONENT
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
5+
compiler: AC6
6+
7+
target-types:
8+
- type: TestHW
9+
device: RteTest_ARMCM4_NOFP
10+
11+
projects:
12+
- project: unknown-component.cproject.yml
13+
14+
packs:
15+
- pack: ARM::RteTest_DFP

tools/projmgr/test/src/ProjMgrRpcTests.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,76 @@
88
#include "ProjMgrTestEnv.h"
99
#include "ProjMgrRpcServer.h"
1010
#include "ProjMgrRpcServerData.h"
11-
12-
1311
#include "ProjMgrLogger.h"
1412

13+
#include "ProductInfo.h"
1514

1615
using namespace std;
1716

1817
class ProjMgrRpcTests : public ProjMgr, public ::testing::Test {
1918
protected:
2019
ProjMgrRpcTests() {}
2120
virtual ~ProjMgrRpcTests() {}
21+
string FormatRequest(const int id, const string& method, const json& params);
22+
vector<json> RunRpcMethods(const string& strIn);
2223
};
2324

24-
TEST_F(ProjMgrRpcTests, Load_Solution) {
25+
string ProjMgrRpcTests::FormatRequest(const int id, const string& method, const json& params = json()) {
26+
json request;
27+
request["jsonrpc"] = "2.0";
28+
request["id"] = id;
29+
request["method"] = method;
30+
if (!params.is_null()) {
31+
request["params"] = params;
32+
}
33+
return request.dump();
34+
}
35+
36+
vector<json> ProjMgrRpcTests::RunRpcMethods(const string& strIn) {
37+
StdStreamRedirect streamRedirect;
38+
streamRedirect.SetInString(strIn);
39+
char* argv[] = { (char*)"csolution", (char*)"rpc" };
40+
EXPECT_EQ(0, RunProjMgr(2, argv, 0));
41+
string line;
42+
vector<json> responses;
43+
istringstream iss(streamRedirect.GetOutString());
44+
while (getline(iss, line)) {
45+
responses.push_back(json::parse(line));
46+
}
47+
return responses;
48+
}
2549

50+
TEST_F(ProjMgrRpcTests, RpcGetVersion) {
51+
const auto& requests = FormatRequest(1, "GetVersion");
52+
const auto& responses = RunRpcMethods(requests);
53+
EXPECT_EQ("2.0", responses[0]["jsonrpc"]);
54+
EXPECT_EQ(1, responses[0]["id"]);
55+
EXPECT_EQ(string(VERSION_STRING), responses[0]["result"]);
56+
}
57+
58+
TEST_F(ProjMgrRpcTests, RpcLoadSolution) {
59+
const string& csolution = testinput_folder + "/TestRpc/minimal.csolution.yml";
60+
const auto& requests =
61+
FormatRequest(1, "LoadPacks") +
62+
FormatRequest(2, "LoadSolution", json({{ "solution", csolution }}));
63+
64+
const auto& responses = RunRpcMethods(requests);
65+
EXPECT_TRUE(responses[0]["result"]);
66+
EXPECT_TRUE(responses[1]["result"]);
67+
}
2668

69+
TEST_F(ProjMgrRpcTests, RpcLoadSolution_UnknownComponent) {
70+
const string& csolution = testinput_folder + "/TestRpc/unknown-component.csolution.yml";
71+
const auto& requests =
72+
FormatRequest(1, "LoadPacks") +
73+
FormatRequest(2, "LoadSolution", json({ { "solution", csolution } })) +
74+
FormatRequest(3, "GetLogMessages");
2775

76+
const auto& responses = RunRpcMethods(requests);
77+
EXPECT_TRUE(responses[0]["result"]);
78+
EXPECT_TRUE(responses[1]["result"]);
79+
EXPECT_EQ("no component was found with identifier 'ARM::UNKNOWN:COMPONENT'",
80+
responses[2]["result"]["errors"][0]);
2881
}
2982

3083
// end of ProjMgrRpcTests.cpp

tools/projmgr/test/src/ProjMgrTestEnv.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -44,6 +44,11 @@ void StdStreamRedirect::ClearStringStreams() {
4444
m_cerrbuffer.str(string());
4545
}
4646

47+
void StdStreamRedirect::SetInString(const std::string& inStr) {
48+
m_inputBuffer = std::istringstream(inStr);
49+
std::cin.rdbuf(m_inputBuffer.rdbuf());
50+
}
51+
4752
StdStreamRedirect::~StdStreamRedirect() {
4853
// reverse redirect
4954
std::cout.rdbuf(m_stdoutStreamBuf);

0 commit comments

Comments
 (0)