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 // Test main for runtests-utils test on Fuchsia.
6 
7 #include "runtests-utils-test-globals.h"
8 
9 #include <lib/async-loop/cpp/loop.h>
10 #include <lib/memfs/memfs.h>
11 #include <runtests-utils/fuchsia-run-test.h>
12 #include <unittest/unittest.h>
13 
14 namespace runtests {
15 
16 // Root directory of memfs installed for duration of test.
17 static constexpr char kMemFsRoot[] = "/test-memfs";
18 
19 const char kScriptShebang[32] = "#!/boot/bin/sh\n\n";
20 const RunTestFn PlatformRunTest = &FuchsiaRunTest;
21 
TestFsRoot()22 const char* TestFsRoot() {
23     return kMemFsRoot;
24 }
25 
26 } // namespace runtests
27 
main(int argc,char ** argv)28 int main(int argc, char** argv) {
29     async::Loop loop(&kAsyncLoopConfigNoAttachToThread);
30     if (loop.StartThread() != ZX_OK) {
31         fprintf(stderr, "Error: Cannot initialize local memfs loop\n");
32         return -1;
33     }
34     if (memfs_install_at(loop.dispatcher(), runtests::kMemFsRoot) != ZX_OK) {
35         fprintf(stderr, "Error: Cannot install local memfs\n");
36         return -1;
37     }
38     return unittest_run_all_tests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
39 }
40