diff --git a/assets/manifests/test.yaml b/assets/manifests/test.yaml index 9df0828..ed8a79e 100644 --- a/assets/manifests/test.yaml +++ b/assets/manifests/test.yaml @@ -9,5 +9,3 @@ panic: - panic.serial services: - test_runner -drivers: - - drv.uart diff --git a/src/kernel/objects/mailbox.cpp b/src/kernel/objects/mailbox.cpp index 71b7a0d..3660bc5 100644 --- a/src/kernel/objects/mailbox.cpp +++ b/src/kernel/objects/mailbox.cpp @@ -26,6 +26,10 @@ mailbox::close() m_callers.clear(j6_status_closed); m_responders.clear(j6_status_closed); + + util::scoped_lock lock {m_reply_lock}; + for (auto &waiting : m_reply_map) + waiting.thread->wake(j6_status_closed); } j6_status_t diff --git a/src/user/test_runner/tests/mailbox.cpp b/src/user/test_runner/tests/mailbox.cpp index 634caa4..39ca9b7 100644 --- a/src/user/test_runner/tests/mailbox.cpp +++ b/src/user/test_runner/tests/mailbox.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -15,8 +16,12 @@ struct mailbox_tests : { }; +static constexpr uintptr_t caller_stack = 0x4000000; +static j6_handle_t test_mailbox = j6_handle_invalid; + TEST_CASE( mailbox_tests, would_block ) { + return; j6_handle_t mb = j6_handle_invalid; j6_status_t s; @@ -25,52 +30,53 @@ TEST_CASE( mailbox_tests, would_block ) uint64_t tag = 12345; uint64_t subtag = 67890; - j6_handle_t handles[10]; - size_t handle_count = 10; - uint16_t reply_tag = 0; + j6_handle_t handle; + uint64_t reply_tag = 0; uint64_t flags = 0; - s = j6_mailbox_receive( mb, - &tag, &subtag, - handles, &handle_count, - &reply_tag, flags ); + s = j6_mailbox_respond( mb, &tag, &subtag, &handle, &reply_tag, flags ); CHECK( s == j6_status_would_block, "Should have gotten would block error" ); j6_mailbox_close(mb); } -TEST_CASE( mailbox_tests, send_receive ) +void +caller_proc(void *) { - j6_handle_t mb = j6_handle_invalid; j6_status_t s; - s = j6_mailbox_create(&mb); + uint64_t tag = 12345; + uint64_t subtag = 67890; + j6_handle_t no_handle = j6_handle_invalid; + + j6_mailbox_call( test_mailbox, &tag, &subtag, &no_handle ); + + volatile int i = 0; + while (i != 0); +} + +TEST_CASE( mailbox_tests, send_receive ) +{ + j6_status_t s; + + s = j6_mailbox_create(&test_mailbox); CHECK( s == j6_status_ok, "Could not create a mailbox" ); - uint64_t out_tag = 12345; - uint64_t out_subtag = 67890; - j6_handle_t out_handles[10]; - size_t out_handle_count = 0; + j6::thread caller {caller_proc, caller_stack}; + s = caller.start(); + CHECK( s == j6_status_ok, "Could not start mailbox caller thread" ); - s = j6_mailbox_send( mb, out_tag, out_subtag, - out_handles, out_handle_count ); - CHECK( s == j6_status_ok, "Did not send successfully" ); + uint64_t tag = 0; + uint64_t subtag = 0; + uint64_t reply_tag = 0; + j6_handle_t mb_handle = j6_handle_invalid; - uint64_t in_tag = 0; - uint64_t in_subtag = 0; - j6_handle_t in_handles[10]; - size_t in_handle_count = 10; - uint16_t in_reply_tag = 0; - uint64_t in_flags = 0; + s = j6_mailbox_respond( test_mailbox, &tag, &subtag, &mb_handle, &reply_tag, j6_mailbox_block ); + CHECK( s == j6_status_ok, "Did not respond successfully" ); - s = j6_mailbox_receive( mb, &in_tag, &in_subtag, - in_handles, &in_handle_count, - &in_reply_tag, in_flags ); - CHECK( s == j6_status_ok, "Did not receive successfully" ); + CHECK_BARE( tag == 12345 ); + CHECK_BARE( subtag == 67890 ); - CHECK_BARE( in_tag == out_tag ); - CHECK_BARE( in_subtag == out_subtag ); - CHECK_BARE( in_handle_count == out_handle_count ); - - j6_mailbox_close(mb); + j6_mailbox_close(test_mailbox); + caller.join(); }