1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <fbl/unique_ptr.h> 8 #include <fbl/unique_fd.h> 9 #include <lib/devmgr-launcher/launch.h> 10 #include <lib/zx/job.h> 11 #include <lib/zx/time.h> 12 13 namespace devmgr_integration_test { 14 15 class IsolatedDevmgr { 16 public: 17 ~IsolatedDevmgr(); 18 19 // Path to the test sysdev driver 20 static const char* kSysdevDriver; 21 22 // Get an args structure pre-populated with the test sysdev driver, the 23 // test control driver, and the test driver directory. 24 static devmgr_launcher::Args DefaultArgs(); 25 26 // Launch a new isolated devmgr. The instance will be destroyed when 27 // |*out|'s dtor runs. 28 static zx_status_t Create(devmgr_launcher::Args args, 29 fbl::unique_ptr<IsolatedDevmgr>* out); 30 31 // Get a fd to the root of the isolate devmgr's devfs. This fd 32 // may be used with openat() and fdio_watch_directory(). devfs_root()33 const fbl::unique_fd& devfs_root() const { return devfs_root_; } 34 35 // Borrow the handle to the job containing the isolated devmgr. This may be 36 // used for things like binding to an exception port. containing_job()37 const zx::job& containing_job() const { return job_; } 38 private: 39 // Job that contains the devmgr environment 40 zx::job job_; 41 42 // FD to the root of devmgr's devfs 43 fbl::unique_fd devfs_root_; 44 }; 45 46 // Wait for |file| to appear in |dir|, and open it when it does. 47 zx_status_t WaitForFile(const fbl::unique_fd& dir, const char* file, zx::time deadline, 48 fbl::unique_fd* out); 49 50 // Waits for the relative |path| starting in |dir| to appear, and opens it. 51 zx_status_t RecursiveWaitForFile(const fbl::unique_fd& dir, const char* path, 52 zx::time deadline, fbl::unique_fd* out); 53 54 } // namespace devmgr_integration_test 55