Skip to content

Commit 331b229

Browse files
PackChk should not report .cc as invalid C++ extension (#1121) (#1950)
* PackChk should not report .cc as invalid C++ extension: SDCMSIS-1306 * Added test * Added Destroy() to ErrLog class --------- Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent 2d97e20 commit 331b229

File tree

9 files changed

+114
-22
lines changed

9 files changed

+114
-22
lines changed

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
@@ -793,7 +793,7 @@ bool CheckFiles::CheckFileExtension(RteItem* item)
793793
}
794794
}
795795
else if(category == "sourceCpp") {
796-
if(_stricmp(extension.c_str(), "cpp")) {
796+
if(_stricmp(extension.c_str(), "cpp") && _stricmp(extension.c_str(), "cc") && _stricmp(extension.c_str(), "cxx")) {
797797
LogMsg("M337", VAL("CAT", category), PATH(name), EXT(extension), lineNo);
798798
ok = false;
799799
}
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: 59 additions & 20 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

@@ -796,7 +807,7 @@ TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
796807
argv[2] = (char *)"--disable-validation";
797808

798809
PackChk packChk;
799-
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
810+
EXPECT_EQ(1, packChk.Check(3, argv, nullptr));
800811

801812
auto errMsgs = ErrLog::Get()->GetLogMessages();
802813
int M357_foundCnt = 0;
@@ -863,7 +874,7 @@ TEST_F(PackChkIntegTests, CheckBoardMountedCompatibleDevices) {
863874
argv[0] = (char*)"";
864875
argv[1] = (char*)pdscFile.c_str();
865876
argv[2] = (char*)"-i";
866-
argv[3] = (char*)pdscFile.c_str();
877+
argv[3] = (char*)pdscFileAdd.c_str();
867878
argv[4] = (char*)"--disable-validation";
868879

869880
PackChk packChk;
@@ -891,36 +902,30 @@ TEST_F(PackChkIntegTests, CheckBoardMountedCompatibleDevices) {
891902
}
892903
}
893904

894-
TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
895-
const char* argv[5];
905+
TEST_F(PackChkIntegTests, CheckSupportCcFiles) {
906+
const char* argv[3];
896907

897-
const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
898-
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
899-
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
900-
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
908+
string pdscFile = PackChkIntegTestEnv::localtestdata_dir +
909+
"/SupportCcFiles/TestVendor.SupportCcFiles_DFP.pdsc";
901910
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
902-
ASSERT_TRUE(RteFsUtils::Exists(refFile));
903911

904912
argv[0] = (char*)"";
905913
argv[1] = (char*)pdscFile.c_str();
906-
argv[2] = (char*)"-x";
907-
argv[3] = (char*)"!M317";
908-
argv[4] = (char*)"--disable-validation";
914+
argv[2] = (char*)"--disable-validation";
909915

910916
PackChk packChk;
911-
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));
917+
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
912918

913919
auto errMsgs = ErrLog::Get()->GetLogMessages();
914-
int M317_foundCnt = 0;
920+
int M337_foundCnt = 0;
915921
for (const string& msg : errMsgs) {
916-
size_t s;
917-
if ((s = msg.find("M317", 0)) != string::npos) {
918-
M317_foundCnt++;
922+
if (msg.find("M337", 0) != string::npos) {
923+
M337_foundCnt++;
919924
}
920925
}
921926

922-
if(M317_foundCnt != 4) {
923-
FAIL() << "error: warning M317 count != 4";
927+
if(!M337_foundCnt) {
928+
FAIL() << "error: Missing message M337: File with category 'sourceCpp' has wrong extension 'ccc': 'Files/fileWillFail.ccc'";
924929
}
925930
}
926931

@@ -958,3 +963,37 @@ TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Pos) {
958963
FAIL() << "error: warning M317 found";
959964
}
960965
}
966+
967+
TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
968+
const char* argv[5];
969+
970+
const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
971+
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
972+
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
973+
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
974+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
975+
ASSERT_TRUE(RteFsUtils::Exists(refFile));
976+
977+
argv[0] = (char*)"";
978+
argv[1] = (char*)pdscFile.c_str();
979+
argv[2] = (char*)"-x";
980+
argv[3] = (char*)"!M317";
981+
argv[4] = (char*)"--disable-validation";
982+
983+
PackChk packChk;
984+
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));
985+
986+
auto errMsgs = ErrLog::Get()->GetLogMessages();
987+
int M317_foundCnt = 0;
988+
for (const string& msg : errMsgs) {
989+
size_t s;
990+
if ((s = msg.find("M317", 0)) != string::npos) {
991+
M317_foundCnt++;
992+
}
993+
}
994+
995+
if(M317_foundCnt != 4) {
996+
FAIL() << "error: warning M317 count != 4";
997+
}
998+
}
999+

0 commit comments

Comments
 (0)