IMPALA-4493: fix string-compare-test when using clang Only the 0 value or sign bit is specified in the return value for strncmp(), so fix up the test accordingly.
Testing: - verified the new test still reproduces IMPALA-4436 - verify the new test passes under ASAN build Change-Id: I5d82ac2bff33fdbf66275fcfc6558c4bc29de5e7 Reviewed-on: http://gerrit.cloudera.org:8080/5110 Reviewed-by: Jim Apple <[email protected]> Tested-by: Internal Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/ab0d21ab Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/ab0d21ab Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/ab0d21ab Branch: refs/heads/master Commit: ab0d21ab797a4511ef2717d1331ebda5cec7bfec Parents: f5e660d Author: Dan Hecht <[email protected]> Authored: Wed Nov 16 12:07:50 2016 -0800 Committer: Internal Jenkins <[email protected]> Committed: Thu Nov 17 01:46:23 2016 +0000 ---------------------------------------------------------------------- be/src/runtime/string-compare-test.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/ab0d21ab/be/src/runtime/string-compare-test.cc ---------------------------------------------------------------------- diff --git a/be/src/runtime/string-compare-test.cc b/be/src/runtime/string-compare-test.cc index ef81ac6..a3c959a 100644 --- a/be/src/runtime/string-compare-test.cc +++ b/be/src/runtime/string-compare-test.cc @@ -28,8 +28,15 @@ namespace impala { // Expect that strncmp() and StringCompare() return the same result. static void RunTestCase(const string& l, const string& r) { int cmp_len = ::min(l.size(), r.size()); - EXPECT_EQ(strncmp(l.c_str(), r.c_str(), cmp_len), - StringCompare(l.c_str(), l.size(), r.c_str(), r.size(), cmp_len)); + int strncmp_r = strncmp(l.c_str(), r.c_str(), cmp_len); + int stringcompare_r = StringCompare(l.c_str(), l.size(), r.c_str(), r.size(), cmp_len); + if (strncmp_r == 0) { + EXPECT_EQ(stringcompare_r, 0) << l << " " << r; + } else if (strncmp_r > 0) { + EXPECT_GT(stringcompare_r, 0) << l << " " << r; + } else { + EXPECT_LT(stringcompare_r, 0) << l << " " << r; + } } TEST(StringCompareTest, Basic) {
