[llvm] r229473 - InstrProf: Use a test fixture in the coverage mapping tests

Aaron Ballman aaron at aaronballman.com
Tue Feb 17 05:21:53 PST 2015


I've reverted this in r229496 since it does not compile with MSVC.
Here's the full text of the compile error:

143>  CoverageMappingTest.cpp
143>E:\llvm\llvm\utils\unittest\googletest\include\gtest/gtest.h(1319):
error C2678: binary '==' : no operator found which takes a left-hand
operand of type 'const llvm::instrprof_error' (or there is no
acceptable conversion)
143>          D:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\include\exception(497): could be 'bool std::operator ==(const
std::exception_ptr &,const std::exception_ptr &)' [found using
argument-dependent lookup]
143>          D:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\include\exception(502): or       'bool std::operator
==(std::nullptr_t,const std::exception_ptr &)' [found using
argument-dependent lookup]
143>          D:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\include\exception(507): or       'bool std::operator ==(const
std::exception_ptr &,std::nullptr_t)' [found using argument-dependent
lookup]
143>          D:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\include\system_error(402): or       'bool std::operator
==(const std::error_code &,const std::error_condition &) throw()'
[found using argument-dependent lookup]
143>          D:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\include\system_error(410): or       'bool std::operator
==(const std::error_condition &,const std::error_code &) throw()'
[found using argument-dependent lookup]
143>          E:\llvm\llvm\include\llvm/ADT/StringRef.h(530): or
'bool llvm::operator ==(llvm::StringRef,llvm::StringRef)' [found using
argument-dependent lookup]
143>          E:\llvm\llvm\include\llvm/ADT/Hashing.h(86): or
'bool llvm::operator ==(const llvm::hash_code &,const llvm::hash_code
&)' [found using argument-dependent lookup]
143>          while trying to match the argument list '(const
llvm::instrprof_error, const std::error_code)'
143>          E:\llvm\llvm\utils\unittest\googletest\include\gtest/gtest.h(1356)
: see reference to function template instantiation
'testing::AssertionResult testing::internal::CmpHelperEQ<T1,T2>(const
char *,const char *,const T1 &,const T2 &)' being compiled
143>          with
143>          [
143>              T1=llvm::instrprof_error
143>  ,            T2=std::error_code
143>          ]
143>          E:\llvm\llvm\unittests\ProfileData\CoverageMappingTest.cpp(86)
: see reference to function template instantiation
'testing::AssertionResult
testing::internal::EqHelper<false>::Compare<llvm::instrprof_error,std::error_code>(const
char *,const char *,const T1 &,const T2 &)' being compiled
143>          with
143>          [
143>              T1=llvm::instrprof_error
143>  ,            T2=std::error_code
143>          ]
143>          E:\llvm\llvm\unittests\ProfileData\CoverageMappingTest.cpp(86)
: see reference to function template instantiation
'testing::AssertionResult
testing::internal::EqHelper<false>::Compare<llvm::instrprof_error,std::error_code>(const
char *,const char *,const T1 &,const T2 &)' being compiled
143>          with
143>          [
143>              T1=llvm::instrprof_error
143>  ,            T2=std::error_code
143>          ]

~Aaron

On Tue, Feb 17, 2015 at 1:56 AM, Justin Bogner <mail at justinbogner.com> wrote:
> Author: bogner
> Date: Tue Feb 17 00:56:49 2015
> New Revision: 229473
>
> URL: http://llvm.org/viewvc/llvm-project?rev=229473&view=rev
> Log:
> InstrProf: Use a test fixture in the coverage mapping tests
>
> Modified:
>     llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
>
> Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=229473&r1=229472&r2=229473&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
> +++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Tue Feb 17 00:56:49 2015
> @@ -33,83 +33,91 @@ void PrintTo(const Counter &C, ::std::os
>
>  namespace {
>
> -static std::string writeCoverage(MutableArrayRef<CounterMappingRegion> Regions,
> -                                 int NumFiles) {
> -  SmallVector<unsigned, 8> FileIDs;
> -  for (int I = 0; I < NumFiles; ++I)
> -    FileIDs.push_back(I);
> -
> -  std::string Coverage;
> -  llvm::raw_string_ostream OS(Coverage);
> -  CoverageMappingWriter(FileIDs, None, Regions).write(OS);
> -  OS.flush();
> +struct CoverageMappingTest : ::testing::Test {
> +  StringMap<unsigned> Files;
> +  unsigned NextFile;
> +  std::vector<CounterMappingRegion> InputCMRs;
> +
> +  std::vector<StringRef> OutputFiles;
> +  std::vector<CounterExpression> OutputExpressions;
> +  std::vector<CounterMappingRegion> OutputCMRs;
>
> -  return Coverage;
> -}
> +  void SetUp() override {
> +    NextFile = 0;
> +  }
>
> -static std::vector<CounterMappingRegion>
> -readCoverageRegions(std::string Coverage, int NumFiles) {
> -  SmallVector<std::string, 8> Filenames;
> -  SmallVector<StringRef, 8> FilenameRefs;
> -  for (int I = 0; I < NumFiles; ++I) {
> -    std::ostringstream S;
> -    S << "file" << I;
> -    Filenames.push_back(S.str());
> -    FilenameRefs.push_back(Filenames.back());
> -  }
> -
> -  std::vector<StringRef> FuncFiles;
> -  std::vector<CounterExpression> Expressions;
> -  std::vector<CounterMappingRegion> Regions;
> -  RawCoverageMappingReader Reader(Coverage, FilenameRefs, FuncFiles,
> -                                  Expressions, Regions);
> -  if (Reader.read())
> -    // ASSERT doesn't work here, we'll just return an empty vector.
> -    Regions.clear();
> -  return Regions;
> -}
> +  unsigned getFile(StringRef Name) {
> +    auto R = Files.find(Name);
> +    if (R != Files.end())
> +      return R->second;
> +    Files[Name] = NextFile;
> +    return NextFile++;
> +  }
> +
> +  void addCMR(Counter C, StringRef File, unsigned LS, unsigned CS, unsigned LE,
> +              unsigned CE) {
> +    InputCMRs.push_back(
> +        CounterMappingRegion::makeRegion(C, getFile(File), LS, CS, LE, CE));
> +  }
> +
> +  void addExpansionCMR(StringRef File, StringRef ExpandedFile, unsigned LS,
> +                       unsigned CS, unsigned LE, unsigned CE) {
> +    InputCMRs.push_back(CounterMappingRegion::makeExpansion(
> +        getFile(File), getFile(ExpandedFile), LS, CS, LE, CE));
> +  }
> +
> +  std::string writeCoverageRegions() {
> +    SmallVector<unsigned, 8> FileIDs;
> +    for (const auto &E : Files)
> +      FileIDs.push_back(E.getValue());
> +    std::string Coverage;
> +    llvm::raw_string_ostream OS(Coverage);
> +    CoverageMappingWriter(FileIDs, None, InputCMRs).write(OS);
> +    return OS.str();
> +  }
> +
> +  void readCoverageRegions(std::string Coverage) {
> +    SmallVector<StringRef, 8> Filenames;
> +    for (const auto &E : Files)
> +      Filenames.push_back(E.getKey());
> +    RawCoverageMappingReader Reader(Coverage, Filenames, OutputFiles,
> +                                    OutputExpressions, OutputCMRs);
> +    std::error_code EC = Reader.read();
> +    ASSERT_EQ(instrprof_error::success, EC);
> +  }
> +};
>
> -TEST(CoverageMappingTest, basic_write_read) {
> -  int NumFiles = 2;
> -  CounterMappingRegion InputRegions[] = {
> -      CounterMappingRegion::makeRegion(Counter::getCounter(0), 0, 1, 1, 1, 1),
> -      CounterMappingRegion::makeRegion(Counter::getCounter(1), 0, 2, 1, 2, 2),
> -      CounterMappingRegion::makeRegion(Counter::getZero(), 0, 3, 1, 3, 4),
> -      CounterMappingRegion::makeRegion(Counter::getCounter(2), 0, 4, 1, 4, 8),
> -      CounterMappingRegion::makeRegion(Counter::getCounter(3), 1, 1, 2, 3, 4),
> -  };
> -  std::string Coverage = writeCoverage(InputRegions, NumFiles);
> -  std::vector<CounterMappingRegion> OutputRegions =
> -      readCoverageRegions(Coverage, NumFiles);
> -  ASSERT_FALSE(OutputRegions.empty());
> +TEST_F(CoverageMappingTest, basic_write_read) {
> +  addCMR(Counter::getCounter(0), "foo", 1, 1, 1, 1);
> +  addCMR(Counter::getCounter(1), "foo", 2, 1, 2, 2);
> +  addCMR(Counter::getZero(),     "foo", 3, 1, 3, 4);
> +  addCMR(Counter::getCounter(2), "foo", 4, 1, 4, 8);
> +  addCMR(Counter::getCounter(3), "bar", 1, 2, 3, 4);
> +  std::string Coverage = writeCoverageRegions();
> +  readCoverageRegions(Coverage);
>
> -  size_t N = makeArrayRef(InputRegions).size();
> -  ASSERT_EQ(N, OutputRegions.size());
> +  size_t N = makeArrayRef(InputCMRs).size();
> +  ASSERT_EQ(N, OutputCMRs.size());
>    for (size_t I = 0; I < N; ++I) {
> -    ASSERT_EQ(InputRegions[I].Count, OutputRegions[I].Count);
> -    ASSERT_EQ(InputRegions[I].FileID, OutputRegions[I].FileID);
> -    ASSERT_EQ(InputRegions[I].startLoc(), OutputRegions[I].startLoc());
> -    ASSERT_EQ(InputRegions[I].endLoc(), OutputRegions[I].endLoc());
> -    ASSERT_EQ(InputRegions[I].Kind, OutputRegions[I].Kind);
> +    ASSERT_EQ(InputCMRs[I].Count,      OutputCMRs[I].Count);
> +    ASSERT_EQ(InputCMRs[I].FileID,     OutputCMRs[I].FileID);
> +    ASSERT_EQ(InputCMRs[I].startLoc(), OutputCMRs[I].startLoc());
> +    ASSERT_EQ(InputCMRs[I].endLoc(),   OutputCMRs[I].endLoc());
> +    ASSERT_EQ(InputCMRs[I].Kind,       OutputCMRs[I].Kind);
>    }
>  }
>
> -TEST(CoverageMappingTest, expansion_gets_first_counter) {
> -  int NumFiles = 2;
> -  CounterMappingRegion InputRegions[] = {
> -      CounterMappingRegion::makeRegion(Counter::getCounter(1), 0, 10, 1, 10, 2),
> -      // This starts earlier in file 0, so the expansion should get its counter.
> -      CounterMappingRegion::makeRegion(Counter::getCounter(2), 0, 1, 1, 20, 1),
> -      CounterMappingRegion::makeExpansion(1, 0, 3, 3, 3, 3),
> -  };
> -  std::string Coverage = writeCoverage(InputRegions, NumFiles);
> -  std::vector<CounterMappingRegion> OutputRegions =
> -      readCoverageRegions(Coverage, NumFiles);
> -  ASSERT_FALSE(OutputRegions.empty());
> -
> -  ASSERT_EQ(CounterMappingRegion::ExpansionRegion, OutputRegions[2].Kind);
> -  ASSERT_EQ(Counter::getCounter(2), OutputRegions[2].Count);
> -  ASSERT_EQ(3U, OutputRegions[2].LineStart);
> +TEST_F(CoverageMappingTest, expansion_gets_first_counter) {
> +  addCMR(Counter::getCounter(1), "foo", 10, 1, 10, 2);
> +  // This starts earlier in "foo", so the expansion should get its counter.
> +  addCMR(Counter::getCounter(2), "foo", 1, 1, 20, 1);
> +  addExpansionCMR("bar", "foo", 3, 3, 3, 3);
> +  std::string Coverage = writeCoverageRegions();
> +  readCoverageRegions(Coverage);
> +
> +  ASSERT_EQ(CounterMappingRegion::ExpansionRegion, OutputCMRs[2].Kind);
> +  ASSERT_EQ(Counter::getCounter(2), OutputCMRs[2].Count);
> +  ASSERT_EQ(3U, OutputCMRs[2].LineStart);
>  }
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list