Skip to content

Commit

Permalink
[projmgr] Rework board mounted devices check (#1033) (#1773)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Brondani <daniel.brondani@arm.com>
  • Loading branch information
grasci-arm and brondani authored Sep 13, 2024
1 parent edef0a9 commit f0da951
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 50 deletions.
65 changes: 36 additions & 29 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ bool ProjMgrWorker::ProcessDevice(ContextItem& context) {
}

RteDeviceItem* matchedBoardDevice = nullptr;
Collection<RteItem*> mountedDevices;
if(!context.board.empty()) {
BoardItem boardItem;
GetBoardItem(context.board, boardItem);
Expand Down Expand Up @@ -1275,38 +1276,31 @@ bool ProjMgrWorker::ProcessDevice(ContextItem& context) {
context.targetAttributes["Bversion"] = matchedBoard->GetRevision(); // deprecated

// find device from the matched board
Collection<RteItem*> mountedDevices;
matchedBoard->GetMountedDevices(mountedDevices);
if (mountedDevices.size() > 1) {
ProjMgrLogger::Get().Error("found multiple mounted devices", context.name);
string msg = "one of the following devices must be specified:";
if (mountedDevices.size() > 1 && deviceItem.name.empty()) {
string msg = "found multiple mounted devices, one of the following must be specified:";
for (const auto& device : mountedDevices) {
msg += "\n" + device->GetDeviceName();
}
ProjMgrLogger::Get().Error(msg, context.name);
return false;
}
else if (mountedDevices.size() == 0) {
} else if (mountedDevices.size() == 0) {
ProjMgrLogger::Get().Error("found no mounted device", context.name);
return false;
} else if (mountedDevices.size() == 1) {
auto mountedDevice = mountedDevices.front();
auto device = context.rteFilteredModel->GetDevice(mountedDevice->GetDeviceName(), mountedDevice->GetDeviceVendor());
if (!device) {
ProjMgrLogger::Get().Error("board mounted device " + mountedDevice->GetFullDeviceName() + " not found", context.name);
return false;
}
matchedBoardDevice = device;
}

auto mountedDevice = *(mountedDevices.begin());
auto device = context.rteFilteredModel->GetDevice(mountedDevice->GetDeviceName(), mountedDevice->GetDeviceVendor());
if (!device) {
ProjMgrLogger::Get().Error("board mounted device " + mountedDevice->GetFullDeviceName() + " not found", context.name);
return false;
}
matchedBoardDevice = device;
}

// find specified device
RteDeviceItem* matchedDevice = nullptr;
if (deviceItem.name.empty()) {
matchedDevice = matchedBoardDevice;
const string& variantName = matchedBoardDevice->GetDeviceVariantName();
const string& selectableDevice = variantName.empty() ? matchedBoardDevice->GetDeviceName() : variantName;
context.device = GetDeviceInfoString("", selectableDevice, deviceItem.pname);
} else {
if (!deviceItem.name.empty()) {
list<RteDevice*> devices;
context.rteFilteredModel->GetDevices(devices, "", "", RteDeviceItem::VARIANT);
list<RteDeviceItem*> matchedDevices;
Expand All @@ -1330,6 +1324,28 @@ bool ProjMgrWorker::ProcessDevice(ContextItem& context) {
}
}

// check board mounted devices
if (matchedDevice && mountedDevices.size() > 0) {
bool match = false;
for (const auto& mountedDevice : mountedDevices) {
if (mountedDevice->GetFullDeviceName() == matchedDevice->GetFullDeviceName()) {
match = true;
break;
}
}
if (!match) {
ProjMgrLogger::Get().Warn("specified device '" + matchedDevice->GetFullDeviceName() + "' is not among board mounted devices", context.name);
}
}

// set device = board mounted device
if (!matchedDevice && matchedBoardDevice) {
matchedDevice = matchedBoardDevice;
const string& variantName = matchedBoardDevice->GetDeviceVariantName();
const string& selectableDevice = variantName.empty() ? matchedBoardDevice->GetDeviceName() : variantName;
context.device = GetDeviceInfoString("", selectableDevice, deviceItem.pname);
}

// check device variants
if (matchedDevice->GetDeviceItemCount() > 0) {
ProjMgrLogger::Get().Error("found multiple device variants", context.name);
Expand All @@ -1341,15 +1357,6 @@ bool ProjMgrWorker::ProcessDevice(ContextItem& context) {
return false;
}

if (matchedBoardDevice && (matchedBoardDevice != matchedDevice)) {
const string DeviceInfoString = matchedDevice->GetFullDeviceName();
const string BoardDeviceInfoString = matchedBoardDevice->GetFullDeviceName();
if (DeviceInfoString.find(BoardDeviceInfoString) == string::npos) {
ProjMgrLogger::Get().Warn("specified device '" + DeviceInfoString + "' and board mounted device '" +
BoardDeviceInfoString + "' are different", context.name);
}
}

// check device processors
const auto& processor = matchedDevice->GetProcessor(deviceItem.pname);
if (!processor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json

project:
description: Project 1
board: Keil::RteTest Test board
compiler: AC6@>=6.18.0
processor:
trustzone: non-secure

components:
- component: Startup
- component: CORE
groups:
- group: Sources
files:
- file: main.c
19 changes: 19 additions & 0 deletions tools/projmgr/test/data/TestSolution/board-devices.csolution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:

compiler: AC6

target-types:
- type: Only_Board
board: RteTest Test board

- type: Board_And_Device
board: RteTest Test board
device: RteTest_ARMCM0_Dual:cm0_core1

projects:
- project: board-devices.cproject.yml

packs:
- pack: ARM::RteTest_DFP
30 changes: 18 additions & 12 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3024,21 +3024,27 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_Correct_Device_Wrong_Board_Info) {
}

TEST_F(ProjMgrUnitTests, RunProjMgr_Board_Multi_Mounted_Devices) {
// Test Project with only board info and multiple mounted devices
char* argv[7];
string csolutionFile = UpdateTestSolutionFile("./TestProject4/test_board_multi_mounted_device.cproject.yml");
const string& expected = "found multiple mounted devices";
// Test Project with board with multiple mounted devices
char* argv[8];
const string& csolution = testinput_folder + "/TestSolution/board-devices.csolution.yml";
StdStreamRedirect streamRedirect;

argv[1] = (char*)"convert";
argv[2] = (char*)"--solution";
argv[3] = (char*)csolutionFile.c_str();
argv[4] = (char*)"-o";
argv[5] = (char*)testoutput_folder.c_str();
argv[6] = (char*)"--cbuildgen";
EXPECT_EQ(1, RunProjMgr(7, argv, 0));
argv[2] = (char*)csolution.c_str();
argv[3] = (char*)"-o";
argv[4] = (char*)testoutput_folder.c_str();
argv[5] = (char*)"--cbuildgen";
argv[6] = (char*)"-c";

// test with only 'board' specified
argv[7] = (char*)"+Only_Board";
EXPECT_EQ(1, RunProjMgr(8, argv, 0));
auto errStr = streamRedirect.GetErrorString();
EXPECT_NE(string::npos, errStr.find(expected));
EXPECT_NE(string::npos, errStr.find("error csolution: found multiple mounted devices, one of the following must be specified:\nRteTest_ARMCM3\nRteTest_ARMCM0_Dual"));

// test with 'board' and 'device' specified
argv[7] = (char*)"+Board_And_Device";
EXPECT_EQ(0, RunProjMgr(8, argv, 0));
}

TEST_F(ProjMgrUnitTests, RunProjMgr_Board_Device_Variant) {
Expand Down Expand Up @@ -3109,7 +3115,7 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_Board_Device_Info) {
// Test Project with board mounted device different than selected devices
char* argv[7];
string csolutionFile = UpdateTestSolutionFile("./TestProject4/test_mounted_device_differs_selected_device.cproject.yml");
const string& expected = "warning csolution: specified device 'RteTest_ARMCM0' and board mounted device 'RteTest_ARMCM0_Dual' are different";
const string& expected = "warning csolution: specified device 'RteTest_ARMCM0' is not among board mounted devices";
StdStreamRedirect streamRedirect;

argv[1] = (char*)"convert";
Expand Down

0 comments on commit f0da951

Please sign in to comment.