blob: a5b73a54e8bde506dc18448942abe472558a30db [file] [log] [blame]
// 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.
#include "gtest/gtest.h"
#include "fuchsia/msd_img_connection.h"
#include "fuchsia/msd_img_semaphore.h"
extern "C"
{
#include "osfunc.h"
#include "osfunc_fuchsia.h"
}
namespace
{
class FakeOwner : public MsdImgConnection::Owner
{
PVRSRV_DEVICE_NODE* device_node() override { return nullptr; }
};
} // namespace
class TestOsFunc
{
public:
static void EventObject()
{
IMG_HANDLE event_object;
EXPECT_EQ(PVRSRV_OK, OSEventObjectCreate("test", &event_object));
EXPECT_EQ(PVRSRV_OK, OSEventObjectSignal(event_object));
IMG_HANDLE hOSEvent;
EXPECT_EQ(PVRSRV_OK, OSEventObjectOpen(event_object, &hOSEvent));
// Should wake because the object was signaled before the open.
EXPECT_EQ(PVRSRV_OK, OSEventObjectWait(hOSEvent));
EXPECT_EQ(PVRSRV_ERROR_TIMEOUT, OSEventObjectWaitTimeout(hOSEvent, 100));
FakeOwner fake_owner;
MsdImgConnection connection(&fake_owner, 0);
std::shared_ptr<MsdImgSemaphore> semaphore(MsdImgSemaphore::Create());
connection.additional_semaphore_ = semaphore;
IMG_HANDLE hOSEvent2;
EXPECT_EQ(PVRSRV_OK, OSEventObjectOpenWithConnection(event_object, &connection, &hOSEvent2));
EXPECT_FALSE(connection.additional_semaphore_);
EXPECT_EQ(MAGMA_STATUS_OK, semaphore->platform_semaphore()->Wait().get());
EXPECT_EQ(MAGMA_STATUS_TIMED_OUT, semaphore->platform_semaphore()->Wait(10).get());
EXPECT_EQ(PVRSRV_OK, OSEventObjectSignal(event_object));
EXPECT_EQ(PVRSRV_OK, OSEventObjectWait(hOSEvent));
EXPECT_EQ(PVRSRV_OK, OSEventObjectWait(hOSEvent2));
EXPECT_EQ(MAGMA_STATUS_OK, semaphore->platform_semaphore()->Wait().get());
EXPECT_EQ(PVRSRV_ERROR_TIMEOUT, OSEventObjectWaitTimeout(hOSEvent, 100));
EXPECT_EQ(PVRSRV_OK, OSEventObjectClose(hOSEvent2));
EXPECT_EQ(PVRSRV_OK, OSEventObjectClose(hOSEvent));
EXPECT_EQ(PVRSRV_OK, OSEventObjectDestroy(event_object));
}
};
TEST(OSFunc, EventObject) { TestOsFunc::EventObject(); }