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
6 changes: 3 additions & 3 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@
"SetupType": {
"type": "object",
"properties": {
"setup": {
"setup": {
"title": "setup:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#setups",
"type": "string",
"description": "Description of the setup."
Expand Down Expand Up @@ -1773,7 +1773,7 @@
"undefine": { "$ref": "#/definitions/UndefinesType" },
"warnings": { "$ref": "#/definitions/WarningsType" }
},
"oneOf": [
"allOf": [
{ "$ref": "#/definitions/TypeListMutualExclusion" }
],
"additionalProperties": false
Expand Down Expand Up @@ -1851,7 +1851,7 @@
"not-for-context": { "$ref": "#/definitions/NotForContext" },
"for-compiler": { "$ref": "#/definitions/CompilersType" }
},
"oneOf": [
"allOf": [
{ "$ref": "#/definitions/TypeListMutualExclusion" }
],
"additionalProperties": false
Expand Down
131 changes: 130 additions & 1 deletion tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 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 @@ -408,6 +408,135 @@ vector<ErrInfo> expectedErrPos = {
}
}

TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Setup_Linker) {
typedef std::pair<int, int> ErrInfo;

// only for-context
const char* valid_setup_schema_Ex1 = "\
project:\n\
setups:\n\
- setup: debug Setup\n\
for-context: +Debug\n\
define:\n\
- TEST: 1\n\
";

//only not-for-context
const char* valid_setup_schema_Ex2 = "\
project:\n\
setups:\n\
- setup: Release Setup\n\
not-for-context: +Release\n\
optimize: speed\n\
";

// neither for-context not not-for-context present
const char* valid_setup_schema_Ex3 = "\
project:\n\
setups:\n\
- setup: test\n\
misc:\n\
- Link:\n\
- --verbose\n\
";

// both for-context and not-for-context
const char* invalid_setup_schema_Ex1 = "\
project:\n\
setups:\n\
- setup: test\n\
for-context: +Debug\n\
not-for-context: +Release\n\
";

// No setup string
const char* invalid_setup_schema_Ex2 = "\
project:\n\
setups:\n\
- setup:\n\
for-context: +Debug\n\
";

const char* valid_linker_schema_Ex1 = "\
project:\n\
linker:\n\
- script: MyLinker.scf.src\n\
for-context: +Debug\n\
";

const char* valid_linker_schema_Ex2 = "\
project:\n\
linker:\n\
- script: MyLinker.scf.src\n\
not-for-context: +Debug\n\
";

const char* valid_linker_schema_Ex3 = "\
project:\n\
linker:\n\
- script: MyLinker.scf.src\n\
for-compiler: AC6\n\
- script: MyLinker.ld\n\
for-compiler: CLANG\n\
";

const char* invalid_linker_schema_Ex1 = "\
project:\n\
linker:\n\
- script: MyLinker.scf.src\n\
for-context: +Debug\n\
not-for-context: +Release\n\
";

const char* invalid_linker_schema_Ex2 = "\
project:\n\
linker:\n\
- script: MyLinker.scf.src\n\
for-context: +Debug\n\
invalid: 1\n\
";

vector<std::tuple<const char*, bool, vector<ErrInfo>>> vecTestData = {
// data, expectedRetVal, errorPos
{ valid_setup_schema_Ex1, true, vector<ErrInfo>{ } },
{ valid_setup_schema_Ex2, true, vector<ErrInfo>{ } },
{ valid_setup_schema_Ex3, true, vector<ErrInfo>{ } },
{ invalid_setup_schema_Ex1, false, vector<ErrInfo>{ {3,7} } },
{ invalid_setup_schema_Ex2, false, vector<ErrInfo>{ {3,7} } },
{ valid_linker_schema_Ex1, true, vector<ErrInfo>{ } },
{ valid_linker_schema_Ex2, true, vector<ErrInfo>{ } },
{ valid_linker_schema_Ex3, true, vector<ErrInfo>{ } },
{ invalid_linker_schema_Ex1, false, vector<ErrInfo>{ {3,7} } },
{ invalid_linker_schema_Ex2, false, vector<ErrInfo>{ {5,7} } }
};

auto writeFile = [](const string& filePath, const char* data) {
ofstream fileStream(filePath);
fileStream << data;
fileStream << endl;
fileStream << flush;
fileStream.close();
};

const string& filename = testoutput_folder +
"/test_schema_validation.cproject.yml";
for (auto [data, expectRetVal, errorPos] : vecTestData) {
writeFile(filename, data);
EXPECT_EQ(expectRetVal, Validate(filename)) << "failed for: " << data;

// Check errors
auto errList = GetErrors();
EXPECT_EQ(errList.size(), expectRetVal ? 0 : errorPos.size()) << "failed for: " << data;
for (auto& err : errList) {
auto errItr = find_if(errorPos.begin(), errorPos.end(),
[&](const std::pair<int, int>& errPos) {
return err.m_line == errPos.first && err.m_col == errPos.second;
});
EXPECT_TRUE(errorPos.end() != errItr) << "failed for: " << data;
}
}
}

TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_define) {
vector<std::pair<int, int>> expectedErrPos = {
// line, col
Expand Down
Loading