| 167 | @tvm.testing.skip_if_32bit(reason="skipping test for i386.") |
| 168 | @pytest.mark.skipif(not env.has_rpc(), reason="need rpc") |
| 169 | def test_rpc_echo(): |
| 170 | def check(remote, local_session): |
| 171 | fecho = remote.get_function("testing.echo") |
| 172 | assert fecho(1, 2, 3) == 1 |
| 173 | assert fecho(100, 2, 3) == 100 |
| 174 | assert fecho("xyz") == "xyz" |
| 175 | assert bytes(fecho(bytearray(b"123"))) == b"123" |
| 176 | |
| 177 | with pytest.raises(RuntimeError): |
| 178 | raise_err = remote.get_function("testing.test_raise_error") |
| 179 | raise_err("RuntimeError", "msg") |
| 180 | |
| 181 | remote.cpu().sync() |
| 182 | # tests around system lib are not threadsafe by design |
| 183 | # and do not work well with multithread pytest |
| 184 | # skip local session as they are being tested elsewhere |
| 185 | if not local_session: |
| 186 | with pytest.raises(AttributeError): |
| 187 | f3 = remote.system_lib()["notexist"] |
| 188 | |
| 189 | temp = rpc.server._server_env([]) |
| 190 | server = rpc.Server() |
| 191 | client = rpc.connect("127.0.0.1", server.port) |
| 192 | check(rpc.LocalSession(), True) |
| 193 | |
| 194 | check(client, False) |
| 195 | |
| 196 | def check_minrpc(): |
| 197 | if tvm.get_global_func("rpc.CreatePipeClient", allow_missing=True) is None: |
| 198 | return |
| 199 | # Test minrpc server. |
| 200 | temp = utils.tempdir() |
| 201 | minrpc_exec = temp.relpath("minrpc") |
| 202 | tvm.rpc.with_minrpc(cc.create_executable)(minrpc_exec, []) |
| 203 | check(rpc.PopenSession(minrpc_exec), False) |
| 204 | # minrpc on the remote |
| 205 | server = rpc.Server() |
| 206 | client = rpc.connect( |
| 207 | "127.0.0.1", |
| 208 | server.port, |
| 209 | session_constructor_args=["rpc.PopenSession", open(minrpc_exec, "rb").read()], |
| 210 | ) |
| 211 | check(client, False) |
| 212 | |
| 213 | # skip for now until we upgrade to new FFI |
| 214 | # check_minrpc() |
| 215 | |
| 216 | |
| 217 | @pytest.mark.skipif(not env.has_rpc(), reason="need rpc") |