Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option "--allow-suppress-error" (#413) #640

Merged
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
1 change: 1 addition & 0 deletions tools/packchk/include/PackOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CPackOptions {
bool GetIgnoreOtherPdscFiles();
bool AddRefPdscFile(const std::string& filename);
bool HaltProgramExecution();
bool SetAllowSuppresssError(bool bAllow);

std::string GetCurrentDateTime();

Expand Down
1 change: 1 addition & 0 deletions tools/packchk/include/ParseOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ParseOptions {
bool SetUrlRef(const std::string& urlRef);
bool SetVerbose(bool bVerbose);
bool SetIgnoreOtherPdscFiles(bool bIgnore);
bool SetAllowSuppresssError(bool bAllow = true);

private:
CPackOptions& m_packOptions;
Expand Down
11 changes: 11 additions & 0 deletions tools/packchk/src/PackOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ bool CPackOptions::SetVerbose(bool bVerbose)
return true;
}

/**
* @brief enable suppressing of error message
* @param bVerbose set verbose mode
* @return passed / failed
*/
bool CPackOptions::SetAllowSuppresssError(bool bAllow)
{
ErrLog::Get()->SetAllowSuppressError(bAllow);
return true;
}

/**
* @brief test if the current PDSC file is under test or a reference file
* @param filename string name to check
Expand Down
16 changes: 16 additions & 0 deletions tools/packchk/src/ParseOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ bool ParseOptions::SetVerbose(bool bVerbose)
return m_packOptions.SetVerbose(bVerbose);
}

/**
* @brief option "--allow-suppress-error"
* @param bVerbose set verbose mode
* @return passed / failed
*/
bool ParseOptions::SetAllowSuppresssError(bool bAllow /*= true*/)
{
return m_packOptions.SetAllowSuppresssError(bAllow);
}

/**
* @brief option "filename under test"
* @param filename string input filename
Expand Down Expand Up @@ -210,6 +220,12 @@ ParseOptions::Result ParseOptions::Parse(int argc, const char* argv[])
}
}

if (parseResult.count("allow-suppress-error")) {
if(!SetAllowSuppresssError()) {
bOk = false;
}
}

if (parseResult.count("diag-suppress")) {
auto& v = parseResult["diag-suppress"].as<std::vector<std::string>>();
for(const auto& s : v) {
Expand Down
1 change: 1 addition & 0 deletions tools/packchk/test/data/AllowSuppressError/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/AllowSuppressError/Files/test1.c
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,42 @@
<?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>TestInvalidPack</name>
<description>TestInvalidPack</description>

<releases>
<release version="0.0.1" date="2021-09-06">>
Initial release of TestInvalidPack.
</release>
</releases>

<keywords>
<keyword>TestInvalidPack</keyword>
</keywords>

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

<components>
<component Cclass="TestClass" Cgroup="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
<description>TestGlobal</description>
<files>
<file category="source" name="Files/test1.c"/>
<file category="TestGlobal" name="Files/header1.h"/>
</files>
</component>
<component Cclass="TestClass" Cgroup="TestLocal" Cversion="1.0.0" condition="Test_Condition">
<description>TestLocal</description>
<files>
<file category="source" name="Files/test2.c"/>
</files>
</component>
</components>

</package>
31 changes: 31 additions & 0 deletions tools/packchk/test/integtests/src/PackChkIntegTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,34 @@ TEST_F(PackChkIntegTests, CheckPackFileName) {
}
}

// Validate "--allow-suppress-error"
TEST_F(PackChkIntegTests, CheckAllowSuppressError) {
const char* argv[5];

const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
"/AllowSuppressError/TestVendor.TestInvalidPack.pdsc";
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));

argv[0] = (char*)"";
argv[1] = (char*)pdscFile.c_str();
argv[2] = (char*)"--allow-suppress-error";
argv[3] = (char*)"-x";
argv[4] = (char*)"M323";

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

auto errMsgs = ErrLog::Get()->GetLogMessages();
bool bFound = false;
for (const string& msg : errMsgs) {
size_t s;
if ((s = msg.find("M323")) != string::npos) {
bFound = true;
break;
}
}

if (bFound) {
FAIL() << "error: found error M323";
}
}