1# RUN: %PYTHON %s | FileCheck %s
2
3import gc
4from mlir.ir import *
5
6
7def run(f):
8  print("\nTEST:", f.__name__)
9  f()
10  gc.collect()
11  assert Context._get_live_count() == 0
12
13
14# CHECK-LABEL: TEST: testCapsuleConversions
15def testCapsuleConversions():
16  ctx = Context()
17  ctx.allow_unregistered_dialects = True
18  with Location.unknown(ctx):
19    i32 = IntegerType.get_signless(32)
20    value = Operation.create("custom.op1", results=[i32]).result
21    value_capsule = value._CAPIPtr
22    assert '"mlir.ir.Value._CAPIPtr"' in repr(value_capsule)
23    value2 = Value._CAPICreate(value_capsule)
24    assert value2 == value
25
26
27run(testCapsuleConversions)
28
29
30# CHECK-LABEL: TEST: testOpResultOwner
31def testOpResultOwner():
32  ctx = Context()
33  ctx.allow_unregistered_dialects = True
34  with Location.unknown(ctx):
35    i32 = IntegerType.get_signless(32)
36    op = Operation.create("custom.op1", results=[i32])
37    assert op.result.owner == op
38
39
40run(testOpResultOwner)
41