diff options
| author | 2017-01-24 08:32:59 +0000 | |
|---|---|---|
| committer | 2017-01-24 08:32:59 +0000 | |
| commit | 53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch) | |
| tree | 7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp | |
| parent | In preparation of compiling our kernels with -ffreestanding, explicitly map (diff) | |
| download | wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip | |
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp | 120 |
1 files changed, 83 insertions, 37 deletions
diff --git a/gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp index 53b40ebae85..49eab4ad788 100644 --- a/gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/gnu/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -16,6 +16,7 @@ #include "gtest/gtest.h" #include <ostream> +#include <utility> using namespace llvm; using namespace coverage; @@ -55,6 +56,17 @@ struct OutputFunctionCoverageData { std::vector<StringRef> Filenames; std::vector<CounterMappingRegion> Regions; + OutputFunctionCoverageData() : Hash(0) {} + + OutputFunctionCoverageData(OutputFunctionCoverageData &&OFCD) + : Name(OFCD.Name), Hash(OFCD.Hash), Filenames(std::move(OFCD.Filenames)), + Regions(std::move(OFCD.Regions)) {} + + OutputFunctionCoverageData(const OutputFunctionCoverageData &) = delete; + OutputFunctionCoverageData & + operator=(const OutputFunctionCoverageData &) = delete; + OutputFunctionCoverageData &operator=(OutputFunctionCoverageData &&) = delete; + void fillCoverageMappingRecord(CoverageMappingRecord &Record) const { Record.FunctionName = Name; Record.FunctionHash = Hash; @@ -95,9 +107,20 @@ struct InputFunctionCoverageData { InputFunctionCoverageData(std::string Name, uint64_t Hash) : Name(std::move(Name)), Hash(Hash) {} + + InputFunctionCoverageData(InputFunctionCoverageData &&IFCD) + : ReverseVirtualFileMapping(std::move(IFCD.ReverseVirtualFileMapping)), + Name(std::move(IFCD.Name)), Hash(IFCD.Hash), + Regions(std::move(IFCD.Regions)) {} + + InputFunctionCoverageData(const InputFunctionCoverageData &) = delete; + InputFunctionCoverageData & + operator=(const InputFunctionCoverageData &) = delete; + InputFunctionCoverageData &operator=(InputFunctionCoverageData &&) = delete; }; -struct CoverageMappingTest : ::testing::Test { +struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> { + bool UseMultipleReaders; StringMap<unsigned> Files; std::vector<InputFunctionCoverageData> InputFunctions; std::vector<OutputFunctionCoverageData> OutputFunctions; @@ -108,7 +131,8 @@ struct CoverageMappingTest : ::testing::Test { std::unique_ptr<CoverageMapping> LoadedCoverage; void SetUp() override { - ProfileWriter.setOutputSparse(false); + ProfileWriter.setOutputSparse(GetParam().first); + UseMultipleReaders = GetParam().second; } unsigned getGlobalFileIndex(StringRef Name) { @@ -116,12 +140,12 @@ struct CoverageMappingTest : ::testing::Test { if (R != Files.end()) return R->second; unsigned Index = Files.size(); - Files.emplace_second(Name, Index); + Files.try_emplace(Name, Index); return Index; } // Return the file index of file 'Name' for the current function. - // Add the file into the global map if necesary. + // Add the file into the global map if necessary. // See also InputFunctionCoverageData::ReverseVirtualFileMapping // for additional comments. unsigned getFileIndexForFunction(StringRef Name) { @@ -164,7 +188,7 @@ struct CoverageMappingTest : ::testing::Test { return OS.str(); } - void readCoverageRegions(std::string Coverage, + void readCoverageRegions(const std::string &Coverage, OutputFunctionCoverageData &Data) { SmallVector<StringRef, 8> Filenames(Files.size()); for (const auto &E : Files) @@ -194,27 +218,30 @@ struct CoverageMappingTest : ::testing::Test { ProfileReader = std::move(ReaderOrErr.get()); } + Expected<std::unique_ptr<CoverageMapping>> readOutputFunctions() { + if (!UseMultipleReaders) { + CoverageMappingReaderMock CovReader(OutputFunctions); + return CoverageMapping::load(CovReader, *ProfileReader); + } + + std::vector<std::unique_ptr<CoverageMappingReader>> CoverageReaders; + for (const auto &OF : OutputFunctions) { + ArrayRef<OutputFunctionCoverageData> Funcs(OF); + CoverageReaders.push_back(make_unique<CoverageMappingReaderMock>(Funcs)); + } + return CoverageMapping::load(CoverageReaders, *ProfileReader); + } + void loadCoverageMapping(bool EmitFilenames = true) { readProfCounts(); writeAndReadCoverageRegions(EmitFilenames); - - CoverageMappingReaderMock CovReader(OutputFunctions); - auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader); + auto CoverageOrErr = readOutputFunctions(); ASSERT_TRUE(NoError(CoverageOrErr.takeError())); LoadedCoverage = std::move(CoverageOrErr.get()); } }; -struct MaybeSparseCoverageMappingTest - : public CoverageMappingTest, - public ::testing::WithParamInterface<bool> { - void SetUp() { - CoverageMappingTest::SetUp(); - ProfileWriter.setOutputSparse(GetParam()); - } -}; - -TEST_P(MaybeSparseCoverageMappingTest, basic_write_read) { +TEST_P(CoverageMappingTest, basic_write_read) { startFunction("func", 0x1234); addCMR(Counter::getCounter(0), "foo", 1, 1, 1, 1); addCMR(Counter::getCounter(1), "foo", 2, 1, 2, 2); @@ -239,8 +266,7 @@ TEST_P(MaybeSparseCoverageMappingTest, basic_write_read) { } } -TEST_P(MaybeSparseCoverageMappingTest, - correct_deserialize_for_more_than_two_files) { +TEST_P(CoverageMappingTest, correct_deserialize_for_more_than_two_files) { const char *FileNames[] = {"bar", "baz", "foo"}; static const unsigned N = array_lengthof(FileNames); @@ -265,7 +291,7 @@ TEST_P(MaybeSparseCoverageMappingTest, } } -TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_more_than_two_files) { +TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) { InstrProfRecord Record("func", 0x1234, {0}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -287,7 +313,7 @@ TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_more_than_two_files) { } } -TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_several_functions) { +TEST_P(CoverageMappingTest, load_coverage_for_several_functions) { InstrProfRecord RecordFunc1("func1", 0x1234, {10}); NoError(ProfileWriter.addRecord(std::move(RecordFunc1))); InstrProfRecord RecordFunc2("func2", 0x2345, {20}); @@ -318,7 +344,7 @@ TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_several_functions) { } } -TEST_P(MaybeSparseCoverageMappingTest, expansion_gets_first_counter) { +TEST_P(CoverageMappingTest, expansion_gets_first_counter) { startFunction("func", 0x1234); addCMR(Counter::getCounter(1), "foo", 10, 1, 10, 2); // This starts earlier in "foo", so the expansion should get its counter. @@ -334,7 +360,7 @@ TEST_P(MaybeSparseCoverageMappingTest, expansion_gets_first_counter) { ASSERT_EQ(3U, Output.Regions[2].LineStart); } -TEST_P(MaybeSparseCoverageMappingTest, basic_coverage_iteration) { +TEST_P(CoverageMappingTest, basic_coverage_iteration) { InstrProfRecord Record("func", 0x1234, {30, 20, 10, 0}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -357,7 +383,7 @@ TEST_P(MaybeSparseCoverageMappingTest, basic_coverage_iteration) { ASSERT_EQ(CoverageSegment(11, 11, false), Segments[6]); } -TEST_P(MaybeSparseCoverageMappingTest, uncovered_function) { +TEST_P(CoverageMappingTest, uncovered_function) { startFunction("func", 0x1234); addCMR(Counter::getZero(), "file1", 1, 2, 3, 4); loadCoverageMapping(); @@ -369,7 +395,7 @@ TEST_P(MaybeSparseCoverageMappingTest, uncovered_function) { ASSERT_EQ(CoverageSegment(3, 4, false), Segments[1]); } -TEST_P(MaybeSparseCoverageMappingTest, uncovered_function_with_mapping) { +TEST_P(CoverageMappingTest, uncovered_function_with_mapping) { startFunction("func", 0x1234); addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9); addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7); @@ -383,7 +409,7 @@ TEST_P(MaybeSparseCoverageMappingTest, uncovered_function_with_mapping) { ASSERT_EQ(CoverageSegment(9, 9, false), Segments[2]); } -TEST_P(MaybeSparseCoverageMappingTest, combine_regions) { +TEST_P(CoverageMappingTest, combine_regions) { InstrProfRecord Record("func", 0x1234, {10, 20, 30}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -402,8 +428,7 @@ TEST_P(MaybeSparseCoverageMappingTest, combine_regions) { ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]); } -TEST_P(MaybeSparseCoverageMappingTest, - restore_combined_counter_after_nested_region) { +TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) { InstrProfRecord Record("func", 0x1234, {10, 20, 40}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -424,7 +449,7 @@ TEST_P(MaybeSparseCoverageMappingTest, // If CodeRegions and ExpansionRegions cover the same area, // only counts of CodeRegions should be used. -TEST_P(MaybeSparseCoverageMappingTest, dont_combine_expansions) { +TEST_P(CoverageMappingTest, dont_combine_expansions) { InstrProfRecord Record1("func", 0x1234, {10, 20}); InstrProfRecord Record2("func", 0x1234, {0, 0}); NoError(ProfileWriter.addRecord(std::move(Record1))); @@ -447,7 +472,7 @@ TEST_P(MaybeSparseCoverageMappingTest, dont_combine_expansions) { } // If an area is covered only by ExpansionRegions, they should be combinated. -TEST_P(MaybeSparseCoverageMappingTest, combine_expansions) { +TEST_P(CoverageMappingTest, combine_expansions) { InstrProfRecord Record("func", 0x1234, {2, 3, 7}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -469,7 +494,7 @@ TEST_P(MaybeSparseCoverageMappingTest, combine_expansions) { EXPECT_EQ(CoverageSegment(5, 5, false), Segments[3]); } -TEST_P(MaybeSparseCoverageMappingTest, strip_filename_prefix) { +TEST_P(CoverageMappingTest, strip_filename_prefix) { InstrProfRecord Record("file1:func", 0x1234, {0}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -484,7 +509,7 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_filename_prefix) { ASSERT_EQ("func", Names[0]); } -TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) { +TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) { InstrProfRecord Record("<unknown>:func", 0x1234, {0}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -499,7 +524,7 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) { ASSERT_EQ("func", Names[0]); } -TEST_P(MaybeSparseCoverageMappingTest, dont_detect_false_instantiations) { +TEST_P(CoverageMappingTest, dont_detect_false_instantiations) { InstrProfRecord Record1("foo", 0x1234, {10}); InstrProfRecord Record2("bar", 0x2345, {20}); NoError(ProfileWriter.addRecord(std::move(Record1))); @@ -520,7 +545,7 @@ TEST_P(MaybeSparseCoverageMappingTest, dont_detect_false_instantiations) { ASSERT_TRUE(Instantiations.empty()); } -TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_expanded_file) { +TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) { InstrProfRecord Record("func", 0x1234, {10}); NoError(ProfileWriter.addRecord(std::move(Record))); @@ -537,7 +562,28 @@ TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_expanded_file) { EXPECT_EQ(CoverageSegment(1, 10, false), Segments[1]); } -INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseCoverageMappingTest, - ::testing::Bool()); +TEST_P(CoverageMappingTest, skip_duplicate_function_record) { + InstrProfRecord Record("func", 0x1234, {1}); + NoError(ProfileWriter.addRecord(std::move(Record))); + + startFunction("func", 0x1234); + addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9); + + startFunction("func", 0x1234); + addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9); + + loadCoverageMapping(); + + auto Funcs = LoadedCoverage->getCoveredFunctions(); + unsigned NumFuncs = std::distance(Funcs.begin(), Funcs.end()); + ASSERT_EQ(1U, NumFuncs); +} + +// FIXME: Use ::testing::Combine() when llvm updates its copy of googletest. +INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest, + ::testing::Values(std::pair<bool, bool>({false, false}), + std::pair<bool, bool>({false, true}), + std::pair<bool, bool>({true, false}), + std::pair<bool, bool>({true, true}))); } // end anonymous namespace |
