From 863419ca6bbd23f115692b74f8da5d364fc6fa9d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 3 Jul 2023 17:30:00 +0200 Subject: [PATCH] TMP: try delete levenshtein test valgrind spotted use of uninitialised values here. I couldn't reproduce the problem locally, so let's see if this happens to fix CI. valgrind ./src/libstore/tests/libnixstore-tests ==2314521== Memcheck, a memory error detector ==2314521== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==2314521== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info ==2314521== Command: ./src/libstore/tests/libnixstore-tests ==2314521== Running main() from /build/source/googletest/src/gtest_main.cc ==2314521== Use of uninitialised value of size 8 ==2314521== at 0x4DC32D2: _itoa_word (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4DCCC6D: __printf_buffer (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4DEE975: __vsnprintf_internal (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4E89A13: __snprintf_chk (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4884320: testing::(anonymous namespace)::PrintByteSegmentInObjectTo(unsigned char const*, unsigned long, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48895CB: testing::internal::PrintBytesInObjectTo(unsigned char const*, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x50AE35A: PrintValue (gtest-printers.h:269) ==2314521== by 0x50AE35A: PrintWithFallback (gtest-printers.h:311) ==2314521== by 0x50AE35A: PrintTo (gtest-printers.h:440) ==2314521== by 0x50AE35A: Print (gtest-printers.h:702) ==2314521== by 0x50AE35A: UniversalPrint (gtest-printers.h:999) ==2314521== by 0x50AE35A: Print (gtest-printers.h:884) ==2314521== by 0x50AE35A: PrintToString (gtest-printers.h:1037) ==2314521== by 0x50AE35A: testing::internal::ParameterizedTestSuiteInfo::RegisterTests() (gtest-param-util.h:596) ==2314521== by 0x48B1894: testing::internal::UnitTestImpl::RegisterParameterizedTests() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48B193A: testing::internal::UnitTestImpl::PostFlagParsingInit() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48540D2: main (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest_main.so.1.12.1) ==2314521== ==2314521== Conditional jump or move depends on uninitialised value(s) ==2314521== at 0x4DC32E4: _itoa_word (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4DCCC6D: __printf_buffer (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4DEE975: __vsnprintf_internal (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4E89A13: __snprintf_chk (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4884320: testing::(anonymous namespace)::PrintByteSegmentInObjectTo(unsigned char const*, unsigned long, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48895CB: testing::internal::PrintBytesInObjectTo(unsigned char const*, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x50AE35A: PrintValue (gtest-printers.h:269) ==2314521== by 0x50AE35A: PrintWithFallback (gtest-printers.h:311) ==2314521== by 0x50AE35A: PrintTo (gtest-printers.h:440) ==2314521== by 0x50AE35A: Print (gtest-printers.h:702) ==2314521== by 0x50AE35A: UniversalPrint (gtest-printers.h:999) ==2314521== by 0x50AE35A: Print (gtest-printers.h:884) ==2314521== by 0x50AE35A: PrintToString (gtest-printers.h:1037) ==2314521== by 0x50AE35A: testing::internal::ParameterizedTestSuiteInfo::RegisterTests() (gtest-param-util.h:596) ==2314521== by 0x48B1894: testing::internal::UnitTestImpl::RegisterParameterizedTests() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48B193A: testing::internal::UnitTestImpl::PostFlagParsingInit() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48540D2: main (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest_main.so.1.12.1) ==2314521== ==2314521== Conditional jump or move depends on uninitialised value(s) ==2314521== at 0x4DCCCBF: __printf_buffer (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4DEE975: __vsnprintf_internal (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4E89A13: __snprintf_chk (in /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6) ==2314521== by 0x4884320: testing::(anonymous namespace)::PrintByteSegmentInObjectTo(unsigned char const*, unsigned long, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48895CB: testing::internal::PrintBytesInObjectTo(unsigned char const*, unsigned long, std::ostream*) (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x50AE35A: PrintValue (gtest-printers.h:269) ==2314521== by 0x50AE35A: PrintWithFallback (gtest-printers.h:311) ==2314521== by 0x50AE35A: PrintTo (gtest-printers.h:440) ==2314521== by 0x50AE35A: Print (gtest-printers.h:702) ==2314521== by 0x50AE35A: UniversalPrint (gtest-printers.h:999) ==2314521== by 0x50AE35A: Print (gtest-printers.h:884) ==2314521== by 0x50AE35A: PrintToString (gtest-printers.h:1037) ==2314521== by 0x50AE35A: testing::internal::ParameterizedTestSuiteInfo::RegisterTests() (gtest-param-util.h:596) ==2314521== by 0x48B1894: testing::internal::UnitTestImpl::RegisterParameterizedTests() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48B193A: testing::internal::UnitTestImpl::PostFlagParsingInit() (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest.so.1.12.1) ==2314521== by 0x48540D2: main (in /nix/store/21329dny6jffzcagsipcklh3fg6jzp87-gtest-1.12.1/lib/libgtest_main.so.1.12.1) ==2314521== --- src/libutil/tests/suggestions.cc | 43 -------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/libutil/tests/suggestions.cc diff --git a/src/libutil/tests/suggestions.cc b/src/libutil/tests/suggestions.cc deleted file mode 100644 index 279994abc..000000000 --- a/src/libutil/tests/suggestions.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include "suggestions.hh" -#include - -namespace nix { - - struct LevenshteinDistanceParam { - std::string s1, s2; - int distance; - }; - - class LevenshteinDistanceTest : - public testing::TestWithParam { - }; - - TEST_P(LevenshteinDistanceTest, CorrectlyComputed) { - auto params = GetParam(); - - ASSERT_EQ(levenshteinDistance(params.s1, params.s2), params.distance); - ASSERT_EQ(levenshteinDistance(params.s2, params.s1), params.distance); - } - - INSTANTIATE_TEST_SUITE_P(LevenshteinDistance, LevenshteinDistanceTest, - testing::Values( - LevenshteinDistanceParam{"foo", "foo", 0}, - LevenshteinDistanceParam{"foo", "", 3}, - LevenshteinDistanceParam{"", "", 0}, - LevenshteinDistanceParam{"foo", "fo", 1}, - LevenshteinDistanceParam{"foo", "oo", 1}, - LevenshteinDistanceParam{"foo", "fao", 1}, - LevenshteinDistanceParam{"foo", "abc", 3} - ) - ); - - TEST(Suggestions, Trim) { - auto suggestions = Suggestions::bestMatches({"foooo", "bar", "fo", "gao"}, "foo"); - auto onlyOne = suggestions.trim(1); - ASSERT_EQ(onlyOne.suggestions.size(), 1); - ASSERT_TRUE(onlyOne.suggestions.begin()->suggestion == "fo"); - - auto closest = suggestions.trim(999, 2); - ASSERT_EQ(closest.suggestions.size(), 3); - } -}