MCPcopy Create free account
hub / github.com/apache/tvm-ffi / test_echo

Function test_echo

tests/python/test_function.py:37–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35
36
37def test_echo() -> None:
38 fecho = tvm_ffi.get_global_func("testing.echo")
39 assert isinstance(fecho, tvm_ffi.Function)
40 # test each type
41 assert fecho(None) is None
42
43 # test bool
44 bool_result = fecho(True)
45 assert isinstance(bool_result, bool)
46 assert bool_result is True
47 bool_result = fecho(False)
48 assert isinstance(bool_result, bool)
49 assert bool_result is False
50
51 # test int/float
52 assert fecho(1) == 1
53 assert fecho(1.2) == 1.2
54
55 # test str
56 str_result = fecho("hello")
57 assert isinstance(str_result, str)
58 assert str_result == "hello"
59
60 # test bytes
61 bytes_result = fecho(b"abc")
62 assert isinstance(bytes_result, bytes)
63 assert bytes_result == b"abc"
64
65 # test dtype
66 dtype_result = fecho(tvm_ffi.dtype("float32"))
67 assert isinstance(dtype_result, tvm_ffi.dtype)
68 assert dtype_result == tvm_ffi.dtype("float32")
69
70 # test device
71 device_result = fecho(tvm_ffi.device("cuda:1"))
72 assert isinstance(device_result, tvm_ffi.Device)
73 assert device_result.dlpack_device_type() == tvm_ffi.DLDeviceType.kDLCUDA
74 assert device_result.index == 1
75 assert str(device_result) == "cuda:1"
76 assert device_result.__repr__() == "device(type='cuda', index=1)"
77
78 # test c_void_p
79 c_void_p_result = fecho(ctypes.c_void_p(0x12345678))
80 assert isinstance(c_void_p_result, ctypes.c_void_p)
81 assert c_void_p_result.value == 0x12345678
82
83 # test c_void_p for nullptr
84 c_void_p_nullptr_result = fecho(ctypes.c_void_p(0))
85 c_void_p_nullptr_result is None
86
87 # test function: aka object
88 fadd = tvm_ffi.convert(lambda a, b: a + b)
89 fadd1 = fecho(fadd)
90 assert fadd1(1, 2) == 3
91 assert fadd1.same_as(fadd)
92
93 def check_tensor() -> None:
94 np_data = np.arange(10, dtype="int32")

Callers 1

test_object_protocolFunction · 0.85

Calls 6

check_tensorFunction · 0.85
dtypeMethod · 0.45
deviceMethod · 0.45
__repr__Method · 0.45
convertMethod · 0.45
same_asMethod · 0.45

Tested by

no test coverage detected