diff --git a/sdk/core/azure-core/CMakeLists.txt b/sdk/core/azure-core/CMakeLists.txt index a0be63fb3..7a8bda523 100644 --- a/sdk/core/azure-core/CMakeLists.txt +++ b/sdk/core/azure-core/CMakeLists.txt @@ -140,3 +140,7 @@ az_vcpkg_export( CORE "azure/core/dll_import_export.hpp" ) + +if (BUILD_PERFORMANCE_TESTS) + add_subdirectory(test/performance) +endif() diff --git a/sdk/core/azure-core/test/performance/CMakeLists.txt b/sdk/core/azure-core/test/performance/CMakeLists.txt new file mode 100644 index 000000000..f737a2c55 --- /dev/null +++ b/sdk/core/azure-core/test/performance/CMakeLists.txt @@ -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 + $ +) + +# 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") diff --git a/sdk/core/azure-core/test/performance/inc/azure/core/test/performance/nullable.hpp b/sdk/core/azure-core/test/performance/inc/azure/core/test/performance/nullable.hpp new file mode 100644 index 000000000..e68298cc4 --- /dev/null +++ b/sdk/core/azure-core/test/performance/inc/azure/core/test/performance/nullable.hpp @@ -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 + +#include + +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 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(options); + }}; + } + }; + +}}}} // namespace Azure::Core::Test::Performance diff --git a/sdk/core/azure-core/test/performance/src/main.cpp b/sdk/core/azure-core/test/performance/src/main.cpp new file mode 100644 index 000000000..6e9433f58 --- /dev/null +++ b/sdk/core/azure-core/test/performance/src/main.cpp @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +#include "azure/core/test/performance/nullable.hpp" + +#include + +int main(int argc, char** argv) +{ + + // Create the test list + std::vector tests{ + Azure::Core::Test::Performance::NullableTest::GetTestMetadata()}; + + Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv); + + return 0; +} diff --git a/sdk/core/performance-stress/CMakeLists.txt b/sdk/core/performance-stress/CMakeLists.txt index 48bbb9396..e406719e8 100644 --- a/sdk/core/performance-stress/CMakeLists.txt +++ b/sdk/core/performance-stress/CMakeLists.txt @@ -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 ) diff --git a/sdk/core/performance-stress/inc/azure/performance-stress/program.hpp b/sdk/core/performance-stress/inc/azure/performance-stress/program.hpp index 7ce113b2e..daecab40c 100644 --- a/sdk/core/performance-stress/inc/azure/performance-stress/program.hpp +++ b/sdk/core/performance-stress/inc/azure/performance-stress/program.hpp @@ -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 -#include -#include -#include -#include +#include 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( - Azure::PerformanceStress::TestOptions)>> const& tests, + std::vector const& tests, int argc, char** argv); }; diff --git a/sdk/core/performance-stress/inc/azure/performance-stress/test_metadata.hpp b/sdk/core/performance-stress/inc/azure/performance-stress/test_metadata.hpp new file mode 100644 index 000000000..207dfa943 --- /dev/null +++ b/sdk/core/performance-stress/inc/azure/performance-stress/test_metadata.hpp @@ -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 +#include +#include + +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( + Azure::PerformanceStress::TestOptions)> + Factory; + }; +}} // namespace Azure::PerformanceStress diff --git a/sdk/core/performance-stress/inc/azure/performance-stress/test_options.hpp b/sdk/core/performance-stress/inc/azure/performance-stress/test_options.hpp index 768acdb4c..cc88c1db4 100644 --- a/sdk/core/performance-stress/inc/azure/performance-stress/test_options.hpp +++ b/sdk/core/performance-stress/inc/azure/performance-stress/test_options.hpp @@ -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 diff --git a/sdk/core/performance-stress/inc/azure/performance_framework.hpp b/sdk/core/performance-stress/inc/azure/performance_framework.hpp new file mode 100644 index 000000000..91ee3f80d --- /dev/null +++ b/sdk/core/performance-stress/inc/azure/performance_framework.hpp @@ -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" diff --git a/sdk/core/performance-stress/src/program.cpp b/sdk/core/performance-stress/src/program.cpp index e75e36ec7..5ff55892c 100644 --- a/sdk/core/performance-stress/src/program.cpp +++ b/sdk/core/performance-stress/src/program.cpp @@ -14,26 +14,19 @@ namespace { inline std::unique_ptr PrintAvailableTests( - std::map< - std::string, - std::function( - Azure::PerformanceStress::TestOptions)>> const& tests) + std::vector 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( - Azure::PerformanceStress::TestOptions)> -GetTest( - std::map< - std::string, - std::function( - Azure::PerformanceStress::TestOptions)>> const& tests, +inline Azure::PerformanceStress::TestMetadata const* GetTestMetadata( + std::vector 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(); + optionsAsJson[option.Name] + = option.sensitiveData ? "***" : parsedArgs[option.Name].as(); } 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( - Azure::PerformanceStress::TestOptions)>> const& tests, + std::vector 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); diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/curl_http_client_get_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/curl_http_client_get_test.hpp index 01991a4c5..5e13d51f3 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/curl_http_client_get_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/curl_http_client_get_test.hpp @@ -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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/delay_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/delay_test.hpp index 819cf978c..361e2b772 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/delay_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/delay_test.hpp @@ -9,12 +9,11 @@ #pragma once -#include -#include -#include +#include #include #include +#include #include #include @@ -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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/exception_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/exception_test.hpp index c82a10bfd..a50efb488 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/exception_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/exception_test.hpp @@ -10,8 +10,9 @@ #pragma once -#include -#include +#include + +#include 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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/extended_options_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/extended_options_test.hpp index db0f30cc7..6a9de8949 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/extended_options_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/extended_options_test.hpp @@ -9,10 +9,9 @@ #pragma once -#include -#include -#include +#include +#include #include 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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/http_client_get_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/http_client_get_test.hpp index a7e9d669a..c3b1f404b 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/http_client_get_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/http_client_get_test.hpp @@ -9,9 +9,7 @@ #pragma once -#include -#include -#include +#include #include #include diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/no_op_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/no_op_test.hpp index c91bdae95..23452d92a 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/no_op_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/no_op_test.hpp @@ -9,8 +9,9 @@ #pragma once -#include -#include +#include + +#include 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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/win_http_client_get_test.hpp b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/win_http_client_get_test.hpp index e5ec05801..dc0f70928 100644 --- a/sdk/core/performance-stress/test/inc/azure/performance-stress/test/win_http_client_get_test.hpp +++ b/sdk/core/performance-stress/test/inc/azure/performance-stress/test/win_http_client_get_test.hpp @@ -38,6 +38,21 @@ namespace Azure { namespace PerformanceStress { namespace Test { { Details::HttpClient = std::make_unique(); } + + /** + * @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(options); + }}; + } }; }}} // namespace Azure::PerformanceStress::Test diff --git a/sdk/core/performance-stress/test/src/main.cpp b/sdk/core/performance-stress/test/src/main.cpp index 503701cb8..e1033715b 100644 --- a/sdk/core/performance-stress/test/src/main.cpp +++ b/sdk/core/performance-stress/test/src/main.cpp @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include -#include +#include #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 -#include -#include +#include int main(int argc, char** argv) { // Create the test list - std::map< - std::string, - std::function( - Azure::PerformanceStress::TestOptions)>> - tests{ - {"noOp", - [](Azure::PerformanceStress::TestOptions options) { - return std::make_unique(options); - }}, - {"extendedOptions", - [](Azure::PerformanceStress::TestOptions options) { - return std::make_unique(options); - }}, - {"delay", - [](Azure::PerformanceStress::TestOptions options) { - return std::make_unique(options); - }}, - {"exception", [](Azure::PerformanceStress::TestOptions options) { - return std::make_unique(options); - }}}; + std::vector 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(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(options); - }); + tests.emplace_back(Azure::PerformanceStress::Test::WinHttpClientGetTest::GetTestMetadata()); #endif Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv); diff --git a/sdk/identity/azure-identity/test/CMakeLists.txt b/sdk/identity/azure-identity/test/CMakeLists.txt index ca722938a..13a8036aa 100644 --- a/sdk/identity/azure-identity/test/CMakeLists.txt +++ b/sdk/identity/azure-identity/test/CMakeLists.txt @@ -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() diff --git a/sdk/identity/azure-identity/test/performance/CMakeLists.txt b/sdk/identity/azure-identity/test/performance/CMakeLists.txt new file mode 100644 index 000000000..1bcef5ccf --- /dev/null +++ b/sdk/identity/azure-identity/test/performance/CMakeLists.txt @@ -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 + $ +) + +# 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") diff --git a/sdk/identity/azure-identity/test/performance/inc/azure/identity/test/performance/secret_credential.hpp b/sdk/identity/azure-identity/test/performance/inc/azure/identity/test/performance/secret_credential.hpp new file mode 100644 index 000000000..57b84dbdc --- /dev/null +++ b/sdk/identity/azure-identity/test/performance/inc/azure/identity/test/performance/secret_credential.hpp @@ -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 + +#include + +#include +#include +#include + +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 m_credentail; + + public: + /** + * @brief Get the Id and secret + * + */ + void Setup() override + { + m_tenantId = m_options.GetMandatoryOption("TenantId"); + m_clientId = m_options.GetMandatoryOption("ClientId"); + m_secret = m_options.GetMandatoryOption("Secret"); + m_scopes.Scopes.push_back(m_options.GetMandatoryOption("Scope")); + m_credentail = std::make_unique( + 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 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( + options); + }}; + } + }; + +}}}} // namespace Azure::Identity::Test::Performance diff --git a/sdk/identity/azure-identity/test/performance/src/main.cpp b/sdk/identity/azure-identity/test/performance/src/main.cpp new file mode 100644 index 000000000..a821c24c2 --- /dev/null +++ b/sdk/identity/azure-identity/test/performance/src/main.cpp @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +#include "azure/identity/test/performance/secret_credential.hpp" + +int main(int argc, char** argv) +{ + + // Create the test list + std::vector tests{ + Azure::Identity::Test::Performance::SecretCredentialTest::GetTestMetadata()}; + + Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv); + + return 0; +} diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/test/CMakeLists.txt index d8bed34c9..24749a62c 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/test/CMakeLists.txt @@ -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() diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/performance/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/test/performance/CMakeLists.txt new file mode 100644 index 000000000..ea492da40 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/performance/CMakeLists.txt @@ -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 + $ +) + +# 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") diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/performance/inc/azure/keyvault/keys/test/performance/get_key.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/performance/inc/azure/keyvault/keys/test/performance/get_key.hpp new file mode 100644 index 000000000..fd93645fc --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/performance/inc/azure/keyvault/keys/test/performance/get_key.hpp @@ -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 + +#include +#include + +#include +#include +#include + +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 m_credentail; + std::unique_ptr m_client; + + public: + /** + * @brief Get the Ids and secret + * + */ + void Setup() override + { + m_vaultUrl = m_options.GetMandatoryOption("vaultUrl"); + m_keyName = m_options.GetMandatoryOption("keyName"); + m_tenantId = m_options.GetMandatoryOption("TenantId"); + m_clientId = m_options.GetMandatoryOption("ClientId"); + m_secret = m_options.GetMandatoryOption("Secret"); + m_credentail = std::make_shared( + m_tenantId, m_clientId, m_secret); + m_client = std::make_unique( + 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 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( + options); + }}; + } + }; + +}}}}}} // namespace Azure::Security::KeyVault::Keys::Test::Performance diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/performance/src/main.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/performance/src/main.cpp new file mode 100644 index 000000000..b92f6d06f --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/performance/src/main.cpp @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +#include "azure/keyvault/keys/test/performance/get_key.hpp" + +int main(int argc, char** argv) +{ + + // Create the test list + std::vector tests{ + Azure::Security::KeyVault::Keys::Test::Performance::GetKey::GetTestMetadata()}; + + Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv); + + return 0; +} diff --git a/sdk/storage/azure-storage-blobs/CMakeLists.txt b/sdk/storage/azure-storage-blobs/CMakeLists.txt index 30bc33eca..e2ecce8dc 100644 --- a/sdk/storage/azure-storage-blobs/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/CMakeLists.txt @@ -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() diff --git a/sdk/storage/azure-storage-blobs/test/performance/CMakeLists.txt b/sdk/storage/azure-storage-blobs/test/performance/CMakeLists.txt new file mode 100644 index 000000000..5985075df --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/performance/CMakeLists.txt @@ -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 + $ +) + +# 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") diff --git a/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/blob_base_test.hpp b/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/blob_base_test.hpp new file mode 100644 index 000000000..5764a024f --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/blob_base_test.hpp @@ -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 + +#include + +#include +#include +#include + +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 m_containerClient; + std::unique_ptr m_blobClient; + + public: + /** + * @brief Creat the container client + * + */ + void Setup() override + { + m_connectionString = m_options.GetMandatoryOption("connectionString"); + m_containerName = m_options.GetMandatoryOption("ContainerName"); + m_blobName = m_options.GetMandatoryOption("BlobName"); + m_containerClient = std::make_unique( + Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString( + m_connectionString, m_containerName)); + m_containerClient->CreateIfNotExists(); + m_blobClient = std::make_unique( + 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 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 diff --git a/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/download_blob.hpp b/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/download_blob.hpp new file mode 100644 index 000000000..6c1c5723e --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/performance/inc/azure/storage/blobs/test/performance/download_blob.hpp @@ -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 + +#include "azure/storage/blobs/test/performance/blob_base_test.hpp" + +#include +#include +#include + +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 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( + options); + }}; + } + }; + +}}}}} // namespace Azure::Storage::Blobs::Test::Performance diff --git a/sdk/storage/azure-storage-blobs/test/performance/src/main.cpp b/sdk/storage/azure-storage-blobs/test/performance/src/main.cpp new file mode 100644 index 000000000..681b69a11 --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/performance/src/main.cpp @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +#include "azure/storage/blobs/test/performance/download_blob.hpp" + +int main(int argc, char** argv) +{ + + // Create the test list + std::vector tests{ + Azure::Storage::Blobs::Test::Performance::DownloadBlob::GetTestMetadata()}; + + Azure::PerformanceStress::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv); + + return 0; +}