|
Packit |
534379 |
// Copyright(c) 2018-2020, 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 |
extern "C" {
|
|
Packit |
534379 |
#include <json-c/json.h>
|
|
Packit |
534379 |
#include <uuid/uuid.h>
|
|
Packit |
534379 |
#include "opae_int.h"
|
|
Packit |
534379 |
#include <libgen.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
char *find_ase_cfg();
|
|
Packit |
534379 |
void opae_init(void);
|
|
Packit |
534379 |
void opae_release(void);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define HOME_CFG_PATHS 3
|
|
Packit |
534379 |
const char *_ase_home_configs[HOME_CFG_PATHS] = {
|
|
Packit |
534379 |
"/.local/opae_ase.cfg",
|
|
Packit |
534379 |
"/.local/opae/opae_ase.cfg",
|
|
Packit |
534379 |
"/.config/opae/opae_ase.cfg",
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <config.h>
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <array>
|
|
Packit |
534379 |
#include <cstdlib>
|
|
Packit |
534379 |
#include <fstream>
|
|
Packit |
534379 |
#include <map>
|
|
Packit |
534379 |
#include <memory>
|
|
Packit |
534379 |
#include <string>
|
|
Packit |
534379 |
#include <vector>
|
|
Packit |
534379 |
#include <stack>
|
|
Packit |
534379 |
#include "gtest/gtest.h"
|
|
Packit |
534379 |
#include "mock/test_system.h"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
using namespace opae::testing;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test opae_init
|
|
Packit |
534379 |
* @brief Test: opae_init, opae_release, opae_print
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, opae_init_rel) {
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
opae_print(OPAE_LOG_ERROR, "OPAE_LOG_ERROR from test opae_init_rel\n");
|
|
Packit |
534379 |
opae_print(OPAE_LOG_MESSAGE, "OPAE_LOG_MESSAGE from test opae_init_rel\n");
|
|
Packit |
534379 |
opae_print(OPAE_LOG_DEBUG, "OPAE_LOG_DEBUG from test opae_init_rel\n");
|
|
Packit |
534379 |
opae_release();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef LIBOPAE_DEBUG
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test log_debug
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the log level is set to debug, then all errors,
|
|
Packit |
534379 |
* messages, and debug info are logged.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, log_debug) {
|
|
Packit |
534379 |
ASSERT_EQ(0, putenv((char*)"LIBOPAE_LOG=2"));
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
testing::internal::CaptureStdout();
|
|
Packit |
534379 |
testing::internal::CaptureStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
OPAE_ERR("Error log.");
|
|
Packit |
534379 |
OPAE_MSG("Message log.");
|
|
Packit |
534379 |
OPAE_DBG("Debug log.");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::string log_stdout = testing::internal::GetCapturedStdout();
|
|
Packit |
534379 |
std::string log_stderr = testing::internal::GetCapturedStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_TRUE(log_stderr.find("Error log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_TRUE(log_stdout.find("Message log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_TRUE(log_stdout.find("Debug log.") != std::string::npos);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_release();
|
|
Packit |
534379 |
EXPECT_EQ(0, unsetenv("LIBOPAE_LOG"));
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test log_message
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the log level is set to message, then all errors
|
|
Packit |
534379 |
* and messages are logged.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, log_message) {
|
|
Packit |
534379 |
ASSERT_EQ(0, putenv((char*)"LIBOPAE_LOG=1"));
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
testing::internal::CaptureStdout();
|
|
Packit |
534379 |
testing::internal::CaptureStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
OPAE_ERR("Error log.");
|
|
Packit |
534379 |
OPAE_MSG("Message log.");
|
|
Packit |
534379 |
OPAE_DBG("Debug log.");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::string log_stdout = testing::internal::GetCapturedStdout();
|
|
Packit |
534379 |
std::string log_stderr = testing::internal::GetCapturedStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_TRUE(log_stderr.find("Error log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_TRUE(log_stdout.find("Message log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_FALSE(log_stdout.find("Debug log.") != std::string::npos);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_release();
|
|
Packit |
534379 |
EXPECT_EQ(0, unsetenv("LIBOPAE_LOG"));
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test log_error
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the log level is set to error, then only errors
|
|
Packit |
534379 |
* are logged.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, log_error) {
|
|
Packit |
534379 |
ASSERT_EQ(0, putenv((char*)"LIBOPAE_LOG=0"));
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
testing::internal::CaptureStdout();
|
|
Packit |
534379 |
testing::internal::CaptureStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
OPAE_ERR("Error log.");
|
|
Packit |
534379 |
OPAE_MSG("Message log.");
|
|
Packit |
534379 |
OPAE_DBG("Debug log.");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::string log_stdout = testing::internal::GetCapturedStdout();
|
|
Packit |
534379 |
std::string log_stderr = testing::internal::GetCapturedStderr();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_TRUE(log_stderr.find("Error log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_FALSE(log_stdout.find("Message log.") != std::string::npos);
|
|
Packit |
534379 |
EXPECT_FALSE(log_stdout.find("Debug log.") != std::string::npos);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_release();
|
|
Packit |
534379 |
EXPECT_EQ(0, unsetenv("LIBOPAE_LOG"));
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test log_file
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When LIBOPAE_LOGFILE is specified, then the logger
|
|
Packit |
534379 |
* will log to the specified file.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, log_file) {
|
|
Packit |
534379 |
struct stat buf;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_NE(0, stat("opae_log.log", &buf));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
ASSERT_EQ(0, putenv((char*)"LIBOPAE_LOGFILE=opae_log.log"));
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(0, stat("opae_log.log", &buf));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_release();
|
|
Packit |
534379 |
EXPECT_EQ(0, unsetenv("LIBOPAE_LOGFILE"));
|
|
Packit |
534379 |
unlink("opae_log.log");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test find_ase_cfg
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When WITH_ASE is specified, opae_ase.cfg will
|
|
Packit |
534379 |
* be searched from OPAE source directory, OPAE
|
|
Packit |
534379 |
* installation directory or home/system config directory.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST(init, DISABLED_find_ase_cfg) {
|
|
Packit |
534379 |
char *cfg_path = nullptr;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
ASSERT_EQ(0, putenv((char*)"WITH_ASE=1"));
|
|
Packit |
534379 |
cfg_path = find_ase_cfg();
|
|
Packit |
534379 |
EXPECT_NE(cfg_path, nullptr);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(0, unsetenv("WITH_ASE"));
|
|
Packit |
534379 |
if (cfg_path)
|
|
Packit |
534379 |
free(cfg_path);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
const char *ase_cfg = R"plug(
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
"configurations": {
|
|
Packit |
534379 |
"ase": {
|
|
Packit |
534379 |
"configuration": {
|
|
Packit |
534379 |
"key1a": 10,
|
|
Packit |
534379 |
"key1b": "hello"
|
|
Packit |
534379 |
},
|
|
Packit |
534379 |
"enabled": true,
|
|
Packit |
534379 |
"plugin": "libase.so"
|
|
Packit |
534379 |
},
|
|
Packit |
534379 |
},
|
|
Packit |
534379 |
"plugins": [
|
|
Packit |
534379 |
"ase"
|
|
Packit |
534379 |
]
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
)plug";
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class init_ase_cfg_p : public ::testing::TestWithParam<const char*> {
|
|
Packit |
534379 |
protected:
|
|
Packit |
534379 |
init_ase_cfg_p() : buffer_ {0}, rename_f(0) {}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void SetUp() override {
|
|
Packit |
534379 |
// let's rename the opae_ase.cfg in OPAE_ASE_CFG_SRC_PATH and OPAE_ASE_CFG_INST_PATH
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// copy it to a temporary buffer that we can use dirname with
|
|
Packit |
534379 |
std::string src_cfg_path = (OPAE_ASE_CFG_SRC_PATH? OPAE_ASE_CFG_SRC_PATH : "");
|
|
Packit |
534379 |
std::copy(src_cfg_path.begin(), src_cfg_path.end(), &buffer_[0]);
|
|
Packit |
534379 |
char *src_cfg_dir = dirname(buffer_);
|
|
Packit |
534379 |
std::string cfg_dir = (src_cfg_dir? src_cfg_dir : "");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename opae_ase.cfg under installation directory
|
|
Packit |
534379 |
strcpy(tmpfile_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile_));
|
|
Packit |
534379 |
src_cfg_file_ = cfg_dir + std::string("/") + std::string(tmpfile_);
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(OPAE_ASE_CFG_SRC_PATH, &st)) {
|
|
Packit |
534379 |
rename_f = rename(OPAE_ASE_CFG_SRC_PATH, src_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_f, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_f = 1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// This parameterized test iterates over the possible config file paths
|
|
Packit |
534379 |
// relative to a user's home directory
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// let's build the full path by prepending the parameter with $HOME
|
|
Packit |
534379 |
char *home_cstr = getenv("HOME");
|
|
Packit |
534379 |
ASSERT_NE(home_cstr, nullptr) << "No home environment found";
|
|
Packit |
534379 |
std::string home = home_cstr;
|
|
Packit |
534379 |
// the parameter paths start with a '/'
|
|
Packit |
534379 |
cfg_file_ = home + std::string(GetParam());
|
|
Packit |
534379 |
memset(buffer_, 0, sizeof(buffer_));
|
|
Packit |
534379 |
// copy it to a temporary buffer that we can use dirname with
|
|
Packit |
534379 |
std::copy(cfg_file_.begin(), cfg_file_.end(), &buffer_[0]);
|
|
Packit |
534379 |
// get the directory name of the file
|
|
Packit |
534379 |
cfg_dir_ = dirname(buffer_);
|
|
Packit |
534379 |
// if the directory doesn't exist, create the entire path
|
|
Packit |
534379 |
if (stat(cfg_dir_, &st)) {
|
|
Packit |
534379 |
std::string dir = cfg_dir_;
|
|
Packit |
534379 |
// find the first '/' after $HOME
|
|
Packit |
534379 |
size_t pos = dir.find('/', home.size());
|
|
Packit |
534379 |
while (pos != std::string::npos) {
|
|
Packit |
534379 |
std::string sub = dir.substr(0, pos);
|
|
Packit |
534379 |
// sub is $HOME/<dir1>, then $HOME/<dir1>/<dir2>, ...
|
|
Packit |
534379 |
// if this directory doesn't exist, create it
|
|
Packit |
534379 |
if (stat(sub.c_str(), &st) && sub != "") {
|
|
Packit |
534379 |
ASSERT_EQ(mkdir(sub.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH),
|
|
Packit |
534379 |
0)
|
|
Packit |
534379 |
<< "Error creating subdirectory (" << sub
|
|
Packit |
534379 |
<< "}: " << strerror(errno);
|
|
Packit |
534379 |
// keep track of directories created
|
|
Packit |
534379 |
dirs_.push(sub);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
pos = pos < dir.size() ? dir.find('/', pos + 1) : std::string::npos;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
// finally, we know the entire path didn't exist, create the last
|
|
Packit |
534379 |
// directory
|
|
Packit |
534379 |
ASSERT_EQ(mkdir(cfg_dir_, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH), 0)
|
|
Packit |
534379 |
<< "Error creating subdirectory (" << cfg_dir_
|
|
Packit |
534379 |
<< "}: " << strerror(errno);
|
|
Packit |
534379 |
dirs_.push(cfg_dir_);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (stat(cfg_file_.c_str(), &st) == 0) {
|
|
Packit |
534379 |
EXPECT_EQ(unlink(cfg_file_.c_str()), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::ofstream cfg_stream(cfg_file_);
|
|
Packit |
534379 |
cfg_stream.write(ase_cfg, strlen(ase_cfg));
|
|
Packit |
534379 |
cfg_stream.close();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
setenv("WITH_ASE", "1", 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void TearDown() override {
|
|
Packit |
534379 |
unsetenv("WITH_ASE");
|
|
Packit |
534379 |
EXPECT_EQ(unlink(cfg_file_.c_str()), 0);
|
|
Packit |
534379 |
// remove any directories we created in SetUp
|
|
Packit |
534379 |
while (!dirs_.empty()) {
|
|
Packit |
534379 |
EXPECT_EQ(rmdir(dirs_.top().c_str()), 0);
|
|
Packit |
534379 |
dirs_.pop();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
// restore the opae_ase.cfg file at OPAE_ASE_CFG_SRC_PATH
|
|
Packit |
534379 |
if (!rename_f) {
|
|
Packit |
534379 |
int ret = rename(src_cfg_file_.c_str(), (char *)OPAE_ASE_CFG_SRC_PATH);
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
if (stat(tmpfile_, &st) == 0) {
|
|
Packit |
534379 |
EXPECT_EQ(unlink(tmpfile_), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
char buffer_[PATH_MAX];
|
|
Packit |
534379 |
std::string cfg_file_;
|
|
Packit |
534379 |
char *cfg_dir_;
|
|
Packit |
534379 |
std::stack<std::string> dirs_;
|
|
Packit |
534379 |
std::string src_cfg_file_;
|
|
Packit |
534379 |
char tmpfile_[32];
|
|
Packit |
534379 |
int rename_f;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test find_ase_cfg_2
|
|
Packit |
534379 |
* @brief Test: find_ase_cfg at OPAE_ASE_CFG_INST_PATH and OPAE_PLATFORM_ROOT
|
|
Packit |
534379 |
* release location
|
|
Packit |
534379 |
* @details After renaming a configuration file located in the OPAE_ASE_CFG_SRC_PATH
|
|
Packit |
534379 |
* and OPAE_ASE_CFG_INST_PATH
|
|
Packit |
534379 |
* When I call find_ase_cfg
|
|
Packit |
534379 |
* Then the call is successful
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(init_ase_cfg_p, find_ase_cfg_2) {
|
|
Packit |
534379 |
char *cfg_file = nullptr;
|
|
Packit |
534379 |
std::string inst_cfg_file_;
|
|
Packit |
534379 |
char tmpfile2_[32];
|
|
Packit |
534379 |
int rename_fail = 0;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// find_ase_cfg at OPAE_ASE_CFG_INST_PATH
|
|
Packit |
534379 |
cfg_file = find_ase_cfg();
|
|
Packit |
534379 |
EXPECT_NE(cfg_file, nullptr);
|
|
Packit |
534379 |
if (cfg_file)
|
|
Packit |
534379 |
free(cfg_file);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// copy it to a temporary buffer that we can use dirname with
|
|
Packit |
534379 |
std::string inst_cfg_path = (OPAE_ASE_CFG_INST_PATH? OPAE_ASE_CFG_INST_PATH : "");
|
|
Packit |
534379 |
std::copy(inst_cfg_path.begin(), inst_cfg_path.end(), &buffer_[0]);
|
|
Packit |
534379 |
char *inst_cfg_dir = dirname(buffer_);
|
|
Packit |
534379 |
std::string cfg_dir = (inst_cfg_dir? inst_cfg_dir : "");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename opae_ase.cfg under installation directory
|
|
Packit |
534379 |
strcpy(tmpfile2_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile2_));
|
|
Packit |
534379 |
inst_cfg_file_ = cfg_dir + std::string("/") + std::string(tmpfile2_);
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(OPAE_ASE_CFG_INST_PATH, &st)) {
|
|
Packit |
534379 |
rename_fail = rename(OPAE_ASE_CFG_INST_PATH, inst_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_fail, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_fail = 1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// find_ase_cfg at release directory
|
|
Packit |
534379 |
cfg_file = find_ase_cfg();
|
|
Packit |
534379 |
EXPECT_NE(cfg_file, nullptr);
|
|
Packit |
534379 |
if (cfg_file)
|
|
Packit |
534379 |
free(cfg_file);
|
|
Packit |
534379 |
if (!rename_fail) {
|
|
Packit |
534379 |
int ret = rename(inst_cfg_file_.c_str(), OPAE_ASE_CFG_INST_PATH);
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (stat(tmpfile2_, &st) == 0) {
|
|
Packit |
534379 |
EXPECT_EQ(unlink(tmpfile2_), 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test find_ase_cfg_3
|
|
Packit |
534379 |
* @brief Test: find_ase_cfg at HOME location
|
|
Packit |
534379 |
* @details After renaming a configuration file located in the OPAE_ASE_CFG_SRC_PATH,
|
|
Packit |
534379 |
* OPAE_ASE_CFG_INST_PATH and OPAE release directory
|
|
Packit |
534379 |
* When I call find_ase_cfg
|
|
Packit |
534379 |
* Then the call is successful
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(init_ase_cfg_p, find_ase_cfg_3) {
|
|
Packit |
534379 |
char *cfg_file = nullptr;
|
|
Packit |
534379 |
char *opae_path;
|
|
Packit |
534379 |
std::string inst_cfg_file_;
|
|
Packit |
534379 |
std::string rel_cfg_file_, rel_cfg_file2_;
|
|
Packit |
534379 |
char tmpfile2_[32];
|
|
Packit |
534379 |
char tmpfile3_[32];
|
|
Packit |
534379 |
int rename_fail = 0;
|
|
Packit |
534379 |
int rename_fail2 = 0;
|
|
Packit |
534379 |
int ret;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// copy it to a temporary buffer that we can use dirname with
|
|
Packit |
534379 |
std::string inst_cfg_path = (OPAE_ASE_CFG_INST_PATH? OPAE_ASE_CFG_INST_PATH : "");
|
|
Packit |
534379 |
std::copy(inst_cfg_path.begin(), inst_cfg_path.end(), &buffer_[0]);
|
|
Packit |
534379 |
char *inst_cfg_dir = dirname(buffer_);
|
|
Packit |
534379 |
std::string cfg_dir = (inst_cfg_dir? inst_cfg_dir : "");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename opae_ase.cfg under installation directory
|
|
Packit |
534379 |
strcpy(tmpfile2_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile2_));
|
|
Packit |
534379 |
inst_cfg_file_ = cfg_dir + std::string("/") + std::string(tmpfile2_);
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(OPAE_ASE_CFG_INST_PATH, &st)) {
|
|
Packit |
534379 |
rename_fail = rename(OPAE_ASE_CFG_INST_PATH, inst_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_fail, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_fail = 1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename opae_ase.cfg under releae directory
|
|
Packit |
534379 |
opae_path = getenv("OPAE_PLATFORM_ROOT");
|
|
Packit |
534379 |
if (opae_path) {
|
|
Packit |
534379 |
std::string rel_cfg_path = (opae_path? opae_path: "");
|
|
Packit |
534379 |
strcpy(tmpfile3_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile3_));
|
|
Packit |
534379 |
rel_cfg_file_ = rel_cfg_path + std::string("/share/opae/ase/opae_ase.cfg");
|
|
Packit |
534379 |
rel_cfg_file2_ = rel_cfg_path + std::string("/share/opae/ase/") + std::string(tmpfile3_);
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(rel_cfg_file_.c_str(), &st)) {
|
|
Packit |
534379 |
rename_fail2 = rename(rel_cfg_file_.c_str(), rel_cfg_file2_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_fail2, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_fail2 = 1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
// find_ase_cfg at HOME directory
|
|
Packit |
534379 |
cfg_file = find_ase_cfg();
|
|
Packit |
534379 |
EXPECT_NE(cfg_file, nullptr);
|
|
Packit |
534379 |
if (cfg_file)
|
|
Packit |
534379 |
free(cfg_file);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (opae_path && !rename_fail2) {
|
|
Packit |
534379 |
ret = rename(rel_cfg_file2_.c_str(), rel_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (!rename_fail) {
|
|
Packit |
534379 |
ret = rename(inst_cfg_file_.c_str(), OPAE_ASE_CFG_INST_PATH);
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (stat(tmpfile2_, &st) == 0)
|
|
Packit |
534379 |
unlink(tmpfile2_);
|
|
Packit |
534379 |
if (opae_path && stat(tmpfile3_, &st) == 0)
|
|
Packit |
534379 |
unlink(tmpfile3_);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test find_ase_cfg_4
|
|
Packit |
534379 |
* @brief Test: find_ase_cfg at OPAE_PLATFORM_ROOT release location
|
|
Packit |
534379 |
* @details After renaming a configuration file located in the OPAE_ASE_CFG_SRC_PATH,
|
|
Packit |
534379 |
* OPAE_ASE_CFG_INST_PATH, OPAE release and HOME directories
|
|
Packit |
534379 |
* When I call find_ase_cfg
|
|
Packit |
534379 |
* Then the call is successful
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(init_ase_cfg_p, find_ase_cfg_4) {
|
|
Packit |
534379 |
char *cfg_file = nullptr;
|
|
Packit |
534379 |
char *opae_path;
|
|
Packit |
534379 |
std::string inst_cfg_file_;
|
|
Packit |
534379 |
std::string rel_cfg_file_, rel_cfg_file2_;
|
|
Packit |
534379 |
char tmpfile2_[32];
|
|
Packit |
534379 |
char tmpfile3_[32];
|
|
Packit |
534379 |
int rename_fail = 0;
|
|
Packit |
534379 |
int rename_fail2 = 0;
|
|
Packit |
534379 |
int ret;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// copy it to a temporary buffer that we can use dirname with
|
|
Packit |
534379 |
std::string inst_cfg_path = (OPAE_ASE_CFG_INST_PATH? OPAE_ASE_CFG_INST_PATH : "");
|
|
Packit |
534379 |
std::copy(inst_cfg_path.begin(), inst_cfg_path.end(), &buffer_[0]);
|
|
Packit |
534379 |
char *inst_cfg_dir = dirname(buffer_);
|
|
Packit |
534379 |
std::string cfg_dir = (inst_cfg_dir? inst_cfg_dir : "");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename opae_ase.cfg under installation directory
|
|
Packit |
534379 |
strcpy(tmpfile2_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile2_));
|
|
Packit |
534379 |
inst_cfg_file_ = cfg_dir + std::string("/") + std::string(tmpfile2_);
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(OPAE_ASE_CFG_INST_PATH, &st)) {
|
|
Packit |
534379 |
rename_fail = rename(OPAE_ASE_CFG_INST_PATH, inst_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_fail, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_fail = 1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// rename the opae_ase.cfg under release directory
|
|
Packit |
534379 |
opae_path = getenv("OPAE_PLATFORM_ROOT");
|
|
Packit |
534379 |
if (opae_path) {
|
|
Packit |
534379 |
std::string rel_cfg_path = (opae_path? opae_path: "");
|
|
Packit |
534379 |
strcpy(tmpfile3_, "opae_ase.cfg.XXXXXX");
|
|
Packit |
534379 |
close(mkstemp(tmpfile3_));
|
|
Packit |
534379 |
rel_cfg_file_ = rel_cfg_path + std::string("/share/opae/ase/opae_ase.cfg");
|
|
Packit |
534379 |
rel_cfg_file2_ = rel_cfg_path + std::string("/share/opae/ase/") + std::string(tmpfile3_);
|
|
Packit |
534379 |
// check if the file exists or not
|
|
Packit |
534379 |
if (!stat(rel_cfg_file_.c_str(), &st)) {
|
|
Packit |
534379 |
rename_fail2 = rename(rel_cfg_file_.c_str(), rel_cfg_file2_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(rename_fail2, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
else
|
|
Packit |
534379 |
rename_fail2 = 1;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// find_ase_cfg at HOME directory
|
|
Packit |
534379 |
cfg_file = find_ase_cfg();
|
|
Packit |
534379 |
EXPECT_NE(cfg_file, nullptr);
|
|
Packit |
534379 |
if (cfg_file)
|
|
Packit |
534379 |
free(cfg_file);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_init();
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (opae_path && !rename_fail2) {
|
|
Packit |
534379 |
ret = rename(rel_cfg_file2_.c_str(), rel_cfg_file_.c_str());
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (!rename_fail) {
|
|
Packit |
534379 |
ret = rename(inst_cfg_file_.c_str(), OPAE_ASE_CFG_INST_PATH);
|
|
Packit |
534379 |
EXPECT_EQ(ret, 0);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (stat(tmpfile2_, &st) == 0)
|
|
Packit |
534379 |
unlink(tmpfile2_);
|
|
Packit |
534379 |
if (opae_path && stat(tmpfile3_, &st) == 0)
|
|
Packit |
534379 |
unlink(tmpfile3_);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
INSTANTIATE_TEST_CASE_P(init_ase_cfg, init_ase_cfg_p,
|
|
Packit |
534379 |
::testing::ValuesIn(_ase_home_configs));
|