diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-04-16 18:25:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-16 15:25:53 -0700 |
| commit | 12b30afb24ac03d69f091f18c25ed2bbefae1acd (patch) | |
| tree | fd5dc0c512c707c46bd3640f604f308a461a6bda | |
| parent | b5a531738baa1e856b15bb3dffdbea9a1ee5cc82 (diff) | |
Workaround for matching of dxc diagnostics (#1324)
* Specialized handling for comparison of dxc output that ignores line/column numbers.
* Simplify areAllEqualWithSplit.
| -rw-r--r-- | source/core/slang-string-util.cpp | 26 | ||||
| -rw-r--r-- | source/core/slang-string-util.h | 8 | ||||
| -rw-r--r-- | tests/cross-compile/dxc-error.hlsl | 2 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 96 |
4 files changed, 98 insertions, 34 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index f961e6060..326bc3191 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -6,6 +6,32 @@ namespace Slang { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! +/* static */bool StringUtil::areAllEqual(const List<UnownedStringSlice>& a, const List<UnownedStringSlice>& b, EqualFn equalFn) +{ + if (a.getCount() != b.getCount()) + { + return false; + } + + const Index count = a.getCount(); + for (Index i = 0; i < count; ++i) + { + if (!equalFn(a[i], b[i])) + { + return false; + } + } + return true; +} + +/* static */bool StringUtil::areAllEqualWithSplit(const UnownedStringSlice& a, const UnownedStringSlice& b, char splitChar, EqualFn equalFn) +{ + List<UnownedStringSlice> slicesA, slicesB; + StringUtil::split(a, splitChar, slicesA); + StringUtil::split(b, splitChar, slicesB); + return areAllEqual(slicesA, slicesB, equalFn); +} + /* static */void StringUtil::split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut) { slicesOut.clear(); diff --git a/source/core/slang-string-util.h b/source/core/slang-string-util.h index ad25dc9a1..9f1508cb1 100644 --- a/source/core/slang-string-util.h +++ b/source/core/slang-string-util.h @@ -13,6 +13,14 @@ namespace Slang { struct StringUtil { + typedef bool (*EqualFn)(const UnownedStringSlice& a, const UnownedStringSlice& b); + + /// True if the splits of a and b (via splitChar) are all equal as compared with the equalFn function + static bool areAllEqualWithSplit(const UnownedStringSlice& a, const UnownedStringSlice& b, char splitChar, EqualFn equalFn); + + /// True if all slices in match are all equal as compared with the equalFn function + static bool areAllEqual(const List<UnownedStringSlice>& a, const List<UnownedStringSlice>& b, EqualFn equalFn); + /// Split in, by specified splitChar into slices out /// Slices contents will directly address into in, so contents will only stay valid as long as in does. static void split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut); diff --git a/tests/cross-compile/dxc-error.hlsl b/tests/cross-compile/dxc-error.hlsl index fb22907c6..0e6b6e489 100644 --- a/tests/cross-compile/dxc-error.hlsl +++ b/tests/cross-compile/dxc-error.hlsl @@ -1,4 +1,4 @@ -//TEST(dxc):SIMPLE:-pass-through dxc -target dxil -entry computeMain -stage compute -profile sm_6_1 +//DIAGNOSTIC_TEST(dxc):SIMPLE:-pass-through dxc -target dxil -entry computeMain -stage compute -profile sm_6_1 [numthreads(4, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index d72144856..da03d67fe 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -977,6 +977,37 @@ static UnownedStringSlice _removeDiagnosticPrefix(const UnownedStringSlice& pref } } +static bool _isUnsignedInteger(const UnownedStringSlice& a) +{ + const char* end = a.end(); + for (const char* cur = a.begin(); cur < end; ++cur) + { + if (!(*cur >= '0' && *cur <= '9')) + { + return false; + } + } + return true; +} + +static bool _isDXCLineSplitEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) +{ + return a == b || (_isUnsignedInteger(a.trim()) && _isUnsignedInteger(b.trim())); +} + +// Returns true if a and b are output from dxc (prefixed with dxc:. +// Ignores line number/column number differences from the dxc specific line format. +static bool _isDXCLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) +{ + // We are going to ignore the line number/column number. + // To do this if we find any sub strings inbetween : that are just all digits we'll assume it's a line number/column number + // and ignore + + // dxc: tests/cross-compile/dxc-error.hlsl:9:2: error: use of undeclared identifier 'gOutputBuffer' + const UnownedStringSlice dxcPrefix = UnownedStringSlice::fromLiteral("dxc:"); + return a.startsWith(dxcPrefix) && b.startsWith(dxcPrefix) && StringUtil::areAllEqualWithSplit(a, b, ':', _isDXCLineSplitEqual); +} + static bool _isLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) { if (a == b) @@ -1004,50 +1035,49 @@ static bool _isLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& } } - return false; + return _isDXCLineEqual(a, b); } -static bool _areResultsEqual(TestOptions::Type type, const String& a, const String& b) +static bool _areDiagnosticsEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) { - switch (type) + // If they are identical we are done + if (a == b) { - case TestOptions::Type::Diagnostic: - { - // If they are identical we are done - if (a == b) - { - return true; - } - - // Okay we are going to go line by line - // If the lines are equal thats ok. - // If they are not.. we will check if the only difference is line numbers from the stdlib + return true; + } - List<UnownedStringSlice> linesA; - List<UnownedStringSlice> linesB; + // Okay we are going to go line by line + // If the lines are equal thats ok. + // If they are not.. we will check if the only difference is line numbers from the stdlib - StringUtil::calcLines(a.getUnownedSlice(), linesA); - StringUtil::calcLines(b.getUnownedSlice(), linesB); + List<UnownedStringSlice> linesA; + List<UnownedStringSlice> linesB; - if (linesA.getCount() != linesB.getCount()) - { - return false; - } + StringUtil::calcLines(a, linesA); + StringUtil::calcLines(b, linesB); - for (Index i = 0; i < linesA.getCount(); ++i) - { - if (!_isLineEqual(linesA[i], linesB[i])) - { - return false; - } - } + if (linesA.getCount() != linesB.getCount()) + { + return false; + } - return true; - } - case TestOptions::Type::Normal: + for (Index i = 0; i < linesA.getCount(); ++i) + { + if (!_isLineEqual(linesA[i], linesB[i])) { - return a == b; + return false; } + } + + return true; +} + +static bool _areResultsEqual(TestOptions::Type type, const String& a, const String& b) +{ + switch (type) + { + case TestOptions::Type::Diagnostic: return _areDiagnosticsEqual(a.getUnownedSlice(), b.getUnownedSlice()); + case TestOptions::Type::Normal: return a == b; default: { SLANG_ASSERT(!"Unknown test type"); |
