| // Copyright 2017 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/syslog/cpp/macros.h> | |
| #include <zircon/process.h> | |
| #include <zircon/syscalls.h> | |
| #include <perftest/perftest.h> | |
| namespace { | |
| bool ThreadCreateAndJoinTest() { | |
| zx_handle_t thread; | |
| constexpr char tname[] = "test thread"; | |
| FX_CHECK(zx_thread_create(zx_process_self(), tname, sizeof(tname), 0, &thread) == ZX_OK); | |
| uint64_t stack_size = 16 * 1024u; | |
| zx_handle_t stack_vmo; | |
| FX_CHECK(zx_vmo_create(stack_size, 0, &stack_vmo) == ZX_OK); | |
| zx_handle_t vmar = zx_vmar_root_self(); | |
| zx_vaddr_t stack_base; | |
| zx_vm_option_t perm = ZX_VM_PERM_READ | ZX_VM_PERM_WRITE; | |
| FX_CHECK(zx_vmar_map(vmar, perm, 0, stack_vmo, 0, stack_size, &stack_base) == ZX_OK); | |
| uintptr_t entry = reinterpret_cast<uintptr_t>(&zx_thread_exit); | |
| uintptr_t stack = reinterpret_cast<uintptr_t>(stack_base + stack_size); | |
| FX_CHECK(zx_thread_start(thread, entry, stack, 0, 0) == ZX_OK); | |
| zx_signals_t observed; | |
| FX_CHECK(zx_object_wait_one(thread, ZX_THREAD_TERMINATED, ZX_TIME_INFINITE, &observed) == ZX_OK); | |
| FX_CHECK(zx_vmar_unmap(vmar, stack_base, stack_size) == ZX_OK); | |
| zx_handle_close(thread); | |
| zx_handle_close(stack_vmo); | |
| return true; | |
| } | |
| void RegisterTests() { | |
| perftest::RegisterSimpleTest<ThreadCreateAndJoinTest>("Thread/CreateAndJoin"); | |
| } | |
| PERFTEST_CTOR(RegisterTests); | |
| } // namespace |