[PATCH] D154680: [llvm-exegesis] Make SubprocessMemoryTest use PIDs

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 21:11:46 PDT 2023


aidengrossman updated this revision to Diff 537974.
aidengrossman added a comment.

Remove unnecessary headers and debug statements.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154680/new/

https://reviews.llvm.org/D154680

Files:
  llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp


Index: llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
===================================================================
--- llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
+++ llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
@@ -16,6 +16,7 @@
 #include <endian.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <unistd.h>
 #endif // __linux__
 
 namespace llvm {
@@ -25,11 +26,21 @@
 
 class SubprocessMemoryTest : public X86TestBase {
 protected:
+  // In this function and below, TestNumber is a one-based index of the test
+  // rather than a zero-based index of the test so that the zero-case doesn't
+  // cancel out the differentiation provided by the process PID.
   void
   testCommon(std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
-             const int MainProcessPID) {
-    EXPECT_FALSE(SM.initializeSubprocessMemory(MainProcessPID));
-    EXPECT_FALSE(SM.addMemoryDefinition(MemoryDefinitions, MainProcessPID));
+             const unsigned TestNumber) {
+    EXPECT_FALSE(SM.initializeSubprocessMemory(getpid() * TestNumber));
+    EXPECT_FALSE(
+        SM.addMemoryDefinition(MemoryDefinitions, getpid() * TestNumber));
+  }
+
+  std::string getSharedMemoryName(const unsigned TestNumber,
+                                  const unsigned DefinitionNumber) {
+    return "/" + std::to_string(getpid() * TestNumber) + "memdef" +
+           std::to_string(DefinitionNumber);
   }
 
   void checkSharedMemoryDefinition(const std::string &DefinitionName,
@@ -58,8 +69,8 @@
 #else
 TEST_F(SubprocessMemoryTest, OneDefinition) {
 #endif
-  testCommon({{"test1", {APInt(8, 0xff), 4096, 0}}}, 0);
-  checkSharedMemoryDefinition("/0memdef0", 4096, {0xff});
+  testCommon({{"test1", {APInt(8, 0xff), 4096, 0}}}, 1);
+  checkSharedMemoryDefinition(getSharedMemoryName(1, 0), 4096, {0xff});
 }
 
 #if defined(__powerpc__) || defined(__s390x__)
@@ -70,10 +81,10 @@
   testCommon({{"test1", {APInt(8, 0xaa), 4096, 0}},
               {"test2", {APInt(8, 0xbb), 4096, 1}},
               {"test3", {APInt(8, 0xcc), 4096, 2}}},
-             1);
-  checkSharedMemoryDefinition("/1memdef0", 4096, {0xaa});
-  checkSharedMemoryDefinition("/1memdef1", 4096, {0xbb});
-  checkSharedMemoryDefinition("/1memdef2", 4096, {0xcc});
+             2);
+  checkSharedMemoryDefinition(getSharedMemoryName(2, 0), 4096, {0xaa});
+  checkSharedMemoryDefinition(getSharedMemoryName(2, 1), 4096, {0xbb});
+  checkSharedMemoryDefinition(getSharedMemoryName(2, 2), 4096, {0xcc});
 }
 
 #if defined(__powerpc__) || defined(__s390x__)
@@ -84,13 +95,13 @@
   testCommon({{"test1", {APInt(8, 0xaa), 4096, 0}},
               {"test2", {APInt(16, 0xbbbb), 4096, 1}},
               {"test3", {APInt(24, 0xcccccc), 4096, 2}}},
-             2);
+             3);
   std::vector<uint8_t> Test1Expected(512, 0xaa);
   std::vector<uint8_t> Test2Expected(512, 0xbb);
   std::vector<uint8_t> Test3Expected(512, 0xcc);
-  checkSharedMemoryDefinition("/2memdef0", 4096, Test1Expected);
-  checkSharedMemoryDefinition("/2memdef1", 4096, Test2Expected);
-  checkSharedMemoryDefinition("/2memdef2", 4096, Test3Expected);
+  checkSharedMemoryDefinition(getSharedMemoryName(3, 0), 4096, Test1Expected);
+  checkSharedMemoryDefinition(getSharedMemoryName(3, 1), 4096, Test2Expected);
+  checkSharedMemoryDefinition(getSharedMemoryName(3, 2), 4096, Test3Expected);
 }
 
 // The following test is only supported on little endian systems.
@@ -99,7 +110,7 @@
 #else
 TEST_F(SubprocessMemoryTest, DefinitionEndTruncation) {
 #endif
-  testCommon({{"test1", {APInt(48, 0xaabbccddeeff), 4096, 0}}}, 3);
+  testCommon({{"test1", {APInt(48, 0xaabbccddeeff), 4096, 0}}}, 4);
   std::vector<uint8_t> Test1Expected(512, 0);
   // order is reversed since we're assuming a little endian system.
   for (size_t I = 0; I < Test1Expected.size(); ++I) {
@@ -123,7 +134,7 @@
       Test1Expected[I] = 0xaa;
     }
   }
-  checkSharedMemoryDefinition("/3memdef0", 4096, Test1Expected);
+  checkSharedMemoryDefinition(getSharedMemoryName(4, 0), 4096, Test1Expected);
 }
 
 #endif // defined(__linux__) && !defined(__ANDROID__)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154680.537974.patch
Type: text/x-patch
Size: 4142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230707/1eb4f648/attachment.bin>


More information about the llvm-commits mailing list