|
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 "mock/test_system.h"
|
|
Packit |
534379 |
#include "gtest/gtest.h"
|
|
Packit |
534379 |
#include <opae/cxx/core/handle.h>
|
|
Packit |
534379 |
#include <opae/cxx/core/properties.h>
|
|
Packit |
534379 |
#include <opae/cxx/core/token.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
using namespace opae::testing;
|
|
Packit |
534379 |
using namespace opae::fpga::types;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class properties_cxx_core : public ::testing::TestWithParam<std::string> {
|
|
Packit |
534379 |
protected:
|
|
Packit |
534379 |
properties_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 |
tokens_ = token::enumerate({properties::get(FPGA_ACCELERATOR)});
|
|
Packit |
534379 |
ASSERT_TRUE(tokens_.size() > 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void TearDown() override {
|
|
Packit |
534379 |
tokens_.clear();
|
|
Packit |
534379 |
handle_.reset();
|
|
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 |
fpga_guid guid_invalid = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
|
Packit |
534379 |
0xf8, 0x9e, 0x43, 0x36, 0x83, 0xf9, 0x04, 0x0b};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
const char *TEST_GUID_STR = "ae2878a7-926f-4332-aba1-2b952ad6df8e";
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test properties::get_no_filter
|
|
Packit |
534379 |
* Calling properties::get with no filter returns a properties object
|
|
Packit |
534379 |
* that will return all tokens when enumerated.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_no_filter) {
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
tokens = token::enumerate({properties::get()});
|
|
Packit |
534379 |
EXPECT_GT(tokens.size(), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test properties::get_guid_valid
|
|
Packit |
534379 |
* Calling properties::get with a valid guid returns a properties
|
|
Packit |
534379 |
* object that will return a token with the same guid when enumerated.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_guid_valid) {
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens;
|
|
Packit |
534379 |
const char *guid = nullptr;
|
|
Packit |
534379 |
fpga_guid valid_guid;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Retrieve first platform device afu guid.
|
|
Packit |
534379 |
guid = platform_.devices[0].afu_guid;
|
|
Packit |
534379 |
ASSERT_EQ(0, uuid_parse(guid, valid_guid));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
tokens = token::enumerate({properties::get(valid_guid)});
|
|
Packit |
534379 |
EXPECT_GT(tokens.size(), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test properties::get_guid_invalid
|
|
Packit |
534379 |
* Calling properties::get with an invalid guid returns a properties
|
|
Packit |
534379 |
* object that will return no tokens when enumerated.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_guid_invalid) {
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
tokens = token::enumerate({properties::get(guid_invalid)});
|
|
Packit |
534379 |
EXPECT_EQ(tokens.size(), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test properties::get_token
|
|
Packit |
534379 |
* Calling properties::get with a token returns a properties object
|
|
Packit |
534379 |
* that will return the a token with the same attributes.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_token) {
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
tokens = token::enumerate({properties::get(tokens_[0])});
|
|
Packit |
534379 |
EXPECT_GT(tokens.size(), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test properties::get_handle
|
|
Packit |
534379 |
* Calling properties::get with a handle returns a properties object
|
|
Packit |
534379 |
* that will return a token with the same attributes.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_handle) {
|
|
Packit |
534379 |
std::vector<token::ptr_t> tokens;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
handle_ = handle::open(tokens_[0], FPGA_OPEN_SHARED);
|
|
Packit |
534379 |
ASSERT_NE(nullptr, handle_.get());
|
|
Packit |
534379 |
tokens = token::enumerate({properties::get(handle_)});
|
|
Packit |
534379 |
EXPECT_GT(tokens.size(), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test set_guid
|
|
Packit |
534379 |
* Given a new properties object and a valid fpga_guid object
|
|
Packit |
534379 |
* When I set the guid property to the fpga_guid object
|
|
Packit |
534379 |
* And I retrieve the same property using fpgaGetPropertiesGUID
|
|
Packit |
534379 |
* Then the known guid matches the one retrieved
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, set_guid) {
|
|
Packit |
534379 |
fpga_guid guid_in, guid_out;
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
// set the guid to an fpga_guid
|
|
Packit |
534379 |
ASSERT_EQ(0, uuid_parse(TEST_GUID_STR, guid_in));
|
|
Packit |
534379 |
p->guid = guid_in;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// now check we set the guid using C APIs
|
|
Packit |
534379 |
ASSERT_EQ(fpgaPropertiesGetGUID(p->c_type(), &guid_out), FPGA_OK);
|
|
Packit |
534379 |
EXPECT_EQ(memcmp(guid_in, guid_out, sizeof(fpga_guid)), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test parse_guid
|
|
Packit |
534379 |
* Given a new properties object
|
|
Packit |
534379 |
* When I set the guid property using its `parse` method
|
|
Packit |
534379 |
* And I retrieve the same property using fpgaGetPropertiesGUID
|
|
Packit |
534379 |
* Then the known guid string parsed matches the one retrieved
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, parse_guid) {
|
|
Packit |
534379 |
fpga_guid guid_out;
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
// set the guid to an fpga_guid
|
|
Packit |
534379 |
p->guid.parse(TEST_GUID_STR);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// now check we set the guid using C APIs
|
|
Packit |
534379 |
ASSERT_EQ(fpgaPropertiesGetGUID(p->c_type(), &guid_out), FPGA_OK);
|
|
Packit |
534379 |
char guid_str[84];
|
|
Packit |
534379 |
uuid_unparse(guid_out, guid_str);
|
|
Packit |
534379 |
EXPECT_STREQ(TEST_GUID_STR, guid_str);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test get_guid
|
|
Packit |
534379 |
* Given a new properties object and a valid fpga_guid object
|
|
Packit |
534379 |
* When I set the guid property using fpgaPropertiesSetGUID
|
|
Packit |
534379 |
* And I get a pointer to the guid member variable of the property object
|
|
Packit |
534379 |
* Then the known guid matches the one retrieved
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_guid) {
|
|
Packit |
534379 |
fpga_guid guid_in;
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
// set the guid using fpgaPropertiesSetGUID
|
|
Packit |
534379 |
uuid_parse(TEST_GUID_STR, guid_in);
|
|
Packit |
534379 |
fpgaPropertiesSetGUID(p->c_type(), guid_in);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
uint8_t *guid_ptr = p->guid;
|
|
Packit |
534379 |
ASSERT_NE(nullptr, guid_ptr);
|
|
Packit |
534379 |
EXPECT_EQ(memcmp(guid_in, guid_ptr, sizeof(fpga_guid)), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test compare_guid
|
|
Packit |
534379 |
* Given a new properties object with a known guid
|
|
Packit |
534379 |
* When I set compare its guid with the known guid
|
|
Packit |
534379 |
* Then the result is true
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, compare_guid) {
|
|
Packit |
534379 |
fpga_guid guid_in;
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
ASSERT_EQ(0, uuid_parse(TEST_GUID_STR, guid_in));
|
|
Packit |
534379 |
EXPECT_FALSE(p->guid == guid_in);
|
|
Packit |
534379 |
p->guid = guid_in;
|
|
Packit |
534379 |
ASSERT_EQ(memcmp(p->guid.c_type(), guid_in, sizeof(fpga_guid)), 0);
|
|
Packit |
534379 |
EXPECT_TRUE(p->guid == guid_in);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test props_ctor_01
|
|
Packit |
534379 |
* Given a new properties object with a known guid
|
|
Packit |
534379 |
* passed in the constructor
|
|
Packit |
534379 |
* When I set compare its guid with the known guid
|
|
Packit |
534379 |
* Then the result is true
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, props_ctor_01) {
|
|
Packit |
534379 |
fpga_guid guid_in;
|
|
Packit |
534379 |
ASSERT_EQ(0, uuid_parse(TEST_GUID_STR, guid_in));
|
|
Packit |
534379 |
auto p = properties::get(guid_in);
|
|
Packit |
534379 |
ASSERT_EQ(memcmp(p->guid.c_type(), guid_in, sizeof(fpga_guid)), 0);
|
|
Packit |
534379 |
EXPECT_TRUE(p->guid == guid_in);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test set_objtype
|
|
Packit |
534379 |
* Given a new properties object
|
|
Packit |
534379 |
* When I set the object type to a known value
|
|
Packit |
534379 |
* Then the property is set
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, set_objtype) {
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
p->type = FPGA_ACCELERATOR;
|
|
Packit |
534379 |
fpga_objtype t = p->type;
|
|
Packit |
534379 |
fpga_objtype other_t =
|
|
Packit |
534379 |
(t == FPGA_ACCELERATOR) ? FPGA_DEVICE : FPGA_ACCELERATOR;
|
|
Packit |
534379 |
p->type = other_t;
|
|
Packit |
534379 |
EXPECT_TRUE(p->type == other_t);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test get_model
|
|
Packit |
534379 |
* Given a properties object
|
|
Packit |
534379 |
* When I get the model property
|
|
Packit |
534379 |
* Then I get an empty string
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_model) {
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
std::string model = "";
|
|
Packit |
534379 |
// Model is currently not supported in libopae-c
|
|
Packit |
534379 |
EXPECT_THROW(model = p->model, not_supported);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test get_num_errors
|
|
Packit |
534379 |
* Given a properties properties object with the num_errors property set to a
|
|
Packit |
534379 |
* known value
|
|
Packit |
534379 |
* When I get the num_errors property
|
|
Packit |
534379 |
* Then the number is the expected value
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_num_errors) {
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
p->num_errors = 9;
|
|
Packit |
534379 |
EXPECT_EQ(static_cast<uint32_t>(p->num_errors), 9);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test get_segment
|
|
Packit |
534379 |
* Given a properties properties object with the segment property set to a
|
|
Packit |
534379 |
* known value
|
|
Packit |
534379 |
* When I get the segment property
|
|
Packit |
534379 |
* Then the number is the expected value
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(properties_cxx_core, get_segment) {
|
|
Packit |
534379 |
auto p = properties::get();
|
|
Packit |
534379 |
p->segment = 9090;
|
|
Packit |
534379 |
EXPECT_EQ(static_cast<uint16_t>(p->segment), 9090);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
INSTANTIATE_TEST_CASE_P(properties, properties_cxx_core,
|
|
Packit |
534379 |
::testing::ValuesIn(test_platform::keys(true)));
|