Skip to content

Commit

Permalink
[packchk] wrong ERROR M310
Browse files Browse the repository at this point in the history
Fixes #110 

Co-authored-by: Sourabh Mehta <73165318+soumeh01@users.noreply.github.com>
  • Loading branch information
grasci-arm and soumeh01 authored Apr 5, 2022
1 parent 07b2887 commit a484c1f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 34 deletions.
68 changes: 34 additions & 34 deletions tools/packchk/src/CheckFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,60 +356,60 @@ bool CheckFiles::FindGetExactFileSystemName(const std::string& path, const std::
* @brief check name as written in PDSC against it's counterpart on the filesystem, for case sensitivity
* @param fileName filename as written in PDSC
* @param lineNo line number for error reporting
* @return
* @return true/false
*/
bool CheckFiles::CheckCaseSense(const string& fileName, int lineNo)
{
if(fileName.empty()) {
if (fileName.empty()) {
return true;
}

LogMsg("M058", PATH(fileName));

string pdscPath = RteUtils::BackSlashesToSlashes(RteUtils::RemoveTrailingBackslash(fileName));
string path = pdscPath;
string systemPath;
vector<string> pathVect;

do {
string actualPath = path;
path = RteUtils::ExtractFilePath(actualPath, 0);
string checkPath = RteUtils::ExtractFileName(actualPath);
string testPath = GetPackagePath();
testPath += "/";
testPath += path;
string outPath;

if(FindGetExactFileSystemName(testPath, checkPath, outPath)) {
pathVect.push_back(outPath);
string filePath, testPath, outPath, packPath;
vector<string> sysPathSegments;
std::list<std::string> filePathSegments;

packPath = GetPackagePath();
filePath = RteUtils::BackSlashesToSlashes(RteUtils::RemoveTrailingBackslash(fileName));
RteUtils::SplitString(filePathSegments, filePath, '/');
testPath = packPath;

for (const auto& seg : filePathSegments) {
if (seg == ".." || seg == ".") {
sysPathSegments.push_back(seg);
testPath += "/" + seg;
continue;
}
} while(!path.empty() && path != ".");

for(auto it2 = pathVect.rbegin(); it2 != pathVect.rend(); it2++) {
if(!systemPath.empty()) {
systemPath += "/";
if (FindGetExactFileSystemName(testPath, seg, outPath)) {
sysPathSegments.push_back(outPath);
testPath += "/" + outPath;
}
else {
string errMsg = string("file/folder \"") + seg + "\" not found";
LogMsg("M103", VAL("REF", errMsg));
return false;
}
systemPath += *it2;
}

string::size_type pos;
string::size_type endPos = pdscPath.find_first_not_of("./");
do {
pos = pdscPath.find_first_of("./");
if(pos < endPos && pos != string::npos)
pdscPath.erase(pos, 1);
} while(pos < endPos && pos != string::npos);
string systemPath;
for (const auto& itrSeg : sysPathSegments) {
if (!systemPath.empty()) {
systemPath += "/";
}
systemPath += itrSeg;
}

bool ok = true;
if(pdscPath.compare(systemPath)) {
LogMsg("M310", VAL("PDSC", pdscPath), VAL("SYSTEM", systemPath), lineNo);
if (filePath.compare(systemPath)) {
LogMsg("M310", VAL("PDSC", filePath), VAL("SYSTEM", systemPath), lineNo);
ok = false;
}

if(ok) {
if (ok) {
LogMsg("M010");
}

return ok;
}

Expand Down
44 changes: 44 additions & 0 deletions tools/packchk/test/unittests/src/TestCheckFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestCheckFiles : public Test {

void TearDown() override {
errLog.ClearLogMessages();
RteFsUtils::RemoveDir(string(BUILD_FOLDER) + "/testdata");
}

private:
Expand Down Expand Up @@ -145,3 +146,46 @@ TEST_F(TestCheckFiles, CheckFileExtension_NullItem) {
// THEN the check is expected to pass
EXPECT_TRUE(res);
}

TEST_F(TestCheckFiles, CheckCaseSense)
{
// test setup
string packPath = checkFiles.GetPackagePath();
string testDataFolder = packPath + "/testdata";
const string& testApiFolder = testDataFolder + "/Api";
if (RteFsUtils::Exists(testDataFolder)) {
RteFsUtils::RemoveDir(testDataFolder);
}
ASSERT_TRUE(RteFsUtils::CreateDirectories(testApiFolder));
ASSERT_TRUE(RteFsUtils::CreateFile(
testApiFolder + "/Exclusive.h", RteUtils::EMPTY_STRING));
ASSERT_TRUE(RteFsUtils::CreateDirectories(testDataFolder + "/.test1"));
ASSERT_TRUE(RteFsUtils::CreateFile(
testDataFolder + "/.test1/NonExclusive.h", RteUtils::EMPTY_STRING));
checkFiles.SetPackagePath(testDataFolder);

// test
map<string, bool> testInputs = {
// FilePath, expectedResults
{ RteUtils::EMPTY_STRING, true},
{ "Api\\Exclusive.h", true},
{ "Api/Exclusive.h", true},
{ "./Api/Exclusive.h", true},
{ "././././Api/Exclusive.h", true},
{ ".test1/NonExclusive.h", true},
{ ".test1/../Api/Exclusive.h", true},
{ "../testdata/Api/Exclusive.h", true},
{ "../Invalid/Path/Exclusive.h", false},
{ "api\\exclusive.h", false},
{ "api/exclusive.h", false}
};

for (const auto& [filePath, result] : testInputs) {
EXPECT_EQ(result, checkFiles.CheckCaseSense(filePath, 1)) <<
"error: failed for input \"" << filePath << "\"" << endl;
}

// cleanup
RteFsUtils::RemoveDir(testDataFolder);
checkFiles.SetPackagePath(packPath);
}

0 comments on commit a484c1f

Please sign in to comment.