From 0772e8d618e2b3db410127c6a7dc46619b4edf71 Mon Sep 17 00:00:00 2001 From: Graham Sider Date: Thu, 6 Apr 2023 16:35:35 -0400 Subject: [PATCH] rocrtst: Throw on LocateKernelFile open() failures Throw runtime error instead of returning empty string when open() fails in LocateKernelFile() Signed-off-by: Graham Sider Change-Id: Iafa360fbc2d3c9b01b9fe7ea4c11d70bd254ccce --- rocrtst/common/base_rocr_utils.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rocrtst/common/base_rocr_utils.cc b/rocrtst/common/base_rocr_utils.cc index 73dbe00eed..44013e9d43 100755 --- a/rocrtst/common/base_rocr_utils.cc +++ b/rocrtst/common/base_rocr_utils.cc @@ -288,18 +288,17 @@ std::string LocateKernelFile(std::string filename, hsa_agent_t agent) { std::string obj_file; hsa_status_t err = hsa_agent_get_info(agent, HSA_AGENT_INFO_NAME, agent_name); RET_IF_HSA_UTILS_ERR_RET(err, obj_file); - + obj_file = "./" + filename; int file_handle = open(obj_file.c_str(), O_RDONLY); - if (file_handle == -1) { + if (file_handle < 0) { obj_file = "./" + std::string(agent_name) + "/" + filename; file_handle = open(obj_file.c_str(), O_RDONLY); + if(file_handle < 0) + std::runtime_error("Could not open file.\n"); } - if(file_handle == -1) - obj_file.clear(); - else - close(file_handle); + close(file_handle); return obj_file; }