Performance projects for services (#1655)

* add test metadata to the tests for the perf fw
This commit is contained in:
Victor Vazquez 2021-02-18 13:05:22 -08:00 committed by GitHub
parent ebe169bc96
commit e9cf40505b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 863 additions and 85 deletions

View File

@ -140,3 +140,7 @@ az_vcpkg_export(
CORE
"azure/core/dll_import_export.hpp"
)
if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(test/performance)
endif()

View File

@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
# Configure CMake project.
cmake_minimum_required (VERSION 3.13)
project(azure-core-performance LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(
AZURE_CORE_PERF_TEST_HEADER
inc/azure/core/test/performance/nullable.hpp
)
set(
AZURE_CORE_PERF_TEST_SOURCE
src/main.cpp
)
# Name the binary to be created.
add_executable (
azure-core-performance
${AZURE_CORE_PERF_TEST_HEADER} ${AZURE_CORE_PERF_TEST_SOURCE}
)
# Include the headers from the project.
target_include_directories(
azure-core-performance
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
)
# link the `azure-performance-stress` lib together with any other library which will be used for the tests.
target_link_libraries(azure-core-performance PRIVATE azure-core azure-performance-stress)
# Make sure the project will appear in the test folder for Visual Studio CMake view
set_target_properties(azure-core-performance PROPERTIES FOLDER "Tests/Core")

View File

@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Test the Nullable component performance.
*
*/
#pragma once
#include <azure/performance_framework.hpp>
#include <memory>
namespace Azure { namespace Core { namespace Test { namespace Performance {
/**
* @brief Measure the Nullable object performance.
*
*/
class NullableTest : public Azure::PerformanceStress::PerformanceTest {
public:
/**
* @brief Construct a new Nullable test.
*
* @param options The test options.
*/
NullableTest(Azure::PerformanceStress::TestOptions options) : PerformanceTest(options) {}
/**
* @brief Use NUllable to assing and read.
*
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const&) override
{
Azure::Core::Nullable<uint64_t> n;
if (!n)
{
n = 1;
}
if (n)
{
n = 0;
}
auto v = n.GetValue();
if (n)
{
n.Reset();
}
if (!n)
{
n = v;
}
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"NullableTest",
"Measures the overhead of using nullable objects",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::Core::Test::Performance::NullableTest>(options);
}};
}
};
}}}} // namespace Azure::Core::Test::Performance

View File

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/performance_framework.hpp>
#include "azure/core/test/performance/nullable.hpp"
#include <vector>
int main(int argc, char** argv)
{
// Create the test list
std::vector<Azure::PerformanceStress::TestMetadata> tests{
Azure::Core::Test::Performance::NullableTest::GetTestMetadata()};
Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);
return 0;
}

View File

@ -14,6 +14,7 @@ set(
inc/azure/performance-stress/dynamic_test_options.hpp
inc/azure/performance-stress/options.hpp
inc/azure/performance-stress/program.hpp
inc/azure/performance-stress/test_metadata.hpp
inc/azure/performance-stress/test.hpp
inc/azure/performance-stress/test_options.hpp
)

View File

@ -10,13 +10,9 @@
#pragma once
#include "azure/performance-stress/argagg.hpp"
#include "azure/performance-stress/test.hpp"
#include "azure/performance-stress/test_metadata.hpp"
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace PerformanceStress {
/**
@ -47,10 +43,7 @@ namespace Azure { namespace PerformanceStress {
*/
static void Run(
Azure::Core::Context const& context,
std::map<
std::string,
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>> const& tests,
std::vector<Azure::PerformanceStress::TestMetadata> const& tests,
int argc,
char** argv);
};

View File

@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Define the metadata of a performance test.
*
*/
#pragma once
#include "azure/performance-stress/test.hpp"
#include "azure/performance-stress/test_options.hpp"
#include <functional>
#include <memory>
#include <string>
namespace Azure { namespace PerformanceStress {
/**
* @brief Define the metadata of a test that can be run by the performance framework.
*
*/
struct TestMetadata
{
/**
* @brief The name of the test.
*
*/
std::string Name;
/**
* @brief Describe the goal or intention of the test.
*
*/
std::string Description;
/**
* @brief The callback function which produces the performance test.
*
*/
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>
Factory;
};
}} // namespace Azure::PerformanceStress

View File

@ -48,5 +48,11 @@ namespace Azure { namespace PerformanceStress {
*
*/
bool required = false;
/**
* @brief Make the option to be replaced with **** on all outputs
*
*/
bool sensitiveData = false;
};
}} // namespace Azure::PerformanceStress

View File

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Convenience top level header to include all the performance framework functionality.
*
*/
#pragma once
#include "azure/performance-stress/argagg.hpp"
#include "azure/performance-stress/base_test.hpp"
#include "azure/performance-stress/dynamic_test_options.hpp"
#include "azure/performance-stress/options.hpp"
#include "azure/performance-stress/program.hpp"
#include "azure/performance-stress/test.hpp"
#include "azure/performance-stress/test_metadata.hpp"
#include "azure/performance-stress/test_options.hpp"

View File

@ -14,26 +14,19 @@
namespace {
inline std::unique_ptr<Azure::PerformanceStress::PerformanceTest> PrintAvailableTests(
std::map<
std::string,
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>> const& tests)
std::vector<Azure::PerformanceStress::TestMetadata> const& tests)
{
std::cout << "Available tests to run:" << std::endl;
std::cout << "No test name found in the input. Available tests to run:" << std::endl;
std::cout << std::endl << "Name\t\tDescription" << std::endl << "---\t\t---" << std::endl;
for (auto test : tests)
{
std::cout << " - " << test.first << std::endl;
std::cout << test.Name << "\t\t" << test.Description << std::endl;
}
return nullptr;
}
inline std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>
GetTest(
std::map<
std::string,
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>> const& tests,
inline Azure::PerformanceStress::TestMetadata const* GetTestMetadata(
std::vector<Azure::PerformanceStress::TestMetadata> const& tests,
int argc,
char** argv)
{
@ -46,11 +39,11 @@ GetTest(
auto testName = std::string(args.pos[0]);
for (auto test : tests)
for (auto& test : tests)
{
if (Azure::Core::Internal::Strings::LocaleInvariantCaseInsensitiveEqual(test.first, testName))
if (Azure::Core::Internal::Strings::LocaleInvariantCaseInsensitiveEqual(test.Name, testName))
{
return test.second;
return &test;
}
}
return nullptr;
@ -77,26 +70,27 @@ inline void PrintOptions(
{
{
std::cout << std::endl << "=== Global Options ===" << std::endl;
Azure::Core::Internal::Json::json optionsJs = options;
std::cout << ReplaceAll(optionsJs.dump(), ",", ",\n") << std::endl;
Azure::Core::Internal::Json::json optionsAsJson = options;
std::cout << ReplaceAll(optionsAsJson.dump(), ",", ",\n") << std::endl;
}
if (testOptions.size() > 0)
{
std::cout << std::endl << "=== Test Options ===" << std::endl;
Azure::Core::Internal::Json::json optionsJs;
Azure::Core::Internal::Json::json optionsAsJson;
for (auto option : testOptions)
{
try
{
optionsJs[option.Name] = parsedArgs[option.Name].as<std::string>();
optionsAsJson[option.Name]
= option.sensitiveData ? "***" : parsedArgs[option.Name].as<std::string>();
}
catch (std::out_of_range const&)
{
if (!option.required)
{
// arg was not parsed
optionsJs[option.Name] = "default value";
optionsAsJson[option.Name] = "default value";
}
else
{
@ -109,7 +103,7 @@ inline void PrintOptions(
throw;
}
}
std::cout << ReplaceAll(optionsJs.dump(), ",", ",\n") << std::endl;
std::cout << ReplaceAll(optionsAsJson.dump(), ",", ",\n") << std::endl << std::endl;
}
}
@ -278,16 +272,14 @@ inline void RunTests(
void Azure::PerformanceStress::Program::Run(
Azure::Core::Context const& context,
std::map<
std::string,
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>> const& tests,
std::vector<Azure::PerformanceStress::TestMetadata> const& tests,
int argc,
char** argv)
{
// Parse args only to get the test name first
auto testGenerator = GetTest(tests, argc, argv);
if (testGenerator == nullptr)
auto testMetadata = GetTestMetadata(tests, argc, argv);
auto const& testGenerator = testMetadata->Factory;
if (testMetadata == nullptr)
{
// Wrong input. Print what are the options.
PrintAvailableTests(tests);
@ -304,9 +296,13 @@ void Azure::PerformanceStress::Program::Run(
if (options.JobStatistics)
{
std::cout << "Application started." << std::endl;
std::cout << std::endl << "Application started." << std::endl;
}
// Print test metadata
std::cout << std::endl << "Running test: " << testMetadata->Name;
std::cout << std::endl << "Description: " << testMetadata->Description << std::endl;
// Print options
PrintOptions(options, testOptions, argResults);

View File

@ -46,6 +46,21 @@ namespace Azure { namespace PerformanceStress { namespace Test {
}
void GlobalCleanup() override { curl_global_cleanup(); }
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"curlHttpClientGet",
"Send an Http Get request to a configurable url using libcurl.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::CurlHttpClientGetTest>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -9,12 +9,11 @@
#pragma once
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/test.hpp>
#include <azure/performance-stress/test_options.hpp>
#include <azure/performance_framework.hpp>
#include <atomic>
#include <chrono>
#include <memory>
#include <thread>
#include <vector>
@ -94,6 +93,21 @@ namespace Azure { namespace PerformanceStress { namespace Test {
"(IterationGrowthFactor ^ IterationCount)). Default to 1",
1}};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"delay",
"The no op test with a configurable time delay for the main test loop.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::DelayTest>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -10,8 +10,9 @@
#pragma once
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/test.hpp>
#include <azure/performance_framework.hpp>
#include <memory>
namespace Azure { namespace PerformanceStress { namespace Test {
@ -44,6 +45,21 @@ namespace Azure { namespace PerformanceStress { namespace Test {
// just ignore
}
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"exception",
"Measure how the impact of catching a runtime exception.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::ExceptionTest>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -9,10 +9,9 @@
#pragma once
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/test.hpp>
#include <azure/performance-stress/test_options.hpp>
#include <azure/performance_framework.hpp>
#include <memory>
#include <vector>
namespace Azure { namespace PerformanceStress { namespace Test {
@ -51,6 +50,22 @@ namespace Azure { namespace PerformanceStress { namespace Test {
{
return {{"extraOption", {"-e"}, "Example for extended option for test.", 1}};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"extendedOptions",
"Demostrate how to include a test option to a test and measures how expensive is to do "
"it.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::ExtendedOptionsTest>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -9,9 +9,7 @@
#pragma once
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/test.hpp>
#include <azure/performance-stress/test_options.hpp>
#include <azure/performance_framework.hpp>
#include <azure/core/http/body_stream.hpp>
#include <azure/core/http/http.hpp>

View File

@ -9,8 +9,9 @@
#pragma once
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/test.hpp>
#include <azure/performance_framework.hpp>
#include <memory>
namespace Azure { namespace PerformanceStress { namespace Test {
@ -33,6 +34,21 @@ namespace Azure { namespace PerformanceStress { namespace Test {
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const&) override {}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"NoOp",
"Simplest test to measure the performance framework speed.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::NoOp>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -38,6 +38,21 @@ namespace Azure { namespace PerformanceStress { namespace Test {
{
Details::HttpClient = std::make_unique<Azure::Core::Http::WinHttpTransport>();
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"winHttpClientGet",
"Send an Http Get request to a configurable url using winHttp.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::WinHttpClientGetTest>(options);
}};
}
};
}}} // namespace Azure::PerformanceStress::Test

View File

@ -1,8 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/performance-stress/options.hpp>
#include <azure/performance-stress/program.hpp>
#include <azure/performance_framework.hpp>
#include "azure/performance-stress/test/delay_test.hpp"
#include "azure/performance-stress/test/extended_options_test.hpp"
@ -15,47 +14,24 @@
#include "azure/performance-stress/test/exception_test.hpp"
#include "azure/performance-stress/test/no_op_test.hpp"
#include <functional>
#include <iostream>
#include <map>
#include <vector>
int main(int argc, char** argv)
{
// Create the test list
std::map<
std::string,
std::function<std::unique_ptr<Azure::PerformanceStress::PerformanceTest>(
Azure::PerformanceStress::TestOptions)>>
tests{
{"noOp",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::NoOp>(options);
}},
{"extendedOptions",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::ExtendedOptionsTest>(options);
}},
{"delay",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::DelayTest>(options);
}},
{"exception", [](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::PerformanceStress::Test::ExceptionTest>(options);
}}};
std::vector<Azure::PerformanceStress::TestMetadata> tests{
Azure::PerformanceStress::Test::NoOp::GetTestMetadata(),
Azure::PerformanceStress::Test::ExtendedOptionsTest::GetTestMetadata(),
Azure::PerformanceStress::Test::DelayTest::GetTestMetadata(),
Azure::PerformanceStress::Test::ExceptionTest::GetTestMetadata()};
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
tests.emplace("curlHttpClientGet", [](Azure::PerformanceStress::TestOptions options) {
// Another test
return std::make_unique<Azure::PerformanceStress::Test::CurlHttpClientGetTest>(options);
});
tests.emplace_back(Azure::PerformanceStress::Test::CurlHttpClientGetTest::GetTestMetadata());
#endif
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
tests.emplace("winHttpClientGet", [](Azure::PerformanceStress::TestOptions options) {
// Another test
return std::make_unique<Azure::PerformanceStress::Test::WinHttpClientGetTest>(options);
});
tests.emplace_back(Azure::PerformanceStress::Test::WinHttpClientGetTest::GetTestMetadata());
#endif
Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);

View File

@ -43,3 +43,7 @@ gtest_discover_tests(azure-identity-test
TEST_PREFIX azure-identity.
NO_PRETTY_TYPES
NO_PRETTY_VALUES)
if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(performance)
endif()

View File

@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
# Configure CMake project.
cmake_minimum_required (VERSION 3.13)
project(azure-identity-performance LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(
AZURE_IDENTITY_PERF_TEST_HEADER
inc/azure/identity/test/performance/secret_credential.hpp
)
set(
AZURE_IDENTITY_PERF_TEST_SOURCE
src/main.cpp
)
# Name the binary to be created.
add_executable (
azure-identity-performance
${AZURE_IDENTITY_PERF_TEST_HEADER} ${AZURE_IDENTITY_PERF_TEST_SOURCE}
)
# Include the headers from the project.
target_include_directories(
azure-identity-performance
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
)
# link the `azure-performance-stress` lib together with any other library which will be used for the tests.
target_link_libraries(azure-identity-performance PRIVATE azure-identity azure-performance-stress)
# Make sure the project will appear in the test folder for Visual Studio CMake view
set_target_properties(azure-identity-performance PROPERTIES FOLDER "Tests/Identity")

View File

@ -0,0 +1,99 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Test the overhead of authenticating with secret credential.
*
*/
#pragma once
#include <azure/performance_framework.hpp>
#include <azure/identity.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Identity { namespace Test { namespace Performance {
/**
* @brief A test to measure the authentication token performance.
*
*/
class SecretCredentialTest : public Azure::PerformanceStress::PerformanceTest {
private:
std::string m_tenantId;
std::string m_clientId;
std::string m_secret;
Azure::Core::Http::TokenRequestOptions m_scopes;
std::unique_ptr<Azure::Identity::ClientSecretCredential> m_credentail;
public:
/**
* @brief Get the Id and secret
*
*/
void Setup() override
{
m_tenantId = m_options.GetMandatoryOption<std::string>("TenantId");
m_clientId = m_options.GetMandatoryOption<std::string>("ClientId");
m_secret = m_options.GetMandatoryOption<std::string>("Secret");
m_scopes.Scopes.push_back(m_options.GetMandatoryOption<std::string>("Scope"));
m_credentail = std::make_unique<Azure::Identity::ClientSecretCredential>(
m_tenantId, m_clientId, m_secret);
}
/**
* @brief Construct a new SecretCredentialTest test.
*
* @param options The test options.
*/
SecretCredentialTest(Azure::PerformanceStress::TestOptions options) : PerformanceTest(options)
{
}
/**
* @brief Define the test
*
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const& context) override
{
auto t = m_credentail->GetToken(context, m_scopes);
}
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::PerformanceStress::TestOption> GetTestOptions() override
{
return {
{"TenantId", {"--tenantId"}, "The tenant Id for the authentication.", 1, true},
{"ClientId", {"--clientId"}, "The client Id for the authentication.", 1, true},
{"Secret", {"--secret"}, "The secret for authentication.", 1, true, true},
{"Scope", {"--scope"}, "One scope to request access to.", 1, true}};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"SecretCredential",
"Get a token using a secret client token credential.",
[](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::Identity::Test::Performance::SecretCredentialTest>(
options);
}};
}
};
}}}} // namespace Azure::Identity::Test::Performance

View File

@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/performance_framework.hpp>
#include "azure/identity/test/performance/secret_credential.hpp"
int main(int argc, char** argv)
{
// Create the test list
std::vector<Azure::PerformanceStress::TestMetadata> tests{
Azure::Identity::Test::Performance::SecretCredentialTest::GetTestMetadata()};
Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);
return 0;
}

View File

@ -51,3 +51,7 @@ gtest_discover_tests(azure-security-keyvault-keys-test-live
NO_PRETTY_TYPES
NO_PRETTY_VALUES
)
if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(performance)
endif()

View File

@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
# Configure CMake project.
cmake_minimum_required (VERSION 3.13)
project(azure-security-keyvault-keys-performance LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(
AZURE_KEYVAULT_KEY_PERF_TEST_HEADER
inc/azure/keyvault/keys/test/performance/get_key.hpp
)
set(
AZURE_KEYVAULT_KEY_PERF_TEST_SOURCE
src/main.cpp
)
# Name the binary to be created.
add_executable (
azure-security-keyvault-keys-performance
${AZURE_KEYVAULT_KEY_PERF_TEST_HEADER} ${AZURE_KEYVAULT_KEY_PERF_TEST_SOURCE}
)
# Include the headers from the project.
target_include_directories(
azure-security-keyvault-keys-performance
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
)
# link the `azure-performance-stress` lib together with any other library which will be used for the tests.
target_link_libraries(azure-security-keyvault-keys-performance PRIVATE azure-identity azure-security-keyvault-keys azure-performance-stress)
# Make sure the project will appear in the test folder for Visual Studio CMake view
set_target_properties(azure-security-keyvault-keys-performance PROPERTIES FOLDER "Tests/Keyvault")

View File

@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Test the overhead of getting a key.
*
*/
#pragma once
#include <azure/performance_framework.hpp>
#include <azure/identity.hpp>
#include <azure/keyvault/key_vault.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace Test {
namespace Performance {
/**
* @brief A test to measure getting a key performance.
*
*/
class GetKey : public Azure::PerformanceStress::PerformanceTest {
private:
std::string m_vaultUrl;
std::string m_keyName;
std::string m_tenantId;
std::string m_clientId;
std::string m_secret;
std::shared_ptr<Azure::Identity::ClientSecretCredential> m_credentail;
std::unique_ptr<Azure::Security::KeyVault::Keys::KeyClient> m_client;
public:
/**
* @brief Get the Ids and secret
*
*/
void Setup() override
{
m_vaultUrl = m_options.GetMandatoryOption<std::string>("vaultUrl");
m_keyName = m_options.GetMandatoryOption<std::string>("keyName");
m_tenantId = m_options.GetMandatoryOption<std::string>("TenantId");
m_clientId = m_options.GetMandatoryOption<std::string>("ClientId");
m_secret = m_options.GetMandatoryOption<std::string>("Secret");
m_credentail = std::make_shared<Azure::Identity::ClientSecretCredential>(
m_tenantId, m_clientId, m_secret);
m_client = std::make_unique<Azure::Security::KeyVault::Keys::KeyClient>(
m_vaultUrl, m_credentail);
}
/**
* @brief Construct a new GetKey test.
*
* @param options The test options.
*/
GetKey(Azure::PerformanceStress::TestOptions options) : PerformanceTest(options) {}
/**
* @brief Define the test
*
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const&) override { auto t = m_client->GetKey(m_keyName); }
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::PerformanceStress::TestOption> GetTestOptions() override
{
return {
{"vaultUrl", {"--vaultUrl"}, "The Key Vault Account.", 1, true},
{"keyName", {"--keyName"}, "The Key name to get.", 1, true},
{"TenantId", {"--tenantId"}, "The tenant Id for the authentication.", 1, true},
{"ClientId", {"--clientId"}, "The client Id for the authentication.", 1, true},
{"Secret", {"--secret"}, "The secret for authentication.", 1, true, true}};
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"GetKey", "Get a key", [](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::Security::KeyVault::Keys::Test::Performance::GetKey>(
options);
}};
}
};
}}}}}} // namespace Azure::Security::KeyVault::Keys::Test::Performance

View File

@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/performance_framework.hpp>
#include "azure/keyvault/keys/test/performance/get_key.hpp"
int main(int argc, char** argv)
{
// Create the test list
std::vector<Azure::PerformanceStress::TestMetadata> tests{
Azure::Security::KeyVault::Keys::Test::Performance::GetKey::GetTestMetadata()};
Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);
return 0;
}

View File

@ -113,3 +113,7 @@ if(BUILD_STORAGE_SAMPLES)
target_link_libraries(azure-storage-sample PRIVATE azure-storage-blobs)
endif()
if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(test/performance)
endif()

View File

@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
# Configure CMake project.
cmake_minimum_required (VERSION 3.13)
project(azure-storage-blobs-performance LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(
AZURE_STORAGE_BLOBS_PERF_TEST_HEADER
inc/azure/storage/blobs/test/performance/download_blob.hpp
)
set(
AZURE_STORAGE_BLOBS_PERF_TEST_SOURCE
src/main.cpp
)
# Name the binary to be created.
add_executable (
azure-storage-blobs-performance
${AZURE_STORAGE_BLOBS_PERF_TEST_HEADER} ${AZURE_STORAGE_BLOBS_PERF_TEST_SOURCE}
)
# Include the headers from the project.
target_include_directories(
azure-storage-blobs-performance
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
)
# link the `azure-performance-stress` lib together with any other library which will be used for the tests.
target_link_libraries(azure-storage-blobs-performance PRIVATE azure-storage-blobs azure-performance-stress)
# Make sure the project will appear in the test folder for Visual Studio CMake view
set_target_properties(azure-storage-blobs-performance PROPERTIES FOLDER "Tests/Storage")

View File

@ -0,0 +1,78 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Define the base bahavior of the tests using a blobs client.
*
*/
#pragma once
#include <azure/performance_framework.hpp>
#include <azure/storage/blobs.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Storage { namespace Blobs { namespace Test { namespace Performance {
/**
* @brief A base test that set up a blobs performance test.
*
*/
class BlobsTest : public Azure::PerformanceStress::PerformanceTest {
protected:
std::string m_containerName;
std::string m_blobName;
std::string m_connectionString;
std::unique_ptr<Azure::Storage::Blobs::BlobContainerClient> m_containerClient;
std::unique_ptr<Azure::Storage::Blobs::BlockBlobClient> m_blobClient;
public:
/**
* @brief Creat the container client
*
*/
void Setup() override
{
m_connectionString = m_options.GetMandatoryOption<std::string>("connectionString");
m_containerName = m_options.GetMandatoryOption<std::string>("ContainerName");
m_blobName = m_options.GetMandatoryOption<std::string>("BlobName");
m_containerClient = std::make_unique<Azure::Storage::Blobs::BlobContainerClient>(
Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
m_connectionString, m_containerName));
m_containerClient->CreateIfNotExists();
m_blobClient = std::make_unique<Azure::Storage::Blobs::BlockBlobClient>(
m_containerClient->GetBlockBlobClient(m_blobName));
}
/**
* @brief Construct a new BlobsTest test.
*
* @param options The test options.
*/
BlobsTest(Azure::PerformanceStress::TestOptions options) : PerformanceTest(options) {}
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::PerformanceStress::TestOption> GetTestOptions() override
{
return {
{"connectionString",
{"--connectionString"},
"The Storage account connection string.",
1,
true,
true},
{"ContainerName", {"--containerName"}, "The name of a blob container", 1, true},
{"BlobName", {"--blobName"}, "The name of a blob.", 1, true}};
}
};
}}}}} // namespace Azure::Storage::Blobs::Test::Performance

View File

@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Test the performance of downloading a block blob.
*
*/
#pragma once
#include <azure/performance_framework.hpp>
#include "azure/storage/blobs/test/performance/blob_base_test.hpp"
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Storage { namespace Blobs { namespace Test { namespace Performance {
/**
* @brief A test to measure downloading a blob.
*
*/
class DownloadBlob : public Azure::Storage::Blobs::Test::Performance::BlobsTest {
public:
/**
* @brief Construct a new DownloadBlob test.
*
* @param options The test options.
*/
DownloadBlob(Azure::PerformanceStress::TestOptions options) : BlobsTest(options) {}
/**
* @brief Define the test
*
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const&) override { auto blob = m_blobClient->Download(); }
/**
* @brief Define the test options for the test.
*
* @return The list of test options.
*/
std::vector<Azure::PerformanceStress::TestOption> GetTestOptions() override
{
return Azure::Storage::Blobs::Test::Performance::BlobsTest::GetTestOptions();
}
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
{
return {
"DownloadBlob", "Download a blob.", [](Azure::PerformanceStress::TestOptions options) {
return std::make_unique<Azure::Storage::Blobs::Test::Performance::DownloadBlob>(
options);
}};
}
};
}}}}} // namespace Azure::Storage::Blobs::Test::Performance

View File

@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/performance_framework.hpp>
#include "azure/storage/blobs/test/performance/download_blob.hpp"
int main(int argc, char** argv)
{
// Create the test list
std::vector<Azure::PerformanceStress::TestMetadata> tests{
Azure::Storage::Blobs::Test::Performance::DownloadBlob::GetTestMetadata()};
Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);
return 0;
}