[PATCH] D144524: [llvm-profdata] Add more unit tests to check --output-size-limit feature when compression is enabled

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 15:14:14 PST 2023


huangjd created this revision.
huangjd added reviewers: davidxl, xur, kazu, ellis, gulfem, snehasish.
Herald added a project: All.
huangjd requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add unit tests for ExtBinary format with compression. This patch doesn't imply there's a bug in the existing implementation,
but as a precaution that planned changes to SampleProfileReader may cause it to break.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144524

Files:
  llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp


Index: llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
===================================================================
--- llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
+++ llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
@@ -77,7 +77,8 @@
 /// Note that even though by default samples with fewest total count are dropped
 /// first, this is not a requirement. Samples can be dropped by any order.
 static ExpectedErrorOr<void *> RunTest(StringRef Input, size_t SizeLimit,
-                                       SampleProfileFormat Format) {
+                                       SampleProfileFormat Format,
+                                       bool Compress = false) {
   // Read Input profile.
   auto FS = vfs::getRealFileSystem();
   LLVMContext Context;
@@ -93,6 +94,8 @@
   {
     DEF_VAR_RETURN_IF_ERROR(Writer,
                             SampleProfileWriter::create(Temp.path(), Format));
+    if (Compress)
+      Writer->setToCompressAllSections();
     std::error_code EC = Writer->writeWithSizeLimit(OldProfiles, SizeLimit);
     // too_large means no sample could be written because SizeLimit is too
     // small. Otherwise any other error code indicates unexpected failure.
@@ -180,3 +183,11 @@
         RunTest(Input1, OutputSizeLimit, llvm::sampleprof::SPF_Text),
         Succeeded());
 }
+
+TEST(TestOutputSizeLimit, TestOutputSizeLimitExtBinaryCompressed) {
+  for (size_t OutputSizeLimit :
+       {507, 506, 505, 494, 493, 492, 483, 482, 481, 480})
+    ASSERT_THAT_EXPECTED(RunTest(Input1, OutputSizeLimit,
+                                 llvm::sampleprof::SPF_Ext_Binary, true),
+                         Succeeded());
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144524.499311.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/a29bceec/attachment.bin>


More information about the llvm-commits mailing list