Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Port Envoy tests to windows #17

Open
wants to merge 6 commits into
base: win32_port
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ include_directories(${ENVOY_DEPENDENCIES_ROOT}/gens/prometheus)
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/gens/lib/debug")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/debug/lib")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows/debug/lib")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/debug/lib/manual-link")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/gens/lib")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/lib")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows/lib")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/lib/manual-link")

if (MSVC)
foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
Expand All @@ -41,3 +43,4 @@ if (MSVC)
endif(MSVC)

add_subdirectory(source)
add_subdirectory(test)
4 changes: 2 additions & 2 deletions source/common/filesystem/filesystem_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ bool directoryExists(const std::string& path) {
#endif
}

std::string fileReadToEnd(const std::string& path) {
std::string fileReadToEnd(const std::string& path, std::ios_base::openmode mode) {
std::ios::sync_with_stdio(false);

std::ifstream file(path);
std::ifstream file(path, mode);
if (!file) {
throw EnvoyException(fmt::format("unable to read file: {}", path));
}
Expand Down
2 changes: 1 addition & 1 deletion source/common/filesystem/filesystem_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool directoryExists(const std::string& path);
* @return full file content as a string.
* Be aware, this is not most highly performing file reading method.
*/
std::string fileReadToEnd(const std::string& path);
std::string fileReadToEnd(const std::string& path, std::ios_base::openmode mode = std::ios_base::in);

/**
* This is a file implementation geared for writing out access logs. It turn out that in certain
Expand Down
2 changes: 2 additions & 0 deletions source/common/filter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ add_library(ratelimit_lib_filter ratelimit.cc)
add_library(tcp_proxy_lib tcp_proxy.cc)

add_subdirectory(auth)
add_subdirectory(listener)

3 changes: 3 additions & 0 deletions source/common/filter/listener/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(original_dst_lib original_dst.cc)

add_library(proxy_protocol_lib proxy_protocol.cc)
2 changes: 2 additions & 0 deletions source/common/filter/listener/proxy_protocol.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "common/filter/listener/proxy_protocol.h"

#if !defined(WIN32)
#include <unistd.h>
#endif

#include <cstdint>
#include <memory>
Expand Down
18 changes: 18 additions & 0 deletions source/common/network/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,32 @@ void ConnectionImpl::noDelay(bool enable) {
}

// Don't set NODELAY for unix domain sockets
#if defined(WIN32)
// AF_UNIX is now supported on windows as well, hence keeping this logic.
// With sockaddr, getsockname returns 10014 for IPV6 addresses.
// Use sockaddr_storage since it is sufficiently large to store address information for IPv4, IPv6, or other address families.
// TODO: Can use this on linux as well instead of sockaddr
sockaddr_storage addr;
socklen_t len = sizeof(addr);

int rc = getsockname(fd(), (struct sockaddr *)&addr, &len);
RELEASE_ASSERT(rc == 0);

if (addr.ss_family == AF_UNIX) {
return;
}
#else
// Don't set NODELAY for unix domain sockets
sockaddr addr;
socklen_t len = sizeof(addr);

int rc = getsockname(fd(), &addr, &len);
RELEASE_ASSERT(rc == 0);

if (addr.sa_family == AF_UNIX) {
return;
}
#endif

// Set NODELAY
int new_value = enable;
Expand Down
13 changes: 4 additions & 9 deletions source/common/ssl/context_config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@ namespace Ssl {
const std::string ContextConfigImpl::DEFAULT_CIPHER_SUITES =
"[ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-CHACHA20-POLY1305]:"
"[ECDHE-RSA-AES128-GCM-SHA256|ECDHE-RSA-CHACHA20-POLY1305]:"
"ECDHE-ECDSA-AES128-SHA256:"
"ECDHE-RSA-AES128-SHA256:"
"ECDHE-ECDSA-AES128-SHA:"
"ECDHE-RSA-AES128-SHA:"
"AES128-GCM-SHA256:"
"AES128-SHA256:"
"AES128-SHA:"
"ECDHE-ECDSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES256-GCM-SHA384:"
"ECDHE-ECDSA-AES256-SHA384:"
"ECDHE-RSA-AES256-SHA384:"
"ECDHE-ECDSA-AES256-SHA:"
"ECDHE-RSA-AES256-SHA:"
"AES256-GCM-SHA384:"
"AES256-SHA256:"
"AES256-SHA";

const std::string ContextConfigImpl::DEFAULT_ECDH_CURVES = "X25519:P-256";
Expand Down Expand Up @@ -77,10 +71,11 @@ ContextConfigImpl::ContextConfigImpl(const envoy::api::v2::CommonTlsContext& con
}

const std::string ContextConfigImpl::readDataSource(const envoy::api::v2::DataSource& source,
bool allow_empty) {
bool allow_empty,
std::ios_base::openmode mode) {
switch (source.specifier_case()) {
case envoy::api::v2::DataSource::kFilename:
return Filesystem::fileReadToEnd(source.filename());
return Filesystem::fileReadToEnd(source.filename(), mode);
case envoy::api::v2::DataSource::kInlineBytes:
return source.inline_bytes();
case envoy::api::v2::DataSource::kInlineString:
Expand Down Expand Up @@ -142,7 +137,7 @@ ServerContextConfigImpl::ServerContextConfigImpl(const envoy::api::v2::Downstrea
switch (config.session_ticket_keys_type_case()) {
case envoy::api::v2::DownstreamTlsContext::kSessionTicketKeys:
for (const auto& datasource : config.session_ticket_keys().keys()) {
validateAndAppendKey(ret, readDataSource(datasource, false));
validateAndAppendKey(ret, readDataSource(datasource, false, std::ios_base::binary));
}
break;
case envoy::api::v2::DownstreamTlsContext::kSessionTicketKeysSdsSecretConfig:
Expand Down
3 changes: 2 additions & 1 deletion source/common/ssl/context_config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ContextConfigImpl : public virtual Ssl::ContextConfig {
ContextConfigImpl(const envoy::api::v2::CommonTlsContext& config);

static const std::string readDataSource(const envoy::api::v2::DataSource& source,
bool allow_empty);
bool allow_empty,
std::ios_base::openmode mode = std::ios_base::in);
static const std::string getDataSourcePath(const envoy::api::v2::DataSource& source);

private:
Expand Down
1 change: 1 addition & 0 deletions source/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_library(watchdog_lib watchdog_impl.cc)

add_library(worker_lib worker_impl.cc)

add_subdirectory(config/access_log)
add_subdirectory(config/http)
add_subdirectory(config/network)
add_subdirectory(config_validation)
Expand Down
3 changes: 3 additions & 0 deletions source/server/config/access_log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project(server_config_access_log)

add_library(file_access_log_lib file_access_log.cc)
27 changes: 27 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include_directories(${PROJECT_SOURCE_DIR})

add_library(test_main main.cc)
target_link_libraries(test_main
thread_lib
libevent_lib
environment_lib
printers_lib
version_lib
test_common_utility_lib
)

target_link_libraries(test_main
debug gmockd.lib
debug gtestd.lib
)

target_link_libraries(test_main
optimized gmock.lib
optimized gtest.lib
)

add_subdirectory(common)
add_subdirectory(test_common)
add_subdirectory(mocks)
#add_subdirectory(proto)
#add_subdirectory(integration)
33 changes: 33 additions & 0 deletions test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
add_subdirectory(access_log)
add_subdirectory(api)
add_subdirectory(buffer)
add_subdirectory(common)
add_subdirectory(config)
#TBD add_subdirectory(dynamo)
add_subdirectory(event)
add_subdirectory(filesystem)
#TBD add_subdirectory(filter)
#TBD add_subdirectory(grpc)
add_subdirectory(html)
add_subdirectory(http)
add_subdirectory(json)
add_subdirectory(network)
add_subdirectory(protobuf)
add_subdirectory(ratelimit)
add_subdirectory(request_info)
add_subdirectory(router)
#TBD add_subdirectory(runtime)
#TBD add_subdirectory(singleton)
add_subdirectory(ssl)
#TBD add_subdirectory(stats)
add_subdirectory(thread_local)
add_subdirectory(tracing)
add_subdirectory(upstream)


#TODO Source not compiled for Win32, hence skipping test folders
#add_subdirectory(compressor)
#add_subdirectory(decompressor)
#add_subdirectory(local_info)
#add_subdirectory(mongo)
#add_subdirectory(redis)
108 changes: 108 additions & 0 deletions test/common/access_log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
add_executable(access_log_impl_test access_log_impl_test.cc)
target_link_libraries(access_log_impl_test
access_log_lib
filter_json_lib
utility_lib

access_log_mocks
event_mocks
filesystem_mocks
runtime_mocks
server_mocks
upstream_mocks
test_common_utility_lib

#dependencies
logger_lib
config_utility_lib
http_utility_lib
uuid_util_lib
http_tracer_lib
well_known_names_lib
hex_lib
filesystem_lib
common_lib
config_schemas_lib
utility_lib_protobuf
stats_lib
buffer_lib
message_lib
header_map_lib
json_loader_lib
network_utility_lib
runtime_lib
access_log_formatter_lib
common_request_info_utility
base64_lib
zero_copy_input_stream_lib

crypto.lib
decrepit.lib
ssl.lib
)

target_link_libraries(access_log_impl_test
debug gtestd.lib
debug gtest_maind.lib
)

target_link_libraries(access_log_impl_test
optimized gtest.lib
optimized gtest_main.lib
)

add_executable(access_log_formatter_test access_log_formatter_test.cc)
target_link_libraries(access_log_formatter_test
access_log_formatter_lib
utility_lib
logger_lib
header_map_lib
common_request_info_utility
access_log_mocks
event_mocks
filesystem_mocks
runtime_mocks
server_mocks
upstream_mocks
test_common_utility_lib
test_main
)

target_link_libraries(access_log_formatter_test
debug gtestd.lib
)

target_link_libraries(access_log_formatter_test
optimized gtest.lib
)


#source file to be ported to Windows, hence skipping test
#add_executable(grpc_access_log_impl_test grpc_access_log_impl_test.cc)

add_executable(access_log_manager_impl_test access_log_manager_impl_test.cc)
target_link_libraries(access_log_manager_impl_test
access_log_manager_lib
stats_lib
access_log_mocks
filesystem_mocks
api_mocks
event_mocks

#dependencies
logger_lib
utility_lib
well_known_names_lib
utility_lib_protobuf
config_schemas_lib
config_utility_lib
test_main
)

target_link_libraries(access_log_manager_impl_test
debug gtestd.lib
)
target_link_libraries(access_log_manager_impl_test
optimized gtest.lib
)

4 changes: 4 additions & 0 deletions test/common/access_log/access_log_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"

#if defined(WIN32)
#define timegm _mkgmtime
#endif

using testing::NiceMock;
using testing::Return;
using testing::SaveArg;
Expand Down
Loading