/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "src/ipc/client_impl.h" #include <stdio.h> #include <string> #include "perfetto/ext/base/file_utils.h" #include "perfetto/ext/base/temp_file.h" #include "perfetto/ext/base/unix_socket.h" #include "perfetto/ext/base/utils.h" #include "perfetto/ext/ipc/service_descriptor.h" #include "perfetto/ext/ipc/service_proxy.h" #include "src/base/test/test_task_runner.h" #include "src/ipc/buffered_frame_deserializer.h" #include "src/ipc/test/test_socket.h" #include "test/gtest_and_gmock.h" #include "protos/perfetto/ipc/wire_protocol.gen.h" #include "src/ipc/test/client_unittest_messages.gen.h" namespace perfetto { namespace ipc { namespace { using ::perfetto::ipc::gen::ReplyProto; using ::perfetto::ipc::gen::RequestProto; _; InSequence; Invoke; Mock; ipc::TestSocket kTestSocket{"client_impl_unittest"}; // A fake ServiceProxy. This fakes the client-side class that would be // auto-generated from .proto-files. class FakeProxy : public ServiceProxy { … }; class MockEventListener : public ServiceProxy::EventListener { … }; // A fake host implementation. Listens on |kTestSocket.name()| and replies to // IPC metohds like a real one. class FakeHost : public base::UnixSocket::EventListener { … }; // FakeHost. class ClientImplTest : public ::testing::Test { … }; TEST_F(ClientImplTest, BindAndInvokeMethod) { … } // Tests that when invoking a method without binding a callback, the resulting // request has the |drop_reply| flag set. TEST_F(ClientImplTest, InvokeMethodDropReply) { … } // Like BindAndInvokeMethod, but this time invoke a streaming method that // provides > 1 reply per invocation. TEST_F(ClientImplTest, BindAndInvokeStreamingMethod) { … } #if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) && \ !PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) // File descriptor sending over IPC is not supported on Windows or Fuchsia. TEST_F(ClientImplTest, ReceiveFileDescriptor) { … } TEST_F(ClientImplTest, SendFileDescriptor) { … } #endif // !OS_WIN TEST_F(ClientImplTest, BindSameServiceMultipleTimesShouldFail) { … } TEST_F(ClientImplTest, BindRequestsAreQueuedIfNotConnected) { … } // The deferred callbacks for both binding a service and invoking a method // should be dropped if the ServiceProxy object is destroyed prematurely. TEST_F(ClientImplTest, DropCallbacksIfServiceProxyIsDestroyed) { … } // If the Client object is destroyed before the ServiceProxy, the ServiceProxy // should see a Disconnect() call and any pending callback should be rejected. TEST_F(ClientImplTest, ClientDestroyedBeforeProxy) { … } // Test that OnDisconnect() is invoked if the host is not reachable. TEST_F(ClientImplTest, HostNotReachable) { … } // Test that OnDisconnect() is invoked if the host shuts down prematurely. TEST_F(ClientImplTest, HostDisconnection) { … } // Test that OnDisconnect() is invoked if the host shuts down prematurely. TEST_F(ClientImplTest, HostDisconnectionBeforeBindReply) { … } // Disabled on Fuchsia because Fuchsia kernel sockets are non-addressable // so there is no connect() step which may fail. #if !PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) TEST_F(ClientImplTest, HostConnectionFailure) { … } #endif // !PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) // TODO(primiano): add the tests below. // TEST(ClientImplTest, UnparsableReply) {} } // namespace } // namespace ipc } // namespace perfetto