/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "hipAPI.h" FileOccurrence::FileOccurrence(std::string file_name, int line_number) : file_name{file_name}, line_number{line_number} {} TestCaseOccurrence::TestCaseOccurrence(std::string test_case_name, std::string file_name, int line_number) : FileOccurrence{file_name, line_number}, test_case_name{test_case_name} {} bool operator==(const TestCaseOccurrence& l_test, const TestCaseOccurrence& r_test) { return l_test.test_case_name == r_test.test_case_name; } bool operator<(const TestCaseOccurrence& l_test, const TestCaseOccurrence& r_test) { return l_test.test_case_name < r_test.test_case_name; } bool operator==(const HipAPI& l_hip_api, const HipAPI& r_hip_api) { return l_hip_api.api_name == r_hip_api.api_name; } bool operator<(const HipAPI& l_hip_api, const HipAPI& r_hip_api) { return l_hip_api.api_name < r_hip_api.api_name; } HipAPI::HipAPI(std::string api_name, bool deprecated_flag, std::string api_group_name, std::string file_restriction) : api_name{api_name}, file_restriction{file_restriction}, deprecated{deprecated_flag}, api_group_name{api_group_name} { test_cases.clear(); } std::string HipAPI::getName() const { return api_name; } std::string HipAPI::getGroupName() const { return api_group_name; } int HipAPI::getNumberOfCalls() const { return file_occurrences.size(); } std::vector HipAPI::getTestCases() const { return test_cases; } void HipAPI::addFileOccurrence(FileOccurrence file_occurrence) { file_occurrences.push_back(file_occurrence); } void HipAPI::addTestCase(TestCaseOccurrence test_case) { if (std::find(test_cases.begin(), test_cases.end(), test_case) == test_cases.end()) { test_cases.push_back(test_case); } } bool HipAPI::isDeprecated() const { return deprecated; } std::string HipAPI::getBasicStatsXML() const { std::stringstream xml_node; xml_node << "\t\t\n"; if (!deprecated) { xml_node << "\t\t\t" << api_name << "\n"; } else { xml_node << "\t\t\t" << "[DEPRECATED] " << api_name << "\n"; } if (!file_occurrences.empty()) { xml_node << "\t\t\t" << file_occurrences.size() << "\n"; xml_node << "\t\t\t\n"; for (auto const& file_occurrence : file_occurrences) { xml_node << "\t\t\t\t" << file_occurrence.file_name << ":" << file_occurrence.line_number << "\n"; } xml_node << "\t\t\t\n"; } xml_node << "\t\t\n"; return xml_node.str(); } std::string HipAPI::createHTMLReport() const { std::stringstream html_report; std::string one_tab{"\n\t"}; std::string two_tabs{"\n\t\t"}; std::string three_tabs{"\n\t\t\t"}; std::string four_tabs{"\n\t\t\t\t"}; std::string five_tabs{"\n\t\t\t\t\t"}; std::string six_tabs{"\n\t\t\t\t\t\t"}; html_report << ""; html_report << "" << one_tab << ""; html_report << one_tab << "" << api_name << " Coverage report" << one_tab << "" << one_tab << ""; html_report << one_tab << "" << one_tab << ""; html_report << two_tabs << ""; html_report << two_tabs << "\n"; html_report << two_tabs << "" << three_tabs << ""; html_report << two_tabs << ""; html_report << two_tabs << "\n"; html_report << one_tab << "
" << api_name << " Coverage report
" << four_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << five_tabs << ""; html_report << five_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << five_tabs << ""; html_report << five_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << five_tabs << ""; html_report << five_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << six_tabs << ""; html_report << five_tabs << ""; html_report << five_tabs << ""; html_report << four_tabs << "
"; html_report << six_tabs << "
Group:" << api_group_name << "
Calls within test source files:" << file_occurrences.size() << "
Number of test cases:" << test_cases.size() << "
"; html_report << three_tabs << "
"; html_report << one_tab << "
"; // Add info about test cases html_report << one_tab << ""; if (!test_cases.empty()) { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; for (auto const& test_case : test_cases) { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; } } else { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; } html_report << one_tab << "



Test case IDTest case occurrence in fileLine number
" << test_case.test_case_name << "" << test_case.file_name << "" << test_case.line_number << "

There are no test " "cases detected within doxygen comments.
"; html_report << one_tab << "
"; html_report << one_tab << ""; html_report << two_tabs << ""; html_report << one_tab << "
"; // Add info about API occurrences in the test files. html_report << one_tab << ""; if (!file_occurrences.empty()) { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; for (auto const& file_occurrence : file_occurrences) { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; } } else { html_report << two_tabs << ""; html_report << three_tabs << ""; html_report << two_tabs << ""; } html_report << one_tab << "


API occurrence in fileLine number
" << file_occurrence.file_name << "" << file_occurrence.line_number << "

There are no " "occurrences within test source files.
"; html_report << one_tab << "
"; html_report << one_tab << "
"; html_report << one_tab << ""; html_report << two_tabs << ""; time_t now{time(nullptr)}; std::string date{asctime(gmtime(&now))}; html_report << two_tabs << ""; html_report << one_tab << "
Generated: " << date; html_report << two_tabs << " UTC
"; html_report << one_tab << "
"; html_report << "\n\n"; return html_report.str(); } std::string HipAPI::getFileRestriction() const { return file_restriction; }