Skip to content

Commit edb794c

Browse files
[packchk] Issue a warning for description attributes and elements that exceed the recommended limit of 128 (US ASCII) characters #1324 (#1141) (#1965)
* [packchk] Issue a warning for description attributes and elements that exceed the recommended limit of 128 (US ASCII) characters #1324 Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent 3779afa commit edb794c

File tree

7 files changed

+126
-1
lines changed

7 files changed

+126
-1
lines changed

tools/packchk/include/CheckFiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CheckFiles {
3131
const std::string& GetPackagePath() const;
3232
bool CheckFile(RteItem* item);
3333
bool CheckUrls(RteItem* item);
34+
bool CheckDescription(RteItem* item);
3435
bool CheckFileExists(const std::string& fileName, int lineNo, bool associated = false);
3536
bool CheckCaseSense(const std::string& fileName, int lineNo);
3637
bool CheckFileIsInPack(const std::string& fileName, int lineNo);
@@ -47,7 +48,6 @@ class CheckFiles {
4748
bool GetFileName(RteItem* item, std::string& filename, FileType& fileType) const;
4849
bool ToUpper(std::string& text);
4950
std::string GetFullFilename(const std::string& fileName);
50-
bool CheckPath(const std::string& fileName, int lineNo);
5151

5252
private:
5353
std::string m_packagePath;

tools/packchk/src/CheckFiles.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
4141
{
4242
m_checkFiles.CheckFile(item);
4343
m_checkFiles.CheckUrls(item);
44+
m_checkFiles.CheckDescription(item);
4445

4546
return VISIT_RESULT::CONTINUE_VISIT;
4647
}
@@ -171,6 +172,38 @@ bool CheckFiles::ToUpper(string& text)
171172
return true;
172173
}
173174

175+
/**
176+
* @brief check aspects of an RTE url item
177+
* @param item RteItem item to check
178+
* @return passed / failed
179+
*/
180+
bool CheckFiles::CheckDescription(RteItem* item)
181+
{
182+
if(!item) {
183+
return true;
184+
}
185+
186+
const auto& tag = item->GetTag();
187+
const auto lineNo = item->GetLineNumber();
188+
if(tag == "description") {
189+
const auto& text = item->GetText();
190+
191+
for(auto c : text) {
192+
if(c < 0x20 || c > 0x7e) {
193+
LogMsg("M388", NAME(text), lineNo);
194+
break;
195+
}
196+
}
197+
198+
if(text.length() > 128) {
199+
LogMsg("M387", TAG(tag), lineNo);
200+
return false;
201+
}
202+
}
203+
204+
return true;
205+
}
206+
174207
/**
175208
* @brief check aspects of an RTE url item
176209
* @param item RteItem item to check

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ const MsgTable PackChk::msgTable = {
203203
{ "M384", { MsgLevel::LEVEL_ERROR, CRLF_B, "Condition '%NAME%': Direct or indirect recursion detected. Skipping condition while searching for '%NAME2%'." } },
204204
{ "M385", { MsgLevel::LEVEL_INFO, CRLF_B, "Release date is empty." } },
205205
{ "M386", { MsgLevel::LEVEL_WARNING, CRLF_B, "Release date is in future: '%RELEASEDATE%' (today: %TODAYDATE%)" } },
206+
{ "M387", { MsgLevel::LEVEL_WARNING, CRLF_B, "Description in '%TAG%' is exceeding the recommended 128 (US ASCII) characters." } },
207+
{ "M388", { MsgLevel::LEVEL_WARNING, CRLF_B, "Unsupported character(s) found in '%NAME%'" } },
206208
{ "M389", { MsgLevel::LEVEL_WARNING, CRLF_B, "The component '%NAME%' (Line %LINE%) has dependency '%EXPR%' : '%NAME2%' that is resolved by the component itself." } },
207209
{ "M390", { MsgLevel::LEVEL_ERROR, CRLF_B, "Condition '%NAME%': Direct or indirect recursion detected. %MSG%" } },
208210
{ "M391", { MsgLevel::LEVEL_WARNING3, CRLF_B, "Redefined Item '%NAME%': %MSG%" } },
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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>https://www.testurl.foo/pack/</url>
6+
<name>TestTextExceedsLength</name>
7+
<description>TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength TestTextExceedsLength </description>
8+
9+
<releases>
10+
<release version="0.0.1" date="2022-06-20">
11+
Initial release of TestTextExceedsLength.
12+
</release>
13+
</releases>
14+
15+
<keywords>
16+
<keyword>TestTextExceedsLength</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="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
28+
<description>Unsupported char € </description>
29+
</component>
30+
<component Cclass="Device" Cgroup="Config Tools" Csub="Init" Cversion="1.0.0" condition="Test_Condition">
31+
<description>Initialization generated by MyConfig</description>
32+
<files>
33+
<file category="source" name="Files/test1.c"/>
34+
</files>
35+
</component>
36+
</components>
37+
38+
<devices>
39+
<family Dfamily="MyDevice Series" Dvendor="ARM:82">
40+
<processor Dcore="Cortex-M3" DcoreVersion="r1p1"/>
41+
42+
<subFamily DsubFamily="MyDevice">
43+
<device Dname="MyDeviceM0">
44+
<processor Dfpu="0" Dmpu="0" Dendian="Little-endian" Dclock="24000000"/>
45+
</device>
46+
</subFamily>
47+
</family>
48+
</devices>
49+
50+
</package>

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ TEST_F(PackChkIntegTests, CheckDescriptionOverviewMd) {
823823
FAIL() << "error: message M337 found";
824824
}
825825
}
826+
826827
// Validate config file vs. include path
827828
TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
828829
const char* argv[3];
@@ -852,6 +853,43 @@ TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
852853
}
853854
}
854855

856+
// Validate config file vs. include path
857+
TEST_F(PackChkIntegTests, CheckTestTextExceedsLength) {
858+
const char* argv[7];
859+
860+
const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
861+
"/TestTextExceedsLength/TestVendor.TestTextExceedsLength.pdsc";
862+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
863+
864+
argv[0] = (char*)"";
865+
argv[1] = (char*)pdscFile.c_str();
866+
argv[2] = (char *)"--disable-validation";
867+
argv[3] = (char*)"-x";
868+
argv[4] = (char*)"!M387";
869+
argv[5] = (char*)"-x";
870+
argv[6] = (char*)"!M388";
871+
872+
PackChk packChk;
873+
EXPECT_EQ(0, packChk.Check(7, argv, nullptr));
874+
875+
auto errMsgs = ErrLog::Get()->GetLogMessages();
876+
int M387_foundCnt = 0;
877+
int M388_foundCnt = 0;
878+
for (const string& msg : errMsgs) {
879+
size_t s;
880+
if ((s = msg.find("M387")) != string::npos) {
881+
M387_foundCnt++;
882+
}
883+
if ((s = msg.find("M388")) != string::npos) {
884+
M388_foundCnt++;
885+
}
886+
}
887+
888+
if (!M387_foundCnt || !M388_foundCnt) {
889+
FAIL() << "error: missing message M387 or M388";
890+
}
891+
}
892+
855893
// Test schema validation
856894
TEST_F(PackChkIntegTests, CheckSchemaValidation) {
857895
const char* argv[3];

0 commit comments

Comments
 (0)