blob: 96810bbffb7e43821244be3838c695883090b705 [file] [log] [blame]
// Copyright 2020 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 "tools/kazoo/outputs.h"
#include "tools/kazoo/syscall_library.h"
#include "tools/kazoo/test.h"
#include "tools/kazoo/test_ir_test_kernel_cases.test.h"
#include "tools/kazoo/test_ir_test_kernelwrappers.test.h"
#include "tools/kazoo/test_ir_test_one_protocol_two_methods.test.h"
#include "tools/kazoo/test_ir_test_one_protocol_two_methods_with_internal.test.h"
#include "tools/kazoo/test_ir_test_ownership_annotations.test.h"
#include "tools/kazoo/test_ir_test_selection.test.h"
#include "tools/kazoo/test_ir_test_vdsowrappers.test.h"
namespace {
TEST(CDeclOutput, Public) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_selection, &library));
Writer writer;
ASSERT_TRUE(PublicDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
#ifndef _ZX_SYSCALL_DECL
#error "<zircon/syscalls.h> is the public API header"
#endif
_ZX_SYSCALL_DECL(selection_futex_requeue, zx_status_t, /* no attributes */, 6,
(value_ptr, wake_count, current_value, requeue_ptr, requeue_count, new_requeue_owner), (
const zx_futex_t* value_ptr,
uint32_t wake_count,
zx_futex_t current_value,
const zx_futex_t* requeue_ptr,
uint32_t requeue_count,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t new_requeue_owner))
_ZX_SYSCALL_DECL(selection_object_wait_one, zx_status_t, /* no attributes */, 4,
(handle, signals, deadline, observed), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
zx_signals_t signals,
zx_time_t deadline,
zx_signals_t* observed))
_ZX_SYSCALL_DECL(selection_ktrace_read, zx_status_t, /* no attributes */, 5,
(handle, data, offset, data_size, actual), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
void* data,
uint32_t offset,
size_t data_size,
size_t* actual))
_ZX_SYSCALL_DECL(selection_pci_cfg_pio_rw, zx_status_t, /* no attributes */, 8,
(handle, bus, dev, func, offset, val, width, write), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint8_t bus,
uint8_t dev,
uint8_t func,
uint8_t offset,
uint32_t* val,
size_t width,
bool write))
_ZX_SYSCALL_DECL(selection_job_set_policy, zx_status_t, /* no attributes */, 5,
(handle, options, topic, policy, policy_size), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
uint32_t topic,
const void* policy,
uint32_t policy_size))
_ZX_SYSCALL_DECL(selection_clock_get, zx_status_t, /* no attributes */, 2,
(clock_id, out), (
zx_clock_t clock_id,
zx_time_t* out))
)");
}
TEST(CDeclOutput, Testonly) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_kernel_cases, &library));
Writer writer;
ASSERT_TRUE(PublicDeclarationsOutput(library, &writer));
Writer testonly_writer;
ASSERT_TRUE(TestonlyPublicDeclarationsOutput(library, &testonly_writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
#ifndef _ZX_SYSCALL_DECL
#error "<zircon/syscalls.h> is the public API header"
#endif
_ZX_SYSCALL_DECL(kernelcases_bti_pin, zx_status_t, /* no attributes */, 8,
(handle, options, vmo, offset, size, addrs, num_addrs, pmt), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t vmo,
uint64_t offset,
uint64_t size,
zx_paddr_t* addrs,
size_t num_addrs,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) zx_handle_t* pmt))
_ZX_SYSCALL_DECL(kernelcases_thread_exit, void, __NO_RETURN, 0,
(), (void))
_ZX_SYSCALL_DECL(kernelcases_mtrace_control, zx_status_t, /* no attributes */, 6,
(handle, kind, action, options, ptr, ptr_size), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t kind,
uint32_t action,
uint32_t options,
void* ptr,
size_t ptr_size))
_ZX_SYSCALL_DECL(kernelcases_read, zx_status_t, /* no attributes */, 8,
(handle, options, bytes, num_bytes, handles, num_handles, actual_bytes, actual_handles), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
void* bytes,
uint32_t num_bytes,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) zx_handle_t* handles,
uint32_t num_handles,
uint32_t* actual_bytes,
uint32_t* actual_handles))
)");
EXPECT_EQ(testonly_writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
#ifndef _ZX_SYSCALL_DECL
#error "<zircon/testonly-syscalls.h> is the public API header"
#endif
_ZX_SYSCALL_DECL(kernelcases_compiled_out_in_non_test, zx_status_t, /* no attributes */, 2,
(a, b), (
int32_t a,
int32_t b))
)");
}
TEST(CDeclOutput, Private) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_selection, &library));
Writer writer;
ASSERT_TRUE(PrivateDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
KERNEL_SYSCALL(selection_futex_requeue, zx_status_t, /* no attributes */, 6,
(value_ptr, wake_count, current_value, requeue_ptr, requeue_count, new_requeue_owner), (
const zx_futex_t* value_ptr,
uint32_t wake_count,
zx_futex_t current_value,
const zx_futex_t* requeue_ptr,
uint32_t requeue_count,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t new_requeue_owner))
KERNEL_SYSCALL(selection_object_wait_one, zx_status_t, /* no attributes */, 4,
(handle, signals, deadline, observed), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
zx_signals_t signals,
zx_time_t deadline,
zx_signals_t* observed))
KERNEL_SYSCALL(selection_ktrace_read, zx_status_t, /* no attributes */, 5,
(handle, data, offset, data_size, actual), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
void* data,
uint32_t offset,
size_t data_size,
size_t* actual))
KERNEL_SYSCALL(selection_pci_cfg_pio_rw, zx_status_t, /* no attributes */, 8,
(handle, bus, dev, func, offset, val, width, write), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint8_t bus,
uint8_t dev,
uint8_t func,
uint8_t offset,
uint32_t* val,
size_t width,
bool write))
KERNEL_SYSCALL(selection_job_set_policy, zx_status_t, /* no attributes */, 5,
(handle, options, topic, policy, policy_size), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
uint32_t topic,
const void* policy,
uint32_t policy_size))
KERNEL_SYSCALL(selection_clock_get, zx_status_t, /* no attributes */, 2,
(clock_id, out), (
zx_clock_t clock_id,
zx_time_t* out))
)");
}
TEST(CDeclOutput, Kernel) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_kernel_cases, &library));
Writer writer;
ASSERT_TRUE(KernelDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
KERNEL_SYSCALL(kernelcases_bti_pin, zx_status_t, /* no attributes */, 8,
(handle, options, vmo, offset, size, addrs, num_addrs, pmt), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t vmo,
uint64_t offset,
uint64_t size,
user_out_ptr<zx_paddr_t> addrs,
size_t num_addrs,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) user_out_handle* pmt))
KERNEL_SYSCALL(kernelcases_thread_exit, void, __NO_RETURN, 0,
(), (void))
KERNEL_SYSCALL(kernelcases_mtrace_control, zx_status_t, /* no attributes */, 6,
(handle, kind, action, options, ptr, ptr_size), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t kind,
uint32_t action,
uint32_t options,
user_inout_ptr<void> ptr,
size_t ptr_size))
KERNEL_SYSCALL(kernelcases_read, zx_status_t, /* no attributes */, 8,
(handle, options, bytes, num_bytes, handles, num_handles, actual_bytes, actual_handles), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
uint32_t options,
user_out_ptr<void> bytes,
uint32_t num_bytes,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) user_out_ptr<zx_handle_t> handles,
uint32_t num_handles,
user_out_ptr<uint32_t> actual_bytes,
user_out_ptr<uint32_t> actual_handles))
KERNEL_SYSCALL(kernelcases_compiled_out_in_non_test, zx_status_t, /* no attributes */, 2,
(a, b), (
int32_t a,
int32_t b))
)");
}
TEST(CDeclOutput, VdsoWrappers) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_vdsowrappers, &library));
Writer writer;
ASSERT_TRUE(PrivateDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
BLOCKING_SYSCALL(syscall_blocking_write, zx_status_t, /* no attributes */, 4,
(handle, buffer, buffer_size, offset), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t handle,
const void* buffer,
size_t buffer_size,
uint64_t offset))
KERNEL_SYSCALL(syscall_test_wrapper, zx_status_t, /* no attributes */, 3,
(a, b, c), (
int32_t a,
int32_t b,
int32_t c))
)");
}
TEST(CDeclOutput, HandleOwnership) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_ownership_annotations, &library));
Writer writer;
ASSERT_TRUE(PrivateDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
KERNEL_SYSCALL(handleownership_fun0, void, /* no attributes */, 4,
(in, num_in, out, num_out), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) const zx_handle_t* in,
size_t num_in,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) zx_handle_t* out,
size_t num_out))
KERNEL_SYSCALL(handleownership_fun1, void, __NO_RETURN, 2,
(in, num_in), (
_ZX_SYSCALL_ANNO(release_handle("Fuchsia")) const zx_handle_t* in,
size_t num_in))
KERNEL_SYSCALL(handleownership_fun2, void, /* no attributes */, 4,
(in, num_in, out, num_out), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) const zx_handle_t* in,
size_t num_in,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t* out,
size_t num_out))
KERNEL_SYSCALL(handleownership_fun3, void, /* no attributes */, 4,
(in, num_in, out, num_out), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) const zx_handle_t* in,
size_t num_in,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) zx_handle_t* out,
size_t num_out))
KERNEL_SYSCALL(handleownership_fun4, zx_status_t, /* no attributes */, 2,
(in, out), (
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t in,
_ZX_SYSCALL_ANNO(acquire_handle("Fuchsia")) zx_handle_t* out))
KERNEL_SYSCALL(handleownership_fun5, zx_status_t, /* no attributes */, 2,
(in, out), (
_ZX_SYSCALL_ANNO(release_handle("Fuchsia")) zx_handle_t in,
_ZX_SYSCALL_ANNO(use_handle("Fuchsia")) zx_handle_t* out))
KERNEL_SYSCALL(handleownership_fun6, void, /* no attributes */, 4,
(in, num_in, out, num_out), (
_ZX_SYSCALL_ANNO(use_handle("FuchsiaUnchecked")) const zx_handle_t* in,
size_t num_in,
_ZX_SYSCALL_ANNO(acquire_handle("FuchsiaUnchecked")) zx_handle_t* out,
size_t num_out))
)");
}
TEST(CDeclOutput, Asm) {
SyscallLibrary library;
ASSERT_TRUE(SyscallLibraryLoader::FromJson(k_test_one_protocol_two_methods, &library));
Writer writer;
ASSERT_TRUE(PrivateDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
KERNEL_SYSCALL(couple_do_thing, zx_status_t, /* no attributes */, 1,
(an_input), (
int32_t an_input))
KERNEL_SYSCALL(couple_get_stuff, zx_status_t, /* no attributes */, 2,
(an_input, input2), (
int32_t an_input,
int32_t input2))
)");
}
TEST(CDeclOutput, AsmWithInternal) {
SyscallLibrary library;
ASSERT_TRUE(
SyscallLibraryLoader::FromJson(k_test_one_protocol_two_methods_with_internal, &library));
Writer writer;
ASSERT_TRUE(PrivateDeclarationsOutput(library, &writer));
EXPECT_EQ(writer.Out(), R"(// 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.
// WARNING: THIS FILE IS MACHINE GENERATED BY //tools/kazoo. DO NOT EDIT.
INTERNAL_SYSCALL(couple_do_thing, zx_status_t, /* no attributes */, 1,
(an_input), (
int32_t an_input))
KERNEL_SYSCALL(couple_get_stuff, zx_status_t, /* no attributes */, 2,
(an_input, input2), (
int32_t an_input,
int32_t input2))
)");
}
} // namespace