Skip to content

Commit

Permalink
Rename and structure unit test and perf tests (#1706)
Browse files Browse the repository at this point in the history
* Rename and structure unit test and perf tests
  • Loading branch information
vhvb1989 authored Feb 23, 2021
1 parent f9eea4d commit b7de244
Show file tree
Hide file tree
Showing 95 changed files with 749 additions and 734 deletions.
18 changes: 2 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,8 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(BUILD_TESTING)
# define a symbol that enables some test hooks in code
add_compile_definitions(TESTING_BUILD)
if(RUN_LONG_UNIT_TESTS)
add_compile_definitions(RUN_LONG_UNIT_TESTS)
endif()

# tests
include(AddGoogleTest)
enable_testing ()
add_subdirectory(sdk/core/azure-core/test/ut)
# Set `AZURE_CORE_ENABLE_JSON_TESTS` env var to run Json tests
if(DEFINED ENV{AZURE_CORE_ENABLE_JSON_TESTS})
add_subdirectory(sdk/core/azure-core/test/nlohmann-json-test)
endif()

add_subdirectory(sdk/identity/azure-identity/test)
include(AddGoogleTest)
enable_testing ()
endif()

# compiler warning flags globally
Expand Down
2 changes: 1 addition & 1 deletion cmake-modules/DownloadJsonTestData.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ message(STATUS "Operating system: ${OS_VERSION_STRINGS}")
# determine the compiler (for debug and support purposes)
if (MSVC)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} OUTPUT_VARIABLE CXX_VERSION_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_VARIABLE CXX_VERSION_RESULT ERROR_STRIP_TRAILING_WHITESPACE)
set(CMAKE_CXX_COMPILER "${CXX_VERSION_RESULT}; MSVC_VERSION=${MSVC_VERSION}; MSVC_TOOLSET_VERSION=${MSVC_TOOLSET_VERSION}")
set(CXX_VERSION_RESULT "${CXX_VERSION_RESULT}; MSVC_VERSION=${MSVC_VERSION}; MSVC_TOOLSET_VERSION=${MSVC_TOOLSET_VERSION}")
else()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE CXX_VERSION_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory(azure-core)
if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(performance-stress)
add_subdirectory(perf)
endif()
17 changes: 16 additions & 1 deletion sdk/core/azure-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ az_vcpkg_export(
"azure/core/dll_import_export.hpp"
)

if(BUILD_TESTING)
# define a symbol that enables some test hooks in code
add_compile_definitions(TESTING_BUILD)

if (NOT AZ_ALL_LIBRARIES)
include(AddGoogleTest)
enable_testing ()
endif()

add_subdirectory(test/ut)
if(DEFINED ENV{AZURE_CORE_ENABLE_JSON_TESTS})
add_subdirectory(test/nlohmann-json-test)
endif()
endif()

if (BUILD_PERFORMANCE_TESTS)
add_subdirectory(test/performance)
add_subdirectory(test/perf)
endif()
4 changes: 4 additions & 0 deletions sdk/core/azure-core/test/nlohmann-json-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set_tests_properties(download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA)
#############################################################################

add_library(doctest_main OBJECT src/unit.cpp)
# Remove global compile options from this target.
set_target_properties(doctest_main PROPERTIES COMPILE_OPTIONS "")
set_target_properties(doctest_main PROPERTIES
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
Expand Down Expand Up @@ -93,6 +95,8 @@ foreach(file ${files})
string(REGEX REPLACE "unit-([^$]+)" "json-test-\\1" testcase ${file_basename})

add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
# Remove global compile options from this target.
set_target_properties(${testcase} PROPERTIES COMPILE_OPTIONS "")
target_compile_definitions(${testcase} PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
target_compile_options(${testcase} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

# Configure CMake project.
cmake_minimum_required (VERSION 3.13)
project(azure-core-performance LANGUAGES CXX)
project(azure-core-perf 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
inc/azure/core/test/nullable.hpp
)

set(
Expand All @@ -19,18 +19,18 @@ set(

# Name the binary to be created.
add_executable (
azure-core-performance
azure-core-perf
${AZURE_CORE_PERF_TEST_HEADER} ${AZURE_CORE_PERF_TEST_SOURCE}
)

# Include the headers from the project.
target_include_directories(
azure-core-performance
azure-core-perf
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)
# link the `azure-perf` lib together with any other library which will be used for the tests.
target_link_libraries(azure-core-perf PRIVATE azure-core azure-perf)
# 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")
set_target_properties(azure-core-perf PROPERTIES FOLDER "Tests/Core")
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@

#pragma once

#include <azure/performance_framework.hpp>
#include <azure/perf.hpp>

#include <memory>

namespace Azure { namespace Core { namespace Test { namespace Performance {
namespace Azure { namespace Core { namespace Test {

/**
* @brief Measure the Nullable object performance.
*
*/
class NullableTest : public Azure::PerformanceStress::PerformanceTest {
class NullableTest : public Azure::Perf::PerfTest {
public:
/**
* @brief Construct a new Nullable test.
*
* @param options The test options.
*/
NullableTest(Azure::PerformanceStress::TestOptions options) : PerformanceTest(options) {}
NullableTest(Azure::Perf::TestOptions options) : PerfTest(options) {}

/**
* @brief Use NUllable to assing and read.
*
* @param ctx The cancellation token.
*/
void Run(Azure::Core::Context const&) override
{
Expand All @@ -58,17 +57,17 @@ namespace Azure { namespace Core { namespace Test { namespace Performance {
/**
* @brief Get the static Test Metadata for the test.
*
* @return Azure::PerformanceStress::TestMetadata describing the test.
* @return Azure::Perf::TestMetadata describing the test.
*/
static Azure::PerformanceStress::TestMetadata GetTestMetadata()
static Azure::Perf::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);
[](Azure::Perf::TestOptions options) {
return std::make_unique<Azure::Core::Test::NullableTest>(options);
}};
}
};

}}}} // namespace Azure::Core::Test::Performance
}}} // namespace Azure::Core::Test
19 changes: 19 additions & 0 deletions sdk/core/azure-core/test/perf/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT

#include <azure/perf.hpp>

#include "azure/core/test/nullable.hpp"

#include <vector>

int main(int argc, char** argv)
{

// Create the test list
std::vector<Azure::Perf::TestMetadata> tests{Azure::Core::Test::NullableTest::GetTestMetadata()};

Azure::Perf::Program::Run(Azure::Core::GetApplicationContext(), tests, argc, argv);

return 0;
}
20 changes: 0 additions & 20 deletions sdk/core/azure-core/test/performance/src/main.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion sdk/core/azure-core/test/ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ if (MSVC)
# - 'testing::internal::Mutex::StaticConstructorSelector'
# - 'testing::TestPartResult::Type'
# is unscoped. Prefer 'enum class' over 'enum' (Enum.3)
target_compile_options(azure-core-test PUBLIC /wd26495 /wd26812)
# - C6323: Google comparisons
target_compile_options(azure-core-test PUBLIC /wd26495 /wd26812 /wd6326 /wd28204 /wd28020 /wd6330 /wd4389)
endif()

# Adding private headers from CORE to the tests so we can test the private APIs with no relative paths include.
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/test/ut/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(Base64, Basic)
int maxLength = 7;

std::vector<uint8_t> data;
for (int i = 0; i < maxLength; i++)
for (uint8_t i = 0; i < maxLength; i++)
{
data.push_back(i + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/test/ut/bodystream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace Azure::Core;

// Used to test virtual, default behavior of BodyStream.
class TestBodyStream : public Http::BodyStream {
int64_t OnRead(Context const& context, uint8_t* buffer, int64_t count) override { return 0; }
int64_t OnRead(Context const&, uint8_t*, int64_t) override { return 0; }
int64_t Length() const override { return 0; }
};

Expand Down
17 changes: 17 additions & 0 deletions sdk/core/azure-core/test/ut/curl_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*
*/

#ifdef _MSC_VER
#pragma warning(push)
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) // !_MSC_VER
#pragma GCC diagnostic push
#elif defined(__clang__) // !_MSC_VER !__clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif // _MSC_VER

#include <azure/core/http/curl/curl.hpp>
#include <curl/curl.h>
#include <gmock/gmock.h>
Expand Down Expand Up @@ -50,3 +59,11 @@ namespace Azure { namespace Core { namespace Test {
};

}}} // namespace Azure::Core::Test

#ifdef _MSC_VER
#pragma warning(pop)
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) // !_MSC_VER
#pragma GCC diagnostic pop
#elif defined(__clang__) // !_MSC_VER !__clang__
#pragma clang diagnostic pop // NOLINT(clang-diagnostic-unknown-pragmas)
#endif // _MSC_VER
6 changes: 3 additions & 3 deletions sdk/core/azure-core/test/ut/curl_session_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ namespace Azure { namespace Core { namespace Test {
request, std::move(uniqueCurlMock), true);

EXPECT_NO_THROW(session->Perform(Azure::Core::GetApplicationContext()));
auto response = session->GetResponse();
response->SetBodyStream(std::move(session));
auto bodyS = response->GetBodyStream();
auto r = session->GetResponse();
r->SetBodyStream(std::move(session));
auto bodyS = r->GetBodyStream();

// Read the bodyStream to get all chunks
EXPECT_THROW(
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core/test/ut/operation_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Azure { namespace Core { namespace Test {
int m_count = 0;

private:
std::unique_ptr<Http::RawResponse> PollInternal(Context& context) override
std::unique_ptr<Http::RawResponse> PollInternal(Context&) override
{
// Artificial delay to require 2 polls
if (++m_count == 2)
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace Azure { namespace Core { namespace Test {
}

public:
StringOperation(StringClient* client) : m_client(client) {}
StringOperation(StringClient* client) : m_client(client) { (void)m_client; }

std::string GetResumeToken() const override { return m_operationToken; }

Expand Down
17 changes: 17 additions & 0 deletions sdk/core/azure-core/test/ut/simplified_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
*
*/

#ifdef _MSC_VER
#pragma warning(push)
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) // !_MSC_VER
#pragma GCC diagnostic push
#elif defined(__clang__) // !_MSC_VER !__clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#endif // _MSC_VER

#include <azure/core.hpp>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -40,3 +49,11 @@ TEST(SimplifiedHeader, core)
}
EXPECT_NO_THROW(Azure::Core::Http::TelemetryPolicy tp("", ""));
}

#ifdef _MSC_VER
#pragma warning(pop)
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) // !_MSC_VER
#pragma GCC diagnostic pop
#elif defined(__clang__) // !_MSC_VER !__clang__
#pragma clang diagnostic pop // NOLINT(clang-diagnostic-unknown-pragmas)
#endif // _MSC_VER
4 changes: 2 additions & 2 deletions sdk/core/azure-core/test/ut/transport_adapter_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ namespace Azure { namespace Core { namespace Test {
// if ref can't be cast, it throws
EXPECT_NO_THROW((void)dynamic_cast<Azure::Core::Http::TransportException&>(err));
EXPECT_NO_THROW((void)dynamic_cast<std::runtime_error&>(err));
EXPECT_THROW(dynamic_cast<std::range_error&>(err), std::bad_cast);
EXPECT_THROW((void)dynamic_cast<std::range_error&>(err), std::bad_cast);
}
}

Expand Down Expand Up @@ -599,7 +599,7 @@ namespace Azure { namespace Core { namespace Test {

if (size > 0)
{ // only for known body size
EXPECT_EQ(bodyVector.size(), size);
EXPECT_EQ(bodyVector.size(), static_cast<size_t>(size));
}

if (expectedBody.size() > 0)
Expand Down
1 change: 0 additions & 1 deletion sdk/core/azure-core/test/ut/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ namespace Azure { namespace Core { namespace Test {

TEST(URL, query_parameter_encode_decode)
{
Http::HttpMethod httpMethod = Http::HttpMethod::Put;
Http::Url url("http://test.com");
EXPECT_NO_THROW(url.AppendQueryParameter("query", Http::Url::Encode("va=lue")));

Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core/test/ut/uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(Uuid, separatorPosition)
auto uuidKey = Uuid::CreateUuid().ToString();
// validate expected format '8-4-4-4-12'
EXPECT_PRED5(
[](std::string const& uuidKey, char pos1, char pos2, char pos3, char pos4) {
[](std::string const&, char pos1, char pos2, char pos3, char pos4) {
return pos1 == pos2 && pos1 == pos3 && pos1 == pos4 && pos1 == '-';
},
uuidKey,
Expand All @@ -50,7 +50,7 @@ TEST(Uuid, validChars)
EXPECT_PRED2(
[](std::string const& uuidKey, int expectedSeparators) {
int separatorsCount = 0;
for (int index = 0; index < uuidKey.size(); index++)
for (size_t index = 0; index < uuidKey.size(); index++)
{
if (uuidKey[index] == '-')
{
Expand Down
Loading

0 comments on commit b7de244

Please sign in to comment.