Commits

Gregor Wegberg  committed 4aa9c7a

generalize previously added test and use it to get two tests

previouse test added in 513744aa7a905300b7389cd1c3724c0150762ee4

  • Participants
  • Parent commits 513744a
  • Branches gc-incminimark-pinning

Comments (0)

Files changed (1)

File rpython/memory/gc/test/test_object_pinning.py

         self.gc.collect()
         assert self.stackroots[0].next.someInt == 100
 
-    def test_old_and_stackroots_point_to_pinned(self):
+    def not_pinned_and_stackroots_point_to_pinned(self, make_old):
         # In this test case we point to a pinned object from an old object
         # *and* from the stackroots
-        old_ptr = self.malloc(S)
-        old_ptr.someInt = 999
-        self.stackroots.append(old_ptr)
-        self.gc.collect() # old_ptr is now old
-        old_ptr = self.stackroots[0]
-        assert not self.gc.is_in_nursery(llmemory.cast_ptr_to_adr(old_ptr))
+        obj_ptr = self.malloc(S)
+        obj_ptr.someInt = 999
+        self.stackroots.append(obj_ptr)
+        if make_old:
+            self.gc.collect() # old_ptr is now old
+            obj_ptr = self.stackroots[0]
+            assert not self.gc.is_in_nursery(llmemory.cast_ptr_to_adr(obj_ptr))
+        else:
+            assert self.gc.is_in_nursery(llmemory.cast_ptr_to_adr(obj_ptr))
 
         pinned_ptr = self.malloc(S)
         pinned_ptr.someInt = 111
         assert self.gc.pin(llmemory.cast_ptr_to_adr(pinned_ptr))
 
         self.stackroots.append(pinned_ptr)
-        self.write(old_ptr, 'next', pinned_ptr)
+        self.write(obj_ptr, 'next', pinned_ptr)
         
         self.gc.collect()
         # done with preparation. do some basic checks
         assert pinned_ptr.someInt == 111
         assert self.stackroots[0].next == pinned_ptr
 
+    def test_old_and_stackroots_point_to_pinned(self):
+        self.not_pinned_and_stackroots_point_to_pinned(make_old=True)
+
+    def test_young_and_stackroots_point_to_pinned(self):
+        self.not_pinned_and_stackroots_point_to_pinned(make_old=False)
+
     def test_pin_old(self):
         ptr = self.malloc(S)
         ptr.someInt = 100