SWDEV-391583: Set default outputdir when filename is specified
Change-Id: I9765582cc0dc870906d0ec16aa9ca38e990e0ef8
This commit is contained in:
committed by
Giovanni Baraldi
parent
d0326a0a28
commit
1b5fed173c
+1
-1
@@ -233,4 +233,4 @@ The resulting `a.out` will depend on
|
||||
- Samples are fixed to show the new usage of phases.
|
||||
- Plugin option validates the plugin names.
|
||||
- Fixing rocsys, for rocsys options, rocsys -h can be called
|
||||
|
||||
- "--output-file" option ignored when no output folder was specified.
|
||||
|
||||
@@ -77,12 +77,14 @@ class file_plugin_t {
|
||||
const char* output_dir = getenv("OUTPUT_PATH");
|
||||
output_file_name = getenv("OUT_FILE_NAME") ? std::string(getenv("OUT_FILE_NAME")) + "_" : "";
|
||||
|
||||
if (output_dir == nullptr) {
|
||||
if (output_dir == nullptr && getenv("OUT_FILE_NAME") == nullptr) {
|
||||
stream_.copyfmt(std::cout);
|
||||
stream_.clear(std::cout.rdstate());
|
||||
stream_.basic_ios<char>::rdbuf(std::cout.rdbuf());
|
||||
return;
|
||||
}
|
||||
if (output_dir == nullptr)
|
||||
output_dir = "./";
|
||||
|
||||
fs::path output_prefix(output_dir);
|
||||
if (!fs::is_directory(fs::status(output_prefix))) {
|
||||
|
||||
@@ -97,12 +97,14 @@ class perfetto_plugin_t {
|
||||
const char* temp_file_name = getenv("OUT_FILE_NAME");
|
||||
output_file_name = temp_file_name ? std::string(temp_file_name) + "_" : "";
|
||||
|
||||
if (output_dir == nullptr) {
|
||||
if (output_dir == nullptr && temp_file_name == nullptr) {
|
||||
stream_.copyfmt(std::cout);
|
||||
stream_.clear(std::cout.rdstate());
|
||||
stream_.basic_ios<char>::rdbuf(std::cout.rdbuf());
|
||||
return;
|
||||
}
|
||||
if (output_dir == nullptr)
|
||||
output_dir = "./";
|
||||
|
||||
output_prefix_ = output_dir;
|
||||
if (!fs::is_directory(fs::status(output_prefix_))) {
|
||||
|
||||
@@ -30,6 +30,7 @@ THE SOFTWARE.
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <array>
|
||||
//#include <experimental/filesystem>
|
||||
|
||||
#include "src/utils/helper.h"
|
||||
#include "utils/test_utils.h"
|
||||
@@ -61,6 +62,7 @@ static void init_test_path() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets application enviornment by seting HSA_TOOLS_LIB.
|
||||
*/
|
||||
@@ -1307,4 +1309,91 @@ TEST(ProfilerMPTest, WhenRunningMultiProcessTestItPasses) {
|
||||
} else { // failure
|
||||
ASSERT_TRUE(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ###################################################
|
||||
* ############ File plugin tests ################
|
||||
* ###################################################
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets application output dir.
|
||||
*/
|
||||
|
||||
/*
|
||||
void FilePluginTest::RunApplication(const char* app_name, const char* appParams) {
|
||||
if (is_installed_path()) return; // Only run these tests from build
|
||||
|
||||
init_test_path();
|
||||
unsetenv("OUTPUT_FOLDER");
|
||||
|
||||
std::stringstream os;
|
||||
os << binary_path << " --hsa-activity " << appParams << " ";
|
||||
os << test_app_path << app_name;
|
||||
ProcessApplication(os);
|
||||
}
|
||||
|
||||
bool FilePluginTest::hasFileInDir(const std::string& filename, const char* directory) {
|
||||
if (is_installed_path()) return true; // Only run these tests from build
|
||||
|
||||
for (const auto& entry : std::experimental::filesystem::directory_iterator(directory)) {
|
||||
if (filename.size() == 0)
|
||||
return true;
|
||||
if (std::string(entry.path().filename()).substr(0, filename.size()) == filename)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FilePluginTest::ProcessApplication(std::stringstream& ss) {
|
||||
FILE* handle = popen(ss.str().c_str(), "r");
|
||||
ASSERT_NE(handle, nullptr);
|
||||
pclose(handle);
|
||||
}
|
||||
|
||||
class VectorAddFileOnlyTest : public FilePluginTest {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
RunApplication("hip_vectoradd", "-o file_test_name");
|
||||
}
|
||||
virtual void TearDown() {
|
||||
std::string filename = "file_test_name";
|
||||
for (const auto& entry : std::experimental::filesystem::directory_iterator("./"))
|
||||
if (std::string(entry.path().filename()).substr(0, filename.size()) == filename)
|
||||
std::experimental::filesystem::remove(entry);
|
||||
}
|
||||
bool hasFile(){ return hasFileInDir("file_test_name", "."); }
|
||||
};
|
||||
|
||||
TEST_F(VectorAddFileOnlyTest, WhenRunningProfilerWithOnlyOutputFilenameSetTest) {
|
||||
EXPECT_EQ(hasFile(), true);
|
||||
}
|
||||
|
||||
class VectorAddFolderOnlyTest : public FilePluginTest {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
RunApplication("hip_vectoradd", "-d ./plugin_test_folder_path");
|
||||
}
|
||||
virtual void TearDown() { std::experimental::filesystem::remove_all("./plugin_test_folder_path"); }
|
||||
bool hasFile(){ return hasFileInDir("", "./plugin_test_folder_path"); }
|
||||
};
|
||||
|
||||
TEST_F(VectorAddFolderOnlyTest, WhenRunningProfilerWithOnlyOutputFilenameSetTest) {
|
||||
EXPECT_EQ(hasFile(), true);
|
||||
}
|
||||
|
||||
class VectorAddFileAndFolderTest : public FilePluginTest {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
RunApplication("hip_vectoradd", "-d ./plugin_test_folder_path -o file_test_name");
|
||||
}
|
||||
virtual void TearDown() { std::experimental::filesystem::remove_all("./plugin_test_folder_path"); }
|
||||
bool hasFile(){ return hasFileInDir("file_test_name", "./plugin_test_folder_path"); }
|
||||
};
|
||||
|
||||
TEST_F(VectorAddFileAndFolderTest, WhenRunningProfilerWithOnlyOutputFilenameSetTest) {
|
||||
EXPECT_EQ(hasFile(), true);
|
||||
}
|
||||
*/
|
||||
@@ -106,4 +106,26 @@ class ProfilerTest : public ApplicationParser {
|
||||
protected:
|
||||
virtual void SetUp(const char* app_name) { ApplicationParser::SetUp(app_name); }
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @Synopsis Base class for file plugin tests.
|
||||
* The file test will check wether certain filenames are created.
|
||||
* Currently, file plugin tests only from build as they need to create files.
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
class FilePluginTest : public ::testing::Test {
|
||||
public:
|
||||
//!< Sets application environment by seting rocprofv2.
|
||||
void RunApplication(const char* app_name, const char* appParams);
|
||||
|
||||
//!< Checks wether a file beginning with "filename" exists in "directory"
|
||||
static bool hasFileInDir(const std::string& filename, const char* directory);
|
||||
private:
|
||||
//!< Runs a given appllication with the hsa activity.
|
||||
void ProcessApplication(std::stringstream& ss);
|
||||
}; */
|
||||
|
||||
#endif // TESTS_FEATURETESTS_PROFILER_GTESTS_APPS_PROFILER_GTEST_H_
|
||||
|
||||
Reference in New Issue
Block a user