From 69a3b6dad7a32b8954c33efdf16645edbbf05c28 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Tue, 22 Feb 2022 00:06:42 -0800 Subject: [PATCH] [test_runner] Add handle test suite For now this just tests handle cloning and basic capability checking. --- src/libraries/j6/j6/caps.h.cog | 2 ++ src/user/test_runner/test_runner.module | 1 + src/user/test_runner/tests/handles.cpp | 26 +++++++++++++++++++++++++ src/user/test_runner/tests/mailbox.cpp | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/user/test_runner/tests/handles.cpp diff --git a/src/libraries/j6/j6/caps.h.cog b/src/libraries/j6/j6/caps.h.cog index e5f8d9c..ab68c7e 100644 --- a/src/libraries/j6/j6/caps.h.cog +++ b/src/libraries/j6/j6/caps.h.cog @@ -4,6 +4,8 @@ /// \file caps.h /// Capability bitfield constants +#define j6_handle_caps(h) (((h)>>32) & 0xffffff) + /*[[[cog code generation from definitions.context import Context diff --git a/src/user/test_runner/test_runner.module b/src/user/test_runner/test_runner.module index 4d9cab1..7e68c05 100644 --- a/src/user/test_runner/test_runner.module +++ b/src/user/test_runner/test_runner.module @@ -9,6 +9,7 @@ module("test_runner", "test_case.cpp", "tests/constexpr_hash.cpp", + "tests/handles.cpp", "tests/linked_list.cpp", "tests/mailbox.cpp", "tests/map.cpp", diff --git a/src/user/test_runner/tests/handles.cpp b/src/user/test_runner/tests/handles.cpp new file mode 100644 index 0000000..0a2a230 --- /dev/null +++ b/src/user/test_runner/tests/handles.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include "test_case.h" + +extern j6_handle_t __handle_self; + +struct handle_tests : + public test::fixture +{ +}; + +TEST_CASE( handle_tests, clone_cap ) +{ + j6_status_t s; + j6_handle_t self0 = __handle_self; + + j6_handle_t self1 = j6_handle_invalid; + s = j6_handle_clone(self0, &self1, j6_handle_caps(self0) & ~j6_cap_object_clone); + CHECK( s == j6_status_ok, "Cloning self handle" ); + + j6_handle_t self2 = j6_handle_invalid; + s = j6_handle_clone(self1, &self2, j6_handle_caps(self1)); + CHECK( s == j6_err_denied, "Cloning non-clonable handle" ); +} diff --git a/src/user/test_runner/tests/mailbox.cpp b/src/user/test_runner/tests/mailbox.cpp index 7520931..afb20ec 100644 --- a/src/user/test_runner/tests/mailbox.cpp +++ b/src/user/test_runner/tests/mailbox.cpp @@ -28,7 +28,7 @@ TEST_CASE( mailbox_tests, would_block ) size_t buffer_size = 128; j6_handle_t handles[10]; size_t handle_count = 10; - uint64_t reply_tag = 0; + uint16_t reply_tag = 0; uint64_t badge = 0; uint64_t flags = 0; @@ -66,7 +66,7 @@ TEST_CASE( mailbox_tests, send_receive ) size_t in_buffer_size = 128; j6_handle_t in_handles[10]; size_t in_handle_count = 10; - uint64_t in_reply_tag = 0; + uint16_t in_reply_tag = 0; uint64_t in_badge = 0; uint64_t in_flags = 0;