From 2f228bab1107be57551d54bcd3bd46931b7469ad Mon Sep 17 00:00:00 2001 From: Mykhailo Kuchma Date: Fri, 1 May 2020 16:44:07 +0300 Subject: [PATCH] Performance testing on android. Added data validation. Fixed Android proxy. Fixed network initialization. --- external/boost/CMakeLists.txt.boost.in | 5 +- tests/performance/CMakeLists.txt | 47 ++++++++++---- tests/performance/MemoryTest.cpp | 89 ++++++++++++-------------- tests/performance/MemoryTestBase.h | 5 ++ tests/utils/olp_server/blob_service.js | 9 ++- 5 files changed, 93 insertions(+), 62 deletions(-) diff --git a/external/boost/CMakeLists.txt.boost.in b/external/boost/CMakeLists.txt.boost.in index 16f2dce19..39a431266 100644 --- a/external/boost/CMakeLists.txt.boost.in +++ b/external/boost/CMakeLists.txt.boost.in @@ -24,12 +24,14 @@ include(ExternalProject) ExternalProject_Add(boost-download GIT_REPOSITORY @OLP_SDK_CPP_BOOST_URL@ GIT_TAG @OLP_SDK_CPP_BOOST_TAG@ - GIT_SUBMODULES libs/any + GIT_SUBMODULES libs/algorithm + libs/any libs/assert libs/config libs/container_hash libs/core libs/detail + libs/exception libs/format libs/function_types libs/headers @@ -43,6 +45,7 @@ ExternalProject_Add(boost-download libs/predef libs/preprocessor libs/random + libs/range libs/serialization libs/smart_ptr libs/static_assert diff --git a/tests/performance/CMakeLists.txt b/tests/performance/CMakeLists.txt index fc63dfe5c..9a0acf4b1 100644 --- a/tests/performance/CMakeLists.txt +++ b/tests/performance/CMakeLists.txt @@ -15,11 +15,6 @@ # SPDX-License-Identifier: Apache-2.0 # License-Filename: LICENSE -if (ANDROID OR IOS) - message(STATUS "Currently the performance test runner for mobile platforms is not supported") - return() -endif() - set(OLP_SDK_PERFORMANCE_TESTS_SOURCES ./MemoryTest.cpp ./MemoryTestBase.h @@ -28,11 +23,37 @@ set(OLP_SDK_PERFORMANCE_TESTS_SOURCES ./PrefetchTest.cpp ) -add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES}) -target_link_libraries(olp-cpp-sdk-performance-tests - PRIVATE - custom-params - gtest_main - olp-cpp-sdk-authentication - olp-cpp-sdk-dataservice-read -) +if (ANDROID OR IOS) + set(OLP_SDK_PERFORMANCE_TESTS_LIB olp-cpp-sdk-performance-tests-lib) + + add_library(${OLP_SDK_PERFORMANCE_TESTS_LIB} ${OLP_SDK_PERFORMANCE_TESTS_SOURCES}) + target_link_libraries(${OLP_SDK_PERFORMANCE_TESTS_LIB} + PRIVATE + custom-params + gtest + olp-cpp-sdk-authentication + olp-cpp-sdk-dataservice-read + ) + + if (ANDROID) + include(${CMAKE_SOURCE_DIR}/cmake/android/gen_android_test.cmake) + gen_android_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB}) + add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/android ${CMAKE_CURRENT_BINARY_DIR}/android) + else() + include(${CMAKE_SOURCE_DIR}/cmake/ios/gen_ios_test.cmake) + gen_ios_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB}) + add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/ios ${CMAKE_CURRENT_BINARY_DIR}/ios) + endif() + +else() + + add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES}) + target_link_libraries(olp-cpp-sdk-performance-tests + PRIVATE + custom-params + gtest_main + olp-cpp-sdk-authentication + olp-cpp-sdk-dataservice-read + ) + +endif() diff --git a/tests/performance/MemoryTest.cpp b/tests/performance/MemoryTest.cpp index fe5c08b77..43e5f0cb1 100644 --- a/tests/performance/MemoryTest.cpp +++ b/tests/performance/MemoryTest.cpp @@ -20,6 +20,9 @@ #include #include +#include +#include + #include #include #include @@ -27,6 +30,42 @@ #include "MemoryTestBase.h" +std::string ComputeSha1(const char* buffer, size_t length) { + using boost::uuids::detail::sha1; + sha1 hash; + sha1::digest_type digest; + sha1::digest_type digest_rotated; + + hash.process_bytes(buffer, length); + hash.get_digest(digest); + + // rotate bytes + for (int i = 0; i < 5; ++i) + { + const char* tmp = reinterpret_cast(&digest); + char* res = reinterpret_cast(&digest_rotated); + res[i*4] = tmp[i*4+3]; + res[i*4+1] = tmp[i*4+2]; + res[i*4+2] = tmp[i*4+1]; + res[i*4+3] = tmp[i*4]; + } + + const auto charDigest = reinterpret_cast(&digest_rotated); + std::string result; + boost::algorithm::hex(charDigest, charDigest + sizeof(sha1::digest_type), + std::back_inserter(result)); + return result; +} + +bool Validate(const std::vector& buffer) { + // 40 first bytes is a string representation of hash + const char* bytes = reinterpret_cast( buffer.data() ); + std::string hash(bytes, bytes + 40); + std::string computed_hash = ComputeSha1(bytes + 40, buffer.size() - 40); + OLP_SDK_LOG_CRITICAL_INFO_F("HASH", "HASHES: %s %s", hash.c_str(), computed_hash.c_str()); + return hash == computed_hash; +} + namespace { using TestFunction = std::function; @@ -183,53 +222,9 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) { request, [&](olp::dataservice::read::DataResponse response) { if (response.IsSuccessful()) { success_responses_.fetch_add(1); - } else { - failed_responses_.fetch_add(1); - ReportError(response.GetError()); - } - }); - - RandomlyCancel(std::move(token)); - - std::this_thread::sleep_for( - GetSleepPeriod(parameter.requests_per_second)); - } - }); -} - -TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) { - // Enable only errors to have a short output. - olp::logging::Log::setLevel(olp::logging::Level::Warning); - - const auto& parameter = GetParam(); - - auto settings = CreateCatalogClientSettings(); - - StartThreads([=](uint8_t /*thread_id*/) { - olp::dataservice::read::VersionedLayerClient service_client( - kCatalog, kVersionedLayerId, boost::none, settings); - - const auto end_timestamp = - std::chrono::steady_clock::now() + parameter.runtime; - - while (end_timestamp > std::chrono::steady_clock::now()) { - const auto level = 10; - const auto tile_count = 1 << level; - - std::vector tile_keys = { - olp::geo::TileKey::FromRowColumnLevel(rand() % tile_count, - rand() % tile_count, level)}; - - auto request = olp::dataservice::read::PrefetchTilesRequest() - .WithMaxLevel(level + 2) - .WithMinLevel(level) - .WithTileKeys(tile_keys); - total_requests_.fetch_add(1); - auto token = service_client.PrefetchTiles( - std::move(request), - [&](olp::dataservice::read::PrefetchTilesResponse response) { - if (response.IsSuccessful()) { - success_responses_.fetch_add(1); + if (!Validate(*response.GetResult())) { + abort(); + } } else { failed_responses_.fetch_add(1); ReportError(response.GetError()); diff --git a/tests/performance/MemoryTestBase.h b/tests/performance/MemoryTestBase.h index 9cced9187..471c415cc 100644 --- a/tests/performance/MemoryTestBase.h +++ b/tests/performance/MemoryTestBase.h @@ -48,7 +48,11 @@ class MemoryTestBase : public ::testing::TestWithParam { protected: olp::http::NetworkProxySettings GetLocalhostProxySettings() { return olp::http::NetworkProxySettings() +#if ANDROID + .WithHostname("10.0.2.2") +#else .WithHostname("localhost") +#endif .WithPort(3000) .WithUsername("test_user") .WithPassword("test_password") @@ -80,6 +84,7 @@ class MemoryTestBase : public ::testing::TestWithParam { client_settings.cache = parameter.cache_factory ? parameter.cache_factory() : nullptr; client_settings.retry_settings.timeout = 1; + //client_settings.retry_settings.max_attempts = 0; return client_settings; } diff --git a/tests/utils/olp_server/blob_service.js b/tests/utils/olp_server/blob_service.js index 379d1c54c..0905e9017 100644 --- a/tests/utils/olp_server/blob_service.js +++ b/tests/utils/olp_server/blob_service.js @@ -17,6 +17,12 @@ * License-Filename: LICENSE */ +var crypto = require('crypto') + +function computeHash(data) { + return crypto.createHash('sha1').update(data).digest('hex').toUpperCase(); +} + function generateGetBlobApiResponse(request) { const layer = request[1] const dataHandle = request[2] // ignored @@ -30,7 +36,8 @@ function generateGetBlobApiResponse(request) { response += characters.charAt(Math.floor(Math.random() * charactersLength)); } - return response; + //console.log(computeHash(response)) + return computeHash(response) + response; } const methods = [