Skip to content

Commit

Permalink
PackChk should not report .cc as invalid C++ extension (#1121) (#1950)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
spcaipers-arm and thorstendb-ARM authored Feb 13, 2025
1 parent 2d97e20 commit 331b229
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 22 deletions.
11 changes: 10 additions & 1 deletion libs/errlog/include/ErrLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ class ErrLog {
return theErrLog;
}

/**
* @brief singleton operation: destroys global application object
*/
static void Destroy() {
if (theErrLog) {
delete theErrLog;
theErrLog = nullptr;
}
}

public:
/**
* @brief empty messages buffer
Expand Down Expand Up @@ -517,7 +527,6 @@ class ErrLog {
~ErrLogDestroyer() { ErrLog::Destroy(); }
};

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

Expand Down
2 changes: 1 addition & 1 deletion tools/packchk/src/CheckFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ bool CheckFiles::CheckFileExtension(RteItem* item)
}
}
else if(category == "sourceCpp") {
if(_stricmp(extension.c_str(), "cpp")) {
if(_stricmp(extension.c_str(), "cpp") && _stricmp(extension.c_str(), "cc") && _stricmp(extension.c_str(), "cxx")) {
LogMsg("M337", VAL("CAT", category), PATH(name), EXT(extension), lineNo);
ok = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests1.c
1 change: 1 addition & 0 deletions tools/packchk/test/data/SupportCcFiles/Files/header1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//header 1
1 change: 1 addition & 0 deletions tools/packchk/test/data/SupportCcFiles/Files/test1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests1.c
1 change: 1 addition & 0 deletions tools/packchk/test/data/SupportCcFiles/Files/test1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests1.c
1 change: 1 addition & 0 deletions tools/packchk/test/data/SupportCcFiles/Files/test1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
<vendor>TestVendor</vendor>
<url>http://www.testurl.com/pack/</url>
<name>SupportCcFiles_DFP</name>
<description>Filename is directory</description>

<releases>
<release version="0.0.1" date="2025-02-03">>
Initial release of SupportCcFiles.
</release>
</releases>

<keywords>
<keyword>SupportCcFiles</keyword>
</keywords>

<conditions>
<condition id="Test_Condition">
<description>Test Device</description>
<require Dvendor="ARM:82"/>
</condition>
</conditions>

<components>
<component Cclass="TestClass" Cgroup="TestFiles" Cversion="1.0.0" condition="Test_Condition">
<description>Test files</description>
<files>
<file category="TestGlobal" name="Files/header1.h"/>
<file category="source" name="Files/test1.c"/>
<file category="sourceC" name="Files/test1.c"/>
<file category="sourceCpp" name="Files/test1.cpp"/>
<file category="sourceCpp" name="Files/test1.cc"/>
<file category="sourceCpp" name="Files/fileWillFail.ccc"/>
</files>
</component>
</components>
</package>
79 changes: 59 additions & 20 deletions tools/packchk/test/integtests/src/PackChkIntegTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void PackChkIntegTests::SetUp() {
}

void PackChkIntegTests::TearDown() {
ErrLog::Get()->ClearLogMessages();
ErrLog::Get()->Destroy();
}

string PackChkIntegTests::GetPackXsd() {
Expand Down Expand Up @@ -80,6 +80,17 @@ TEST_F(PackChkIntegTests, FileNotAVailable) {
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
}

TEST_F(PackChkIntegTests, FileNotAVailable2) {
const char* argv[2];

argv[0] = (char*)"";
argv[1] = (char*)"UNKNOWN.FILE.pdsc";

PackChk packChk;
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
}


TEST_F(PackChkIntegTests, VersionOption) {
const char* argv[2];

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

PackChk packChk;
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
EXPECT_EQ(1, packChk.Check(3, argv, nullptr));

auto errMsgs = ErrLog::Get()->GetLogMessages();
int M357_foundCnt = 0;
Expand Down Expand Up @@ -863,7 +874,7 @@ TEST_F(PackChkIntegTests, CheckBoardMountedCompatibleDevices) {
argv[0] = (char*)"";
argv[1] = (char*)pdscFile.c_str();
argv[2] = (char*)"-i";
argv[3] = (char*)pdscFile.c_str();
argv[3] = (char*)pdscFileAdd.c_str();
argv[4] = (char*)"--disable-validation";

PackChk packChk;
Expand Down Expand Up @@ -891,36 +902,30 @@ TEST_F(PackChkIntegTests, CheckBoardMountedCompatibleDevices) {
}
}

TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
const char* argv[5];
TEST_F(PackChkIntegTests, CheckSupportCcFiles) {
const char* argv[3];

const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
string pdscFile = PackChkIntegTestEnv::localtestdata_dir +
"/SupportCcFiles/TestVendor.SupportCcFiles_DFP.pdsc";
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
ASSERT_TRUE(RteFsUtils::Exists(refFile));

argv[0] = (char*)"";
argv[1] = (char*)pdscFile.c_str();
argv[2] = (char*)"-x";
argv[3] = (char*)"!M317";
argv[4] = (char*)"--disable-validation";
argv[2] = (char*)"--disable-validation";

PackChk packChk;
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));

auto errMsgs = ErrLog::Get()->GetLogMessages();
int M317_foundCnt = 0;
int M337_foundCnt = 0;
for (const string& msg : errMsgs) {
size_t s;
if ((s = msg.find("M317", 0)) != string::npos) {
M317_foundCnt++;
if (msg.find("M337", 0) != string::npos) {
M337_foundCnt++;
}
}

if(M317_foundCnt != 4) {
FAIL() << "error: warning M317 count != 4";
if(!M337_foundCnt) {
FAIL() << "error: Missing message M337: File with category 'sourceCpp' has wrong extension 'ccc': 'Files/fileWillFail.ccc'";
}
}

Expand Down Expand Up @@ -958,3 +963,37 @@ TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Pos) {
FAIL() << "error: warning M317 found";
}
}

TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Neg) {
const char* argv[5];

const string& pdscFile = PackChkIntegTestEnv::globaltestdata_dir +
"/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc";
const string& refFile = PackChkIntegTestEnv::globaltestdata_dir +
"/packs/ARM/RteTest/0.1.0/ARM.RteTest.pdsc";
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
ASSERT_TRUE(RteFsUtils::Exists(refFile));

argv[0] = (char*)"";
argv[1] = (char*)pdscFile.c_str();
argv[2] = (char*)"-x";
argv[3] = (char*)"!M317";
argv[4] = (char*)"--disable-validation";

PackChk packChk;
EXPECT_EQ(0, packChk.Check(5, argv, nullptr));

auto errMsgs = ErrLog::Get()->GetLogMessages();
int M317_foundCnt = 0;
for (const string& msg : errMsgs) {
size_t s;
if ((s = msg.find("M317", 0)) != string::npos) {
M317_foundCnt++;
}
}

if(M317_foundCnt != 4) {
FAIL() << "error: warning M317 count != 4";
}
}

0 comments on commit 331b229

Please sign in to comment.