From 77f3008adfc6cc7526c4772a3d884692ef05c2b8 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Tue, 21 Mar 2023 10:00:50 -0700 Subject: [PATCH 01/11] Use c++17 filesystem instead of boost and std::experimental --- CMakeLists.txt | 15 ++- client-lite/CMakeLists.txt | 4 - client-lite/src/ipc/rest_port_advertiser.h | 8 +- client-lite/src/util/do_json_parser.cpp | 6 +- client-lite/src/util/proc_launch_helper.h | 8 +- client-lite/test/CMakeLists.txt | 7 +- client-lite/test/do_log_tests.cpp | 4 +- client-lite/test/docs_tests.cpp | 4 +- client-lite/test/download_manager_tests.cpp | 2 +- client-lite/test/json_parser_tests.cpp | 12 +- client-lite/test/mcc_manager.tests.cpp | 24 ++-- client-lite/test/test_common.h | 12 +- client-lite/test/test_verifiers.h | 4 +- sdk-cpp/CMakeLists.txt | 17 --- .../src/internal/rest/do_config_internal.cpp | 14 +-- .../src/internal/rest/util/do_port_finder.cpp | 16 +-- sdk-cpp/tests/CMakeLists.txt | 8 +- sdk-cpp/tests/download_properties_tests.cpp | 8 +- sdk-cpp/tests/download_tests_common.cpp | 104 +++++++++--------- sdk-cpp/tests/rest/config_tests.cpp | 7 +- sdk-cpp/tests/rest/mcc_download_tests.cpp | 7 +- .../tests/rest/network_connectivity_tests.cpp | 4 +- sdk-cpp/tests/rest/port_discovery_tests.cpp | 10 +- sdk-cpp/tests/rest/rest_interface_tests.cpp | 7 +- sdk-cpp/tests/rest/test_helpers.cpp | 8 +- sdk-cpp/tests/test_data.cpp | 10 +- sdk-cpp/tests/test_helpers.h | 27 ++--- sdk-cpp/tests/tests_common.h | 2 +- 28 files changed, 165 insertions(+), 194 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e453045..a8c951a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,6 @@ option (DO_INCLUDE_SDK "Build subproject sdk-cpp" OFF) option (DO_BUILD_TESTS "Set DO_BUILD_TESTS to OFF to skip building tests." ON) option (DO_BUILD_FOR_SNAP "Enable DO Snap build option" OFF) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - # Get verbose output from cmake generation and build steps set(CMAKE_VERBOSE_MAKEFILE ON) @@ -62,6 +58,15 @@ else() message(FATAL_ERROR "Unknown platform for client") endif() +if (DO_INCLUDE_SDK AND DO_PLATFORM_WINDOWS) + # Edge build is not ready to move up to C++17 yet. + set(CMAKE_CXX_STANDARD 14) +else () + set(CMAKE_CXX_STANDARD 17) +endif () +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + # PIC (Position Independent Code) ensures .a files can be linked to executables that have PIE enabled set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -85,7 +90,7 @@ if (DO_PLATFORM_LINUX) # not relevant for our usage or they are symlinks to /usr/lib and /usr/bin. if (NOT CMAKE_PREFIX_PATH) set(CMAKE_PREFIX_PATH "/usr") - endif () + endif () endif (DO_PLATFORM_LINUX) if (DO_PLATFORM_WINDOWS AND DO_INCLUDE_SDK) diff --git a/client-lite/CMakeLists.txt b/client-lite/CMakeLists.txt index 35d95007..b71f4823 100644 --- a/client-lite/CMakeLists.txt +++ b/client-lite/CMakeLists.txt @@ -9,8 +9,6 @@ project (${DOSVC_BIN_NAME} VERSION 1.0.0) option (DO_PROXY_SUPPORT "Set DO_PROXY_SUPPORT to OFF to turn off proxy support for downloads and thus remove dependency on libproxy." ON) -add_definitions(-DBOOST_ALL_DYN_LINK=1) - # -Wno-noexcept-type, the offending function is SetResultLoggingCallback, this warning is fixed in C++17 because exception specification # is part of a function type. Since the offending function is not public when compiled into docs_common just add the compiler flag here # to disable the warning. @@ -29,7 +27,6 @@ function (target_link_dl_lib target) endfunction () # Include external libraries here: -find_package(Boost COMPONENTS filesystem REQUIRED) find_package(CURL REQUIRED) # g++ requires explicit specification of the thread library to be used find_package(Threads REQUIRED) @@ -124,7 +121,6 @@ add_platform_interface_definitions(${DOSVC_BIN_NAME}) target_include_directories(${DOSVC_BIN_NAME} PRIVATE ${docs_common_includes}) target_link_libraries(${DOSVC_BIN_NAME} docs_common - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/client-lite/src/ipc/rest_port_advertiser.h b/client-lite/src/ipc/rest_port_advertiser.h index 9780f3aa..5e860a15 100644 --- a/client-lite/src/ipc/rest_port_advertiser.h +++ b/client-lite/src/ipc/rest_port_advertiser.h @@ -7,7 +7,7 @@ #include // open, write #include // getpid #include -#include +#include #include #include "do_persistence.h" #include "error_macros.h" @@ -60,13 +60,13 @@ class RestPortAdvertiser void _DeleteOlderPortFiles() try { auto& runtimeDirectory = docli::GetRuntimeDirectory(); - for (boost::filesystem::directory_iterator itr(runtimeDirectory); itr != boost::filesystem::directory_iterator(); ++itr) + for (std::filesystem::directory_iterator itr(runtimeDirectory); itr != std::filesystem::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find(_restPortFileNamePrefix) != std::string::npos) { - boost::system::error_code ec; - boost::filesystem::remove(dirEntry, ec); + std::error_code ec; + std::filesystem::remove(dirEntry, ec); if (ec) { DoLogWarning("Failed to delete old port file (%d, %s) %s", ec.value(), ec.message().data(), dirEntry.string().data()); diff --git a/client-lite/src/util/do_json_parser.cpp b/client-lite/src/util/do_json_parser.cpp index 5ff42980..e9f1676c 100644 --- a/client-lite/src/util/do_json_parser.cpp +++ b/client-lite/src/util/do_json_parser.cpp @@ -4,7 +4,7 @@ #include "do_common.h" #include "do_json_parser.h" -#include +#include #include std::chrono::seconds JsonParser::RefreshInterval = std::chrono::seconds(60); @@ -13,7 +13,7 @@ std::chrono::seconds JsonParser::RefreshInterval = std::chrono::seconds(60); JsonParser::JsonParser(const std::string& jsonFilePath, bool alwaysCreateFile) : _jsonFilePath(jsonFilePath) { - if (alwaysCreateFile && !(boost::filesystem::exists(_jsonFilePath))) + if (alwaysCreateFile && !(std::filesystem::exists(_jsonFilePath))) { DoLogInfo("json file not found at %s, creating file", _jsonFilePath.data()); boost::property_tree::ptree json; @@ -33,7 +33,7 @@ void JsonParser::_TryRefresh(bool force) return; } - if (boost::filesystem::exists(_jsonFilePath)) + if (std::filesystem::exists(_jsonFilePath)) { try { diff --git a/client-lite/src/util/proc_launch_helper.h b/client-lite/src/util/proc_launch_helper.h index 6c4abfde..66a7e613 100644 --- a/client-lite/src/util/proc_launch_helper.h +++ b/client-lite/src/util/proc_launch_helper.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "do_common.h" #include "do_persistence.h" @@ -54,11 +54,11 @@ inline void SetDOPathPermissions(const std::string& path, mode_t mode) inline void InitializePath(const std::string& path, mode_t mode = 0) try { - boost::filesystem::path dirPath(path); - if (!boost::filesystem::exists(dirPath)) + std::filesystem::path dirPath(path); + if (!std::filesystem::exists(dirPath)) { DoLogInfo("Creating directories for %s", path.c_str()); - boost::filesystem::create_directories(dirPath); + std::filesystem::create_directories(dirPath); if (mode != 0) { diff --git a/client-lite/test/CMakeLists.txt b/client-lite/test/CMakeLists.txt index ea9db484..d0e3ff03 100644 --- a/client-lite/test/CMakeLists.txt +++ b/client-lite/test/CMakeLists.txt @@ -1,11 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# Unit tests for DOCS - -# Only need program_options here but have to include others required by docs_common. -# TODO: docs_common should declare what it needs via target_link_libraries(PUBLIC). -find_package(Boost COMPONENTS filesystem program_options REQUIRED) +find_package(Boost COMPONENTS program_options REQUIRED) find_package(GTest REQUIRED) file (GLOB files_docs_tests @@ -15,7 +11,6 @@ add_platform_interface_definitions(deliveryoptimization-agent-tests) target_link_libraries(deliveryoptimization-agent-tests docs_common dotestutil - stdc++fs ${Boost_LIBRARIES} GTest::GTest ) diff --git a/client-lite/test/do_log_tests.cpp b/client-lite/test/do_log_tests.cpp index 2d3dfbad..66479191 100644 --- a/client-lite/test/do_log_tests.cpp +++ b/client-lite/test/do_log_tests.cpp @@ -26,12 +26,12 @@ TEST_F(DOLoggerTests, BasicWriteToFile) DOLog::Close(); UINT nLogFilesFound = 0; - for (cppfs::recursive_directory_iterator itr(g_testTempDir); itr != cppfs::recursive_directory_iterator{}; ++itr) + for (std::filesystem::recursive_directory_iterator itr(g_testTempDir); itr != std::filesystem::recursive_directory_iterator{}; ++itr) { ++nLogFilesFound; const auto filePath = itr->path(); ASSERT_NE(strstr(filePath.c_str(), "do-agent."), nullptr); - ASSERT_GT(cppfs::file_size(filePath), 0); + ASSERT_GT(std::filesystem::file_size(filePath), 0); std::ifstream fs; fs.open(filePath.string()); diff --git a/client-lite/test/docs_tests.cpp b/client-lite/test/docs_tests.cpp index 7911af2c..4ae7c830 100644 --- a/client-lite/test/docs_tests.cpp +++ b/client-lite/test/docs_tests.cpp @@ -6,7 +6,7 @@ #include #include "test_data.h" -const cppfs::path g_testTempDir = "/tmp/docs_test_scratch"; +const std::filesystem::path g_testTempDir = "/tmp/docs_test_scratch"; int main(int argc, char** argv) { @@ -15,7 +15,7 @@ int main(int argc, char** argv) // TODO(shishirb) enable console only logging std::error_code ec; - cppfs::create_directories(g_testTempDir, ec); + std::filesystem::create_directories(g_testTempDir, ec); if (ec) { printf("Failed to create test dir: %s\n", g_testTempDir.string().data()); diff --git a/client-lite/test/download_manager_tests.cpp b/client-lite/test/download_manager_tests.cpp index cbb21c0e..29ec9aa6 100644 --- a/client-lite/test/download_manager_tests.cpp +++ b/client-lite/test/download_manager_tests.cpp @@ -136,7 +136,7 @@ TEST_F(DownloadManagerTests, FileDownloadFatal404) ASSERT_EQ(status.BytesTotal, 0); VerifyError(status, HTTP_E_STATUS_NOT_FOUND); VerifyDownloadHttpStatus(*DownloadForId(manager, id), 404); - ASSERT_TRUE(cppfs::exists(destFile)); + ASSERT_TRUE(std::filesystem::exists(destFile)); manager.AbortDownload(id); VerifyFileNotFound(destFile); } diff --git a/client-lite/test/json_parser_tests.cpp b/client-lite/test/json_parser_tests.cpp index e0b01daa..cb8b6954 100644 --- a/client-lite/test/json_parser_tests.cpp +++ b/client-lite/test/json_parser_tests.cpp @@ -12,7 +12,7 @@ #include #include -const cppfs::path g_jsonTestFilePath = g_testTempDir / "docs_config.json"; +const std::filesystem::path g_jsonTestFilePath = g_testTempDir / "docs_config.json"; const std::map g_testData = { @@ -70,9 +70,9 @@ class JsonParserTests : public ::testing::Test void SetUp() override { JsonParser::RefreshInterval = std::chrono::seconds(10); // for faster test times - if (cppfs::exists(g_jsonTestFilePath)) + if (std::filesystem::exists(g_jsonTestFilePath)) { - cppfs::remove(g_jsonTestFilePath); + std::filesystem::remove(g_jsonTestFilePath); } } }; @@ -111,7 +111,7 @@ TEST_F(JsonParserTests, ReadConfigsWithUpdates) VerifyItemFound(reader, "newkey", "newvalue"); // Delete config file and verify - cppfs::remove(g_jsonTestFilePath); + std::filesystem::remove(g_jsonTestFilePath); VerifyItemFound(reader, "newkey", "newvalue"); // within refresh interval VerifyTestData(reader, true); @@ -122,9 +122,9 @@ TEST_F(JsonParserTests, ReadConfigsWithUpdates) TEST_F(JsonParserTests, ReadConfigsWithFileCreatedLater) { - if (cppfs::exists(g_jsonTestFilePath)) + if (std::filesystem::exists(g_jsonTestFilePath)) { - cppfs::remove(g_jsonTestFilePath); + std::filesystem::remove(g_jsonTestFilePath); } JsonParser reader(g_jsonTestFilePath); diff --git a/client-lite/test/mcc_manager.tests.cpp b/client-lite/test/mcc_manager.tests.cpp index 3769df46..89f8f1bd 100644 --- a/client-lite/test/mcc_manager.tests.cpp +++ b/client-lite/test/mcc_manager.tests.cpp @@ -28,13 +28,13 @@ using btcp_t = boost::asio::ip::tcp; #define TEST_MOCK_MCC_HOST "10.130.48.179" #define TEST_MOCK_MCC_HOST2 "10.130.48.180" -const cppfs::path g_adminConfigFilePath = g_testTempDir / "admin-config.json"; -const cppfs::path g_sdkConfigFilePath = g_testTempDir / "sdk-config.json"; +const std::filesystem::path g_adminConfigFilePath = g_testTempDir / "admin-config.json"; +const std::filesystem::path g_sdkConfigFilePath = g_testTempDir / "sdk-config.json"; static void SetIoTConnectionString(const char* connectionString) { boost::property_tree::ptree json; - if (cppfs::exists(g_sdkConfigFilePath)) + if (std::filesystem::exists(g_sdkConfigFilePath)) { boost::property_tree::read_json(g_sdkConfigFilePath, json); } @@ -45,7 +45,7 @@ static void SetIoTConnectionString(const char* connectionString) static void SetDOCacheHostConfig(const char* server) { boost::property_tree::ptree json; - if (cppfs::exists(g_adminConfigFilePath)) + if (std::filesystem::exists(g_adminConfigFilePath)) { boost::property_tree::read_json(g_adminConfigFilePath, json); } @@ -56,7 +56,7 @@ static void SetDOCacheHostConfig(const char* server) static void SetFallbackDelayConfig(std::chrono::seconds delay) { boost::property_tree::ptree json; - if (cppfs::exists(g_adminConfigFilePath)) + if (std::filesystem::exists(g_adminConfigFilePath)) { boost::property_tree::read_json(g_adminConfigFilePath, json); } @@ -71,13 +71,13 @@ class MCCManagerTests : public ::testing::Test { ClearTestTempDir(); - if (cppfs::exists(g_adminConfigFilePath)) + if (std::filesystem::exists(g_adminConfigFilePath)) { - cppfs::remove(g_adminConfigFilePath); + std::filesystem::remove(g_adminConfigFilePath); } - if (cppfs::exists(g_sdkConfigFilePath)) + if (std::filesystem::exists(g_sdkConfigFilePath)) { - cppfs::remove(g_sdkConfigFilePath); + std::filesystem::remove(g_sdkConfigFilePath); } } @@ -107,7 +107,7 @@ TEST_F(MCCManagerTests, ParseIoTConnectionString) _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); // No gateway specified - cppfs::remove(g_sdkConfigFilePath); + std::filesystem::remove(g_sdkConfigFilePath); _VerifyExpectedCacheHost(""); } @@ -117,7 +117,7 @@ TEST_F(MCCManagerTests, AdminConfigOverride) SetDOCacheHostConfig(TEST_MOCK_MCC_HOST2); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST2); - cppfs::remove(g_adminConfigFilePath); + std::filesystem::remove(g_adminConfigFilePath); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); } @@ -127,7 +127,7 @@ TEST_F(MCCManagerTests, AdminConfigEmptyString) SetDOCacheHostConfig(""); _VerifyExpectedCacheHost(""); - cppfs::remove(g_adminConfigFilePath); + std::filesystem::remove(g_adminConfigFilePath); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); } diff --git a/client-lite/test/test_common.h b/client-lite/test/test_common.h index 45ea5716..f50719f9 100644 --- a/client-lite/test/test_common.h +++ b/client-lite/test/test_common.h @@ -6,19 +6,17 @@ #include "do_common.h" #include -#include +#include #include #include -namespace cppfs = std::experimental::filesystem; - -extern const cppfs::path g_testTempDir; +extern const std::filesystem::path g_testTempDir; inline void ClearTestTempDir() { - if (cppfs::exists(g_testTempDir)) + if (std::filesystem::exists(g_testTempDir)) { - cppfs::remove_all(g_testTempDir); + std::filesystem::remove_all(g_testTempDir); } - cppfs::create_directories(g_testTempDir); + std::filesystem::create_directories(g_testTempDir); } diff --git a/client-lite/test/test_verifiers.h b/client-lite/test/test_verifiers.h index 6dbccb40..71ff3f28 100644 --- a/client-lite/test/test_verifiers.h +++ b/client-lite/test/test_verifiers.h @@ -10,12 +10,12 @@ inline void VerifyFileSize(const std::string& path, UINT64 cbExpectedSize) { - ASSERT_EQ(cppfs::file_size(path), cbExpectedSize) << "File size check: " << path; + ASSERT_EQ(std::filesystem::file_size(path), cbExpectedSize) << "File size check: " << path; } inline void VerifyFileNotFound(const std::string& path) { - ASSERT_FALSE(cppfs::exists(path)) << "File absent check: " << path; + ASSERT_FALSE(std::filesystem::exists(path)) << "File absent check: " << path; } inline void VerifyNoError(const DownloadStatus& status) diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index 8c3070a1..f187165b 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -3,14 +3,6 @@ project (deliveryoptimization_sdk VERSION 1.0.0) -if (DO_PLATFORM_LINUX OR DO_PLATFORM_MAC) - message("DO configured to use shared Boost libraries") - add_definitions(-DBOOST_ALL_DYN_LINK=1) - - # Include external libraries here - find_package(Boost COMPONENTS filesystem REQUIRED) -endif() - if (DO_PLATFORM_LINUX) fixup_compile_options_for_arm() endif() @@ -65,10 +57,6 @@ if(DO_PLATFORM_LINUX) dohttp ) - set(sdk_public_linked_libs - ${Boost_LIBRARIES} - ) - strip_symbols(${DO_SDK_LIB_NAME}) elseif(DO_PLATFORM_MAC) @@ -90,9 +78,6 @@ elseif(DO_PLATFORM_MAC) dohttp ) - set(sdk_public_linked_libs - ${Boost_LIBRARIES} - ) elseif(DO_PLATFORM_WINDOWS) file(GLOB sdk_source ${sdk_source_common} @@ -134,8 +119,6 @@ endif () add_platform_interface_definitions(${DO_SDK_LIB_NAME}) target_link_libraries(${DO_SDK_LIB_NAME} - PUBLIC - ${sdk_public_linked_libs} PRIVATE ${sdk_private_linked_libs} ) diff --git a/sdk-cpp/src/internal/rest/do_config_internal.cpp b/sdk-cpp/src/internal/rest/do_config_internal.cpp index 0a27f628..950b679d 100644 --- a/sdk-cpp/src/internal/rest/do_config_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_config_internal.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -31,9 +31,9 @@ static int WriteIoTConnectionStringToConfigFile(const char* value) noexcept int returnValue = 0; // ptree's exceptions do not provide an error code, and SDK has no logging of its own. // Return specific errors as a workaround. - boost::filesystem::path filePath{microsoft::deliveryoptimization::details::GetConfigFilePath()}; - boost::system::error_code ec; - if (boost::filesystem::exists(filePath.parent_path(), ec)) + std::filesystem::path filePath{microsoft::deliveryoptimization::details::GetConfigFilePath()}; + std::error_code ec; + if (std::filesystem::exists(filePath.parent_path(), ec)) { try { @@ -74,10 +74,10 @@ static std::string GetSdkVersion() return msdoutil::ComponentVersion(false); } -static std::string GetBinaryVersion(const boost::filesystem::path& binaryFilePath) +static std::string GetBinaryVersion(const std::filesystem::path& binaryFilePath) { std::string version; - if (boost::filesystem::exists(binaryFilePath)) + if (std::filesystem::exists(binaryFilePath)) { FILE* fp = nullptr; try @@ -118,7 +118,7 @@ static void AppendBinaryVersion(const char* binFileName, std::stringstream& allV // to cover special cases (for example, installed not via our deb/rpm packages). // We do not use bp::search_path() in order to avoid executing a malicious program with the // same name and which appears earlier in the PATH environment variable. - boost::filesystem::path binFilePath("/usr/local/bin"); + std::filesystem::path binFilePath("/usr/local/bin"); binFilePath /= binFileName; std::string version = GetBinaryVersion(binFilePath); if (version.empty()) diff --git a/sdk-cpp/src/internal/rest/util/do_port_finder.cpp b/sdk-cpp/src/internal/rest/util/do_port_finder.cpp index 7835d19a..ab8ef442 100644 --- a/sdk-cpp/src/internal/rest/util/do_port_finder.cpp +++ b/sdk-cpp/src/internal/rest/util/do_port_finder.cpp @@ -2,11 +2,11 @@ #include #include +#include +#include #include #include -#include - #include "do_errors.h" #include "do_error_helpers.h" #include "do_persistence.h" @@ -25,19 +25,19 @@ namespace details static std::string g_DiscoverDOPort() { const std::string runtimeDirectory = GetRuntimeDirectory(); - if (!boost::filesystem::exists(runtimeDirectory)) + if (!std::filesystem::exists(runtimeDirectory)) { return std::string(); } - boost::filesystem::path mostRecentFile(""); - std::time_t mostRecentTime = 0; - for (boost::filesystem::directory_iterator itr(runtimeDirectory); itr != boost::filesystem::directory_iterator(); ++itr) + std::filesystem::path mostRecentFile(""); + auto mostRecentTime = std::filesystem::file_time_type::min(); + for (std::filesystem::directory_iterator itr(runtimeDirectory); itr != std::filesystem::directory_iterator(); ++itr) { - const boost::filesystem::path& dirEntry = itr->path(); + const std::filesystem::path& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) { - std::time_t currTime = boost::filesystem::last_write_time(dirEntry); + auto currTime = std::filesystem::last_write_time(dirEntry); if (currTime > mostRecentTime) { mostRecentTime = currTime; diff --git a/sdk-cpp/tests/CMakeLists.txt b/sdk-cpp/tests/CMakeLists.txt index 7d1978cd..44686aee 100644 --- a/sdk-cpp/tests/CMakeLists.txt +++ b/sdk-cpp/tests/CMakeLists.txt @@ -3,7 +3,7 @@ ## Tests for DO SDK -find_package(Boost COMPONENTS filesystem program_options REQUIRED) +find_package(Boost COMPONENTS program_options REQUIRED) find_package(GTest REQUIRED) set(sdk_tests_linked_libs_common @@ -30,10 +30,6 @@ if(DO_PLATFORM_LINUX) "../src/internal/rest/util" ) - set(sdk_tests_linked_libs - stdc++fs - ) - set(test_source_private "rest/*.cpp" ) @@ -77,9 +73,9 @@ target_include_directories(deliveryoptimization-sdk-tests PRIVATE ${dosdkcpp_private_includes} ${dosdkcpp_private_includes_common} + ${Boost_INCLUDE_DIRS} ) target_link_libraries(deliveryoptimization-sdk-tests - ${sdk_tests_linked_libs} ${sdk_tests_linked_libs_common} ) \ No newline at end of file diff --git a/sdk-cpp/tests/download_properties_tests.cpp b/sdk-cpp/tests/download_properties_tests.cpp index e49b32b6..4ed74d74 100644 --- a/sdk-cpp/tests/download_properties_tests.cpp +++ b/sdk-cpp/tests/download_properties_tests.cpp @@ -22,7 +22,7 @@ class DownloadPropertyTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } void TearDown() override { @@ -62,7 +62,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadSetCallerNameTest) ASSERT_EQ(strCallerName, outCallerName); simpleDownload->start_and_wait_until_completion(); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) @@ -83,7 +83,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, InvalidPhfDigestTest) @@ -102,7 +102,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithCustomHeaders) auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); simpleDownload->set_property(msdo::download_property::http_custom_headers, "XCustom1=someData\nXCustom2=moreData\n"); simpleDownload->start_and_wait_until_completion(); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, CallbackTestUseDownload) diff --git a/sdk-cpp/tests/download_tests_common.cpp b/sdk-cpp/tests/download_tests_common.cpp index 616b07ab..e8729c7b 100644 --- a/sdk-cpp/tests/download_tests_common.cpp +++ b/sdk-cpp/tests/download_tests_common.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include "do_download.h" #include "do_download_status.h" @@ -80,21 +80,21 @@ TEST_F(DownloadTests, SimpleDownloadTest) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); } TEST_F(DownloadTests, SimpleBlockingDownloadTest) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); } TEST_F(DownloadTests, CancelBlockingDownloadTest) { std::atomic_bool cancelToken { false }; - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); std::thread downloadThread([&]() { try @@ -110,7 +110,7 @@ TEST_F(DownloadTests, CancelBlockingDownloadTest) std::this_thread::sleep_for(1s); cancelToken = true; downloadThread.join(); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadTests, BlockingDownloadTimeout) @@ -128,13 +128,13 @@ TEST_F(DownloadTests, BlockingDownloadTimeout) ASSERT_GE(elapsedTime, std::chrono::seconds(2)); ASSERT_LE(elapsedTime, std::chrono::seconds(5)); } - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } // Note: This test takes a long time to execute due to 30 retry intervals from DOCS TEST_F(DownloadTests, SimpleDownloadTest_With404Url) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); try { @@ -165,13 +165,13 @@ TEST_F(DownloadTests, SimpleDownloadTest_WithMalformedPath) #elif defined(DO_INTERFACE_REST) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(ENOENT)); #endif - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } } TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); try { @@ -189,7 +189,7 @@ TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) #elif defined(DO_INTERFACE_REST) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(ENOENT)); #endif - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } catch (const std::exception& se) { @@ -200,7 +200,7 @@ TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -214,7 +214,7 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) #ifdef DO_CLIENT_AGENT // Only DO Agent creates the output file upon calling start() - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)) << "Verify output file created for first download"; + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)) << "Verify output file created for first download"; // DO Agent does not support downloading to an already existing path (yet?). // Verify second download fails and the first download resumes successfully. @@ -229,23 +229,23 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(EEXIST)); } simpleDownload2->abort(); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); // not deleted, the earlier download is still active + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); // not deleted, the earlier download is still active simpleDownload->abort(); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); // download2 should now succeed simpleDownload2 = msdot::download::make(g_smallFileUrl, g_tmpFileName); simpleDownload2->start(); WaitForDownloadCompletion(*simpleDownload2); - ASSERT_EQ(boost::filesystem::file_size(g_tmpFileName), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(g_tmpFileName), g_smallFileSizeBytes); #elif defined(DO_CLIENT_DOSVC) // DoSvc does support downloading to an already existing path via // aborting the first download. Verify this and that the second download succeeds. msdo::test::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::aborted); @@ -257,7 +257,7 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) TEST_F(DownloadTests, Download1PausedDownload2SameFileDownload1Resume) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -271,19 +271,19 @@ TEST_F(DownloadTests, Download1PausedDownload2SameFileDownload1Resume) std::cout << "Downloading the same file with a second download" << std::endl; msdot::download::download_url_to_path(g_largeFileUrl, g_tmpFileName2); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName2)), g_largeFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_largeFileSizeBytes); std::cout << "Resuming and waiting for completion of first download" << std::endl; simpleDownload->resume(); TestHelpers::WaitForState(*simpleDownload, msdo::download_state::transferred, g_largeFileWaitTime); simpleDownload->finalize(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); } TEST_F(DownloadTests, Download1NeverStartedDownload2CancelledSameFileTest) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -298,7 +298,7 @@ TEST_F(DownloadTests, Download1NeverStartedDownload2CancelledSameFileTest) { ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); } - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadTests, ResumeOnAlreadyDownloadedFileTest) @@ -316,7 +316,7 @@ TEST_F(DownloadTests, ResumeOnAlreadyDownloadedFileTest) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); try { @@ -348,7 +348,7 @@ TEST_F(DownloadTests, CancelDownloadOnCompletedState) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); try { @@ -380,7 +380,7 @@ TEST_F(DownloadTests, CancelDownloadInTransferredState) #if defined(DO_INTERFACE_REST) // On Windows need to finalize in order for file to show up on disk, so exclude check here - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); #endif try { @@ -422,7 +422,7 @@ static void _PauseResumeTest(bool delayAfterStart = false) ASSERT_EQ(status.state(), msdo::download_state::transferred); ASSERT_EQ(status.bytes_total(), status.bytes_transferred()); simpleDownload->finalize(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); } TEST_F(DownloadTests, PauseResumeTest) @@ -437,25 +437,25 @@ TEST_F(DownloadTests, PauseResumeTestWithDelayAfterStart) TEST_F(DownloadTests, MultipleConsecutiveDownloadTest) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName2)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName2); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName2)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName2)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName3)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName3)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName3); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName3)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName3)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, MultipleConcurrentDownloadTest) { - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); std::thread downloadThread([&]() { try @@ -495,9 +495,9 @@ TEST_F(DownloadTests, MultipleConcurrentDownloadTest) downloadThread2.join(); downloadThread3.join(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, MultipleConcurrentDownloadTest_WithCancels) @@ -546,9 +546,9 @@ TEST_F(DownloadTests, MultipleConcurrentDownloadTest_WithCancels) downloadThread2.join(); downloadThread3.join(); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName2)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, FileDeletionAfterPause) @@ -566,8 +566,8 @@ TEST_F(DownloadTests, FileDeletionAfterPause) auto status = largeDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::paused) << "Download is paused"; - boost::filesystem::remove(g_tmpFileName2); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName2)) << "Output file deleted"; + std::filesystem::remove(g_tmpFileName2); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)) << "Output file deleted"; #if defined(DO_CLIENT_AGENT) try @@ -600,7 +600,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunning) }); TestHelpers::DeleteRestPortFiles(); // can be removed if docs deletes file on shutdown - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); try { msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); @@ -610,7 +610,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunning) { ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent) @@ -623,7 +623,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent TestHelpers::DeleteRestPortFiles(); TestHelpers::CreateRestPortFiles(1); - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); try { msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); @@ -633,7 +633,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent { ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadTests, MultipleRestPortFileExists_Download) @@ -649,10 +649,10 @@ TEST_F(DownloadTests, MultipleRestPortFileExists_Download) std::this_thread::sleep_for(std::chrono::seconds(2)); ASSERT_EQ(TestHelpers::CountRestPortFiles(), 1u) << "All other restport files must be deleted by the agent"; - ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); } #endif // DO_INTERFACE_REST diff --git a/sdk-cpp/tests/rest/config_tests.cpp b/sdk-cpp/tests/rest/config_tests.cpp index 181e7431..3771350e 100644 --- a/sdk-cpp/tests/rest/config_tests.cpp +++ b/sdk-cpp/tests/rest/config_tests.cpp @@ -4,7 +4,7 @@ #include "tests_common.h" #include -#include +#include #include #include #include "do_config.h" @@ -12,7 +12,6 @@ #include "test_data.h" #include "test_helpers.h" -namespace cppfs = std::experimental::filesystem; namespace msdo = microsoft::deliveryoptimization; namespace msdod = microsoft::deliveryoptimization::details; @@ -22,9 +21,9 @@ class ConfigTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - if (cppfs::exists(msdod::GetConfigFilePath())) + if (std::filesystem::exists(msdod::GetConfigFilePath())) { - cppfs::remove(msdod::GetConfigFilePath()); + std::filesystem::remove(msdod::GetConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/mcc_download_tests.cpp b/sdk-cpp/tests/rest/mcc_download_tests.cpp index ccd03ae9..3493c4a1 100644 --- a/sdk-cpp/tests/rest/mcc_download_tests.cpp +++ b/sdk-cpp/tests/rest/mcc_download_tests.cpp @@ -3,9 +3,9 @@ #include "tests_common.h" +#include #include #include -#include #include "do_config.h" #include "do_download.h" #include "do_download_status.h" @@ -14,7 +14,6 @@ #include "test_data.h" #include "test_helpers.h" -namespace cppfs = std::experimental::filesystem; namespace msdo = microsoft::deliveryoptimization; namespace msdod = microsoft::deliveryoptimization::details; namespace msdot = microsoft::deliveryoptimization::test; @@ -25,9 +24,9 @@ class MCCDownloadTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - if (cppfs::exists(msdod::GetConfigFilePath())) + if (std::filesystem::exists(msdod::GetConfigFilePath())) { - cppfs::remove(msdod::GetConfigFilePath()); + std::filesystem::remove(msdod::GetConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/network_connectivity_tests.cpp b/sdk-cpp/tests/rest/network_connectivity_tests.cpp index 093ce228..ce5231ab 100644 --- a/sdk-cpp/tests/rest/network_connectivity_tests.cpp +++ b/sdk-cpp/tests/rest/network_connectivity_tests.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include "do_download.h" #include "do_download_status.h" @@ -65,7 +65,7 @@ TEST_F(NetworkConnectivityTests, DISABLED_SimpleBlockingDownloadNetworkReconnect try { msdo::download::download_url_to_path(g_largeFileUrl, g_tmpFileName); - ASSERT_EQ(boost::filesystem::file_size(boost::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); } catch (const msdod::exception& e) { diff --git a/sdk-cpp/tests/rest/port_discovery_tests.cpp b/sdk-cpp/tests/rest/port_discovery_tests.cpp index 6bd2214d..014bbad0 100644 --- a/sdk-cpp/tests/rest/port_discovery_tests.cpp +++ b/sdk-cpp/tests/rest/port_discovery_tests.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include "do_persistence.h" #include "do_port_finder.h" @@ -34,9 +34,9 @@ void PortDiscoveryTests::SetUp() { TestHelpers::StopService(g_docsSvcName); // ensure agent does not write to port file TestHelpers::DeleteRestPortFiles(); - if (!boost::filesystem::exists(msdod::GetRuntimeDirectory())) + if (!std::filesystem::exists(msdod::GetRuntimeDirectory())) { - boost::filesystem::create_directories(msdod::GetRuntimeDirectory()); + std::filesystem::create_directories(msdod::GetRuntimeDirectory()); } std::ofstream file(_testFilePath); @@ -45,9 +45,9 @@ void PortDiscoveryTests::SetUp() void PortDiscoveryTests::TearDown() { - if (boost::filesystem::exists(_testFilePath)) + if (std::filesystem::exists(_testFilePath)) { - boost::filesystem::remove(_testFilePath); + std::filesystem::remove(_testFilePath); } TestHelpers::StartService(g_docsSvcName); } diff --git a/sdk-cpp/tests/rest/rest_interface_tests.cpp b/sdk-cpp/tests/rest/rest_interface_tests.cpp index 3570de6b..b2c52ff4 100644 --- a/sdk-cpp/tests/rest/rest_interface_tests.cpp +++ b/sdk-cpp/tests/rest/rest_interface_tests.cpp @@ -3,9 +3,8 @@ #include "tests_common.h" +#include #include -#include -namespace cppfs = std::experimental::filesystem; #include using btcp_t = boost::asio::ip::tcp; @@ -23,9 +22,9 @@ class RestInterfaceTests : public ::testing::Test public: void SetUp() override { - if (cppfs::exists(msdod::GetAdminConfigFilePath())) + if (std::filesystem::exists(msdod::GetAdminConfigFilePath())) { - cppfs::remove(msdod::GetAdminConfigFilePath()); + std::filesystem::remove(msdod::GetAdminConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/test_helpers.cpp b/sdk-cpp/tests/rest/test_helpers.cpp index c2c2c235..804d52ef 100644 --- a/sdk-cpp/tests/rest/test_helpers.cpp +++ b/sdk-cpp/tests/rest/test_helpers.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include "do_persistence.h" #include "do_port_finder.h" @@ -64,12 +64,12 @@ void TestHelpers::CreateRestPortFiles(int numFiles) void TestHelpers::DeleteRestPortFiles() { - for (boost::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != boost::filesystem::directory_iterator(); ++itr) + for (std::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != std::filesystem::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) { - boost::filesystem::remove(dirEntry); + std::filesystem::remove(dirEntry); } } } @@ -77,7 +77,7 @@ void TestHelpers::DeleteRestPortFiles() unsigned int TestHelpers::CountRestPortFiles() { unsigned int count = 0; - for (boost::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != boost::filesystem::directory_iterator(); ++itr) + for (std::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != std::filesystem::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) diff --git a/sdk-cpp/tests/test_data.cpp b/sdk-cpp/tests/test_data.cpp index cbc01004..d71916c7 100644 --- a/sdk-cpp/tests/test_data.cpp +++ b/sdk-cpp/tests/test_data.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #include "test_data.h" -#include "boost/filesystem.hpp" +#include using namespace std::chrono_literals; // NOLINT(build/namespaces) @@ -14,14 +14,14 @@ const uint64_t g_prodFileSizeBytes = 25006511u; // For testing production scenario, use the same path DU agent will use static const std::string downloadPath = "/var/lib/deviceupdate-agent-downloads"; #else -static const std::string downloadPath = boost::filesystem::temp_directory_path().string(); +static const std::string downloadPath = std::filesystem::temp_directory_path().string(); #endif const std::string g_largeFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/ReplacementDCATFile.txt"; const std::string g_malformedFilePath = "?f309adfasdf///dfasdfj39fjasldfjasdf/// ///.1"; -const std::string g_tmpFileName = (downloadPath / boost::filesystem::path("docsdk_testfile.txt")).string(); -const std::string g_tmpFileName2 = (downloadPath / boost::filesystem::path("docsdk_testfile2.txt")).string(); -const std::string g_tmpFileName3 = (downloadPath / boost::filesystem::path("docsdk_testfile3.txt")).string(); +const std::string g_tmpFileName = (downloadPath / std::filesystem::path("docsdk_testfile.txt")).string(); +const std::string g_tmpFileName2 = (downloadPath / std::filesystem::path("docsdk_testfile2.txt")).string(); +const std::string g_tmpFileName3 = (downloadPath / std::filesystem::path("docsdk_testfile3.txt")).string(); const std::string g_smallFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/49c591d405d307e25e72a19f7e79b53d69f19954/43A54FC03C6A979E9AAEAE2493757D1429A5C8A8D093FB7B8103E8CC8DF7B6B6"; const std::string g_smallFilePhfInfoJson = R"( { diff --git a/sdk-cpp/tests/test_helpers.h b/sdk-cpp/tests/test_helpers.h index f638a1c8..4a00d485 100644 --- a/sdk-cpp/tests/test_helpers.h +++ b/sdk-cpp/tests/test_helpers.h @@ -4,6 +4,7 @@ #ifndef _DELIVERY_OPTIMIZATION_TEST_HELPERS_H #define _DELIVERY_OPTIMIZATION_TEST_HELPERS_H +#include #include #include @@ -150,34 +151,34 @@ class TestHelpers public: static void CleanTestDir() { - if (boost::filesystem::exists(g_tmpFileName)) + if (std::filesystem::exists(g_tmpFileName)) { - boost::filesystem::remove(g_tmpFileName); + std::filesystem::remove(g_tmpFileName); } - if (boost::filesystem::exists(g_tmpFileName2)) + if (std::filesystem::exists(g_tmpFileName2)) { - boost::filesystem::remove(g_tmpFileName2); + std::filesystem::remove(g_tmpFileName2); } - if (boost::filesystem::exists(g_tmpFileName3)) + if (std::filesystem::exists(g_tmpFileName3)) { - boost::filesystem::remove(g_tmpFileName3); + std::filesystem::remove(g_tmpFileName3); } } // DoSvc creates temporary files with a unique name in the same directory as the output file - static void DeleteDoSvcTemporaryFiles(const boost::filesystem::path& outputFilePath) + static void DeleteDoSvcTemporaryFiles(const std::filesystem::path& outputFilePath) { - const boost::filesystem::path parentDir = outputFilePath.parent_path(); - for (boost::filesystem::directory_iterator itr(parentDir); itr != boost::filesystem::directory_iterator(); ++itr) + const std::filesystem::path parentDir = outputFilePath.parent_path(); + for (std::filesystem::directory_iterator itr(parentDir); itr != std::filesystem::directory_iterator(); ++itr) { - const boost::filesystem::directory_entry& dirEntry = *itr; + const std::filesystem::directory_entry& dirEntry = *itr; // Remove all files with names that match DO*.tmp - if (boost::filesystem::is_regular_file(dirEntry) + if (std::filesystem::is_regular_file(dirEntry) && (dirEntry.path().filename().string().find("DO") == 0) && (dirEntry.path().extension() == ".tmp")) { - boost::system::error_code ec; - boost::filesystem::remove(dirEntry, ec); + std::error_code ec; + std::filesystem::remove(dirEntry, ec); if (ec) { std::cout << "Temp file deletion error: " << ec.message() << ", " << dirEntry.path() << '\n'; diff --git a/sdk-cpp/tests/tests_common.h b/sdk-cpp/tests/tests_common.h index e47dc26d..e05e997b 100644 --- a/sdk-cpp/tests/tests_common.h +++ b/sdk-cpp/tests/tests_common.h @@ -4,7 +4,7 @@ #ifndef _DELIVERY_OPTIMIZATION_TESTS_COMMON_H #define _DELIVERY_OPTIMIZATION_TESTS_COMMON_H -#include +#include #include #include From 918b4ec7986c5634f48f6d23c6e10cad39a74c16 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Tue, 21 Mar 2023 12:01:28 -0700 Subject: [PATCH 02/11] Remove boost filesystem from bootstrap, snapcraft, and cmake config --- build/scripts/bootstrap.sh | 2 +- build/scripts/install-vcpkg-deps.ps1 | 1 - build/scripts/install-vcpkg-deps.sh | 3 --- sdk-cpp/build/cmake/deliveryoptimization_sdk-config.cmake | 7 ------- snapcraft-options/snapcraft-agent.yaml | 1 - snapcraft-options/snapcraft-sdk.yaml | 1 - 6 files changed, 1 insertion(+), 14 deletions(-) diff --git a/build/scripts/bootstrap.sh b/build/scripts/bootstrap.sh index c42441ad..43d35584 100755 --- a/build/scripts/bootstrap.sh +++ b/build/scripts/bootstrap.sh @@ -69,7 +69,7 @@ function installBuildDependencies apt-get install -y make build-essential g++ gdb gdbserver gcc git wget apt-get install -y python3 ninja-build apt-get install -y cmake libmsgsl-dev - apt-get install -y libboost-system-dev libboost-filesystem-dev libboost-program-options-dev + apt-get install -y libboost-program-options-dev apt-get install -y libproxy-dev libssl-dev uuid-dev libcurl4-openssl-dev rm -rf /tmp/gtest diff --git a/build/scripts/install-vcpkg-deps.ps1 b/build/scripts/install-vcpkg-deps.ps1 index 8a56e683..af43b7cc 100644 --- a/build/scripts/install-vcpkg-deps.ps1 +++ b/build/scripts/install-vcpkg-deps.ps1 @@ -13,5 +13,4 @@ git checkout 2021.05.12 .\vcpkg integrate install .\vcpkg update .\vcpkg install gtest:x64-windows -.\vcpkg install boost-filesystem:x64-windows .\vcpkg install boost-program-options:x64-windows diff --git a/build/scripts/install-vcpkg-deps.sh b/build/scripts/install-vcpkg-deps.sh index af4213fe..2a6a71f7 100644 --- a/build/scripts/install-vcpkg-deps.sh +++ b/build/scripts/install-vcpkg-deps.sh @@ -17,9 +17,6 @@ git checkout 2021.05.12 ./vcpkg integrate install ./vcpkg install ms-gsl -./vcpkg install boost-log -./vcpkg install boost-beast -./vcpkg install boost-iostreams ./vcpkg install boost-uuid ./vcpkg install boost-program-options ./vcpkg install gtest diff --git a/sdk-cpp/build/cmake/deliveryoptimization_sdk-config.cmake b/sdk-cpp/build/cmake/deliveryoptimization_sdk-config.cmake index 63e550b8..45122fe8 100644 --- a/sdk-cpp/build/cmake/deliveryoptimization_sdk-config.cmake +++ b/sdk-cpp/build/cmake/deliveryoptimization_sdk-config.cmake @@ -1,11 +1,4 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -include(CMakeFindDependencyMacro) -if (${CMAKE_VERSION} VERSION_GREATER "3.9.0") - find_dependency(Boost COMPONENTS filesystem system) -else () - # Old cmake versions do not support extra args to find_dependency - find_dependency(Boost) -endif () include("${CMAKE_CURRENT_LIST_DIR}/deliveryoptimization_sdk-targets.cmake") diff --git a/snapcraft-options/snapcraft-agent.yaml b/snapcraft-options/snapcraft-agent.yaml index f8826526..0ab5000c 100644 --- a/snapcraft-options/snapcraft-agent.yaml +++ b/snapcraft-options/snapcraft-agent.yaml @@ -44,7 +44,6 @@ parts: stage-packages: - libasn1-8-heimdal - - libboost-filesystem1.71.0 - libbrotli1 - libcurl4 - libgssapi3-heimdal diff --git a/snapcraft-options/snapcraft-sdk.yaml b/snapcraft-options/snapcraft-sdk.yaml index 5ab07bee..ca375e5d 100644 --- a/snapcraft-options/snapcraft-sdk.yaml +++ b/snapcraft-options/snapcraft-sdk.yaml @@ -46,7 +46,6 @@ parts: stage-packages: - libboost-program-options1.71.0 - - libboost-filesystem1.71.0 apps: sdk-tests: From eb3008424a1405306e272e6e540559bd9fbf0a6d Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 11:23:40 -0700 Subject: [PATCH 03/11] Choose between fs and exp fs in agent --- client-lite/src/include/do_filesystem.h | 27 +++++++++++++++++++++ client-lite/src/ipc/rest_port_advertiser.h | 6 ++--- client-lite/src/util/do_json_parser.cpp | 6 ++--- client-lite/src/util/proc_launch_helper.h | 9 +++---- client-lite/test/do_log_tests.cpp | 4 +-- client-lite/test/docs_tests.cpp | 4 +-- client-lite/test/download_manager_tests.cpp | 2 +- client-lite/test/json_parser_tests.cpp | 12 ++++----- client-lite/test/mcc_manager.tests.cpp | 24 +++++++++--------- client-lite/test/test_common.h | 10 ++++---- client-lite/test/test_verifiers.h | 4 +-- 11 files changed, 67 insertions(+), 41 deletions(-) create mode 100644 client-lite/src/include/do_filesystem.h diff --git a/client-lite/src/include/do_filesystem.h b/client-lite/src/include/do_filesystem.h new file mode 100644 index 00000000..ec4f1fd0 --- /dev/null +++ b/client-lite/src/include/do_filesystem.h @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#if defined(__cpp_lib_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#elif defined(__cpp_lib_experimental_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#elif !defined(__has_include) +// Cannot check if headers exist, assume experimental +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#else +#error Could not find system header "" or "" +#endif + +#if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif diff --git a/client-lite/src/ipc/rest_port_advertiser.h b/client-lite/src/ipc/rest_port_advertiser.h index 5e860a15..c137f0d3 100644 --- a/client-lite/src/ipc/rest_port_advertiser.h +++ b/client-lite/src/ipc/rest_port_advertiser.h @@ -7,8 +7,8 @@ #include // open, write #include // getpid #include -#include #include +#include "do_filesystem.h" #include "do_persistence.h" #include "error_macros.h" @@ -60,13 +60,13 @@ class RestPortAdvertiser void _DeleteOlderPortFiles() try { auto& runtimeDirectory = docli::GetRuntimeDirectory(); - for (std::filesystem::directory_iterator itr(runtimeDirectory); itr != std::filesystem::directory_iterator(); ++itr) + for (fs::directory_iterator itr(runtimeDirectory); itr != fs::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find(_restPortFileNamePrefix) != std::string::npos) { std::error_code ec; - std::filesystem::remove(dirEntry, ec); + fs::remove(dirEntry, ec); if (ec) { DoLogWarning("Failed to delete old port file (%d, %s) %s", ec.value(), ec.message().data(), dirEntry.string().data()); diff --git a/client-lite/src/util/do_json_parser.cpp b/client-lite/src/util/do_json_parser.cpp index e9f1676c..11d1d962 100644 --- a/client-lite/src/util/do_json_parser.cpp +++ b/client-lite/src/util/do_json_parser.cpp @@ -4,7 +4,7 @@ #include "do_common.h" #include "do_json_parser.h" -#include +#include "do_filesystem.h" #include std::chrono::seconds JsonParser::RefreshInterval = std::chrono::seconds(60); @@ -13,7 +13,7 @@ std::chrono::seconds JsonParser::RefreshInterval = std::chrono::seconds(60); JsonParser::JsonParser(const std::string& jsonFilePath, bool alwaysCreateFile) : _jsonFilePath(jsonFilePath) { - if (alwaysCreateFile && !(std::filesystem::exists(_jsonFilePath))) + if (alwaysCreateFile && !(fs::exists(_jsonFilePath))) { DoLogInfo("json file not found at %s, creating file", _jsonFilePath.data()); boost::property_tree::ptree json; @@ -33,7 +33,7 @@ void JsonParser::_TryRefresh(bool force) return; } - if (std::filesystem::exists(_jsonFilePath)) + if (fs::exists(_jsonFilePath)) { try { diff --git a/client-lite/src/util/proc_launch_helper.h b/client-lite/src/util/proc_launch_helper.h index 66a7e613..312324de 100644 --- a/client-lite/src/util/proc_launch_helper.h +++ b/client-lite/src/util/proc_launch_helper.h @@ -9,9 +9,8 @@ #include #include -#include - #include "do_common.h" +#include "do_filesystem.h" #include "do_persistence.h" inline gid_t GetGroupIdByName(const char *name) @@ -54,11 +53,11 @@ inline void SetDOPathPermissions(const std::string& path, mode_t mode) inline void InitializePath(const std::string& path, mode_t mode = 0) try { - std::filesystem::path dirPath(path); - if (!std::filesystem::exists(dirPath)) + fs::path dirPath(path); + if (!fs::exists(dirPath)) { DoLogInfo("Creating directories for %s", path.c_str()); - std::filesystem::create_directories(dirPath); + fs::create_directories(dirPath); if (mode != 0) { diff --git a/client-lite/test/do_log_tests.cpp b/client-lite/test/do_log_tests.cpp index 66479191..d5ab0606 100644 --- a/client-lite/test/do_log_tests.cpp +++ b/client-lite/test/do_log_tests.cpp @@ -26,12 +26,12 @@ TEST_F(DOLoggerTests, BasicWriteToFile) DOLog::Close(); UINT nLogFilesFound = 0; - for (std::filesystem::recursive_directory_iterator itr(g_testTempDir); itr != std::filesystem::recursive_directory_iterator{}; ++itr) + for (fs::recursive_directory_iterator itr(g_testTempDir); itr != fs::recursive_directory_iterator{}; ++itr) { ++nLogFilesFound; const auto filePath = itr->path(); ASSERT_NE(strstr(filePath.c_str(), "do-agent."), nullptr); - ASSERT_GT(std::filesystem::file_size(filePath), 0); + ASSERT_GT(fs::file_size(filePath), 0); std::ifstream fs; fs.open(filePath.string()); diff --git a/client-lite/test/docs_tests.cpp b/client-lite/test/docs_tests.cpp index 4ae7c830..c531ec56 100644 --- a/client-lite/test/docs_tests.cpp +++ b/client-lite/test/docs_tests.cpp @@ -6,7 +6,7 @@ #include #include "test_data.h" -const std::filesystem::path g_testTempDir = "/tmp/docs_test_scratch"; +const fs::path g_testTempDir = "/tmp/docs_test_scratch"; int main(int argc, char** argv) { @@ -15,7 +15,7 @@ int main(int argc, char** argv) // TODO(shishirb) enable console only logging std::error_code ec; - std::filesystem::create_directories(g_testTempDir, ec); + fs::create_directories(g_testTempDir, ec); if (ec) { printf("Failed to create test dir: %s\n", g_testTempDir.string().data()); diff --git a/client-lite/test/download_manager_tests.cpp b/client-lite/test/download_manager_tests.cpp index 29ec9aa6..90e6d0a5 100644 --- a/client-lite/test/download_manager_tests.cpp +++ b/client-lite/test/download_manager_tests.cpp @@ -136,7 +136,7 @@ TEST_F(DownloadManagerTests, FileDownloadFatal404) ASSERT_EQ(status.BytesTotal, 0); VerifyError(status, HTTP_E_STATUS_NOT_FOUND); VerifyDownloadHttpStatus(*DownloadForId(manager, id), 404); - ASSERT_TRUE(std::filesystem::exists(destFile)); + ASSERT_TRUE(fs::exists(destFile)); manager.AbortDownload(id); VerifyFileNotFound(destFile); } diff --git a/client-lite/test/json_parser_tests.cpp b/client-lite/test/json_parser_tests.cpp index cb8b6954..946d55a9 100644 --- a/client-lite/test/json_parser_tests.cpp +++ b/client-lite/test/json_parser_tests.cpp @@ -12,7 +12,7 @@ #include #include -const std::filesystem::path g_jsonTestFilePath = g_testTempDir / "docs_config.json"; +const fs::path g_jsonTestFilePath = g_testTempDir / "docs_config.json"; const std::map g_testData = { @@ -70,9 +70,9 @@ class JsonParserTests : public ::testing::Test void SetUp() override { JsonParser::RefreshInterval = std::chrono::seconds(10); // for faster test times - if (std::filesystem::exists(g_jsonTestFilePath)) + if (fs::exists(g_jsonTestFilePath)) { - std::filesystem::remove(g_jsonTestFilePath); + fs::remove(g_jsonTestFilePath); } } }; @@ -111,7 +111,7 @@ TEST_F(JsonParserTests, ReadConfigsWithUpdates) VerifyItemFound(reader, "newkey", "newvalue"); // Delete config file and verify - std::filesystem::remove(g_jsonTestFilePath); + fs::remove(g_jsonTestFilePath); VerifyItemFound(reader, "newkey", "newvalue"); // within refresh interval VerifyTestData(reader, true); @@ -122,9 +122,9 @@ TEST_F(JsonParserTests, ReadConfigsWithUpdates) TEST_F(JsonParserTests, ReadConfigsWithFileCreatedLater) { - if (std::filesystem::exists(g_jsonTestFilePath)) + if (fs::exists(g_jsonTestFilePath)) { - std::filesystem::remove(g_jsonTestFilePath); + fs::remove(g_jsonTestFilePath); } JsonParser reader(g_jsonTestFilePath); diff --git a/client-lite/test/mcc_manager.tests.cpp b/client-lite/test/mcc_manager.tests.cpp index 89f8f1bd..c9523a2e 100644 --- a/client-lite/test/mcc_manager.tests.cpp +++ b/client-lite/test/mcc_manager.tests.cpp @@ -28,13 +28,13 @@ using btcp_t = boost::asio::ip::tcp; #define TEST_MOCK_MCC_HOST "10.130.48.179" #define TEST_MOCK_MCC_HOST2 "10.130.48.180" -const std::filesystem::path g_adminConfigFilePath = g_testTempDir / "admin-config.json"; -const std::filesystem::path g_sdkConfigFilePath = g_testTempDir / "sdk-config.json"; +const fs::path g_adminConfigFilePath = g_testTempDir / "admin-config.json"; +const fs::path g_sdkConfigFilePath = g_testTempDir / "sdk-config.json"; static void SetIoTConnectionString(const char* connectionString) { boost::property_tree::ptree json; - if (std::filesystem::exists(g_sdkConfigFilePath)) + if (fs::exists(g_sdkConfigFilePath)) { boost::property_tree::read_json(g_sdkConfigFilePath, json); } @@ -45,7 +45,7 @@ static void SetIoTConnectionString(const char* connectionString) static void SetDOCacheHostConfig(const char* server) { boost::property_tree::ptree json; - if (std::filesystem::exists(g_adminConfigFilePath)) + if (fs::exists(g_adminConfigFilePath)) { boost::property_tree::read_json(g_adminConfigFilePath, json); } @@ -56,7 +56,7 @@ static void SetDOCacheHostConfig(const char* server) static void SetFallbackDelayConfig(std::chrono::seconds delay) { boost::property_tree::ptree json; - if (std::filesystem::exists(g_adminConfigFilePath)) + if (fs::exists(g_adminConfigFilePath)) { boost::property_tree::read_json(g_adminConfigFilePath, json); } @@ -71,13 +71,13 @@ class MCCManagerTests : public ::testing::Test { ClearTestTempDir(); - if (std::filesystem::exists(g_adminConfigFilePath)) + if (fs::exists(g_adminConfigFilePath)) { - std::filesystem::remove(g_adminConfigFilePath); + fs::remove(g_adminConfigFilePath); } - if (std::filesystem::exists(g_sdkConfigFilePath)) + if (fs::exists(g_sdkConfigFilePath)) { - std::filesystem::remove(g_sdkConfigFilePath); + fs::remove(g_sdkConfigFilePath); } } @@ -107,7 +107,7 @@ TEST_F(MCCManagerTests, ParseIoTConnectionString) _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); // No gateway specified - std::filesystem::remove(g_sdkConfigFilePath); + fs::remove(g_sdkConfigFilePath); _VerifyExpectedCacheHost(""); } @@ -117,7 +117,7 @@ TEST_F(MCCManagerTests, AdminConfigOverride) SetDOCacheHostConfig(TEST_MOCK_MCC_HOST2); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST2); - std::filesystem::remove(g_adminConfigFilePath); + fs::remove(g_adminConfigFilePath); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); } @@ -127,7 +127,7 @@ TEST_F(MCCManagerTests, AdminConfigEmptyString) SetDOCacheHostConfig(""); _VerifyExpectedCacheHost(""); - std::filesystem::remove(g_adminConfigFilePath); + fs::remove(g_adminConfigFilePath); _VerifyExpectedCacheHost(TEST_MOCK_MCC_HOST); } diff --git a/client-lite/test/test_common.h b/client-lite/test/test_common.h index f50719f9..96dd9c51 100644 --- a/client-lite/test/test_common.h +++ b/client-lite/test/test_common.h @@ -4,19 +4,19 @@ #pragma once #include "do_common.h" +#include "do_filesystem.h" #include -#include #include #include -extern const std::filesystem::path g_testTempDir; +extern const fs::path g_testTempDir; inline void ClearTestTempDir() { - if (std::filesystem::exists(g_testTempDir)) + if (fs::exists(g_testTempDir)) { - std::filesystem::remove_all(g_testTempDir); + fs::remove_all(g_testTempDir); } - std::filesystem::create_directories(g_testTempDir); + fs::create_directories(g_testTempDir); } diff --git a/client-lite/test/test_verifiers.h b/client-lite/test/test_verifiers.h index 71ff3f28..e05d550e 100644 --- a/client-lite/test/test_verifiers.h +++ b/client-lite/test/test_verifiers.h @@ -10,12 +10,12 @@ inline void VerifyFileSize(const std::string& path, UINT64 cbExpectedSize) { - ASSERT_EQ(std::filesystem::file_size(path), cbExpectedSize) << "File size check: " << path; + ASSERT_EQ(fs::file_size(path), cbExpectedSize) << "File size check: " << path; } inline void VerifyFileNotFound(const std::string& path) { - ASSERT_FALSE(std::filesystem::exists(path)) << "File absent check: " << path; + ASSERT_FALSE(fs::exists(path)) << "File absent check: " << path; } inline void VerifyNoError(const DownloadStatus& status) From f95a8030e5d948d6cde1020d8df376ee78a8e987 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 15:04:35 -0700 Subject: [PATCH 04/11] Fix boost system undefined ref --- client-lite/CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client-lite/CMakeLists.txt b/client-lite/CMakeLists.txt index b71f4823..13a8a2d2 100644 --- a/client-lite/CMakeLists.txt +++ b/client-lite/CMakeLists.txt @@ -27,6 +27,7 @@ function (target_link_dl_lib target) endfunction () # Include external libraries here: +find_package(Boost REQUIRED) find_package(CURL REQUIRED) # g++ requires explicit specification of the thread library to be used find_package(Threads REQUIRED) @@ -87,12 +88,18 @@ endif () add_do_version_lib(${PROJECT_NAME} ${PROJECT_VERSION}) -# Build product files into a lib for use by other targets +# Build product files into a lib for use by other targets. +# BOOST_ERROR_CODE_HEADER_ONLY and BOOST_SYSTEM_NO_DEPRECATED are required to use header-only components +# like boost.asio without linking to the boost.system shared library. add_library(docs_common STATIC ${files_docs_common}) target_compile_definitions(docs_common - PRIVATE DO_CONFIG_DIRECTORY_PATH="${docs_svc_config_dir_path}" - DO_AGENT_LOG_DIRECTORY_PATH="${docs_svc_log_dir_path}" - DO_RUN_DIRECTORY_PATH="${docs_svc_run_dir_path}" + PUBLIC + BOOST_ERROR_CODE_HEADER_ONLY + BOOST_SYSTEM_NO_DEPRECATED + PRIVATE + DO_CONFIG_DIRECTORY_PATH="${docs_svc_config_dir_path}" + DO_AGENT_LOG_DIRECTORY_PATH="${docs_svc_log_dir_path}" + DO_RUN_DIRECTORY_PATH="${docs_svc_run_dir_path}" ) if (DO_DEV_DEBUG) target_compile_definitions(docs_common PUBLIC DO_DEV_DEBUG) From ed5892ad102b0001806d9fe1c86b85180cf45d96 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 15:53:17 -0700 Subject: [PATCH 05/11] Fix fs linking for agent --- CMakeLists.txt | 4 +- client-lite/CMakeLists.txt | 3 ++ client-lite/test/CMakeLists.txt | 1 + common/cmake/do-filesystem.cmake | 66 ++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 common/cmake/do-filesystem.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c951a2..f80b36b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,9 @@ else() message(FATAL_ERROR "Unknown platform for client") endif() +# C++17 is required to use std::filesystem but Edge builds on Windows is not ready to move up yet. +# Luckily, we do not need std::filesystem on Windows. if (DO_INCLUDE_SDK AND DO_PLATFORM_WINDOWS) - # Edge build is not ready to move up to C++17 yet. set(CMAKE_CXX_STANDARD 14) else () set(CMAKE_CXX_STANDARD 17) @@ -119,6 +120,7 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/common/cmake) include (do-build-helpers) +include (do-filesystem) include (do-packaging-helpers) # For contributors, please modify builder name here if changes are made to project source diff --git a/client-lite/CMakeLists.txt b/client-lite/CMakeLists.txt index 13a8a2d2..f16b12d8 100644 --- a/client-lite/CMakeLists.txt +++ b/client-lite/CMakeLists.txt @@ -44,6 +44,8 @@ if (GSL_INCLUDE_DIR STREQUAL "GSL_INCLUDE_DIR-NOTFOUND") message(FATAL_ERROR "Could not find MS Guidelines Support Library.") endif() +try_set_filesystem_lib() + set (docs_common_includes ${include_directories_for_arm} ${GSL_INCLUDE_DIR} @@ -129,6 +131,7 @@ target_include_directories(${DOSVC_BIN_NAME} PRIVATE ${docs_common_includes}) target_link_libraries(${DOSVC_BIN_NAME} docs_common ${CMAKE_THREAD_LIBS_INIT} + ${CXX_FILESYSTEM_LIBS} ) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/client-lite/test/CMakeLists.txt b/client-lite/test/CMakeLists.txt index d0e3ff03..404bb2eb 100644 --- a/client-lite/test/CMakeLists.txt +++ b/client-lite/test/CMakeLists.txt @@ -13,4 +13,5 @@ target_link_libraries(deliveryoptimization-agent-tests dotestutil ${Boost_LIBRARIES} GTest::GTest + ${CXX_FILESYSTEM_LIBS} ) diff --git a/common/cmake/do-filesystem.cmake b/common/cmake/do-filesystem.cmake new file mode 100644 index 00000000..2a7cd087 --- /dev/null +++ b/common/cmake/do-filesystem.cmake @@ -0,0 +1,66 @@ + +# The C++17 std::filesystem support is implemented in std::experimental::filesystem prior to GCC 9. +# However, and this is so messed up, only the experimental version requires linking to stdc++fs library. +# There is no built-in support in cmake to handle this difference. +# So this function attempts to determine which version is available using the check_cxx_source_compiles() feature. +# See also: Portable linking for C++17 std::filesystem (https://gitlab.kitware.com/cmake/cmake/-/issues/17834) +function (try_set_filesystem_lib) + + if (DO_PLATFORM_WINDOWS) + # std::filesystem not required for Windows builds + return () + endif () + + if (CXX_FILESYSTEM_LIBS) + # Already set, no need to redo + return () + endif () + + set(FS_TESTCODE + " + #if defined(CXX17_FILESYSTEM) || defined (CXX17_FILESYSTEM_LIBFS) + #include + #elif defined(CXX11_EXP_FILESYSTEM) || defined (CXX11_EXP_FILESYSTEM_LIBFS) + #include + namespace std { + namespace filesystem { + using experimental::filesystem::is_regular_file; + } + } + #endif + int main(void) + { + return std::filesystem::is_regular_file(\"/\") ? 0 : 1; + } + " + ) + + include (CMakePushCheckState) + include (CheckCXXSourceCompiles) + + # Note that check_cxx_source_compiles automatically adds the result variable itself as a preprocessor symbol. + + cmake_push_check_state(RESET) + check_cxx_source_compiles("${FS_TESTCODE}" CXX17_FILESYSTEM) + if (NOT CXX17_FILESYSTEM) + set(CMAKE_REQUIRED_LIBRARIES stdc++fs) + check_cxx_source_compiles("${FS_TESTCODE}" CXX17_FILESYSTEM_LIBFS) + cmake_reset_check_state() + endif () + + if (NOT CXX17_FILESYSTEM AND NOT CXX17_FILESYSTEM_LIBFS) + check_cxx_source_compiles("${FS_TESTCODE}" CXX11_EXP_FILESYSTEM) + if (NOT CXX11_EXP_FILESYSTEM) + set(CMAKE_REQUIRED_LIBRARIES stdc++fs) + check_cxx_source_compiles("${FS_TESTCODE}" CXX11_EXP_FILESYSTEM_LIBFS) + endif () + endif () + cmake_pop_check_state() + + if (CXX17_FILESYSTEM_LIBFS OR CXX11_EXP_FILESYSTEM_LIBFS) + set(CXX_FILESYSTEM_LIBS stdc++fs PARENT_SCOPE) + endif () + + unset(FS_TESTCODE) + +endfunction () From 51f562a5c7591802d38632a1d127dd468a503a53 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 16:19:37 -0700 Subject: [PATCH 06/11] Fix fs linking for sdk --- sdk-cpp/CMakeLists.txt | 2 + sdk-cpp/src/internal/do_filesystem.h | 27 +++++ .../src/internal/rest/do_config_internal.cpp | 13 +-- .../src/internal/rest/util/do_port_finder.cpp | 14 +-- sdk-cpp/tests/CMakeLists.txt | 1 + sdk-cpp/tests/download_properties_tests.cpp | 8 +- sdk-cpp/tests/download_tests_common.cpp | 104 +++++++++--------- sdk-cpp/tests/rest/config_tests.cpp | 5 +- sdk-cpp/tests/rest/mcc_download_tests.cpp | 5 +- .../tests/rest/network_connectivity_tests.cpp | 4 +- sdk-cpp/tests/rest/port_discovery_tests.cpp | 10 +- sdk-cpp/tests/rest/rest_interface_tests.cpp | 5 +- sdk-cpp/tests/rest/test_helpers.cpp | 8 +- sdk-cpp/tests/test_data.cpp | 10 +- sdk-cpp/tests/test_helpers.h | 25 ++--- sdk-cpp/tests/tests_common.h | 2 +- 16 files changed, 130 insertions(+), 113 deletions(-) create mode 100644 sdk-cpp/src/internal/do_filesystem.h diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index f187165b..2c5493c6 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -13,6 +13,7 @@ endif() set(DO_SDK_LIB_NAME "deliveryoptimization") add_do_version_lib("${DO_SDK_LIB_NAME}-lib" ${PROJECT_VERSION}) +try_set_filesystem_lib() ### Region CMake Build ### @@ -121,6 +122,7 @@ add_platform_interface_definitions(${DO_SDK_LIB_NAME}) target_link_libraries(${DO_SDK_LIB_NAME} PRIVATE ${sdk_private_linked_libs} + ${CXX_FILESYSTEM_LIBS} ) ### Endregion CMake Build ### diff --git a/sdk-cpp/src/internal/do_filesystem.h b/sdk-cpp/src/internal/do_filesystem.h new file mode 100644 index 00000000..ec4f1fd0 --- /dev/null +++ b/sdk-cpp/src/internal/do_filesystem.h @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#if defined(__cpp_lib_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#elif defined(__cpp_lib_experimental_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#elif !defined(__has_include) +// Cannot check if headers exist, assume experimental +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#else +#error Could not find system header "" or "" +#endif + +#if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif diff --git a/sdk-cpp/src/internal/rest/do_config_internal.cpp b/sdk-cpp/src/internal/rest/do_config_internal.cpp index 950b679d..3018e676 100644 --- a/sdk-cpp/src/internal/rest/do_config_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_config_internal.cpp @@ -8,10 +8,9 @@ #include #include -#include - #include #include +#include "do_filesystem.h" #include "do_persistence.h" #include "do_version.h" #elif defined(DO_CLIENT_DOSVC) @@ -31,9 +30,9 @@ static int WriteIoTConnectionStringToConfigFile(const char* value) noexcept int returnValue = 0; // ptree's exceptions do not provide an error code, and SDK has no logging of its own. // Return specific errors as a workaround. - std::filesystem::path filePath{microsoft::deliveryoptimization::details::GetConfigFilePath()}; + fs::path filePath{microsoft::deliveryoptimization::details::GetConfigFilePath()}; std::error_code ec; - if (std::filesystem::exists(filePath.parent_path(), ec)) + if (fs::exists(filePath.parent_path(), ec)) { try { @@ -74,10 +73,10 @@ static std::string GetSdkVersion() return msdoutil::ComponentVersion(false); } -static std::string GetBinaryVersion(const std::filesystem::path& binaryFilePath) +static std::string GetBinaryVersion(const fs::path& binaryFilePath) { std::string version; - if (std::filesystem::exists(binaryFilePath)) + if (fs::exists(binaryFilePath)) { FILE* fp = nullptr; try @@ -118,7 +117,7 @@ static void AppendBinaryVersion(const char* binFileName, std::stringstream& allV // to cover special cases (for example, installed not via our deb/rpm packages). // We do not use bp::search_path() in order to avoid executing a malicious program with the // same name and which appears earlier in the PATH environment variable. - std::filesystem::path binFilePath("/usr/local/bin"); + fs::path binFilePath("/usr/local/bin"); binFilePath /= binFileName; std::string version = GetBinaryVersion(binFilePath); if (version.empty()) diff --git a/sdk-cpp/src/internal/rest/util/do_port_finder.cpp b/sdk-cpp/src/internal/rest/util/do_port_finder.cpp index ab8ef442..3ba369a6 100644 --- a/sdk-cpp/src/internal/rest/util/do_port_finder.cpp +++ b/sdk-cpp/src/internal/rest/util/do_port_finder.cpp @@ -2,13 +2,13 @@ #include #include -#include #include #include #include #include "do_errors.h" #include "do_error_helpers.h" +#include "do_filesystem.h" #include "do_persistence.h" using namespace std::chrono_literals; // NOLINT(build/namespaces) @@ -25,19 +25,19 @@ namespace details static std::string g_DiscoverDOPort() { const std::string runtimeDirectory = GetRuntimeDirectory(); - if (!std::filesystem::exists(runtimeDirectory)) + if (!fs::exists(runtimeDirectory)) { return std::string(); } - std::filesystem::path mostRecentFile(""); - auto mostRecentTime = std::filesystem::file_time_type::min(); - for (std::filesystem::directory_iterator itr(runtimeDirectory); itr != std::filesystem::directory_iterator(); ++itr) + fs::path mostRecentFile(""); + auto mostRecentTime = fs::file_time_type::min(); + for (fs::directory_iterator itr(runtimeDirectory); itr != fs::directory_iterator(); ++itr) { - const std::filesystem::path& dirEntry = itr->path(); + const fs::path& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) { - auto currTime = std::filesystem::last_write_time(dirEntry); + auto currTime = fs::last_write_time(dirEntry); if (currTime > mostRecentTime) { mostRecentTime = currTime; diff --git a/sdk-cpp/tests/CMakeLists.txt b/sdk-cpp/tests/CMakeLists.txt index 44686aee..02ffd31b 100644 --- a/sdk-cpp/tests/CMakeLists.txt +++ b/sdk-cpp/tests/CMakeLists.txt @@ -78,4 +78,5 @@ target_include_directories(deliveryoptimization-sdk-tests target_link_libraries(deliveryoptimization-sdk-tests ${sdk_tests_linked_libs_common} + ${CXX_FILESYSTEM_LIBS} ) \ No newline at end of file diff --git a/sdk-cpp/tests/download_properties_tests.cpp b/sdk-cpp/tests/download_properties_tests.cpp index 4ed74d74..16637949 100644 --- a/sdk-cpp/tests/download_properties_tests.cpp +++ b/sdk-cpp/tests/download_properties_tests.cpp @@ -22,7 +22,7 @@ class DownloadPropertyTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } void TearDown() override { @@ -62,7 +62,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadSetCallerNameTest) ASSERT_EQ(strCallerName, outCallerName); simpleDownload->start_and_wait_until_completion(); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(fs::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) @@ -83,7 +83,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(fs::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, InvalidPhfDigestTest) @@ -102,7 +102,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithCustomHeaders) auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); simpleDownload->set_property(msdo::download_property::http_custom_headers, "XCustom1=someData\nXCustom2=moreData\n"); simpleDownload->start_and_wait_until_completion(); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); + ASSERT_TRUE(fs::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, CallbackTestUseDownload) diff --git a/sdk-cpp/tests/download_tests_common.cpp b/sdk-cpp/tests/download_tests_common.cpp index e8729c7b..3bd02da2 100644 --- a/sdk-cpp/tests/download_tests_common.cpp +++ b/sdk-cpp/tests/download_tests_common.cpp @@ -11,8 +11,6 @@ #include #include -#include - #include "do_download.h" #include "do_download_status.h" #include "do_errors.h" @@ -80,21 +78,21 @@ TEST_F(DownloadTests, SimpleDownloadTest) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); } TEST_F(DownloadTests, SimpleBlockingDownloadTest) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(fs::exists(g_tmpFileName)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); } TEST_F(DownloadTests, CancelBlockingDownloadTest) { std::atomic_bool cancelToken { false }; - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); std::thread downloadThread([&]() { try @@ -110,7 +108,7 @@ TEST_F(DownloadTests, CancelBlockingDownloadTest) std::this_thread::sleep_for(1s); cancelToken = true; downloadThread.join(); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } TEST_F(DownloadTests, BlockingDownloadTimeout) @@ -128,13 +126,13 @@ TEST_F(DownloadTests, BlockingDownloadTimeout) ASSERT_GE(elapsedTime, std::chrono::seconds(2)); ASSERT_LE(elapsedTime, std::chrono::seconds(5)); } - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } // Note: This test takes a long time to execute due to 30 retry intervals from DOCS TEST_F(DownloadTests, SimpleDownloadTest_With404Url) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); try { @@ -165,13 +163,13 @@ TEST_F(DownloadTests, SimpleDownloadTest_WithMalformedPath) #elif defined(DO_INTERFACE_REST) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(ENOENT)); #endif - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } } TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); try { @@ -189,7 +187,7 @@ TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) #elif defined(DO_INTERFACE_REST) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(ENOENT)); #endif - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } catch (const std::exception& se) { @@ -200,7 +198,7 @@ TEST_F(DownloadTests, SimpleDownloadTest_With404UrlAndMalformedPath) TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -214,7 +212,7 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) #ifdef DO_CLIENT_AGENT // Only DO Agent creates the output file upon calling start() - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)) << "Verify output file created for first download"; + ASSERT_TRUE(fs::exists(g_tmpFileName)) << "Verify output file created for first download"; // DO Agent does not support downloading to an already existing path (yet?). // Verify second download fails and the first download resumes successfully. @@ -229,23 +227,23 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) ASSERT_EQ(e.error_code().value(), DO_ERROR_FROM_SYSTEM_ERROR(EEXIST)); } simpleDownload2->abort(); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); // not deleted, the earlier download is still active + ASSERT_TRUE(fs::exists(g_tmpFileName)); // not deleted, the earlier download is still active simpleDownload->abort(); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); // download2 should now succeed simpleDownload2 = msdot::download::make(g_smallFileUrl, g_tmpFileName); simpleDownload2->start(); WaitForDownloadCompletion(*simpleDownload2); - ASSERT_EQ(std::filesystem::file_size(g_tmpFileName), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(g_tmpFileName), g_smallFileSizeBytes); #elif defined(DO_CLIENT_DOSVC) // DoSvc does support downloading to an already existing path via // aborting the first download. Verify this and that the second download succeeds. msdo::test::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::aborted); @@ -257,7 +255,7 @@ TEST_F(DownloadTests, Download1PausedDownload2SameDestTest) TEST_F(DownloadTests, Download1PausedDownload2SameFileDownload1Resume) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -271,19 +269,19 @@ TEST_F(DownloadTests, Download1PausedDownload2SameFileDownload1Resume) std::cout << "Downloading the same file with a second download" << std::endl; msdot::download::download_url_to_path(g_largeFileUrl, g_tmpFileName2); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_largeFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName2)), g_largeFileSizeBytes); std::cout << "Resuming and waiting for completion of first download" << std::endl; simpleDownload->resume(); TestHelpers::WaitForState(*simpleDownload, msdo::download_state::transferred, g_largeFileWaitTime); simpleDownload->finalize(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_largeFileSizeBytes); } TEST_F(DownloadTests, Download1NeverStartedDownload2CancelledSameFileTest) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); msdo::download_status status = simpleDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::created); @@ -298,7 +296,7 @@ TEST_F(DownloadTests, Download1NeverStartedDownload2CancelledSameFileTest) { ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); } - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } TEST_F(DownloadTests, ResumeOnAlreadyDownloadedFileTest) @@ -316,7 +314,7 @@ TEST_F(DownloadTests, ResumeOnAlreadyDownloadedFileTest) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); try { @@ -348,7 +346,7 @@ TEST_F(DownloadTests, CancelDownloadOnCompletedState) ASSERT_EQ(status.bytes_total(), g_smallFileSizeBytes); simpleDownload->finalize(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); try { @@ -380,7 +378,7 @@ TEST_F(DownloadTests, CancelDownloadInTransferredState) #if defined(DO_INTERFACE_REST) // On Windows need to finalize in order for file to show up on disk, so exclude check here - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); #endif try { @@ -422,7 +420,7 @@ static void _PauseResumeTest(bool delayAfterStart = false) ASSERT_EQ(status.state(), msdo::download_state::transferred); ASSERT_EQ(status.bytes_total(), status.bytes_transferred()); simpleDownload->finalize(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_largeFileSizeBytes); } TEST_F(DownloadTests, PauseResumeTest) @@ -437,25 +435,25 @@ TEST_F(DownloadTests, PauseResumeTestWithDelayAfterStart) TEST_F(DownloadTests, MultipleConsecutiveDownloadTest) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(fs::exists(g_tmpFileName)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)); + ASSERT_FALSE(fs::exists(g_tmpFileName2)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName2); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName2)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); + ASSERT_TRUE(fs::exists(g_tmpFileName2)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName2)), g_smallFileSizeBytes); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName3)); + ASSERT_FALSE(fs::exists(g_tmpFileName3)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName3); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName3)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_TRUE(fs::exists(g_tmpFileName3)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, MultipleConcurrentDownloadTest) { - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); std::thread downloadThread([&]() { try @@ -495,9 +493,9 @@ TEST_F(DownloadTests, MultipleConcurrentDownloadTest) downloadThread2.join(); downloadThread3.join(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName2)), g_smallFileSizeBytes); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName2)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, MultipleConcurrentDownloadTest_WithCancels) @@ -546,9 +544,9 @@ TEST_F(DownloadTests, MultipleConcurrentDownloadTest_WithCancels) downloadThread2.join(); downloadThread3.join(); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName3)), g_smallFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_FALSE(fs::exists(g_tmpFileName2)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName3)), g_smallFileSizeBytes); } TEST_F(DownloadTests, FileDeletionAfterPause) @@ -566,8 +564,8 @@ TEST_F(DownloadTests, FileDeletionAfterPause) auto status = largeDownload->get_status(); ASSERT_EQ(status.state(), msdo::download_state::paused) << "Download is paused"; - std::filesystem::remove(g_tmpFileName2); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName2)) << "Output file deleted"; + fs::remove(g_tmpFileName2); + ASSERT_FALSE(fs::exists(g_tmpFileName2)) << "Output file deleted"; #if defined(DO_CLIENT_AGENT) try @@ -600,7 +598,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunning) }); TestHelpers::DeleteRestPortFiles(); // can be removed if docs deletes file on shutdown - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); try { msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); @@ -610,7 +608,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunning) { ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent) @@ -623,7 +621,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent TestHelpers::DeleteRestPortFiles(); TestHelpers::CreateRestPortFiles(1); - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); try { msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); @@ -633,7 +631,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent { ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); } TEST_F(DownloadTests, MultipleRestPortFileExists_Download) @@ -649,10 +647,10 @@ TEST_F(DownloadTests, MultipleRestPortFileExists_Download) std::this_thread::sleep_for(std::chrono::seconds(2)); ASSERT_EQ(TestHelpers::CountRestPortFiles(), 1u) << "All other restport files must be deleted by the agent"; - ASSERT_FALSE(std::filesystem::exists(g_tmpFileName)); + ASSERT_FALSE(fs::exists(g_tmpFileName)); msdot::download::download_url_to_path(g_smallFileUrl, g_tmpFileName); - ASSERT_TRUE(std::filesystem::exists(g_tmpFileName)); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_smallFileSizeBytes); + ASSERT_TRUE(fs::exists(g_tmpFileName)); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_smallFileSizeBytes); } #endif // DO_INTERFACE_REST diff --git a/sdk-cpp/tests/rest/config_tests.cpp b/sdk-cpp/tests/rest/config_tests.cpp index 3771350e..8ffa7057 100644 --- a/sdk-cpp/tests/rest/config_tests.cpp +++ b/sdk-cpp/tests/rest/config_tests.cpp @@ -4,7 +4,6 @@ #include "tests_common.h" #include -#include #include #include #include "do_config.h" @@ -21,9 +20,9 @@ class ConfigTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - if (std::filesystem::exists(msdod::GetConfigFilePath())) + if (fs::exists(msdod::GetConfigFilePath())) { - std::filesystem::remove(msdod::GetConfigFilePath()); + fs::remove(msdod::GetConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/mcc_download_tests.cpp b/sdk-cpp/tests/rest/mcc_download_tests.cpp index 3493c4a1..64aa4bcf 100644 --- a/sdk-cpp/tests/rest/mcc_download_tests.cpp +++ b/sdk-cpp/tests/rest/mcc_download_tests.cpp @@ -3,7 +3,6 @@ #include "tests_common.h" -#include #include #include #include "do_config.h" @@ -24,9 +23,9 @@ class MCCDownloadTests : public ::testing::Test void SetUp() override { TestHelpers::CleanTestDir(); - if (std::filesystem::exists(msdod::GetConfigFilePath())) + if (fs::exists(msdod::GetConfigFilePath())) { - std::filesystem::remove(msdod::GetConfigFilePath()); + fs::remove(msdod::GetConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/network_connectivity_tests.cpp b/sdk-cpp/tests/rest/network_connectivity_tests.cpp index ce5231ab..f5daff7c 100644 --- a/sdk-cpp/tests/rest/network_connectivity_tests.cpp +++ b/sdk-cpp/tests/rest/network_connectivity_tests.cpp @@ -6,8 +6,6 @@ #include #include -#include - #include "do_download.h" #include "do_download_status.h" #include "do_errors.h" @@ -65,7 +63,7 @@ TEST_F(NetworkConnectivityTests, DISABLED_SimpleBlockingDownloadNetworkReconnect try { msdo::download::download_url_to_path(g_largeFileUrl, g_tmpFileName); - ASSERT_EQ(std::filesystem::file_size(std::filesystem::path(g_tmpFileName)), g_largeFileSizeBytes); + ASSERT_EQ(fs::file_size(fs::path(g_tmpFileName)), g_largeFileSizeBytes); } catch (const msdod::exception& e) { diff --git a/sdk-cpp/tests/rest/port_discovery_tests.cpp b/sdk-cpp/tests/rest/port_discovery_tests.cpp index 014bbad0..220c982d 100644 --- a/sdk-cpp/tests/rest/port_discovery_tests.cpp +++ b/sdk-cpp/tests/rest/port_discovery_tests.cpp @@ -2,8 +2,6 @@ #include -#include - #include "do_persistence.h" #include "do_port_finder.h" #include "test_data.h" @@ -34,9 +32,9 @@ void PortDiscoveryTests::SetUp() { TestHelpers::StopService(g_docsSvcName); // ensure agent does not write to port file TestHelpers::DeleteRestPortFiles(); - if (!std::filesystem::exists(msdod::GetRuntimeDirectory())) + if (!fs::exists(msdod::GetRuntimeDirectory())) { - std::filesystem::create_directories(msdod::GetRuntimeDirectory()); + fs::create_directories(msdod::GetRuntimeDirectory()); } std::ofstream file(_testFilePath); @@ -45,9 +43,9 @@ void PortDiscoveryTests::SetUp() void PortDiscoveryTests::TearDown() { - if (std::filesystem::exists(_testFilePath)) + if (fs::exists(_testFilePath)) { - std::filesystem::remove(_testFilePath); + fs::remove(_testFilePath); } TestHelpers::StartService(g_docsSvcName); } diff --git a/sdk-cpp/tests/rest/rest_interface_tests.cpp b/sdk-cpp/tests/rest/rest_interface_tests.cpp index b2c52ff4..42856ca9 100644 --- a/sdk-cpp/tests/rest/rest_interface_tests.cpp +++ b/sdk-cpp/tests/rest/rest_interface_tests.cpp @@ -3,7 +3,6 @@ #include "tests_common.h" -#include #include #include @@ -22,9 +21,9 @@ class RestInterfaceTests : public ::testing::Test public: void SetUp() override { - if (std::filesystem::exists(msdod::GetAdminConfigFilePath())) + if (fs::exists(msdod::GetAdminConfigFilePath())) { - std::filesystem::remove(msdod::GetAdminConfigFilePath()); + fs::remove(msdod::GetAdminConfigFilePath()); } } diff --git a/sdk-cpp/tests/rest/test_helpers.cpp b/sdk-cpp/tests/rest/test_helpers.cpp index 804d52ef..34cf6900 100644 --- a/sdk-cpp/tests/rest/test_helpers.cpp +++ b/sdk-cpp/tests/rest/test_helpers.cpp @@ -17,8 +17,6 @@ #include #include -#include - #include "do_persistence.h" #include "do_port_finder.h" @@ -64,12 +62,12 @@ void TestHelpers::CreateRestPortFiles(int numFiles) void TestHelpers::DeleteRestPortFiles() { - for (std::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != std::filesystem::directory_iterator(); ++itr) + for (fs::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != fs::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) { - std::filesystem::remove(dirEntry); + fs::remove(dirEntry); } } } @@ -77,7 +75,7 @@ void TestHelpers::DeleteRestPortFiles() unsigned int TestHelpers::CountRestPortFiles() { unsigned int count = 0; - for (std::filesystem::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != std::filesystem::directory_iterator(); ++itr) + for (fs::directory_iterator itr(msdod::GetRuntimeDirectory()); itr != fs::directory_iterator(); ++itr) { auto& dirEntry = itr->path(); if (dirEntry.filename().string().find("restport") != std::string::npos) diff --git a/sdk-cpp/tests/test_data.cpp b/sdk-cpp/tests/test_data.cpp index d71916c7..c0fbc30e 100644 --- a/sdk-cpp/tests/test_data.cpp +++ b/sdk-cpp/tests/test_data.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #include "test_data.h" -#include +#include "do_filesystem.h" using namespace std::chrono_literals; // NOLINT(build/namespaces) @@ -14,14 +14,14 @@ const uint64_t g_prodFileSizeBytes = 25006511u; // For testing production scenario, use the same path DU agent will use static const std::string downloadPath = "/var/lib/deviceupdate-agent-downloads"; #else -static const std::string downloadPath = std::filesystem::temp_directory_path().string(); +static const std::string downloadPath = fs::temp_directory_path().string(); #endif const std::string g_largeFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/ReplacementDCATFile.txt"; const std::string g_malformedFilePath = "?f309adfasdf///dfasdfj39fjasldfjasdf/// ///.1"; -const std::string g_tmpFileName = (downloadPath / std::filesystem::path("docsdk_testfile.txt")).string(); -const std::string g_tmpFileName2 = (downloadPath / std::filesystem::path("docsdk_testfile2.txt")).string(); -const std::string g_tmpFileName3 = (downloadPath / std::filesystem::path("docsdk_testfile3.txt")).string(); +const std::string g_tmpFileName = (downloadPath / fs::path("docsdk_testfile.txt")).string(); +const std::string g_tmpFileName2 = (downloadPath / fs::path("docsdk_testfile2.txt")).string(); +const std::string g_tmpFileName3 = (downloadPath / fs::path("docsdk_testfile3.txt")).string(); const std::string g_smallFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/49c591d405d307e25e72a19f7e79b53d69f19954/43A54FC03C6A979E9AAEAE2493757D1429A5C8A8D093FB7B8103E8CC8DF7B6B6"; const std::string g_smallFilePhfInfoJson = R"( { diff --git a/sdk-cpp/tests/test_helpers.h b/sdk-cpp/tests/test_helpers.h index 4a00d485..264327a6 100644 --- a/sdk-cpp/tests/test_helpers.h +++ b/sdk-cpp/tests/test_helpers.h @@ -4,7 +4,6 @@ #ifndef _DELIVERY_OPTIMIZATION_TEST_HELPERS_H #define _DELIVERY_OPTIMIZATION_TEST_HELPERS_H -#include #include #include @@ -151,34 +150,34 @@ class TestHelpers public: static void CleanTestDir() { - if (std::filesystem::exists(g_tmpFileName)) + if (fs::exists(g_tmpFileName)) { - std::filesystem::remove(g_tmpFileName); + fs::remove(g_tmpFileName); } - if (std::filesystem::exists(g_tmpFileName2)) + if (fs::exists(g_tmpFileName2)) { - std::filesystem::remove(g_tmpFileName2); + fs::remove(g_tmpFileName2); } - if (std::filesystem::exists(g_tmpFileName3)) + if (fs::exists(g_tmpFileName3)) { - std::filesystem::remove(g_tmpFileName3); + fs::remove(g_tmpFileName3); } } // DoSvc creates temporary files with a unique name in the same directory as the output file - static void DeleteDoSvcTemporaryFiles(const std::filesystem::path& outputFilePath) + static void DeleteDoSvcTemporaryFiles(const fs::path& outputFilePath) { - const std::filesystem::path parentDir = outputFilePath.parent_path(); - for (std::filesystem::directory_iterator itr(parentDir); itr != std::filesystem::directory_iterator(); ++itr) + const fs::path parentDir = outputFilePath.parent_path(); + for (fs::directory_iterator itr(parentDir); itr != fs::directory_iterator(); ++itr) { - const std::filesystem::directory_entry& dirEntry = *itr; + const fs::directory_entry& dirEntry = *itr; // Remove all files with names that match DO*.tmp - if (std::filesystem::is_regular_file(dirEntry) + if (fs::is_regular_file(dirEntry) && (dirEntry.path().filename().string().find("DO") == 0) && (dirEntry.path().extension() == ".tmp")) { std::error_code ec; - std::filesystem::remove(dirEntry, ec); + fs::remove(dirEntry, ec); if (ec) { std::cout << "Temp file deletion error: " << ec.message() << ", " << dirEntry.path() << '\n'; diff --git a/sdk-cpp/tests/tests_common.h b/sdk-cpp/tests/tests_common.h index e05e997b..7a278253 100644 --- a/sdk-cpp/tests/tests_common.h +++ b/sdk-cpp/tests/tests_common.h @@ -4,10 +4,10 @@ #ifndef _DELIVERY_OPTIMIZATION_TESTS_COMMON_H #define _DELIVERY_OPTIMIZATION_TESTS_COMMON_H -#include #include #include #include "do_error_helpers.h" +#include "do_filesystem.h" #endif From fe111e200ce0cbaa9acb41bd99dc937d26c66a9b Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 16:23:19 -0700 Subject: [PATCH 07/11] Fix Boost linking for sdk --- sdk-cpp/CMakeLists.txt | 11 +++++++++++ sdk-cpp/tests/CMakeLists.txt | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index 2c5493c6..69bf620a 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -3,6 +3,10 @@ project (deliveryoptimization_sdk VERSION 1.0.0) +if (DO_PLATFORM_LINUX OR DO_PLATFORM_MAC) + find_package(Boost REQUIRED) +endif() + if (DO_PLATFORM_LINUX) fixup_compile_options_for_arm() endif() @@ -45,6 +49,8 @@ if(DO_PLATFORM_LINUX) set(sdk_compile_definitions DOSVC_BIN_NAME="${DOSVC_BIN_NAME}" DO_PLUGIN_APT_BIN_NAME="${DO_PLUGIN_APT_BIN_NAME}" + BOOST_ERROR_CODE_HEADER_ONLY + BOOST_SYSTEM_NO_DEPRECATED ) set(sdk_private_includes @@ -69,6 +75,11 @@ elseif(DO_PLATFORM_MAC) add_library(${DO_SDK_LIB_NAME} SHARED "${sdk_source}") + set(sdk_compile_definitions + BOOST_ERROR_CODE_HEADER_ONLY + BOOST_SYSTEM_NO_DEPRECATED + ) + set(sdk_private_includes "src/internal/rest" "src/internal/rest/util" diff --git a/sdk-cpp/tests/CMakeLists.txt b/sdk-cpp/tests/CMakeLists.txt index 02ffd31b..eb9abe7b 100644 --- a/sdk-cpp/tests/CMakeLists.txt +++ b/sdk-cpp/tests/CMakeLists.txt @@ -62,7 +62,12 @@ file (GLOB test_source add_executable(deliveryoptimization-sdk-tests ${test_source}) # Tests make use of C++ exceptions. MSEdge build on Windows disables C++ exceptions but also does not build our tests. -target_compile_definitions(deliveryoptimization-sdk-tests PRIVATE DO_ENABLE_EXCEPTIONS) +target_compile_definitions(deliveryoptimization-sdk-tests + PRIVATE + DO_ENABLE_EXCEPTIONS + BOOST_ERROR_CODE_HEADER_ONLY + BOOST_SYSTEM_NO_DEPRECATED +) add_platform_interface_definitions(deliveryoptimization-sdk-tests) if (DO_BUILD_FOR_SNAP) From 62e5588ab7f3ef8ce356685a29d3f9d0d0ba4b9a Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 21:06:39 -0700 Subject: [PATCH 08/11] use compiler version check instead --- common/cmake/do-filesystem.cmake | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/common/cmake/do-filesystem.cmake b/common/cmake/do-filesystem.cmake index 2a7cd087..1ae44e84 100644 --- a/common/cmake/do-filesystem.cmake +++ b/common/cmake/do-filesystem.cmake @@ -16,21 +16,26 @@ function (try_set_filesystem_lib) return () endif () + message ("Compiler identified: ${CMAKE_CXX_COMPILER_ID} - ${CMAKE_CXX_COMPILER_VERSION}") + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 9.0.0) + message (STATUS "Using std::experimental filesystem library") + set(CXX_FILESYSTEM_LIBS stdc++fs PARENT_SCOPE) + endif () + + if (FALSE) + set(FS_TESTCODE " - #if defined(CXX17_FILESYSTEM) || defined (CXX17_FILESYSTEM_LIBFS) + #if defined(CXX17_FILESYSTEM) || defined(CXX17_FILESYSTEM_LIBFS) #include + namespace fs = std::filesystem; #elif defined(CXX11_EXP_FILESYSTEM) || defined (CXX11_EXP_FILESYSTEM_LIBFS) #include - namespace std { - namespace filesystem { - using experimental::filesystem::is_regular_file; - } - } + namespace fs = std::experimental::filesystem; #endif int main(void) { - return std::filesystem::is_regular_file(\"/\") ? 0 : 1; + return fs::is_regular_file(\"/\") ? 0 : 1; } " ) @@ -62,5 +67,6 @@ function (try_set_filesystem_lib) endif () unset(FS_TESTCODE) + endif() endfunction () From ed5ff129e5b785da2a74218aef105d9d401f3046 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 21:21:29 -0700 Subject: [PATCH 09/11] Cleanup do-filesystem --- CMakeLists.txt | 1 - common/cmake/do-build-helpers.cmake | 23 +++++++++ common/cmake/do-filesystem.cmake | 72 ----------------------------- 3 files changed, 23 insertions(+), 73 deletions(-) delete mode 100644 common/cmake/do-filesystem.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f80b36b6..c279e92d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,6 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/common/cmake) include (do-build-helpers) -include (do-filesystem) include (do-packaging-helpers) # For contributors, please modify builder name here if changes are made to project source diff --git a/common/cmake/do-build-helpers.cmake b/common/cmake/do-build-helpers.cmake index f7e2bd03..073a2798 100644 --- a/common/cmake/do-build-helpers.cmake +++ b/common/cmake/do-build-helpers.cmake @@ -160,3 +160,26 @@ function (add_platform_interface_definitions target_name) endif () endfunction () + +function (try_set_filesystem_lib) + + # Sets the variable CXX_FILESYSTEM_LIBS if an extra lib is required for c++ filesystem support. + # C++17 std::filesystem support is implemented in std::experimental::filesystem prior to GCC 9. + # Only the experimental version requires linking to stdc++fs library (so troublesome!). + # There is no built-in support in cmake to handle this difference (like a FindFileSystem.cmake module). + # See also: Portable linking for C++17 std::filesystem (https://gitlab.kitware.com/cmake/cmake/-/issues/17834) + + if (DO_PLATFORM_WINDOWS) + # std::filesystem not required for Windows builds + return () + endif () + + message ("Compiler identified: ${CMAKE_CXX_COMPILER_ID} - ${CMAKE_CXX_COMPILER_VERSION}") + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 9.0.0) + message (STATUS "Using std::experimental filesystem library") + set(CXX_FILESYSTEM_LIBS stdc++fs PARENT_SCOPE) + endif () + endif () + +endfunction () diff --git a/common/cmake/do-filesystem.cmake b/common/cmake/do-filesystem.cmake deleted file mode 100644 index 1ae44e84..00000000 --- a/common/cmake/do-filesystem.cmake +++ /dev/null @@ -1,72 +0,0 @@ - -# The C++17 std::filesystem support is implemented in std::experimental::filesystem prior to GCC 9. -# However, and this is so messed up, only the experimental version requires linking to stdc++fs library. -# There is no built-in support in cmake to handle this difference. -# So this function attempts to determine which version is available using the check_cxx_source_compiles() feature. -# See also: Portable linking for C++17 std::filesystem (https://gitlab.kitware.com/cmake/cmake/-/issues/17834) -function (try_set_filesystem_lib) - - if (DO_PLATFORM_WINDOWS) - # std::filesystem not required for Windows builds - return () - endif () - - if (CXX_FILESYSTEM_LIBS) - # Already set, no need to redo - return () - endif () - - message ("Compiler identified: ${CMAKE_CXX_COMPILER_ID} - ${CMAKE_CXX_COMPILER_VERSION}") - if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 9.0.0) - message (STATUS "Using std::experimental filesystem library") - set(CXX_FILESYSTEM_LIBS stdc++fs PARENT_SCOPE) - endif () - - if (FALSE) - - set(FS_TESTCODE - " - #if defined(CXX17_FILESYSTEM) || defined(CXX17_FILESYSTEM_LIBFS) - #include - namespace fs = std::filesystem; - #elif defined(CXX11_EXP_FILESYSTEM) || defined (CXX11_EXP_FILESYSTEM_LIBFS) - #include - namespace fs = std::experimental::filesystem; - #endif - int main(void) - { - return fs::is_regular_file(\"/\") ? 0 : 1; - } - " - ) - - include (CMakePushCheckState) - include (CheckCXXSourceCompiles) - - # Note that check_cxx_source_compiles automatically adds the result variable itself as a preprocessor symbol. - - cmake_push_check_state(RESET) - check_cxx_source_compiles("${FS_TESTCODE}" CXX17_FILESYSTEM) - if (NOT CXX17_FILESYSTEM) - set(CMAKE_REQUIRED_LIBRARIES stdc++fs) - check_cxx_source_compiles("${FS_TESTCODE}" CXX17_FILESYSTEM_LIBFS) - cmake_reset_check_state() - endif () - - if (NOT CXX17_FILESYSTEM AND NOT CXX17_FILESYSTEM_LIBFS) - check_cxx_source_compiles("${FS_TESTCODE}" CXX11_EXP_FILESYSTEM) - if (NOT CXX11_EXP_FILESYSTEM) - set(CMAKE_REQUIRED_LIBRARIES stdc++fs) - check_cxx_source_compiles("${FS_TESTCODE}" CXX11_EXP_FILESYSTEM_LIBFS) - endif () - endif () - cmake_pop_check_state() - - if (CXX17_FILESYSTEM_LIBFS OR CXX11_EXP_FILESYSTEM_LIBFS) - set(CXX_FILESYSTEM_LIBS stdc++fs PARENT_SCOPE) - endif () - - unset(FS_TESTCODE) - endif() - -endfunction () From d681af165f84ff218b257fda693c64964c983728 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 21:39:34 -0700 Subject: [PATCH 10/11] add_boost_definitions --- client-lite/CMakeLists.txt | 6 +----- client-lite/src/include/do_filesystem.h | 5 ++++- client-lite/test/CMakeLists.txt | 2 +- common/cmake/do-build-helpers.cmake | 8 ++++++++ sdk-cpp/CMakeLists.txt | 8 +------- sdk-cpp/tests/CMakeLists.txt | 8 ++------ 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/client-lite/CMakeLists.txt b/client-lite/CMakeLists.txt index f16b12d8..ee6bca08 100644 --- a/client-lite/CMakeLists.txt +++ b/client-lite/CMakeLists.txt @@ -91,18 +91,14 @@ endif () add_do_version_lib(${PROJECT_NAME} ${PROJECT_VERSION}) # Build product files into a lib for use by other targets. -# BOOST_ERROR_CODE_HEADER_ONLY and BOOST_SYSTEM_NO_DEPRECATED are required to use header-only components -# like boost.asio without linking to the boost.system shared library. add_library(docs_common STATIC ${files_docs_common}) target_compile_definitions(docs_common - PUBLIC - BOOST_ERROR_CODE_HEADER_ONLY - BOOST_SYSTEM_NO_DEPRECATED PRIVATE DO_CONFIG_DIRECTORY_PATH="${docs_svc_config_dir_path}" DO_AGENT_LOG_DIRECTORY_PATH="${docs_svc_log_dir_path}" DO_RUN_DIRECTORY_PATH="${docs_svc_run_dir_path}" ) +add_boost_definitions(docs_common PUBLIC) if (DO_DEV_DEBUG) target_compile_definitions(docs_common PUBLIC DO_DEV_DEBUG) endif () diff --git a/client-lite/src/include/do_filesystem.h b/client-lite/src/include/do_filesystem.h index ec4f1fd0..773bf536 100644 --- a/client-lite/src/include/do_filesystem.h +++ b/client-lite/src/include/do_filesystem.h @@ -1,7 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#pragma once +#ifndef _DELIVERY_OPTIMIZATION_DO_FILESYSTEM_H +#define _DELIVERY_OPTIMIZATION_DO_FILESYSTEM_H #if defined(__cpp_lib_filesystem) #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 @@ -25,3 +26,5 @@ namespace fs = std::experimental::filesystem; #include namespace fs = std::filesystem; #endif + +#endif // _DELIVERY_OPTIMIZATION_DO_FILESYSTEM_H diff --git a/client-lite/test/CMakeLists.txt b/client-lite/test/CMakeLists.txt index 404bb2eb..3249ba35 100644 --- a/client-lite/test/CMakeLists.txt +++ b/client-lite/test/CMakeLists.txt @@ -6,7 +6,7 @@ find_package(GTest REQUIRED) file (GLOB files_docs_tests *.cpp) -add_executable (deliveryoptimization-agent-tests ${files_docs_tests}) +add_executable(deliveryoptimization-agent-tests ${files_docs_tests}) add_platform_interface_definitions(deliveryoptimization-agent-tests) target_link_libraries(deliveryoptimization-agent-tests docs_common diff --git a/common/cmake/do-build-helpers.cmake b/common/cmake/do-build-helpers.cmake index 073a2798..e7178ec2 100644 --- a/common/cmake/do-build-helpers.cmake +++ b/common/cmake/do-build-helpers.cmake @@ -161,6 +161,14 @@ function (add_platform_interface_definitions target_name) endfunction () +function (add_boost_definitions target_name scope) + if (DO_PLATFORM_LINUX OR DO_PLATFORM_MAC) + # BOOST_ERROR_CODE_HEADER_ONLY and BOOST_SYSTEM_NO_DEPRECATED are required to use header-only components + # like boost.asio without linking to the boost.system shared library. + target_compile_definitions(${target_name} ${scope} BOOST_ERROR_CODE_HEADER_ONLY BOOST_SYSTEM_NO_DEPRECATED) + endif () +endfunction () + function (try_set_filesystem_lib) # Sets the variable CXX_FILESYSTEM_LIBS if an extra lib is required for c++ filesystem support. diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index 69bf620a..e58850c5 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -49,8 +49,6 @@ if(DO_PLATFORM_LINUX) set(sdk_compile_definitions DOSVC_BIN_NAME="${DOSVC_BIN_NAME}" DO_PLUGIN_APT_BIN_NAME="${DO_PLUGIN_APT_BIN_NAME}" - BOOST_ERROR_CODE_HEADER_ONLY - BOOST_SYSTEM_NO_DEPRECATED ) set(sdk_private_includes @@ -75,11 +73,6 @@ elseif(DO_PLATFORM_MAC) add_library(${DO_SDK_LIB_NAME} SHARED "${sdk_source}") - set(sdk_compile_definitions - BOOST_ERROR_CODE_HEADER_ONLY - BOOST_SYSTEM_NO_DEPRECATED - ) - set(sdk_private_includes "src/internal/rest" "src/internal/rest/util" @@ -118,6 +111,7 @@ target_compile_definitions(${DO_SDK_LIB_NAME} PRIVATE ${sdk_compile_definitions} ) +add_boost_definitions(${DO_SDK_LIB_NAME} PRIVATE) if (DO_DEV_DEBUG) target_compile_definitions(${DO_SDK_LIB_NAME} PRIVATE DO_DEV_DEBUG) endif () diff --git a/sdk-cpp/tests/CMakeLists.txt b/sdk-cpp/tests/CMakeLists.txt index eb9abe7b..d22d1623 100644 --- a/sdk-cpp/tests/CMakeLists.txt +++ b/sdk-cpp/tests/CMakeLists.txt @@ -62,12 +62,8 @@ file (GLOB test_source add_executable(deliveryoptimization-sdk-tests ${test_source}) # Tests make use of C++ exceptions. MSEdge build on Windows disables C++ exceptions but also does not build our tests. -target_compile_definitions(deliveryoptimization-sdk-tests - PRIVATE - DO_ENABLE_EXCEPTIONS - BOOST_ERROR_CODE_HEADER_ONLY - BOOST_SYSTEM_NO_DEPRECATED -) +target_compile_definitions(deliveryoptimization-sdk-tests PRIVATE DO_ENABLE_EXCEPTIONS) +add_boost_definitions(deliveryoptimization-sdk-tests PRIVATE) add_platform_interface_definitions(deliveryoptimization-sdk-tests) if (DO_BUILD_FOR_SNAP) From 055a033072546784ab2b935156088862f211417e Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Wed, 22 Mar 2023 23:01:03 -0700 Subject: [PATCH 11/11] Update expected binary sizes (stdc++fs on Ubuntu 18.04) --- .../build/linux/du/templates/doclient-lite-native-steps.yml | 2 +- .../build/linux/du/templates/dosdkcpp-native-steps.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines/build/linux/du/templates/doclient-lite-native-steps.yml b/azure-pipelines/build/linux/du/templates/doclient-lite-native-steps.yml index 1c3480f5..a630bfe7 100644 --- a/azure-pipelines/build/linux/du/templates/doclient-lite-native-steps.yml +++ b/azure-pipelines/build/linux/du/templates/doclient-lite-native-steps.yml @@ -24,7 +24,7 @@ steps: inputs: targetType: 'filePath' filePath: 'build/scripts/check_binary_size.sh' - arguments: '363928 /tmp/build-deliveryoptimization-agent/linux-${{parameters.config}}/client-lite/deliveryoptimization-agent' + arguments: '523672 /tmp/build-deliveryoptimization-agent/linux-${{parameters.config}}/client-lite/deliveryoptimization-agent' displayName: 'Limit binary size increase' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dosdkcpp-native-steps.yml b/azure-pipelines/build/linux/du/templates/dosdkcpp-native-steps.yml index 318c0bc7..3b699b4c 100644 --- a/azure-pipelines/build/linux/du/templates/dosdkcpp-native-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dosdkcpp-native-steps.yml @@ -38,7 +38,7 @@ steps: inputs: targetType: 'filePath' filePath: 'build/scripts/check_binary_size.sh' - arguments: '431184 /tmp/build-deliveryoptimization-sdk/linux-${{parameters.config}}/sdk-cpp/libdeliveryoptimization.so.*.*.?' + arguments: '596080 /tmp/build-deliveryoptimization-sdk/linux-${{parameters.config}}/sdk-cpp/libdeliveryoptimization.so.*.*.?' displayName: 'Limit binary size increase' - task: CmdLine@2