blob: 4727541f2dceee49aa566b402464baa7332e8501 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <object/exceptionate.h>
#include <object/channel_dispatcher.h>
#include <object/excp_port.h>
#include <object/handle.h>
#include <zircon/rights.h>
#include <fbl/ref_ptr.h>
#include <lib/unittest/unittest.h>
namespace {
bool overwrite_valid_channel_fails() {
BEGIN_TEST;
KernelHandle<ChannelDispatcher> channels[4];
zx_rights_t rights;
ASSERT_EQ(ZX_OK, ChannelDispatcher::Create(&channels[0], &channels[1], &rights), "");
ASSERT_EQ(ZX_OK, ChannelDispatcher::Create(&channels[2], &channels[3], &rights), "");
Exceptionate exceptionate(ExceptionPort::Type::THREAD);
ASSERT_EQ(ZX_OK, exceptionate.SetChannel(ktl::move(channels[0]), 0, 0), "");
EXPECT_EQ(ZX_ERR_ALREADY_BOUND, exceptionate.SetChannel(ktl::move(channels[2]), 0, 0), "");
END_TEST;
}
bool overwrite_invalid_channel_succeeds() {
BEGIN_TEST;
KernelHandle<ChannelDispatcher> channels[4];
zx_rights_t rights;
ASSERT_EQ(ZX_OK, ChannelDispatcher::Create(&channels[0], &channels[1], &rights), "");
ASSERT_EQ(ZX_OK, ChannelDispatcher::Create(&channels[2], &channels[3], &rights), "");
Exceptionate exceptionate(ExceptionPort::Type::THREAD);
ASSERT_EQ(ZX_OK, exceptionate.SetChannel(ktl::move(channels[0]), 0, 0), "");
channels[1].reset();
EXPECT_EQ(ZX_OK, exceptionate.SetChannel(ktl::move(channels[2]), 0, 0), "");
END_TEST;
}
} // namespace
UNITTEST_START_TESTCASE(exception_tests)
UNITTEST("overwrite_valid_channel_fails", overwrite_valid_channel_fails)
UNITTEST("overwrite_invalid_channel_succeeds", overwrite_invalid_channel_succeeds)
UNITTEST_END_TESTCASE(exception_tests, "exception", "Exception tests");