Skip to content

Commit 2f228ba

Browse files
Performance testing on android.
Added data validation. Fixed Android proxy. Fixed network initialization.
1 parent ff56916 commit 2f228ba

File tree

5 files changed

+93
-62
lines changed

5 files changed

+93
-62
lines changed

external/boost/CMakeLists.txt.boost.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ include(ExternalProject)
2424
ExternalProject_Add(boost-download
2525
GIT_REPOSITORY @OLP_SDK_CPP_BOOST_URL@
2626
GIT_TAG @OLP_SDK_CPP_BOOST_TAG@
27-
GIT_SUBMODULES libs/any
27+
GIT_SUBMODULES libs/algorithm
28+
libs/any
2829
libs/assert
2930
libs/config
3031
libs/container_hash
3132
libs/core
3233
libs/detail
34+
libs/exception
3335
libs/format
3436
libs/function_types
3537
libs/headers
@@ -43,6 +45,7 @@ ExternalProject_Add(boost-download
4345
libs/predef
4446
libs/preprocessor
4547
libs/random
48+
libs/range
4649
libs/serialization
4750
libs/smart_ptr
4851
libs/static_assert

tests/performance/CMakeLists.txt

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
# SPDX-License-Identifier: Apache-2.0
1616
# License-Filename: LICENSE
1717

18-
if (ANDROID OR IOS)
19-
message(STATUS "Currently the performance test runner for mobile platforms is not supported")
20-
return()
21-
endif()
22-
2318
set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
2419
./MemoryTest.cpp
2520
./MemoryTestBase.h
@@ -28,11 +23,37 @@ set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
2823
./PrefetchTest.cpp
2924
)
3025

31-
add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
32-
target_link_libraries(olp-cpp-sdk-performance-tests
33-
PRIVATE
34-
custom-params
35-
gtest_main
36-
olp-cpp-sdk-authentication
37-
olp-cpp-sdk-dataservice-read
38-
)
26+
if (ANDROID OR IOS)
27+
set(OLP_SDK_PERFORMANCE_TESTS_LIB olp-cpp-sdk-performance-tests-lib)
28+
29+
add_library(${OLP_SDK_PERFORMANCE_TESTS_LIB} ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
30+
target_link_libraries(${OLP_SDK_PERFORMANCE_TESTS_LIB}
31+
PRIVATE
32+
custom-params
33+
gtest
34+
olp-cpp-sdk-authentication
35+
olp-cpp-sdk-dataservice-read
36+
)
37+
38+
if (ANDROID)
39+
include(${CMAKE_SOURCE_DIR}/cmake/android/gen_android_test.cmake)
40+
gen_android_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
41+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/android ${CMAKE_CURRENT_BINARY_DIR}/android)
42+
else()
43+
include(${CMAKE_SOURCE_DIR}/cmake/ios/gen_ios_test.cmake)
44+
gen_ios_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
45+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/ios ${CMAKE_CURRENT_BINARY_DIR}/ios)
46+
endif()
47+
48+
else()
49+
50+
add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
51+
target_link_libraries(olp-cpp-sdk-performance-tests
52+
PRIVATE
53+
custom-params
54+
gtest_main
55+
olp-cpp-sdk-authentication
56+
olp-cpp-sdk-dataservice-read
57+
)
58+
59+
endif()

tests/performance/MemoryTest.cpp

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,52 @@
2020
#include <chrono>
2121
#include <memory>
2222

23+
#include <boost/uuid/detail/sha1.hpp>
24+
#include <boost/algorithm/hex.hpp>
25+
2326
#include <gtest/gtest.h>
2427
#include <olp/core/client/HRN.h>
2528
#include <olp/core/logging/Log.h>
2629
#include <olp/dataservice/read/VersionedLayerClient.h>
2730

2831
#include "MemoryTestBase.h"
2932

33+
std::string ComputeSha1(const char* buffer, size_t length) {
34+
using boost::uuids::detail::sha1;
35+
sha1 hash;
36+
sha1::digest_type digest;
37+
sha1::digest_type digest_rotated;
38+
39+
hash.process_bytes(buffer, length);
40+
hash.get_digest(digest);
41+
42+
// rotate bytes
43+
for (int i = 0; i < 5; ++i)
44+
{
45+
const char* tmp = reinterpret_cast<char*>(&digest);
46+
char* res = reinterpret_cast<char*>(&digest_rotated);
47+
res[i*4] = tmp[i*4+3];
48+
res[i*4+1] = tmp[i*4+2];
49+
res[i*4+2] = tmp[i*4+1];
50+
res[i*4+3] = tmp[i*4];
51+
}
52+
53+
const auto charDigest = reinterpret_cast<const char*>(&digest_rotated);
54+
std::string result;
55+
boost::algorithm::hex(charDigest, charDigest + sizeof(sha1::digest_type),
56+
std::back_inserter(result));
57+
return result;
58+
}
59+
60+
bool Validate(const std::vector<unsigned char>& buffer) {
61+
// 40 first bytes is a string representation of hash
62+
const char* bytes = reinterpret_cast<const char*>( buffer.data() );
63+
std::string hash(bytes, bytes + 40);
64+
std::string computed_hash = ComputeSha1(bytes + 40, buffer.size() - 40);
65+
OLP_SDK_LOG_CRITICAL_INFO_F("HASH", "HASHES: %s %s", hash.c_str(), computed_hash.c_str());
66+
return hash == computed_hash;
67+
}
68+
3069
namespace {
3170
using TestFunction = std::function<void(uint8_t thread_id)>;
3271

@@ -183,53 +222,9 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
183222
request, [&](olp::dataservice::read::DataResponse response) {
184223
if (response.IsSuccessful()) {
185224
success_responses_.fetch_add(1);
186-
} else {
187-
failed_responses_.fetch_add(1);
188-
ReportError(response.GetError());
189-
}
190-
});
191-
192-
RandomlyCancel(std::move(token));
193-
194-
std::this_thread::sleep_for(
195-
GetSleepPeriod(parameter.requests_per_second));
196-
}
197-
});
198-
}
199-
200-
TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
201-
// Enable only errors to have a short output.
202-
olp::logging::Log::setLevel(olp::logging::Level::Warning);
203-
204-
const auto& parameter = GetParam();
205-
206-
auto settings = CreateCatalogClientSettings();
207-
208-
StartThreads([=](uint8_t /*thread_id*/) {
209-
olp::dataservice::read::VersionedLayerClient service_client(
210-
kCatalog, kVersionedLayerId, boost::none, settings);
211-
212-
const auto end_timestamp =
213-
std::chrono::steady_clock::now() + parameter.runtime;
214-
215-
while (end_timestamp > std::chrono::steady_clock::now()) {
216-
const auto level = 10;
217-
const auto tile_count = 1 << level;
218-
219-
std::vector<olp::geo::TileKey> tile_keys = {
220-
olp::geo::TileKey::FromRowColumnLevel(rand() % tile_count,
221-
rand() % tile_count, level)};
222-
223-
auto request = olp::dataservice::read::PrefetchTilesRequest()
224-
.WithMaxLevel(level + 2)
225-
.WithMinLevel(level)
226-
.WithTileKeys(tile_keys);
227-
total_requests_.fetch_add(1);
228-
auto token = service_client.PrefetchTiles(
229-
std::move(request),
230-
[&](olp::dataservice::read::PrefetchTilesResponse response) {
231-
if (response.IsSuccessful()) {
232-
success_responses_.fetch_add(1);
225+
if (!Validate(*response.GetResult())) {
226+
abort();
227+
}
233228
} else {
234229
failed_responses_.fetch_add(1);
235230
ReportError(response.GetError());

tests/performance/MemoryTestBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
4848
protected:
4949
olp::http::NetworkProxySettings GetLocalhostProxySettings() {
5050
return olp::http::NetworkProxySettings()
51+
#if ANDROID
52+
.WithHostname("10.0.2.2")
53+
#else
5154
.WithHostname("localhost")
55+
#endif
5256
.WithPort(3000)
5357
.WithUsername("test_user")
5458
.WithPassword("test_password")
@@ -80,6 +84,7 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
8084
client_settings.cache =
8185
parameter.cache_factory ? parameter.cache_factory() : nullptr;
8286
client_settings.retry_settings.timeout = 1;
87+
//client_settings.retry_settings.max_attempts = 0;
8388

8489
return client_settings;
8590
}

tests/utils/olp_server/blob_service.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
var crypto = require('crypto')
21+
22+
function computeHash(data) {
23+
return crypto.createHash('sha1').update(data).digest('hex').toUpperCase();
24+
}
25+
2026
function generateGetBlobApiResponse(request) {
2127
const layer = request[1]
2228
const dataHandle = request[2] // ignored
@@ -30,7 +36,8 @@ function generateGetBlobApiResponse(request) {
3036
response += characters.charAt(Math.floor(Math.random() * charactersLength));
3137
}
3238

33-
return response;
39+
//console.log(computeHash(response))
40+
return computeHash(response) + response;
3441
}
3542

3643
const methods = [

0 commit comments

Comments
 (0)