mesa/src/intel/mda/mda_test.cpp
Caio Oliveira 05fc275837 intel/mda: Change the matching logic
Previously the matching logic was designed to match names
like this

```
99993681767ac...32132a.anv.mda.tar/CS/NIR8/046-ssa
```

So up until the first slash of a pattern, a prefix match would be used,
followed by fuzzy matching for the remaining pattern.  This don't
work well when there are subdirectories in the name, so when we see

```
before/99993681767ac...32132a.anv.mda.tar/CS/NIR8/046-ssa
before/91132154353bd...090919.anv.mda.tar/CS/NIR8/046-ssa
after/91132154353bd...090919.anv.mda.tar/CS/NIR8/046-ssa
```

the first entry can't be matched by `before/9999/first` since the fuzzy
match will kick in for the 9999 and if the second entry has four 9s
(which it does here) there would be multiple choices.

In practice the flexibility of fuzzy matching is not really needed
since we've been using consistent small prefixes (like CS, NIR8, BRW,
etc).  The exception is the last part (the object versions, i.e.
"pass names"), where sometimes is convenient to reach by a substring.

The new matching logic is to use prefix match by default, except when
matching the "object version", where substring match is used. In the
example a possible set of the patterns to identify each entry can be
`b/99/ssa`, `b/91/ssa` and `a/91/ssa`.

The patch adds a few tests to the `is_match()` to clarify the behavior.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39506>
2026-01-28 21:56:59 +00:00

62 lines
2.6 KiB
C++

/*
* Copyright 2026 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include <gtest/gtest.h>
#include "mda_private.h"
TEST(MDA, IsMatch)
{
constexpr match_flags _ = MATCH_FLAG_NONE;
constexpr match_flags SUBSTRING_LAST = MATCH_FLAG_SUBSTRING_LAST;
struct T {
const char *entry;
const char *pattern;
match_flags flags;
bool expected;
} tests[] = {
/* Empty pattern matches anything. */
{ "c9a50159a389eb1f/CS/NIR8/first", "", _, true },
{ "c9a50159a389eb1f/CS/NIR8/first", "", SUBSTRING_LAST, true },
/* Pattern segments are matched in order but can skip name segments. */
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "c9a/BRW8", _, true },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "c/CS/00-03", _, true },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "CS/BRW8", _, true },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "c/BRW/CS", _, false },
/* Not a match if pattern has extra segments. */
{ "c9a50159a389eb1f/CS/NIR8/first", "c/CS/NIR8/first", _, true },
{ "c9a50159a389eb1f/CS/NIR8/first", "c/CS/NIR8/first/out", _, false },
/* Empty segments match any single name segment, but must match one. */
{ "c9a50159a389eb1f/CS/NIR8/first", "c//NIR8/first", _, true },
{ "c9a50159a389eb1f/CS/NIR8/first", "c//CS/NIR8/first", _, false },
{ "c9a50159a389eb1f/CS/NIR8/first", "c/CS/NIR8/", _, true },
{ "c9a50159a389eb1f/CS/NIR8/first", "c/CS/NIR8/first/", _, false },
{ "foo/bar", "/bar", _, true },
{ "bar", "/bar", _, false },
/* Last segment can be matched as substring with SUBSTRING_LAST. */
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "BRW8/dead_code", _, false },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "BRW8/dead_code", SUBSTRING_LAST, true },
/* SUBSTRING_LAST only applies to last segment. */
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "dead_code", SUBSTRING_LAST, true },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "8", SUBSTRING_LAST, false },
{ "c9a50159a389eb1f/CS/BRW8/00-03-brw_opt_dead_code_eliminate", "9a501", SUBSTRING_LAST, false },
};
for (const auto &t : tests) {
slice entry = slice_from_cstr(t.entry);
slice pattern = slice_from_cstr(t.pattern);
EXPECT_EQ(is_match(entry, pattern, t.flags), t.expected)
<< "entry='" << t.entry << "' "
<< "pattern='" << t.pattern << "' "
<< "flags=" << t.flags;
}
}