Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for CR-1183009 mem-bw test failing without platform.json #7847

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/runtime_src/core/tools/common/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#endif

// Local - Include Files
#include "BusyBar.h"
#include "EscapeCodes.h"
#include "Process.h"
#include "XBUtilitiesCore.h"
Expand Down Expand Up @@ -138,8 +137,6 @@ unsigned int
XBUtilities::runScript( const std::string & env,
const std::string & script,
const std::vector<std::string> & args,
const std::string & running_description,
const std::chrono::seconds & max_duration_s,
std::ostringstream & os_stdout,
std::ostringstream & os_stderr)
{
Expand All @@ -158,25 +155,15 @@ XBUtilities::runScript( const std::string & env,
}
cmd += script + " " + args_str.str();

BusyBar busy_bar(running_description, std::cout);
busy_bar.start(XBUtilities::is_escape_codes_disabled());
bool is_thread_running = true;

// Start the test process
// std::thread test_thread(run_script, cmd, std::ref(os_stdout), std::ref(os_stderr), std::ref(is_thread_running));
std::thread test_thread([&] { run_script(cmd, os_stdout, os_stderr, is_thread_running); });
// Wait for the test process to finish
while (is_thread_running) {
std::this_thread::sleep_for(std::chrono::seconds(1));
try {
busy_bar.check_timeout(max_duration_s);
} catch (const std::exception& ex) {
test_thread.detach();
throw;
}
}
test_thread.join();
busy_bar.finish();

bool passed = (os_stdout.str().find("PASS") != std::string::npos) ? true : false;
bool skipped = (os_stdout.str().find("NOT SUPPORTED") != std::string::npos) ? true : false;
Expand Down Expand Up @@ -214,8 +201,6 @@ unsigned int
XBUtilities::runScript( const std::string & env,
const std::string & script,
const std::vector<std::string> & args,
const std::string & running_description,
const std::chrono::seconds& max_running_duration,
std::ostringstream & os_stdout,
std::ostringstream & os_stderr)
{
Expand All @@ -239,9 +224,6 @@ XBUtilities::runScript( const std::string & env,
boost::process::environment _env = boost::this_process::environment();
_env.erase("XCL_EMULATION_MODE");

BusyBar run_test(running_description, std::cout);
run_test.start(XBUtilities::is_escape_codes_disabled());

// Execute the python script and capture the outputs
boost::process::ipstream ip_stdout;
boost::process::ipstream ip_stderr;
Expand All @@ -254,12 +236,10 @@ XBUtilities::runScript( const std::string & env,
// Wait for the process to finish
while (runningProcess.running()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
run_test.check_timeout(max_running_duration);
}

// Not really needed, but should be added for completeness
runningProcess.wait();
run_test.finish();

// boost::process::ipstream::rdbuf() gives conversion error in
// 1.65.1 Base class is constructed with underlying buffer so just
Expand Down
2 changes: 0 additions & 2 deletions src/runtime_src/core/tools/common/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace XBUtilities {
runScript(const std::string & env,
const std::string & script,
const std::vector<std::string> & args,
const std::string & running_description,
const std::chrono::seconds& max_running_duration,
std::ostringstream & os_stdout,
std::ostringstream & os_stderr);
};
Expand Down
132 changes: 28 additions & 104 deletions src/runtime_src/core/tools/common/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ TestRunner::searchLegacyXclbin(const uint16_t vendor, const std::string& dev_nam
}

/*
* helper funtion for kernel and bandwidth test cases
* helper funtion for kernel and bandwidth python test cases when there is no platform.json
* Steps:
* 1. Find xclbin after determining if the shell is 1RP or 2RP
* 2. Find testcase
* 3. Spawn a testcase process
* 4. Check results
*/
void
TestRunner::runTestCase( const std::shared_ptr<xrt_core::device>& _dev, const std::string& py,
TestRunner::runPyTestCase( const std::shared_ptr<xrt_core::device>& _dev, const std::string& py,
boost::property_tree::ptree& _ptTest)
{
const auto xclbin = _ptTest.get<std::string>("xclbin", "");
Expand All @@ -273,11 +273,6 @@ TestRunner::runTestCase( const std::shared_ptr<xrt_core::device>& _dev, const st
logger(_ptTest, "Xclbin", xclbin_parent_path);

std::string platform_path = findPlatformPath(_dev, _ptTest);
auto json_exists = [platform_path]() {
const static std::string platform_metadata = "/platform.json";
std::string platform_json_path(platform_path + platform_metadata);
return std::filesystem::exists(platform_json_path) ? true : false;
};

// Some testcases require additional binaries to be present on the device
std::string dependency_args;
Expand All @@ -294,101 +289,38 @@ TestRunner::runTestCase( const std::shared_ptr<xrt_core::device>& _dev, const st
#define XRT_TEST_CASE_DIR "/opt/xilinx/xrt/test/"
#endif

if (json_exists()) {
//map old testcase names to new testcase names
static const std::map<std::string, std::string> test_map = {
{ "22_verify.py", "validate.exe" },
{ "23_bandwidth.py", "kernel_bw.exe" },
{ "versal_23_bandwidth.py", "kernel_bw.exe" },
{ "host_mem_23_bandwidth.py", "hostmemory.exe" },
{ "xcl_vcu_test.exe", "xcl_vcu_test.exe"},
{ "xcl_iops_test.exe", "xcl_iops_test.exe"},
{ "aie_pl.exe", "aie_pl.exe"}
};

// Validate the legacy names
// If no legacy name exists use the passed in test name
std::string test_name = py;
if (test_map.find(py) != test_map.end())
test_name = test_map.find(py)->second;

// Parse if the file exists here
std::string xrtTestCasePath = XRT_TEST_CASE_DIR + test_name;
std::filesystem::path xrt_path(xrtTestCasePath);
if (!std::filesystem::exists(xrt_path)) {
logger(_ptTest, "Error", boost::str(boost::format("Failed to find %s") % xrtTestCasePath));
logger(_ptTest, "Error", "Please check if the platform package is installed correctly");
_ptTest.put("status", test_token_failed);
return;
}

// log testcase path for debugging purposes
logger(_ptTest, "Testcase", xrtTestCasePath);

std::vector<std::string> args = { "-x", xclbinPath,
"-p", platform_path,
"-d", xrt_core::query::pcie_bdf::to_string(xrt_core::device_query<xrt_core::query::pcie_bdf>(_dev)) };
//Check if testcase is present
std::string xrtTestCasePath = XRT_TEST_CASE_DIR + py;
std::filesystem::path xrt_path(xrtTestCasePath);
if (!std::filesystem::exists(xrt_path)) {
logger(_ptTest, "Error", boost::str(boost::format("Failed to find %s") % xrtTestCasePath));
logger(_ptTest, "Error", "Please check if the platform package is installed correctly");
_ptTest.put("status", test_token_failed);
return;
}
// log testcase path for debugging purposes
logger(_ptTest, "Testcase", xrtTestCasePath);

if (!dependency_args.empty()) {
args.push_back("-i");
args.push_back(dependency_args);
}
std::vector<std::string> args = { "-k", xclbinPath,
"-d", xrt_core::query::pcie_bdf::to_string(xrt_core::device_query<xrt_core::query::pcie_bdf>(_dev)) };
int exit_code;
try {
exit_code = XBU::runScript("python", xrtTestCasePath, args, os_stdout, os_stderr);

try {
int exit_code = XBU::runScript("sh", xrtTestCasePath, args, "Running Test", max_test_duration, os_stdout, os_stderr);
if (exit_code == EOPNOTSUPP) {
_ptTest.put("status", test_token_skipped);
}
else if (exit_code == EXIT_SUCCESS) {
_ptTest.put("status", test_token_passed);
}
else {
logger(_ptTest, "Error", os_stdout.str());
logger(_ptTest, "Error", os_stderr.str());
_ptTest.put("status", test_token_failed);
}
} catch (const std::exception& e) {
logger(_ptTest, "Error", e.what());
_ptTest.put("status", test_token_failed);
if (exit_code == EOPNOTSUPP) {
_ptTest.put("status", test_token_skipped);
}
}
else {
//check if testcase is present
std::string xrtTestCasePath = XRT_TEST_CASE_DIR + py;
std::filesystem::path xrt_path(xrtTestCasePath);
if (!std::filesystem::exists(xrt_path)) {
logger(_ptTest, "Error", boost::str(boost::format("Failed to find %s") % xrtTestCasePath));
logger(_ptTest, "Error", "Please check if the platform package is installed correctly");
_ptTest.put("status", test_token_failed);
return;
else if (exit_code == EXIT_SUCCESS) {
_ptTest.put("status", test_token_passed);
}
// log testcase path for debugging purposes
logger(_ptTest, "Testcase", xrtTestCasePath);

std::vector<std::string> args = { "-k", xclbinPath,
"-d", xrt_core::query::pcie_bdf::to_string(xrt_core::device_query<xrt_core::query::pcie_bdf>(_dev)) };
int exit_code;
try {
if (py.find(".exe") != std::string::npos)
exit_code = XBU::runScript("", xrtTestCasePath, args, "Running Test", max_test_duration, os_stdout, os_stderr);
else
exit_code = XBU::runScript("python", xrtTestCasePath, args, "Running Test", max_test_duration, os_stdout, os_stderr);

if (exit_code == EOPNOTSUPP) {
_ptTest.put("status", test_token_skipped);
}
else if (exit_code == EXIT_SUCCESS) {
_ptTest.put("status", test_token_passed);
}
else {
logger(_ptTest, "Error", os_stdout.str());
logger(_ptTest, "Error", os_stderr.str());
_ptTest.put("status", test_token_failed);
}
} catch (const std::exception& e) {
logger(_ptTest, "Error", e.what());
else {
logger(_ptTest, "Error", os_stdout.str());
logger(_ptTest, "Error", os_stderr.str());
_ptTest.put("status", test_token_failed);
}
} catch (const std::exception& e) {
logger(_ptTest, "Error", e.what());
_ptTest.put("status", test_token_failed);
}

// Get out max thruput for bandwidth testcase
Expand All @@ -409,14 +341,6 @@ TestRunner::runTestCase( const std::shared_ptr<xrt_core::device>& _dev, const st
}
}
}

if (py.compare("xcl_iops_test.exe") == 0) {
auto st = os_stdout.str().find("IOPS:");
if (st != std::string::npos) {
size_t end = os_stdout.str().find("\n", st);
logger(_ptTest, "Details", os_stdout.str().substr(st, end - st));
}
}
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/TestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestRunner : public JSONConfigurable {
protected:
TestRunner(const std::string & test_name, const std::string & description,
const std::string & xclbin = "", bool is_explicit = false);
void runTestCase( const std::shared_ptr<xrt_core::device>& _dev, const std::string& py,
void runPyTestCase( const std::shared_ptr<xrt_core::device>& _dev, const std::string& py,
boost::property_tree::ptree& _ptTest);
void logger(boost::property_tree::ptree& ptree, const std::string& tag, const std::string& msg);
bool search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boost::property_tree::ptree& ptTest);
Expand Down
10 changes: 10 additions & 0 deletions src/runtime_src/core/tools/common/tests/TestBandwidthKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ TestBandwidthKernel::runTest(std::shared_ptr<xrt_core::device> dev, boost::prope
ptree.put("status", test_token_failed);
return;
}
auto json_exists = [test_path]() {
const static std::string platform_metadata = "/platform.json";
std::string platform_json_path(test_path + platform_metadata);
return std::filesystem::exists(platform_json_path) ? true : false;
};
if (!json_exists()) {
// Without a platform.json, we need to run the python test file.
runPyTestCase(dev, "23_bandwidth.py", ptree);
return;
}

int num_kernel = 0;
int num_kernel_ddr = 0;
Expand Down
Loading