Fixed alignment of code sections in the JIT mode. Added a test to the JITMemoryManager.
[oota-llvm.git] / unittests / ExecutionEngine / JIT / JITMemoryManagerTest.cpp
index 21ca0d448ced39de021cbcfde03ce99c8a449c32..c06b89cf43ee609d0ad579b5518d33271d4376f5 100644 (file)
@@ -277,4 +277,27 @@ TEST(JITMemoryManagerTest, TestManyStubs) {
   EXPECT_EQ(3U, MemMgr->GetNumStubSlabs());
 }
 
+// Check section allocation and alignment
+TEST(JITMemoryManagerTest, AllocateSection) {
+  OwningPtr<JITMemoryManager> MemMgr(
+      JITMemoryManager::CreateDefaultMemManager());
+  uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1);\r
+  uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, true);\r
+  uint8_t *code2 = MemMgr->allocateCodeSection(257, 32, 3);\r
+  uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, false);\r
+  uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5);\r
+\r
+  EXPECT_NE((uint8_t*)0, code1);\r
+  EXPECT_NE((uint8_t*)0, code2);\r
+  EXPECT_NE((uint8_t*)0, data1);\r
+  EXPECT_NE((uint8_t*)0, data2);\r
+\r
+  // Check alignment\r
+  EXPECT_EQ((uint64_t)code1 & 0xf, 0);\r
+  EXPECT_EQ((uint64_t)code2 & 0x1f, 0);\r
+  EXPECT_EQ((uint64_t)code3 & 0x3f, 0);\r
+  EXPECT_EQ((uint64_t)data1 & 0xf, 0);\r
+  EXPECT_EQ((uint64_t)data2 & 0x3f, 0);\r
+}
+
 }