Skip to content
Open
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
2 changes: 1 addition & 1 deletion libs/rtemodel/src/RteCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ RteItem::ConditionResult RteConditionExpression::EvaluateExpression(RteTarget* t
continue;
}
// all other attributes
if(!WildCards::Match(va, v))
if(!WildCards::MatchAny(va, v))
return FAILED;
} else if(GetExpressionType() == DENY) {
return FAILED; // for denied attributes, all must be given
Expand Down
43 changes: 43 additions & 0 deletions libs/rtemodel/test/src/RteConditionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ TEST(RteConditionValidateTest, Validate)
EXPECT_FALSE(deviceExpression.Validate());
}

TEST_F(RteConditionTest, PipeSeparatedWildcardEvaluation) {
RteKernelSlim rteKernel;
rteKernel.SetCmsisPackRoot(RteModelTestConfig::CMSIS_PACK_ROOT);
RteCprjProject* loadedCprjProject = rteKernel.LoadCprj(RteTestM3_cprj);
ASSERT_NE(loadedCprjProject, nullptr);
EXPECT_TRUE(loadedCprjProject->Validate());

RteTarget* activeTarget = loadedCprjProject->GetActiveTarget();
ASSERT_NE(activeTarget, nullptr);
RteConditionContext* filterContext = activeTarget->GetFilterContext();
ASSERT_NE(filterContext, nullptr);

RteRequireExpression deviceExpression(nullptr);
deviceExpression.AddAttribute("Dname", "DoesNotMatch|RteTest_ARMCM?");
deviceExpression.ConstructID();
EXPECT_EQ(deviceExpression.Evaluate(filterContext), RteItem::FULFILLED);

deviceExpression.SetAttribute("Dname", "DoesNotMatch|RteTest_ARMCM4");
EXPECT_EQ(deviceExpression.Evaluate(filterContext), RteItem::FAILED);

activeTarget->SetAttribute("Tcompiler", "ARMCC|GCC");

RteRequireExpression armccExpression(nullptr);
armccExpression.AddAttribute("Tcompiler", "ARMCC");
armccExpression.ConstructID();
EXPECT_EQ(armccExpression.Evaluate(filterContext), RteItem::FULFILLED);

RteRequireExpression gccExpression(nullptr);
gccExpression.AddAttribute("Tcompiler", "GCC");
gccExpression.ConstructID();
EXPECT_EQ(gccExpression.Evaluate(filterContext), RteItem::FULFILLED);

RteRequireExpression alternativeCompilerExpression(nullptr);
alternativeCompilerExpression.AddAttribute("Tcompiler", "XC|GCC");
alternativeCompilerExpression.ConstructID();
EXPECT_EQ(alternativeCompilerExpression.Evaluate(filterContext), RteItem::FULFILLED);

RteRequireExpression unsupportedCompilerExpression(nullptr);
unsupportedCompilerExpression.AddAttribute("Tcompiler", "XC");
unsupportedCompilerExpression.ConstructID();
EXPECT_EQ(unsupportedCompilerExpression.Evaluate(filterContext), RteItem::FAILED);
}

TEST_F(RteConditionTest, MissingIgnoredFulfilledSelectable) {
// load project to get a working target and condition contexts
RteKernelSlim rteKernel;
Expand Down
8 changes: 8 additions & 0 deletions libs/rteutils/include/WildCards.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class WildCards
*/
static bool Match(const std::string& s1, const std::string& s2);

/**
* @brief match any pair of non-empty, pipe-separated strings
* @param s1 pipe-separated strings to be matched, can contain wild card patterns
* @param s2 pipe-separated strings to be matched, can contain wild card patterns
* @return true if any pair of strings matches, otherwise false
*/
static bool MatchAny(const std::string& s1, const std::string& s2);

/**
* @brief converts "*" to ".*" and "?" to "."
* @param s string to be converted
Expand Down
35 changes: 35 additions & 0 deletions libs/rteutils/src/WildCards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/******************************************************************************/

#include "WildCards.h"
#include "RteUtils.h"

#include <regex>


Expand All @@ -38,6 +40,39 @@ bool WildCards::Match(const std::string& s1, const std::string& s2)
return false;
}

bool WildCards::MatchAny(const std::string& s1, const std::string& s2)
{
// first compare strings as is to save time by further match
if (s1 == s2) {
return true;
}

if (s1.empty() || s2.empty()) {
return false;
}


std::list<std::string> alternatives1;
std::list<std::string> alternatives2;
RteUtils::SplitString(alternatives1, s1, '|');
RteUtils::SplitString(alternatives2, s2, '|');

for (const auto& alternative1 : alternatives1) {
if (alternative1.empty()) {
continue;
}
for (const auto& alternative2 : alternatives2) {
if (alternative2.empty()) {
continue;
}
if (Match(alternative1, alternative2)) {
return true;
}
}
}
return false;
}

std::string WildCards::ToRegEx(const std::string& s)
{
// Char translations:
Expand Down
24 changes: 24 additions & 0 deletions libs/rteutils/test/src/RteUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ TEST(RteUtilsTest, WildCardsTo) {
}

TEST(RteUtilsTest, WildCardMatch) {
EXPECT_EQ(true, WildCards::Match("", ""));
EXPECT_EQ(true, WildCards::Match("a", "a"));
EXPECT_EQ(false, WildCards::Match("a", ""));
EXPECT_EQ(false, WildCards::Match("", "d"));
Expand Down Expand Up @@ -286,6 +287,29 @@ TEST(RteUtilsTest, WildCardMatch) {
}
}

TEST(RteUtilsTest, WildCardMatchAny) {
EXPECT_TRUE(WildCards::MatchAny("", ""));
EXPECT_TRUE(WildCards::MatchAny("*", "*"));
EXPECT_TRUE(WildCards::MatchAny("foo", "foo"));
EXPECT_TRUE(WildCards::MatchAny("foo*", "foo"));
EXPECT_TRUE(WildCards::MatchAny("foo*", "foo*"));
EXPECT_TRUE(WildCards::MatchAny("foo|bar", "bar"));
EXPECT_TRUE(WildCards::MatchAny("bar", "foo|bar"));
EXPECT_FALSE(WildCards::MatchAny("foo|bar", "baz|qux"));

EXPECT_TRUE(WildCards::MatchAny("foo*|bar", "food|baz"));
EXPECT_TRUE(WildCards::MatchAny("food|baz", "foo*|bar"));
EXPECT_TRUE(WildCards::MatchAny("foo?|bar", "f*|baz"));
EXPECT_TRUE(WildCards::MatchAny("foo", "foo"));

EXPECT_TRUE(WildCards::MatchAny("|foo||bar|", "||bar|"));
EXPECT_FALSE(WildCards::MatchAny("|foo||bar|", "||baz|"));
EXPECT_FALSE(WildCards::MatchAny("", "foo"));
EXPECT_FALSE(WildCards::MatchAny("foo", ""));

EXPECT_FALSE(WildCards::Match("foo|bar", "bar"));
}

TEST(RteUtilsTest, AlnumCmp_Char) {
EXPECT_EQ( -1, AlnumCmp::Compare(nullptr, "2.1"));
EXPECT_EQ( 1, AlnumCmp::Compare("10.1", nullptr));
Expand Down
Loading