|
Packit |
534379 |
// Copyright(c) 2018, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <chrono>
|
|
Packit |
534379 |
#include <thread>
|
|
Packit |
534379 |
#include <unistd.h>
|
|
Packit |
534379 |
#include "gtest/gtest.h"
|
|
Packit |
534379 |
#include "mock/test_system.h"
|
|
Packit |
534379 |
#include "mock/fpgad_control.h"
|
|
Packit |
534379 |
#include <opae/cxx/core/events.h>
|
|
Packit |
534379 |
#include <opae/cxx/core/token.h>
|
|
Packit |
534379 |
#include <opae/cxx/core/handle.h>
|
|
Packit |
534379 |
#include <opae/cxx/core/properties.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "intel-fpga.h"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
using namespace opae::testing;
|
|
Packit |
534379 |
using namespace opae::fpga::types;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class events_cxx_core : public ::testing::TestWithParam<std::string>,
|
|
Packit |
534379 |
public fpgad_control {
|
|
Packit |
534379 |
protected:
|
|
Packit |
534379 |
events_cxx_core() : handle_(nullptr) {}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void SetUp() override {
|
|
Packit |
534379 |
ASSERT_TRUE(test_platform::exists(GetParam()));
|
|
Packit |
534379 |
platform_ = test_platform::get(GetParam());
|
|
Packit |
534379 |
system_ = test_system::instance();
|
|
Packit |
534379 |
system_->initialize();
|
|
Packit |
534379 |
system_->prepare_syfs(platform_);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
ASSERT_EQ(fpgaInitialize(nullptr), FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
properties::ptr_t props = properties::get(FPGA_ACCELERATOR);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
auto device_id = platform_.devices[0].device_id;
|
|
Packit |
534379 |
if (platform_.devices[0].num_vfs) {
|
|
Packit |
534379 |
device_id++;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
props->device_id = device_id;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
tokens_ = token::enumerate({props});
|
|
Packit |
534379 |
ASSERT_TRUE(tokens_.size() > 0);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
handle_= handle::open(tokens_[0], 0);
|
|
Packit |
534379 |
ASSERT_NE(nullptr, handle_.get());
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpgad_start();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void TearDown() override {
|
|
Packit |
534379 |
fpgad_stop();
|
|
Packit |
534379 |
handle_.reset();
|
|
Packit |
534379 |
ASSERT_NO_THROW(tokens_.clear());
|
|
Packit |
534379 |
fpgaFinalize();
|
|
Packit |
534379 |
system_->finalize();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens_;
|
|
Packit |
534379 |
handle::ptr_t handle_;
|
|
Packit |
534379 |
test_platform platform_;
|
|
Packit |
534379 |
test_system *system_;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test register_event_01
|
|
Packit |
534379 |
* Given an open accelerator handle object
|
|
Packit |
534379 |
* When I call event::register_event() with nullptr handle
|
|
Packit |
534379 |
* And event type of FPGA_EVENT_ERROR
|
|
Packit |
534379 |
* Then exception is thrown
|
|
Packit |
534379 |
* And I get a std invalid_argument
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(events_cxx_core, register_event_01) {
|
|
Packit |
534379 |
event::ptr_t ev;
|
|
Packit |
534379 |
ASSERT_THROW(ev = event::register_event(nullptr, FPGA_EVENT_ERROR), std::invalid_argument);
|
|
Packit |
534379 |
ASSERT_EQ(nullptr, ev.get());
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test register_event_02
|
|
Packit |
534379 |
* Given an open handleerator handle object
|
|
Packit |
534379 |
* When I call event::register_event() with that handle
|
|
Packit |
534379 |
* And event type of event::type_t::error
|
|
Packit |
534379 |
* Then no exception is thrown
|
|
Packit |
534379 |
* And I get a non-null event shared pointer
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(events_cxx_core, register_event_02) {
|
|
Packit |
534379 |
event::ptr_t ev;
|
|
Packit |
534379 |
ASSERT_NO_THROW(ev = event::register_event(handle_, event::type_t::error));
|
|
Packit |
534379 |
ASSERT_NE(nullptr, ev.get());
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test register_event_03
|
|
Packit |
534379 |
* Given an open handleerator handle object
|
|
Packit |
534379 |
* When I call event::register_event() with that handle
|
|
Packit |
534379 |
* And event type of FPGA_EVENT_ERROR
|
|
Packit |
534379 |
* Then no exception is thrown
|
|
Packit |
534379 |
* And I get a non-null event shared pointer
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(events_cxx_core, register_event_03) {
|
|
Packit |
534379 |
event::ptr_t ev;
|
|
Packit |
534379 |
ASSERT_NO_THROW(ev = event::register_event(handle_, FPGA_EVENT_ERROR));
|
|
Packit |
534379 |
ASSERT_NE(nullptr, ev.get());
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test get_os_object
|
|
Packit |
534379 |
* Given an open handleerator handle object
|
|
Packit |
534379 |
* And an event object created with event::register_event()
|
|
Packit |
534379 |
* When I call event::os_object using the event object
|
|
Packit |
534379 |
* Then I get a valid file descriptor for polling on the event
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(events_cxx_core, get_os_object) {
|
|
Packit |
534379 |
event::ptr_t ev;
|
|
Packit |
534379 |
ASSERT_NO_THROW(ev = event::register_event(handle_, FPGA_EVENT_ERROR));
|
|
Packit |
534379 |
ASSERT_NE(nullptr, ev.get());
|
|
Packit |
534379 |
auto fd = ev->os_object();
|
|
Packit |
534379 |
auto res = fcntl(fd, F_GETFL);
|
|
Packit |
534379 |
ASSERT_NE(res, -1);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
INSTANTIATE_TEST_CASE_P(events, events_cxx_core, ::testing::ValuesIn(test_platform::keys(true)));
|