Skip to content

Commit acb64ed

Browse files
PackChk should not report .cc as invalid C++ extension (#1121)
* PackChk should not report .cc as invalid C++ extension: SDCMSIS-1306 * Added test * Added Destroy() to ErrLog class
1 parent c56c2cf commit acb64ed

File tree

10 files changed

+111
-22
lines changed

10 files changed

+111
-22
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@
2020
*.opendb
2121
.vscode
2222
/build*/
23-
**/cmake-*
23+
**/cmake-*
24+
/.cache
25+
/tools/projmgr/test
26+
/tools/projmgr/test
27+
tools/svdconv/CMakeCache.txt
28+
tools/svdconv/CMakeFiles/cmake.check_cache

libs/errlog/include/ErrLog.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ class ErrLog {
197197
return theErrLog;
198198
}
199199

200+
/**
201+
* @brief singleton operation: destroys global application object
202+
*/
203+
static void Destroy() {
204+
if (theErrLog) {
205+
delete theErrLog;
206+
theErrLog = nullptr;
207+
}
208+
}
209+
200210
public:
201211
/**
202212
* @brief empty messages buffer
@@ -517,7 +527,6 @@ class ErrLog {
517527
~ErrLogDestroyer() { ErrLog::Destroy(); }
518528
};
519529

520-
static void Destroy() { delete theErrLog; theErrLog = nullptr; }
521530
static ErrLogDestroyer theErrLogDestroyer;
522531
static ErrLog* theErrLog; // the application-wide ErrLog Object
523532

tools/packchk/src/CheckFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ bool CheckFiles::CheckFileExtension(RteItem* item)
787787
}
788788
}
789789
else if(category == "sourceCpp") {
790-
if(_stricmp(extension.c_str(), "cpp")) {
790+
if(_stricmp(extension.c_str(), "cpp") && _stricmp(extension.c_str(), "cc") && _stricmp(extension.c_str(), "cxx")) {
791791
LogMsg("M337", VAL("CAT", category), PATH(name), EXT(extension), lineNo);
792792
ok = false;
793793
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tests1.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//header 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tests1.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tests1.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tests1.c
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<vendor>TestVendor</vendor>
5+
<url>http://www.testurl.com/pack/</url>
6+
<name>SupportCcFiles_DFP</name>
7+
<description>Filename is directory</description>
8+
9+
<releases>
10+
<release version="0.0.1" date="2025-02-03">>
11+
Initial release of SupportCcFiles.
12+
</release>
13+
</releases>
14+
15+
<keywords>
16+
<keyword>SupportCcFiles</keyword>
17+
</keywords>
18+
19+
<conditions>
20+
<condition id="Test_Condition">
21+
<description>Test Device</description>
22+
<require Dvendor="ARM:82"/>
23+
</condition>
24+
</conditions>
25+
26+
<components>
27+
<component Cclass="TestClass" Cgroup="TestFiles" Cversion="1.0.0" condition="Test_Condition">
28+
<description>Test files</description>
29+
<files>
30+
<file category="TestGlobal" name="Files/header1.h"/>
31+
<file category="source" name="Files/test1.c"/>
32+
<file category="sourceC" name="Files/test1.c"/>
33+
<file category="sourceCpp" name="Files/test1.cpp"/>
34+
<file category="sourceCpp" name="Files/test1.cc"/>
35+
<file category="sourceCpp" name="Files/fileWillFail.ccc"/>
36+
</files>
37+
</component>
38+
</components>
39+
</package>

tools/packchk/test/integtests/src/PackChkIntegTests.cpp

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void PackChkIntegTests::SetUp() {
2727
}
2828

2929
void PackChkIntegTests::TearDown() {
30-
ErrLog::Get()->ClearLogMessages();
30+
ErrLog::Get()->Destroy();
3131
}
3232

3333
string PackChkIntegTests::GetPackXsd() {
@@ -80,6 +80,17 @@ TEST_F(PackChkIntegTests, FileNotAVailable) {
8080
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
8181
}
8282

83+
TEST_F(PackChkIntegTests, FileNotAVailable2) {
84+
const char* argv[2];
85+
86+
argv[0] = (char*)"";
87+
argv[1] = (char*)"UNKNOWN.FILE.pdsc";
88+
89+
PackChk packChk;
90+
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
91+
}
92+
93+
8394
TEST_F(PackChkIntegTests, VersionOption) {
8495
const char* argv[2];
8596

@@ -790,37 +801,30 @@ TEST_F(PackChkIntegTests, CheckSchemaValidation) {
790801
}
791802
}
792803

804+
TEST_F(PackChkIntegTests, CheckSupportCcFiles) {
805+
const char* argv[3];
793806

794-
TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
795-
const char* argv[5];
796-
797-
const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
798-
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
799-
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
800-
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
807+
string pdscFile = PackChkIntegTestEnv::localtestdata_dir +
808+
"/SupportCcFiles/TestVendor.SupportCcFiles_DFP.pdsc";
801809
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
802-
ASSERT_TRUE(RteFsUtils::Exists(refFile));
803810

804811
argv[0] = (char*)"";
805812
argv[1] = (char*)pdscFile.c_str();
806-
argv[2] = (char*)"-x";
807-
argv[3] = (char*)"!M317";
808-
argv[4] = (char*)"--disable-validation";
813+
argv[2] = (char*)"--disable-validation";
809814

810815
PackChk packChk;
811-
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));
816+
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
812817

813818
auto errMsgs = ErrLog::Get()->GetLogMessages();
814-
int M317_foundCnt = 0;
819+
int M337_foundCnt = 0;
815820
for (const string& msg : errMsgs) {
816-
size_t s;
817-
if ((s = msg.find("M317", 0)) != string::npos) {
818-
M317_foundCnt++;
821+
if (msg.find("M337", 0) != string::npos) {
822+
M337_foundCnt++;
819823
}
820824
}
821825

822-
if(M317_foundCnt != 4) {
823-
FAIL() << "error: warning M317 count != 4";
826+
if(!M337_foundCnt) {
827+
FAIL() << "error: Missing message M337: File with category 'sourceCpp' has wrong extension 'ccc': 'Files/fileWillFail.ccc'";
824828
}
825829
}
826830

@@ -859,8 +863,35 @@ TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Pos) {
859863
}
860864
}
861865

866+
TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
867+
const char* argv[5];
862868

869+
const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
870+
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
871+
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
872+
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
873+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
874+
ASSERT_TRUE(RteFsUtils::Exists(refFile));
863875

876+
argv[0] = (char*)"";
877+
argv[1] = (char*)pdscFile.c_str();
878+
argv[2] = (char*)"-x";
879+
argv[3] = (char*)"!M317";
880+
argv[4] = (char*)"--disable-validation";
864881

882+
PackChk packChk;
883+
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));
865884

885+
auto errMsgs = ErrLog::Get()->GetLogMessages();
886+
int M317_foundCnt = 0;
887+
for (const string& msg : errMsgs) {
888+
size_t s;
889+
if ((s = msg.find("M317", 0)) != string::npos) {
890+
M317_foundCnt++;
891+
}
892+
}
866893

894+
if(M317_foundCnt != 4) {
895+
FAIL() << "error: warning M317 count != 4";
896+
}
897+
}

0 commit comments

Comments
 (0)