| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include <lib/zx/eventpair.h> |
| |
| #include <gtest/gtest.h> |
| |
| #include "src/performance/lib/test_utils/run_program.h" |
| |
| namespace tracing { |
| namespace test { |
| |
| namespace { |
| |
| const char kReturnCodeChildPath[] = "/pkg/bin/return_1234"; |
| |
| constexpr int kChildReturnCode = 1234; |
| |
| const char kSignalPeerChildPath[] = "/pkg/bin/signal_peer"; |
| |
| constexpr int kSignalPeerReturnCode = 4321; |
| |
| TEST(TraceTestUtils, SpawnAndWait) { |
| zx::job job{}; // -> default job |
| zx::process child; |
| std::vector<std::string> argv{kReturnCodeChildPath}; |
| |
| ASSERT_EQ(SpawnProgram(job, argv, ZX_HANDLE_INVALID, &child), ZX_OK); |
| |
| int64_t return_code; |
| ASSERT_TRUE(WaitAndGetReturnCode(argv[0], child, &return_code)); |
| EXPECT_EQ(return_code, kChildReturnCode); |
| } |
| |
| TEST(TraceTestUtils, SpawnAndWaitSignalPeer) { |
| zx::job job{}; // -> default job |
| zx::process child; |
| std::vector<std::string> argv{kSignalPeerChildPath}; |
| |
| zx::eventpair our_event, their_event; |
| ASSERT_EQ(zx::eventpair::create(0u, &our_event, &their_event), ZX_OK); |
| |
| ASSERT_EQ(SpawnProgram(job, argv, their_event.release(), &child), ZX_OK); |
| |
| zx_signals_t pending; |
| EXPECT_EQ(our_event.wait_one(ZX_EVENTPAIR_SIGNALED, zx::time::infinite(), &pending), ZX_OK); |
| |
| int64_t return_code; |
| ASSERT_TRUE(WaitAndGetReturnCode(argv[0], child, &return_code)); |
| EXPECT_EQ(return_code, kSignalPeerReturnCode); |
| } |
| |
| } // namespace |
| |
| } // namespace test |
| } // namespace tracing |