Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
6e5fca3
Fix url 404 not found error
colibie Sep 7, 2021
51bab1c
Working version of quicTestServer
colibie Sep 7, 2021
15cfb05
remove traces of argc and argv
colibie Sep 7, 2021
91e1af8
[WIP] create quicTestServerTest
colibie Sep 7, 2021
a49baf9
[WIP] quicTestServerTest
colibie Sep 7, 2021
c608e2e
[WIP] checkpoint
colibie Sep 22, 2021
22bc6bb
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 22, 2021
cec798e
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 23, 2021
1e98c4d
move submodule to latest commit in main
colibie Sep 23, 2021
8a6208f
added direct response to test engine
colibie Sep 23, 2021
bc01022
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 29, 2021
189e3e9
WIP
colibie Sep 30, 2021
7511986
[wip]
colibie Oct 4, 2021
2b61716
add JVM test for the QuicTestServer
colibie Oct 4, 2021
75f52ef
wip
colibie Oct 7, 2021
9004b8c
add QuicTestServer and its associated test
colibie Oct 8, 2021
32401c4
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Oct 8, 2021
4864676
checkout to correct envoy version
colibie Oct 8, 2021
69983dd
Fix thread issue
colibie Oct 11, 2021
0789bec
Fix thread issue
colibie Oct 11, 2021
c6ef82a
nit fixes
colibie Oct 11, 2021
7aca613
add linux jni header and nit changes
colibie Oct 12, 2021
79819e2
add linux jni header and nit changes
colibie Oct 12, 2021
ad9170b
testing
colibie Oct 12, 2021
d09958c
fix PR comments and check test asan build
colibie Oct 12, 2021
4123d56
ci test
colibie Oct 12, 2021
cb3e22b
ci testing
colibie Oct 12, 2021
9836d38
reverting cc_binary changes
colibie Oct 12, 2021
05c30c8
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Oct 15, 2021
03c2053
pull in updates
colibie Oct 15, 2021
274aae7
fix format issues
colibie Oct 15, 2021
4bc0fd9
potential fix for mac timeouts
colibie Oct 15, 2021
f6e5b72
should fix failures
colibie Oct 15, 2021
34c70be
testonly field added to genrule
colibie Oct 15, 2021
5b6dd43
add binary jnilib to dep
colibie Oct 15, 2021
02fd58f
Kick CI
colibie Oct 15, 2021
701395b
remove redundancies
colibie Oct 15, 2021
f1a9a75
some more cleanup
colibie Oct 18, 2021
3b40d92
Merge remote-tracking branch 'origin' into java/quicTestServer
colibie Oct 18, 2021
1fae837
Kick CI
colibie Oct 19, 2021
71748ef
[WIP] mac not working yet
colibie Oct 25, 2021
e807c7f
Merge branch 'main' into cronvoy052
carloseltuerto Dec 27, 2021
ea28dc4
Adjust dependencies
carloseltuerto Dec 27, 2021
ba0d57c
Fix for Thread issue.
carloseltuerto Jan 1, 2022
1c65b1c
Load Cert/Key from original file
carloseltuerto Jan 4, 2022
3b279a8
Fix BUILD format
carloseltuerto Jan 4, 2022
b4ed90d
BUILD fix
carloseltuerto Jan 4, 2022
4f4c930
Attempt to fix BUILD format
carloseltuerto Jan 4, 2022
8109c4e
Kick CI
carloseltuerto Jan 4, 2022
8f846be
Kick CI
carloseltuerto Jan 4, 2022
8a0accb
Kick CI
carloseltuerto Jan 4, 2022
d8c2585
Merge branch 'main' into cronvoy052
carloseltuerto Jan 4, 2022
be6bdfb
Merge branch 'main' into cronvoy052
carloseltuerto Jan 11, 2022
29aabd1
Kick CI
carloseltuerto Jan 11, 2022
1b0ffc9
Remove logs
carloseltuerto Jan 11, 2022
16f14c9
Use port zero to avoid conflicts
carloseltuerto Jan 11, 2022
fbfa612
Try another port
carloseltuerto Jan 12, 2022
9ccb763
Desperate attempt with Manifest
carloseltuerto Jan 12, 2022
2e8cdcf
Update QuicTestServer BUILD file
carloseltuerto Jan 12, 2022
097f6f4
Enable networking for CI
carloseltuerto Jan 13, 2022
3373d94
Revert unwanted file
carloseltuerto Jan 13, 2022
8b6e8f2
Kick CI
carloseltuerto Jan 14, 2022
1b4321e
Addressed Ryan's comments.
carloseltuerto Jan 19, 2022
6e998da
Fix ASSERT put at the wrong place
carloseltuerto Jan 19, 2022
e6d6b26
Add comments to JNI interface
carloseltuerto Jan 19, 2022
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: 2 additions & 1 deletion bazel/kotlin_lib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def envoy_mobile_kt_library(name, visibility = None, srcs = [], deps = []):
# name = "java_jni_lib.jnilib",
# native_dep = "libjava_jni_lib.so",
# )
def envoy_mobile_so_to_jni_lib(name, native_dep):
def envoy_mobile_so_to_jni_lib(name, native_dep, testonly = False):
lib_name = native_lib_name(native_dep)
output = "{}.jnilib".format(lib_name)

return native.genrule(
name = name,
testonly = testonly,
outs = [output],
srcs = [native_dep],
cmd = """
Expand Down
1 change: 1 addition & 0 deletions bazel/kotlin_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def envoy_mobile_android_test(name, srcs, deps = [], native_deps = [], repositor
visibility = ["//visibility:public"],
data = native_deps,
exports = deps,
testonly = True,
)

native.android_local_test(
Expand Down
32 changes: 31 additions & 1 deletion test/common/integration/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_package")
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_cc_test_library", "envoy_package")

licenses(["notice"]) # Apache 2

Expand All @@ -21,5 +21,35 @@ envoy_cc_test(
"@envoy//test/common/http:common_lib",
"@envoy//test/integration:http_integration_lib",
"@envoy//test/server:utility_lib",
"@envoy//test/test_common:environment_lib",
],
)

# interface libs for quic test server's jni implementation
envoy_cc_test_library(
name = "quic_test_server_interface_lib",
srcs = [
"quic_test_server.cc",
"quic_test_server_interface.cc",
],
hdrs = [
"quic_test_server.h",
"quic_test_server_interface.h",
],
data = [
"@envoy//test/config/integration/certs",
],
repository = "@envoy",
deps = [
"@envoy//source/exe:process_wide_lib",
"@envoy//test/config:utility_lib",
"@envoy//test/integration:autonomous_upstream_lib",
"@envoy//test/mocks/server:transport_socket_factory_context_mocks",
"@envoy//test/test_common:environment_lib",
] + select({
"@envoy//bazel:disable_signal_trace": [],
"//conditions:default": [
"@envoy//source/common/signal:sigaction_lib",
],
}),
)
68 changes: 68 additions & 0 deletions test/common/integration/quic_test_server.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "quic_test_server.h"

#include "test/test_common/environment.h"

namespace Envoy {

Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>& factory_context) {
envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context;
Extensions::TransportSockets::Tls::ContextManagerImpl context_manager{time_system_};
const std::string yaml = absl::StrFormat(
R"EOF(
common_tls_context:
alpn_protocols: h3
tls_certificates:
- certificate_chain:
filename: ../envoy/test/config/integration/certs/upstreamcert.pem
private_key:
filename: ../envoy/test/config/integration/certs/upstreamkey.pem
)EOF");
TestUtility::loadFromYaml(yaml, tls_context);
envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config;
quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context);

std::vector<std::string> server_names;
auto& config_factory = Config::Utility::getAndCheckFactoryByName<
Server::Configuration::DownstreamTransportSocketConfigFactory>(
"envoy.transport_sockets.quic");

return config_factory.createTransportSocketFactory(quic_config, factory_context, server_names);
}

QuicTestServer::QuicTestServer()
: api_(Api::createApiForTest(stats_store_, time_system_)),
version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) {
ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_));
ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_));
upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig();
}

void QuicTestServer::startQuicTestServer() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps ASSERT(!upstream_)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ASSERT(!upstream_);
// pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc
Logger::Context logging_state(spdlog::level::level_enum::err,
"[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false);
// end pre-setup

upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3;

Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_);

upstream_ = std::make_unique<AutonomousUpstream>(std::move(factory), port_, version_,
upstream_config_, false);

// see upstream address
ENVOY_LOG_MISC(debug, "Upstream now listening on {}", upstream_->localAddress()->asString());
}

void QuicTestServer::shutdownQuicTestServer() {
ASSERT(upstream_);
upstream_.reset();
}

int QuicTestServer::getServerPort() {
ASSERT(upstream_);
return upstream_->localAddress()->ip()->port();
}
} // namespace Envoy
52 changes: 52 additions & 0 deletions test/common/integration/quic_test_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "source/extensions/transport_sockets/tls/ssl_socket.h"

// test_runner setups
#include "source/exe/process_wide.h"

#include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h"
#include "test/mocks/server/transport_socket_factory_context.h"
#include "test/integration/autonomous_upstream.h"
#include "test/config/utility.h"

namespace Envoy {
class QuicTestServer {
private:
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext> factory_context_;
Stats::IsolatedStoreImpl stats_store_;
Event::GlobalTimeSystem time_system_;
Api::ApiPtr api_;
Network::Address::IpVersion version_;
std::unique_ptr<AutonomousUpstream> upstream_;
FakeUpstreamConfig upstream_config_;
int port_;
Thread::SkipAsserts skip_asserts_;
ProcessWide process_wide;
Thread::MutexBasicLockable lock;

Network::TransportSocketFactoryPtr createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>&);

public:
QuicTestServer();

/**
* Starts the server. Can only have one server active per JVM. This is blocking until the port can
* start accepting requests.
*/
void startQuicTestServer();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brief comments here would be nice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Shutdowns the server. Can be restarted later. This is blocking until the server has freed all
* resources.
*/
void shutdownQuicTestServer();

/**
* Returns the port that got attributed. Can only be called once the server has been started.
*/
int getServerPort();
};

} // namespace Envoy
34 changes: 34 additions & 0 deletions test/common/integration/quic_test_server_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "test/common/integration/quic_test_server_interface.h"

// NOLINT(namespace-envoy)

static std::shared_ptr<Envoy::QuicTestServer> strong_quic_test_server_;
static std::weak_ptr<Envoy::QuicTestServer> weak_quic_test_server_;

static std::shared_ptr<Envoy::QuicTestServer> quic_test_server() {
return weak_quic_test_server_.lock();
}

void start_server() {
strong_quic_test_server_ = std::make_shared<Envoy::QuicTestServer>();
weak_quic_test_server_ = strong_quic_test_server_;

if (auto e = quic_test_server()) {
e->startQuicTestServer();
}
}

void shutdown_server() {
// Reset the primary handle to the test_server,
// but retain it long enough to synchronously shutdown.
auto e = strong_quic_test_server_;
strong_quic_test_server_.reset();
e->shutdownQuicTestServer();
}

int get_server_port() {
if (auto e = quic_test_server()) {
return e->getServerPort();
}
return -1; // failure
}
30 changes: 30 additions & 0 deletions test/common/integration/quic_test_server_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "test/common/integration/quic_test_server.h"

// NOLINT(namespace-envoy)

#ifdef __cplusplus
extern "C" { // functions
#endif

/**
* Starts the server. Can only have one server active per JVM. This is blocking until the port can
* start accepting requests.
*/
void start_server();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we have brief comments for these methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Shutdowns the server. Can be restarted later. This is blocking until the server has freed all
* resources.
*/
void shutdown_server();

/**
* Returns the port that got attributed. Can only be called once the server has been started.
*/
int get_server_port();

#ifdef __cplusplus
} // functions
#endif
32 changes: 32 additions & 0 deletions test/common/jni/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib")

licenses(["notice"]) # Apache 2

envoy_package()

# OS X binary (.jnilib) for Quic Test Server
envoy_mobile_so_to_jni_lib(
name = "libquic_test_server_jni.jnilib",
testonly = True,
native_dep = "libquic_test_server_jni.so",
)

# Binary for Quic Test Server
cc_binary(
name = "libquic_test_server_jni.so",
testonly = True,
srcs = [
"quic_test_server_jni_interface.cc",
"//library/common/jni:android_test_jni_interface.cc",
"//library/common/jni:jni_interface.cc",
"@local_jdk//:jni_header",
],
copts = ["-std=c++17"],
linkshared = True,
deps = [
"//library/common/jni:base_java_jni_lib",
"//test/common/integration:quic_test_server_interface_lib",
],
)
32 changes: 32 additions & 0 deletions test/common/jni/quic_test_server_jni_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <jni.h>

#include "test/common/integration/quic_test_server_interface.h"

#include "library/common/jni/jni_support.h"
#include "library/common/jni/jni_utility.h"
#include "library/common/jni/jni_version.h"

// NOLINT(namespace-envoy)

// Quic Test ServerJniLibrary

extern "C" JNIEXPORT void JNICALL
Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeStartQuicTestServer(
JNIEnv* env, jclass clazz) {
jni_log("[QTS]", "starting server");
start_server();
}

extern "C" JNIEXPORT jint JNICALL
Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env,
jclass clazz) {
jni_log("[QTS]", "getting server port");
return get_server_port();
}

extern "C" JNIEXPORT void JNICALL
Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeShutdownQuicTestServer(
JNIEnv* env, jclass clazz) {
jni_log("[QTS]", "shutting down server");
shutdown_server();
}
35 changes: 35 additions & 0 deletions test/java/io/envoyproxy/envoymobile/engine/testing/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test")

licenses(["notice"]) # Apache 2

envoy_package()

android_library(
name = "testing",
testonly = True,
srcs = [
"QuicTestServer.java",
],
visibility = ["//test:__subpackages__"],
)

envoy_mobile_android_test(
name = "quic_test_server_test",
srcs = [
"QuicTestServerTest.java",
],
exec_properties = {
# TODO(lfpino): Remove this once the sandboxNetwork=off works for ipv4 localhost addresses.
"sandboxNetwork": "standard",
},
library_path = "test/common/jni",
native_deps = [
"//test/common/jni:libquic_test_server_jni.so",
"//test/common/jni:libquic_test_server_jni.jnilib",
],
deps = [
":testing",
"//library/kotlin/io/envoyproxy/envoymobile:envoy_lib",
],
)
Loading