diff --git a/CHANGELOG.md b/CHANGELOG.md index b74ce0d985..64e497af82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/plugin/file/file.cpp b/plugin/file/file.cpp index 2992ce86d0..522b4935b9 100644 --- a/plugin/file/file.cpp +++ b/plugin/file/file.cpp @@ -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::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))) { diff --git a/plugin/perfetto/perfetto.cpp b/plugin/perfetto/perfetto.cpp index 082a0f21e5..c30b9e7de9 100644 --- a/plugin/perfetto/perfetto.cpp +++ b/plugin/perfetto/perfetto.cpp @@ -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::rdbuf(std::cout.rdbuf()); return; } + if (output_dir == nullptr) + output_dir = "./"; output_prefix_ = output_dir; if (!fs::is_directory(fs::status(output_prefix_))) { diff --git a/tests/featuretests/profiler/profiler_gtest.cpp b/tests/featuretests/profiler/profiler_gtest.cpp index 444ea0a724..286b37f538 100644 --- a/tests/featuretests/profiler/profiler_gtest.cpp +++ b/tests/featuretests/profiler/profiler_gtest.cpp @@ -30,6 +30,7 @@ THE SOFTWARE. #include #include #include +//#include #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); } -} \ No newline at end of file +} + +/* + * ################################################### + * ############ 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); +} +*/ \ No newline at end of file diff --git a/tests/featuretests/profiler/profiler_gtest.h b/tests/featuretests/profiler/profiler_gtest.h index 4cc9b1d5b1..a6c0da8c45 100644 --- a/tests/featuretests/profiler/profiler_gtest.h +++ b/tests/featuretests/profiler/profiler_gtest.h @@ -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_