Test Refactoring and Improvements (#513)

This commit is contained in:
Nick Banks 2020-06-17 13:06:34 -07:00 коммит произвёл GitHub
Родитель 4d613d762f
Коммит e401501cdb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
22 изменённых файлов: 695 добавлений и 488 удалений

Просмотреть файл

@ -35,7 +35,7 @@ jobs:
inputs:
pwsh: true
filePath: scripts/test.ps1
arguments: -NoProgress -IsolationMode Isolated -LogProfile ${{ parameters.logProfile }} -ConvertLogs -GenerateXmlResults -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls schannel ${{ parameters.extraArgs }}
arguments: -NoProgress -IsolationMode Isolated -LogProfile ${{ parameters.logProfile }} -GenerateXmlResults -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls schannel ${{ parameters.extraArgs }}
- template: ./upload-test-artifacts.yml
parameters:

Просмотреть файл

@ -40,7 +40,7 @@ jobs:
inputs:
pwsh: true
filePath: scripts/test.ps1
arguments: -NoProgress -IsolationMode Isolated -LogProfile ${{ parameters.logProfile }} -ConvertLogs -GenerateXmlResults -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} ${{ parameters.extraArgs }}
arguments: -NoProgress -IsolationMode Isolated -LogProfile ${{ parameters.logProfile }} -GenerateXmlResults -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} ${{ parameters.extraArgs }}
- template: ./upload-test-artifacts.yml
parameters:

Просмотреть файл

@ -35,7 +35,7 @@ jobs:
inputs:
pwsh: true
filePath: scripts/spin.ps1
arguments: -GenerateXmlResults -Timeout 600000 -RepeatCount 6 -ConvertLogs -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }}
arguments: -GenerateXmlResults -Timeout 600000 -RepeatCount 6 -Config ${{ parameters.config }} -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }}
- template: ./upload-test-artifacts.yml
parameters:

Просмотреть файл

@ -24,9 +24,6 @@ This script runs quicinterop locally.
.PARAMETER LogProfile
The name of the profile to use for log collection.
.PARAMETER ConvertLogs
Convert any collected logs to text. Only works when LogProfile is set.
.PARAMETER Target
A target to connect to.
@ -73,9 +70,6 @@ param (
[ValidateSet("None", "Basic.Light", "Basic.Verbose", "Full.Light", "Full.Verbose", "SpinQuic.Light")]
[string]$LogProfile = "None",
[Parameter(Mandatory = $false)]
[switch]$ConvertLogs = $false,
[Parameter(Mandatory = $false)]
[string]$Target = "",
@ -138,10 +132,7 @@ if ($Debugger) {
$Arguments += " -Debugger"
}
if ("None" -ne $LogProfile) {
$Arguments += " -LogProfile $($LogProfile)"
}
if ($ConvertLogs) {
$Arguments += " -ConvertLogs"
$Arguments += " -LogProfile $($LogProfile) -ConvertLogs"
}
$ExtraArgs = ""

Просмотреть файл

@ -30,9 +30,6 @@ This script runs spinquic locally for a period of time.
.PARAMETER LogProfile
The name of the profile to use for log collection.
.PARAMETER ConvertLogs
Convert any collected logs to text. Only works when LogProfile is set.
#>
param (
@ -65,10 +62,7 @@ param (
[Parameter(Mandatory = $false)]
[ValidateSet("None", "Basic.Light", "Basic.Verbose", "Full.Light", "Full.Verbose", "SpinQuic.Light")]
[string]$LogProfile = "None",
[Parameter(Mandatory = $false)]
[switch]$ConvertLogs = $false
[string]$LogProfile = "None"
)
Set-StrictMode -Version 'Latest'
@ -114,10 +108,7 @@ if ($Debugger) {
$Arguments += " -Debugger"
}
if ("None" -ne $LogProfile) {
$Arguments += " -LogProfile $($LogProfile)"
}
if ($ConvertLogs) {
$Arguments += " -ConvertLogs"
$Arguments += " -LogProfile $($LogProfile) -ConvertLogs"
}
# Run the script.

Просмотреть файл

@ -43,9 +43,6 @@ This script provides helpers for running executing the MsQuic tests.
.PARAMETER LogProfile
The name of the profile to use for log collection.
.PARAMETER ConvertLogs
Convert any collected logs to text. Only works when LogProfile is set.
.PARAMETER CompressOutput
Compresses the output files generated for failed test cases.
@ -118,9 +115,6 @@ param (
[ValidateSet("None", "Basic.Light", "Basic.Verbose", "Full.Light", "Full.Verbose")]
[string]$LogProfile = "None",
[Parameter(Mandatory = $false)]
[switch]$ConvertLogs = $false,
[Parameter(Mandatory = $false)]
[switch]$CompressOutput = $false,
@ -190,10 +184,7 @@ if ($BreakOnFailure) {
$TestArguments += " -BreakOnFailure"
}
if ("None" -ne $LogProfile) {
$TestArguments += " -LogProfile $($LogProfile)"
}
if ($ConvertLogs) {
$TestArguments += " -ConvertLogs"
$TestArguments += " -LogProfile $($LogProfile) -ConvertLogs"
}
if ($CompressOutput) {
$TestArguments += " -CompressOutput"

Просмотреть файл

@ -307,6 +307,22 @@ QuicAddrIsBoundExplicitly(
return Addr->Ipv6.sin6_scope_id == 0;
}
//
// Test only API to increment the IP address value.
//
inline
void
QuicAddrIncrement(
_Inout_ QUIC_ADDR * Addr
)
{
if (Addr->Ip.sa_family == AF_INET) {
((uint8_t*)&Addr->Ipv4.sin_addr)[3]++;
} else {
((uint8_t*)&Addr->Ipv6.sin6_addr)[15]++;
}
}
inline
void
QuicAddrSetToLoopback(

Просмотреть файл

@ -242,6 +242,22 @@ QuicAddrSetToLoopback(
}
}
//
// Test only API to increment the IP address value.
//
inline
void
QuicAddrIncrement(
_Inout_ QUIC_ADDR * Addr
)
{
if (Addr->si_family == AF_INET) {
Addr->Ipv4.sin_addr.S_un.S_un_b.s_b4++;
} else {
Addr->Ipv6.sin6_addr.u.Byte[15]++;
}
}
inline
uint32_t
QuicAddrHash(

Просмотреть файл

@ -237,6 +237,22 @@ QuicAddrSetToLoopback(
}
}
//
// Test only API to increment the IP address value.
//
inline
void
QuicAddrIncrement(
_Inout_ QUIC_ADDR * Addr
)
{
if (Addr->si_family == AF_INET) {
Addr->Ipv4.sin_addr.S_un.S_un_b.s_b4++;
} else {
Addr->Ipv6.sin6_addr.u.Byte[15]++;
}
}
inline
uint32_t
QuicAddrHash(

Просмотреть файл

@ -229,6 +229,11 @@ QuicAddrIsBoundExplicitly(
_In_ const QUIC_ADDR* const Addr
);
void
QuicAddrIncrement(
_Inout_ QUIC_ADDR * Addr
);
void
QuicAddrSetToLoopback(
_Inout_ QUIC_ADDR* Addr

Просмотреть файл

@ -39,6 +39,7 @@ void QuicTestValidateServerSecConfig(void* CertContext, QUIC_CERTIFICATE_HASH_ST
//
// Event Validation Tests
//
void QuicTestValidateConnectionEvents();
void QuicTestValidateStreamEvents();
@ -66,8 +67,6 @@ QuicTestConnect(
_In_ int Family,
_In_ bool ServerStatelessRetry,
_In_ bool ClientUsesOldVersion,
_In_ bool ClientRebind,
_In_ bool ChangeMaxStreamID,
_In_ bool MultipleALPNs,
_In_ bool AsyncSecConfig,
_In_ bool MultiPacketClientInitial,
@ -104,6 +103,25 @@ QuicTestConnectServerRejected(
_In_ int Family
);
//
// Post Handshake Tests
//
void
QuicTestNatPortRebind(
_In_ int Family
);
void
QuicTestNatAddrRebind(
_In_ int Family
);
void
QuicTestChangeMaxStreamID(
_In_ int Family
);
//
// Application Data Tests
//
@ -363,8 +381,6 @@ typedef struct {
int Family;
uint8_t ServerStatelessRetry;
uint8_t ClientUsesOldVersion;
uint8_t ClientRebind;
uint8_t ChangeMaxStreamID;
uint8_t MultipleALPNs;
uint8_t AsyncSecConfig;
uint8_t MultiPacketClientInitial;
@ -546,4 +562,16 @@ typedef struct {
QUIC_CTL_CODE(40, METHOD_BUFFERED, FILE_WRITE_DATA)
// int - Family
#define QUIC_MAX_IOCTL_FUNC_CODE 40
#define IOCTL_QUIC_RUN_NAT_PORT_REBIND \
QUIC_CTL_CODE(41, METHOD_BUFFERED, FILE_WRITE_DATA)
// int - Family
#define IOCTL_QUIC_RUN_NAT_ADDR_REBIND \
QUIC_CTL_CODE(42, METHOD_BUFFERED, FILE_WRITE_DATA)
// int - Family
#define IOCTL_QUIC_RUN_CHANGE_MAX_STREAM_ID \
QUIC_CTL_CODE(43, METHOD_BUFFERED, FILE_WRITE_DATA)
// int - Family
#define QUIC_MAX_IOCTL_FUNC_CODE 43

Просмотреть файл

@ -336,8 +336,6 @@ TEST_P(WithHandshakeArgs1, Connect) {
GetParam().Family,
(uint8_t)GetParam().ServerStatelessRetry,
0, // ClientUsesOldVersion
0, // ClientRebind
0, // ChangeMaxStreamID
(uint8_t)GetParam().MultipleALPNs,
0, // AsyncSecConfig
(uint8_t)GetParam().MultiPacketClientInitial,
@ -350,8 +348,6 @@ TEST_P(WithHandshakeArgs1, Connect) {
GetParam().Family,
GetParam().ServerStatelessRetry,
false, // ClientUsesOldVersion
false, // ClientRebind
false, // ChangeMaxStreamID
GetParam().MultipleALPNs,
false, // AsyncSecConfig
GetParam().MultiPacketClientInitial,
@ -367,8 +363,6 @@ TEST_P(WithHandshakeArgs2, OldVersion) {
GetParam().Family,
(uint8_t)GetParam().ServerStatelessRetry,
1, // ClientUsesOldVersion
0, // ClientRebind
0, // ChangeMaxStreamID
0, // MultipleALPNs
0, // AsyncSecConfig
0, // MultiPacketClientInitial
@ -381,8 +375,6 @@ TEST_P(WithHandshakeArgs2, OldVersion) {
GetParam().Family,
GetParam().ServerStatelessRetry,
false, // ClientUsesOldVersion
false, // ClientRebind
false, // ChangeMaxStreamID
false, // MultipleALPNs
false, // AsyncSecConfig
false, // MultiPacketClientInitial
@ -391,6 +383,33 @@ TEST_P(WithHandshakeArgs2, OldVersion) {
}
}
TEST_P(WithHandshakeArgs3, AsyncSecurityConfig) {
TestLoggerT<ParamType> Logger("QuicTestConnect-AsyncSecurityConfig", GetParam());
if (TestingKernelMode) {
QUIC_RUN_CONNECT_PARAMS Params = {
GetParam().Family,
(uint8_t)GetParam().ServerStatelessRetry,
0, // ClientUsesOldVersion
(uint8_t)GetParam().MultipleALPNs,
1, // AsyncSecConfig
0, // MultiPacketClientInitial
0, // SessionResumption
0 // RandomLossPercentage
};
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CONNECT, Params));
} else {
QuicTestConnect(
GetParam().Family,
GetParam().ServerStatelessRetry,
false, // ClientUsesOldVersion
GetParam().MultipleALPNs,
true, // AsyncSecConfig
false, // MultiPacketClientInitial
false, // SessionResumption
0); // RandomLossPercentage
}
}
TEST_P(WithFamilyArgs, VersionNegotiation) {
TestLoggerT<ParamType> Logger("QuicTestVersionNegotiation", GetParam());
if (TestingKernelMode) {
@ -400,102 +419,6 @@ TEST_P(WithFamilyArgs, VersionNegotiation) {
}
}
#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
TEST_P(WithFamilyArgs, Rebind) {
TestLoggerT<ParamType> Logger("QuicTestConnect-Rebind", GetParam());
if (TestingKernelMode) {
GTEST_SKIP_(":Unsupported in kernel mode");
QUIC_RUN_CONNECT_PARAMS Params = {
GetParam().Family,
0, // ServerStatelessRetry
0, // ClientUsesOldVersion
1, // ClientRebind
0, // ChangeMaxStreamID
0, // MultipleALPNs
0, // AsyncSecConfig
0, // MultiPacketClientInitial
0, // SessionResumption
0 // RandomLossPercentage
};
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CONNECT, Params));
} else {
QuicTestConnect(
GetParam().Family,
false, // ServerStatelessRetry
false, // ClientUsesOldVersion
true, // ClientRebind
false, // ChangeMaxStreamID
false, // MultipleALPNs
false, // AsyncSecConfig
false, // MultiPacketClientInitial
false, // SessionResumption
0); // RandomLossPercentage
}
}
#endif
TEST_P(WithFamilyArgs, ChangeMaxStreamIDs) {
TestLoggerT<ParamType> Logger("QuicTestConnect-ChangeMaxStreamIDs", GetParam());
if (TestingKernelMode) {
QUIC_RUN_CONNECT_PARAMS Params = {
GetParam().Family,
0, // ServerStatelessRetry
0, // ClientUsesOldVersion
0, // ClientRebind
1, // ChangeMaxStreamID
0, // MultipleALPNs
0, // AsyncSecConfig
0, // MultiPacketClientInitial
0, // SessionResumption
0 // RandomLossPercentage
};
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CONNECT, Params));
} else {
QuicTestConnect(
GetParam().Family,
false, // ServerStatelessRetry
false, // ClientUsesOldVersion
false, // ClientRebind
true, // ChangeMaxStreamID
false, // MultipleALPNs
false, // AsyncSecConfig
false, // MultiPacketClientInitial
false, // SessionResumption
0); // RandomLossPercentage
}
}
TEST_P(WithHandshakeArgs3, AsyncSecurityConfig) {
TestLoggerT<ParamType> Logger("QuicTestConnect-AsyncSecurityConfig", GetParam());
if (TestingKernelMode) {
QUIC_RUN_CONNECT_PARAMS Params = {
GetParam().Family,
(uint8_t)GetParam().ServerStatelessRetry,
0, // ClientUsesOldVersion
0, // ClientRebind
0, // ChangeMaxStreamID
(uint8_t)GetParam().MultipleALPNs,
1, // AsyncSecConfig
0, // MultiPacketClientInitial
0, // SessionResumption
0 // RandomLossPercentage
};
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CONNECT, Params));
} else {
QuicTestConnect(
GetParam().Family,
GetParam().ServerStatelessRetry,
false, // ClientUsesOldVersion
false, // ClientRebind
false, // ChangeMaxStreamID
GetParam().MultipleALPNs,
true, // AsyncSecConfig
false, // MultiPacketClientInitial
false, // SessionResumption
0); // RandomLossPercentage
}
}
#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
TEST_P(WithHandshakeArgs4, RandomLoss) {
TestLoggerT<ParamType> Logger("QuicTestConnect-RandomLoss", GetParam());
@ -504,8 +427,6 @@ TEST_P(WithHandshakeArgs4, RandomLoss) {
GetParam().Family,
(uint8_t)GetParam().ServerStatelessRetry,
0, // ClientUsesOldVersion
0, // ClientRebind
0, // ChangeMaxStreamID
0, // MultipleALPNs
0, // AsyncSecConfig
(uint8_t)GetParam().MultiPacketClientInitial,
@ -518,8 +439,6 @@ TEST_P(WithHandshakeArgs4, RandomLoss) {
GetParam().Family,
GetParam().ServerStatelessRetry,
false, // ClientUsesOldVersion
false, // ClientRebind
false, // ChangeMaxStreamID
false, // MultipleALPNs,
false, // AsyncSecConfig
GetParam().MultiPacketClientInitial,
@ -565,6 +484,35 @@ TEST_P(WithFamilyArgs, ServerRejected) {
}
}
#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
TEST_P(WithFamilyArgs, RebindPort) {
TestLoggerT<ParamType> Logger("QuicTestNatPortRebind", GetParam());
if (TestingKernelMode) {
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_NAT_PORT_REBIND, GetParam().Family));
} else {
QuicTestNatPortRebind(GetParam().Family);
}
}
TEST_P(WithFamilyArgs, RebindAddr) {
TestLoggerT<ParamType> Logger("QuicTestNatAddrRebind", GetParam());
if (TestingKernelMode) {
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_NAT_ADDR_REBIND, GetParam().Family));
} else {
QuicTestNatAddrRebind(GetParam().Family);
}
}
#endif
TEST_P(WithFamilyArgs, ChangeMaxStreamIDs) {
TestLoggerT<ParamType> Logger("QuicTestChangeMaxStreamID", GetParam());
if (TestingKernelMode) {
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CHANGE_MAX_STREAM_ID, GetParam().Family));
} else {
QuicTestChangeMaxStreamID(GetParam().Family);
}
}
TEST_P(WithSendArgs1, Send) {
TestLoggerT<ParamType> Logger("QuicTestConnectAndPing", GetParam());
if (TestingKernelMode) {

Просмотреть файл

@ -538,6 +538,9 @@ size_t QUIC_IOCTL_BUFFER_SIZES[] =
sizeof(INT32),
0,
sizeof(QUIC_RUN_DATAGRAM_NEGOTIATION),
sizeof(INT32),
sizeof(INT32),
sizeof(INT32),
sizeof(INT32)
};
@ -738,8 +741,6 @@ QuicTestCtlEvtIoDeviceControl(
Params->Params1.Family,
Params->Params1.ServerStatelessRetry != 0,
Params->Params1.ClientUsesOldVersion != 0,
Params->Params1.ClientRebind != 0,
Params->Params1.ChangeMaxStreamID != 0,
Params->Params1.MultipleALPNs != 0,
Params->Params1.AsyncSecConfig != 0,
Params->Params1.MultiPacketClientInitial != 0,
@ -918,6 +919,27 @@ QuicTestCtlEvtIoDeviceControl(
Params->Family));
break;
case IOCTL_QUIC_RUN_NAT_PORT_REBIND:
QUIC_FRE_ASSERT(Params != nullptr);
QuicTestCtlRun(
QuicTestNatPortRebind(
Params->Family));
break;
case IOCTL_QUIC_RUN_NAT_ADDR_REBIND:
QUIC_FRE_ASSERT(Params != nullptr);
QuicTestCtlRun(
QuicTestNatAddrRebind(
Params->Family));
break;
case IOCTL_QUIC_RUN_CHANGE_MAX_STREAM_ID:
QUIC_FRE_ASSERT(Params != nullptr);
QuicTestCtlRun(
QuicTestChangeMaxStreamID(
Params->Family));
break;
default:
Status = STATUS_NOT_IMPLEMENTED;
break;

Просмотреть файл

@ -674,18 +674,6 @@ void QuicTestValidateConnection()
}
}
_Function_class_(NEW_STREAM_CALLBACK)
static
void
ConnectionIgnoreStreamCallback(
_In_ TestConnection* /* Connection */,
_In_ HQUIC Stream,
_In_ QUIC_STREAM_OPEN_FLAGS /* Flags */
)
{
MsQuic->StreamClose(Stream);
}
_Function_class_(NEW_CONNECTION_CALLBACK)
static
void
@ -695,7 +683,7 @@ ListenerAcceptCallback(
)
{
TestConnection** NewConnection = (TestConnection**)Listener->Context;
*NewConnection = new TestConnection(ConnectionHandle, ConnectionIgnoreStreamCallback, true);
*NewConnection = new TestConnection(ConnectionHandle);
if (*NewConnection == nullptr || !(*NewConnection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete *NewConnection;
@ -748,7 +736,7 @@ void QuicTestValidateStream(bool Connect)
MyListener.Context = &Server;
{
TestConnection Client(Session, ConnectionIgnoreStreamCallback, false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
if (Connect) {
TEST_QUIC_SUCCEEDED(MyListener.Start());
@ -763,7 +751,7 @@ void QuicTestValidateStream(bool Connect)
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
//
// Wait for connection.

Просмотреть файл

@ -22,18 +22,6 @@ ListenerDoNothingCallback(
TEST_FAILURE("This callback should never be called!");
}
_Function_class_(NEW_STREAM_CALLBACK)
static
void
ConnectionDoNothingCallback(
_In_ TestConnection* /* Connection */,
_In_ HQUIC /* StreamHandle */,
_In_ QUIC_STREAM_OPEN_FLAGS /* Flags */
)
{
TEST_FAILURE("This callback should never be called!");
}
void QuicTestCreateListener()
{
MsQuicSession Session;
@ -206,7 +194,7 @@ void QuicTestCreateConnection()
TEST_TRUE(Session.IsValid());
{
TestConnection Connection(Session.Handle, ConnectionDoNothingCallback, false);
TestConnection Connection(Session);
TEST_TRUE(Connection.IsValid());
}
}
@ -217,7 +205,7 @@ void QuicTestBindConnectionImplicit(_In_ int Family)
TEST_TRUE(Session.IsValid());
{
TestConnection Connection(Session.Handle, ConnectionDoNothingCallback, false);
TestConnection Connection(Session);
TEST_TRUE(Connection.IsValid());
QuicAddr LocalAddress(Family == 4 ? AF_INET : AF_INET6);
@ -231,7 +219,7 @@ void QuicTestBindConnectionExplicit(_In_ int Family)
TEST_TRUE(Session.IsValid());
{
TestConnection Connection(Session.Handle, ConnectionDoNothingCallback, false);
TestConnection Connection(Session);
TEST_TRUE(Connection.IsValid());
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;

Просмотреть файл

@ -11,18 +11,6 @@ Abstract:
#include "precomp.h"
_Function_class_(NEW_STREAM_CALLBACK)
static
void
ConnectionDoNothingCallback(
_In_ TestConnection* /* Connection */,
_In_ HQUIC /* StreamHandle */,
_In_ QUIC_STREAM_OPEN_FLAGS /* Flags */
)
{
TEST_FAILURE("This callback should never be called!");
}
struct ServerAcceptContext {
QUIC_EVENT NewConnectionReady;
TestConnection** NewConnection;
@ -249,64 +237,63 @@ ListenerAcceptPingConnection(
{
TestScopeLogger logScope(__FUNCTION__);
if (Listener->Context != nullptr) {
auto Connection = new TestConnection(ConnectionHandle, ConnectionAcceptPingStream, true, true);
if (Connection == nullptr || !(Connection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete Connection;
MsQuic->ConnectionClose(ConnectionHandle);
return;
}
auto Connection = new TestConnection(ConnectionHandle, ConnectionAcceptPingStream);
if (Connection == nullptr || !(Connection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete Connection;
MsQuic->ConnectionClose(ConnectionHandle);
return;
}
Connection->SetAutoDelete();
auto Stats = (PingStats*)Listener->Context;
Connection->Context = new PingConnState(Stats, Connection);
Connection->SetShutdownCompleteCallback(PingConnectionShutdown);
Connection->SetExpectedResumed(Stats->ZeroRtt);
if (Stats->ExpectedCloseStatus != QUIC_STATUS_SUCCESS) {
Connection->SetExpectedTransportCloseStatus(Stats->ExpectedCloseStatus);
if (Stats->ExpectedCloseStatus == QUIC_STATUS_CONNECTION_TIMEOUT) {
Connection->SetDisconnectTimeout(1000); // ms
}
auto Stats = (PingStats*)Listener->Context;
Connection->Context = new PingConnState(Stats, Connection);
Connection->SetShutdownCompleteCallback(PingConnectionShutdown);
Connection->SetExpectedResumed(Stats->ZeroRtt);
if (Stats->ExpectedCloseStatus != QUIC_STATUS_SUCCESS) {
Connection->SetExpectedTransportCloseStatus(Stats->ExpectedCloseStatus);
if (Stats->ExpectedCloseStatus == QUIC_STATUS_CONNECTION_TIMEOUT) {
Connection->SetDisconnectTimeout(1000); // ms
}
}
Connection->SetPriorityScheme(
Stats->FifoScheduling ?
QUIC_STREAM_SCHEDULING_SCHEME_FIFO :
QUIC_STREAM_SCHEDULING_SCHEME_ROUND_ROBIN);
Connection->SetPriorityScheme(
Stats->FifoScheduling ?
QUIC_STREAM_SCHEDULING_SCHEME_FIFO :
QUIC_STREAM_SCHEDULING_SCHEME_ROUND_ROBIN);
if (Stats->ServerInitiatedStreams) {
SendPingBurst(
Connection,
Stats->StreamCount,
Stats->PayloadLength);
}
} else {
auto Connection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true, true);
if (Connection == nullptr || !(Connection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete Connection;
MsQuic->ConnectionClose(ConnectionHandle);
return;
}
if (Stats->ServerInitiatedStreams) {
SendPingBurst(
Connection,
Stats->StreamCount,
Stats->PayloadLength);
}
}
TestConnection*
NewPingConnection(
_In_ HQUIC SessionHandle,
_In_ MsQuicSession& Session,
_In_ PingStats* ClientStats,
_In_ bool UseSendBuffer
)
{
TestScopeLogger logScope(__FUNCTION__);
auto Connection = new TestConnection(SessionHandle, ConnectionAcceptPingStream, false, true, UseSendBuffer);
auto Connection = new TestConnection(Session, ConnectionAcceptPingStream);
if (Connection == nullptr || !(Connection)->IsValid()) {
TEST_FAILURE("Failed to create new TestConnection.");
delete Connection;
return nullptr;
}
Connection->SetAutoDelete();
if (UseSendBuffer) {
if (QUIC_FAILED(Connection->SetUseSendBuffer(true))) {
TEST_FAILURE("SetUseSendBuffer failed.");
delete Connection;
return nullptr;
}
}
Connection->Context = new PingConnState(ClientStats, Connection);
Connection->SetShutdownCompleteCallback(PingConnectionShutdown);
@ -349,6 +336,7 @@ QuicTestConnectAndPing(
{
const uint32_t TimeoutMs = EstimateTimeoutMs(Length) * StreamBurstCount;
const uint16_t TotalStreamCount = (uint16_t)(StreamCount * StreamBurstCount);
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
PingStats ServerStats(Length, ConnectionCount, TotalStreamCount, FifoScheduling, UnidirectionalStreams, ServerInitiatedStreams, ClientZeroRtt && !ServerRejectZeroRtt, false, QUIC_STATUS_SUCCESS);
PingStats ClientStats(Length, ConnectionCount, TotalStreamCount, FifoScheduling, UnidirectionalStreams, ServerInitiatedStreams, ClientZeroRtt && !ServerRejectZeroRtt);
@ -366,6 +354,14 @@ QuicTestConnectAndPing(
TEST_QUIC_SUCCEEDED(Session.SetTlsTicketKey(NewTicketKey));
}
if (ClientZeroRtt) {
bool Success;
QuicTestPrimeResumption(Session, QuicAddrFamily, Success);
if (!Success) {
return;
}
}
StatelessRetryHelper RetryHelper(ServerStatelessRetry);
{
@ -373,34 +369,9 @@ QuicTestConnectAndPing(
TEST_TRUE(Listener.IsValid());
TEST_QUIC_SUCCEEDED(Listener.Start());
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
QuicAddr ServerLocalAddr;
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
if (ClientZeroRtt) {
TestScopeLogger logScope("PrimeZeroRtt");
{
TestConnection Client(Session.Handle, ConnectionDoNothingCallback, false);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
if (!Client.WaitForZeroRttTicket()) {
return;
}
Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_NO_ERROR);
if (!Client.WaitForShutdownComplete()) {
return;
}
}
}
if (ServerRejectZeroRtt) {
uint8_t NewTicketKey[44] = {0};
TEST_QUIC_SUCCEEDED(Session.SetTlsTicketKey(NewTicketKey));
@ -413,7 +384,7 @@ QuicTestConnectAndPing(
for (uint32_t i = 0; i < ClientStats.ConnectionCount; ++i) {
Connections.get()[i] =
NewPingConnection(
Session.Handle,
Session,
&ClientStats,
UseSendBuffer);
if (Connections.get()[i] == nullptr) {
@ -447,7 +418,7 @@ QuicTestConnectAndPing(
Connections.get()[i]->Start(
QuicAddrFamily,
ClientZeroRtt ? QUIC_LOCALHOST_FOR_AF(QuicAddrFamily) : nullptr,
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (i == 0) {
Connections.get()[i]->GetLocalAddr(LocalAddr);
}
@ -492,7 +463,7 @@ QuicTestServerDisconnect(
{
TestConnection* Client =
NewPingConnection(
Session.Handle,
Session,
&ClientStats,
FALSE);
if (Client == nullptr) {
@ -505,7 +476,7 @@ QuicTestServerDisconnect(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
QuicSleep(100); // Sleep for a little bit.
@ -554,7 +525,7 @@ ListenerAcceptConnectionAndStreams(
)
{
ServerAcceptContext* AcceptContext = (ServerAcceptContext*)Listener->Context;
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle, ConnectionAcceptAndIgnoreStream, true);
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle, ConnectionAcceptAndIgnoreStream);
if (*AcceptContext->NewConnection == nullptr || !(*AcceptContext->NewConnection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete *AcceptContext->NewConnection;
@ -601,9 +572,9 @@ QuicTestClientDisconnect(
Client =
NewPingConnection(
Session.Handle,
Session,
&ClientStats,
FALSE);
false);
if (Client == nullptr) {
return;
}
@ -622,7 +593,7 @@ QuicTestClientDisconnect(
Client->Start(
AF_INET,
QUIC_LOCALHOST_FOR_AF(AF_INET),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client->WaitForConnectionComplete()) {
return;
@ -958,7 +929,7 @@ QuicAbortiveTransfers(
ClientContext.Conn.Handle,
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr));
ServerLocalAddr.GetPort());
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuic->ConnectionStart failed, 0x%x.", Status);
return;
@ -1406,7 +1377,7 @@ QuicTestReceiveResume(
ClientContext.Conn.Handle,
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr));
ServerLocalAddr.GetPort());
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuic->ConnectionStart failed, 0x%x.", Status);
return;
@ -1670,7 +1641,7 @@ QuicTestReceiveResumeNoData(
ClientContext.Conn.Handle,
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr));
ServerLocalAddr.GetPort());
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuic->ConnectionStart failed, 0x%x.", Status);
return;

Просмотреть файл

@ -11,18 +11,6 @@ Abstract:
#include "precomp.h"
_Function_class_(NEW_STREAM_CALLBACK)
static
void
ConnectionDoNothingCallback(
_In_ TestConnection* /* Connection */,
_In_ HQUIC /* StreamHandle */,
_In_ QUIC_STREAM_OPEN_FLAGS /* Flags */
)
{
TEST_FAILURE("This callback should never be called!");
}
struct ServerAcceptContext {
QUIC_EVENT NewConnectionReady;
TestConnection** NewConnection;
@ -44,22 +32,7 @@ ListenerAcceptConnection(
)
{
ServerAcceptContext* AcceptContext = (ServerAcceptContext*)Listener->Context;
if (AcceptContext == nullptr) { // Prime Resumption scenario.
auto NewConnection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true, true);
if (NewConnection == nullptr || !NewConnection->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete NewConnection;
MsQuic->ConnectionClose(ConnectionHandle);
} else {
NewConnection->SetHasRandomLoss(Listener->GetHasRandomLoss());
}
return;
}
if (*AcceptContext->NewConnection != nullptr) { // Retry scenario.
delete *AcceptContext->NewConnection;
*AcceptContext->NewConnection = nullptr;
}
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true);
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle);
if (*AcceptContext->NewConnection == nullptr || !(*AcceptContext->NewConnection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete *AcceptContext->NewConnection;
@ -103,10 +76,7 @@ QuicTestDatagramNegotiation(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
ClientSession.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(ClientSession);
TEST_TRUE(Client.IsValid());
TEST_TRUE(Client.GetDatagramSendEnabled()); // Datagrams start as enabled
@ -123,7 +93,7 @@ QuicTestDatagramNegotiation(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
@ -194,10 +164,7 @@ QuicTestDatagramSend(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_TRUE(Client.GetDatagramSendEnabled());
@ -206,7 +173,7 @@ QuicTestDatagramSend(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;

Просмотреть файл

@ -282,7 +282,7 @@ QuicTestValidateConnectionEvents1(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
TEST_TRUE(QuicEventWaitWithTimeout(Client.Complete, 2000));
TEST_TRUE(QuicEventWaitWithTimeout(Server.Complete, 1000));
@ -344,7 +344,7 @@ QuicTestValidateConnectionEvents2(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
TEST_TRUE(QuicEventWaitWithTimeout(Client.Complete, 2000));
TEST_TRUE(QuicEventWaitWithTimeout(Server.Complete, 1000));
@ -483,7 +483,7 @@ QuicTestValidateStreamEvents1(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
TEST_TRUE(QuicEventWaitWithTimeout(Client.Complete, 2000));
TEST_TRUE(QuicEventWaitWithTimeout(Server.Complete, 1000));
@ -579,7 +579,7 @@ QuicTestValidateStreamEvents2(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr),
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
TEST_TRUE(QuicEventWaitWithTimeout(Client.Complete, 2000));
TEST_TRUE(QuicEventWaitWithTimeout(Server.Complete, 1000));

Просмотреть файл

@ -28,16 +28,56 @@ void QuicTestUninitialize()
DatapathHooks::Instance = nullptr;
}
_Function_class_(NEW_STREAM_CALLBACK)
static
void
ConnectionDoNothingCallback(
_In_ TestConnection* /* Connection */,
_In_ HQUIC /* StreamHandle */,
_In_ QUIC_STREAM_OPEN_FLAGS /* Flags */
QuicTestPrimeResumption(
MsQuicSession& Session,
QUIC_ADDRESS_FAMILY Family,
bool& Success
)
{
TEST_FAILURE("This callback should never be called!");
TestScopeLogger logScope("PrimeResumption");
Success = false;
struct PrimeResumption {
_Function_class_(NEW_CONNECTION_CALLBACK) static void
ListenerAccept(_In_ TestListener* /* Listener */, _In_ HQUIC ConnectionHandle) {
auto NewConnection = new TestConnection(ConnectionHandle);
if (NewConnection == nullptr || !NewConnection->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete NewConnection;
MsQuic->ConnectionClose(ConnectionHandle);
} else {
NewConnection->SetAutoDelete();
}
}
};
TestListener Listener(Session.Handle, PrimeResumption::ListenerAccept);
TEST_TRUE(Listener.IsValid());
QuicAddr ServerLocalAddr(Family);
TEST_QUIC_SUCCEEDED(Listener.Start(&ServerLocalAddr.SockAddr));
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
{
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
Family,
QUIC_LOCALHOST_FOR_AF(Family),
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
if (!Client.WaitForZeroRttTicket()) {
return;
}
Session.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT, 0);
}
Success = true;
}
struct ServerAcceptContext {
@ -61,22 +101,7 @@ ListenerAcceptConnection(
)
{
ServerAcceptContext* AcceptContext = (ServerAcceptContext*)Listener->Context;
if (AcceptContext == nullptr) { // Prime Resumption scenario.
auto NewConnection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true, true);
if (NewConnection == nullptr || !NewConnection->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete NewConnection;
MsQuic->ConnectionClose(ConnectionHandle);
} else {
NewConnection->SetHasRandomLoss(Listener->GetHasRandomLoss());
}
return;
}
if (*AcceptContext->NewConnection != nullptr) { // Retry scenario.
delete *AcceptContext->NewConnection;
*AcceptContext->NewConnection = nullptr;
}
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true);
*AcceptContext->NewConnection = new TestConnection(ConnectionHandle);
if (*AcceptContext->NewConnection == nullptr || !(*AcceptContext->NewConnection)->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete *AcceptContext->NewConnection;
@ -93,8 +118,6 @@ QuicTestConnect(
_In_ int Family,
_In_ bool ServerStatelessRetry,
_In_ bool ClientUsesOldVersion,
_In_ bool ClientRebind,
_In_ bool ChangeMaxStreamID,
_In_ bool MultipleALPNs,
_In_ bool AsyncSecConfig,
_In_ bool MultiPacketClientInitial,
@ -110,10 +133,6 @@ QuicTestConnect(
TEST_QUIC_SUCCEEDED(Session2.SetPeerBidiStreamCount(4));
TEST_QUIC_SUCCEEDED(Session2.SetIdleTimeout(10000));
StatelessRetryHelper RetryHelper(ServerStatelessRetry);
PrivateTransportHelper TpHelper(MultiPacketClientInitial);
RandomLossHelper LossHelper(RandomLossPercentage);
if (RandomLossPercentage != 0) {
TEST_QUIC_SUCCEEDED(Session.SetIdleTimeout(30000));
TEST_QUIC_SUCCEEDED(Session.SetDisconnectTimeout(30000));
@ -124,6 +143,20 @@ QuicTestConnect(
TEST_QUIC_SUCCEEDED(Session2.SetIdleTimeout(10000));
}
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
if (SessionResumption) {
bool Success;
QuicTestPrimeResumption(Session, QuicAddrFamily, Success);
if (!Success) {
return;
}
}
StatelessRetryHelper RetryHelper(ServerStatelessRetry);
PrivateTransportHelper TpHelper(MultiPacketClientInitial);
RandomLossHelper LossHelper(RandomLossPercentage);
{
TestListener Listener(
MultipleALPNs ? Session2.Handle : Session.Handle,
@ -132,47 +165,17 @@ QuicTestConnect(
TEST_TRUE(Listener.IsValid());
Listener.SetHasRandomLoss(RandomLossPercentage != 0);
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
QuicAddr ServerLocalAddr(QuicAddrFamily);
TEST_QUIC_SUCCEEDED(Listener.Start(&ServerLocalAddr.SockAddr));
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
if (SessionResumption) {
TestScopeLogger logScope("PrimeResumption");
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TEST_TRUE(Client.IsValid());
Client.SetHasRandomLoss(RandomLossPercentage != 0);
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
if (!Client.WaitForZeroRttTicket()) {
return;
}
Session.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT, 0);
Session2.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT, 0);
}
}
{
UniquePtr<TestConnection> Server;
ServerAcceptContext ServerAcceptCtx((TestConnection**)&Server);
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
Client.SetHasRandomLoss(RandomLossPercentage != 0);
@ -194,7 +197,7 @@ QuicTestConnect(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (AsyncSecConfig) {
if (!QuicEventWaitWithTimeout(ServerAcceptCtx.NewConnectionReady, TestWaitTimeout)) {
@ -237,44 +240,6 @@ QuicTestConnect(
Server->GetPeerBidiStreamCount(),
Client.GetLocalBidiStreamCount());
if (ClientRebind) {
QuicAddr OrigLocalAddr;
TEST_QUIC_SUCCEEDED(Client.GetLocalAddr(OrigLocalAddr));
QuicAddr NewLocalAddr(OrigLocalAddr, 1);
QuicSleep(100);
ReplaceAddressHelper AddrHelper(OrigLocalAddr.SockAddr, NewLocalAddr.SockAddr);
TEST_FALSE(Client.GetIsShutdown());
Client.SetKeepAlive(25);
bool ServerAddressUpdated = false;
uint32_t Try = 0;
do {
if (Try != 0) {
QuicSleep(200);
}
QuicAddr ServerRemoteAddr;
TEST_QUIC_SUCCEEDED(Server->GetRemoteAddr(ServerRemoteAddr));
if (Server->GetPeerAddrChanged() &&
QuicAddrCompare(&NewLocalAddr.SockAddr, &ServerRemoteAddr.SockAddr)) {
ServerAddressUpdated = true;
break;
}
} while (++Try <= 3);
TEST_TRUE(ServerAddressUpdated);
}
if (ChangeMaxStreamID) {
TEST_QUIC_SUCCEEDED(Client.SetPeerBidiStreamCount(101));
TEST_EQUAL(101, Client.GetPeerBidiStreamCount());
QuicSleep(100);
TEST_EQUAL(101, Server->GetLocalBidiStreamCount());
TEST_QUIC_SUCCEEDED(Server->SetPeerBidiStreamCount(100));
TEST_EQUAL(100, Server->GetPeerBidiStreamCount());
QuicSleep(100);
TEST_EQUAL(100, Client.GetLocalBidiStreamCount());
}
if (RandomLossPercentage == 0) {
//
// Don't worry about graceful shutdown if we have random
@ -301,6 +266,259 @@ QuicTestConnect(
}
}
void
QuicTestNatPortRebind(
_In_ int Family
)
{
MsQuicSession Session;
TEST_TRUE(Session.IsValid());
TEST_QUIC_SUCCEEDED(Session.SetIdleTimeout(10000));
{
TestListener Listener(Session.Handle, ListenerAcceptConnection);
TEST_TRUE(Listener.IsValid());
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
QuicAddr ServerLocalAddr(QuicAddrFamily);
TEST_QUIC_SUCCEEDED(Listener.Start(&ServerLocalAddr.SockAddr));
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
{
UniquePtr<TestConnection> Server;
ServerAcceptContext ServerAcceptCtx((TestConnection**)&Server);
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());
TEST_EQUAL(
Server->GetPeerBidiStreamCount(),
Client.GetLocalBidiStreamCount());
QuicAddr OrigLocalAddr;
TEST_QUIC_SUCCEEDED(Client.GetLocalAddr(OrigLocalAddr));
QuicAddr NewLocalAddr(OrigLocalAddr, 1);
QuicSleep(100);
ReplaceAddressHelper AddrHelper(OrigLocalAddr.SockAddr, NewLocalAddr.SockAddr);
TEST_FALSE(Client.GetIsShutdown());
Client.SetKeepAlive(25);
bool ServerAddressUpdated = false;
uint32_t Try = 0;
do {
if (Try != 0) {
QuicSleep(200);
}
QuicAddr ServerRemoteAddr;
TEST_QUIC_SUCCEEDED(Server->GetRemoteAddr(ServerRemoteAddr));
if (Server->GetPeerAddrChanged() &&
QuicAddrCompare(&NewLocalAddr.SockAddr, &ServerRemoteAddr.SockAddr)) {
ServerAddressUpdated = true;
break;
}
} while (++Try <= 3);
TEST_TRUE(ServerAddressUpdated);
Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_NO_ERROR);
if (!Client.WaitForShutdownComplete()) {
return;
}
TEST_FALSE(Client.GetPeerClosed());
TEST_FALSE(Client.GetTransportClosed());
}
TEST_TRUE(Server->GetPeerClosed());
TEST_EQUAL(Server->GetPeerCloseErrorCode(), QUIC_TEST_NO_ERROR);
}
}
}
void
QuicTestNatAddrRebind(
_In_ int Family
)
{
MsQuicSession Session;
TEST_TRUE(Session.IsValid());
TEST_QUIC_SUCCEEDED(Session.SetIdleTimeout(10000));
{
TestListener Listener(Session.Handle, ListenerAcceptConnection);
TEST_TRUE(Listener.IsValid());
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
QuicAddr ServerLocalAddr(QuicAddrFamily);
TEST_QUIC_SUCCEEDED(Listener.Start(&ServerLocalAddr.SockAddr));
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
{
UniquePtr<TestConnection> Server;
ServerAcceptContext ServerAcceptCtx((TestConnection**)&Server);
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());
TEST_EQUAL(
Server->GetPeerBidiStreamCount(),
Client.GetLocalBidiStreamCount());
QuicAddr OrigLocalAddr;
TEST_QUIC_SUCCEEDED(Client.GetLocalAddr(OrigLocalAddr));
QuicAddr NewLocalAddr(OrigLocalAddr, 1);
NewLocalAddr.IncrementAddr();
QuicSleep(100);
ReplaceAddressHelper AddrHelper(OrigLocalAddr.SockAddr, NewLocalAddr.SockAddr);
TEST_FALSE(Client.GetIsShutdown());
Client.SetKeepAlive(25);
bool ServerAddressUpdated = false;
uint32_t Try = 0;
do {
if (Try != 0) {
QuicSleep(200);
}
QuicAddr ServerRemoteAddr;
TEST_QUIC_SUCCEEDED(Server->GetRemoteAddr(ServerRemoteAddr));
if (Server->GetPeerAddrChanged() &&
QuicAddrCompare(&NewLocalAddr.SockAddr, &ServerRemoteAddr.SockAddr)) {
ServerAddressUpdated = true;
break;
}
} while (++Try <= 3);
TEST_TRUE(ServerAddressUpdated);
Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_NO_ERROR);
if (!Client.WaitForShutdownComplete()) {
return;
}
TEST_FALSE(Client.GetPeerClosed());
TEST_FALSE(Client.GetTransportClosed());
}
TEST_TRUE(Server->GetPeerClosed());
TEST_EQUAL(Server->GetPeerCloseErrorCode(), QUIC_TEST_NO_ERROR);
}
}
}
void
QuicTestChangeMaxStreamID(
_In_ int Family
)
{
MsQuicSession Session;
TEST_TRUE(Session.IsValid());
TEST_QUIC_SUCCEEDED(Session.SetIdleTimeout(10000));
{
TestListener Listener(Session.Handle, ListenerAcceptConnection);
TEST_TRUE(Listener.IsValid());
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
QuicAddr ServerLocalAddr(QuicAddrFamily);
TEST_QUIC_SUCCEEDED(Listener.Start(&ServerLocalAddr.SockAddr));
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
{
UniquePtr<TestConnection> Server;
ServerAcceptContext ServerAcceptCtx((TestConnection**)&Server);
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());
TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());
TEST_EQUAL(
Server->GetPeerBidiStreamCount(),
Client.GetLocalBidiStreamCount());
TEST_QUIC_SUCCEEDED(Client.SetPeerBidiStreamCount(101));
TEST_EQUAL(101, Client.GetPeerBidiStreamCount());
QuicSleep(100);
TEST_EQUAL(101, Server->GetLocalBidiStreamCount());
TEST_QUIC_SUCCEEDED(Server->SetPeerBidiStreamCount(100));
TEST_EQUAL(100, Server->GetPeerBidiStreamCount());
QuicSleep(100);
TEST_EQUAL(100, Client.GetLocalBidiStreamCount());
Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_NO_ERROR);
if (!Client.WaitForShutdownComplete()) {
return;
}
TEST_FALSE(Client.GetPeerClosed());
TEST_FALSE(Client.GetTransportClosed());
}
TEST_TRUE(Server->GetPeerClosed());
TEST_EQUAL(Server->GetPeerCloseErrorCode(), QUIC_TEST_NO_ERROR);
}
}
}
void
QuicTestConnectAndIdle(
_In_ bool EnableKeepAlive
@ -324,10 +542,7 @@ QuicTestConnectAndIdle(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
if (!EnableKeepAlive) {
@ -339,7 +554,7 @@ QuicTestConnectAndIdle(
AF_UNSPEC,
QUIC_LOCALHOST_FOR_AF(
QuicAddrGetFamily(&ServerLocalAddr.SockAddr)),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
@ -399,10 +614,7 @@ QuicTestConnectUnreachable(
{
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? AF_INET : AF_INET6;
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
Client.SetExpectedTransportCloseStatus(QUIC_STATUS_UNREACHABLE);
@ -444,10 +656,7 @@ QuicTestVersionNegotiation(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
@ -458,7 +667,7 @@ QuicTestVersionNegotiation(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
@ -498,10 +707,7 @@ QuicTestConnectBadAlpn(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
BadSession.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(BadSession);
TEST_TRUE(Client.IsValid());
Client.SetExpectedTransportCloseStatus(QUIC_STATUS_ALPN_NEG_FAILURE);
@ -509,7 +715,7 @@ QuicTestConnectBadAlpn(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
@ -546,10 +752,7 @@ QuicTestConnectBadSni(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
QuicAddr RemoteAddr(Family == 4 ? AF_INET : AF_INET6, true);
@ -560,7 +763,7 @@ QuicTestConnectBadSni(
Client.Start(
Family == 4 ? AF_INET : AF_INET6,
"badlocalhost",
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
@ -582,8 +785,15 @@ ListenerRejectConnection(
_In_ HQUIC ConnectionHandle
)
{
auto Connection = new TestConnection(ConnectionHandle, ConnectionDoNothingCallback, true, true);
Connection->Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_SPECIAL_ERROR);
auto Connection = new TestConnection(ConnectionHandle);
if (Connection == nullptr || !Connection->IsValid()) {
TEST_FAILURE("Failed to accept new TestConnection.");
delete Connection;
MsQuic->ConnectionClose(ConnectionHandle);
} else {
Connection->SetAutoDelete();
Connection->Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_SPECIAL_ERROR);
}
}
void
@ -605,10 +815,7 @@ QuicTestConnectServerRejected(
TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
Client.SetExpectedTransportCloseStatus(QUIC_STATUS_USER_CANCELED);
@ -616,7 +823,7 @@ QuicTestConnectServerRejected(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
}
@ -659,17 +866,14 @@ QuicTestKeyUpdate(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;
@ -776,17 +980,14 @@ QuicTestCidUpdate(
Listener.Context = &ServerAcceptCtx;
{
TestConnection Client(
Session.Handle,
ConnectionDoNothingCallback,
false);
TestConnection Client(Session);
TEST_TRUE(Client.IsValid());
TEST_QUIC_SUCCEEDED(
Client.Start(
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
QuicAddrGetPort(&ServerLocalAddr.SockAddr)));
ServerLocalAddr.GetPort()));
if (!Client.WaitForConnectionComplete()) {
return;

Просмотреть файл

@ -13,20 +13,16 @@ Abstract:
TestConnection::TestConnection(
_In_ HQUIC Handle,
_In_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler,
_In_ bool Server,
_In_ bool AutoDelete,
_In_ bool UseSendBuffer
_In_opt_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler
) :
QuicConnection(Server ? Handle : nullptr),
Context(nullptr), IsServer(Server), IsStarted(Server), IsConnected(false), Resumed(false),
QuicConnection(Handle),
Context(nullptr), IsServer(true), IsStarted(true), IsConnected(false), Resumed(false),
PeerAddrChanged(false), PeerClosed(false), ExpectedResumed(false),
ExpectedTransportCloseStatus(QUIC_STATUS_SUCCESS),
ExpectedPeerCloseErrorCode(QUIC_TEST_NO_ERROR),
TransportClosed(false), IsShutdown(false),
ShutdownTimedOut(false), AutoDelete(AutoDelete),
ShutdownTimedOut(false), AutoDelete(false),
NewStreamCallback(NewStreamCallbackHandler), ShutdownCompleteCallback(nullptr),
UseSendBuffer(UseSendBuffer),
DatagramsSent(0), DatagramsCanceled(0), DatagramsSuspectLost(0),
DatagramsLost(0), DatagramsAcknowledged(0)
{
@ -34,35 +30,48 @@ TestConnection::TestConnection(
QuicEventInitialize(&EventPeerClosed, TRUE, FALSE);
QuicEventInitialize(&EventShutdownComplete, TRUE, FALSE);
if (IsServer) {
if (QuicConnection == nullptr) {
TEST_FAILURE("Invalid handle passed into TestConnection.");
} else {
MsQuic->SetCallbackHandler(QuicConnection, (void*)QuicConnectionHandler, this);
}
if (QuicConnection == nullptr) {
TEST_FAILURE("Invalid handle passed into TestConnection.");
} else {
QUIC_STATUS Status =
MsQuic->ConnectionOpen(
Handle,
QuicConnectionHandler,
this,
&QuicConnection);
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuic->ConnectionOpen failed, 0x%x.", Status);
QuicConnection = nullptr;
}
MsQuic->SetCallbackHandler(QuicConnection, (void*)QuicConnectionHandler, this);
}
BOOLEAN Opt = UseSendBuffer;
Status =
MsQuic->SetParam(
QuicConnection,
QUIC_PARAM_LEVEL_CONNECTION,
QUIC_PARAM_CONN_SEND_BUFFERING,
sizeof(Opt),
(uint8_t*)&Opt);
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuicSetParam(SEND_BUFFERING) failed, 0x%x.", Status);
}
//
// Test code uses self-signed certificates, so we cannot validate the root.
//
SetCertValidationFlags(
QUIC_CERTIFICATE_FLAG_IGNORE_UNKNOWN_CA |
QUIC_CERTIFICATE_FLAG_IGNORE_CERTIFICATE_CN_INVALID);
}
TestConnection::TestConnection(
_In_ MsQuicSession& Session,
_In_opt_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler
) :
QuicConnection(nullptr),
Context(nullptr), IsServer(false), IsStarted(false), IsConnected(false), Resumed(false),
PeerAddrChanged(false), PeerClosed(false), ExpectedResumed(false),
ExpectedTransportCloseStatus(QUIC_STATUS_SUCCESS),
ExpectedPeerCloseErrorCode(QUIC_TEST_NO_ERROR),
TransportClosed(false), IsShutdown(false),
ShutdownTimedOut(false), AutoDelete(false),
NewStreamCallback(NewStreamCallbackHandler), ShutdownCompleteCallback(nullptr),
DatagramsSent(0), DatagramsCanceled(0), DatagramsSuspectLost(0),
DatagramsLost(0), DatagramsAcknowledged(0)
{
QuicEventInitialize(&EventConnectionComplete, TRUE, FALSE);
QuicEventInitialize(&EventPeerClosed, TRUE, FALSE);
QuicEventInitialize(&EventShutdownComplete, TRUE, FALSE);
QUIC_STATUS Status =
MsQuic->ConnectionOpen(
Session.Handle,
QuicConnectionHandler,
this,
&QuicConnection);
if (QUIC_FAILED(Status)) {
TEST_FAILURE("MsQuic->ConnectionOpen failed, 0x%x.", Status);
QuicConnection = nullptr;
}
//
@ -579,6 +588,40 @@ TestConnection::SetCertValidationFlags(
&value);
}
bool
TestConnection::GetUseSendBuffer()
{
BOOLEAN value;
uint32_t valueSize = sizeof(value);
QUIC_STATUS Status =
MsQuic->GetParam(
QuicConnection,
QUIC_PARAM_LEVEL_CONNECTION,
QUIC_PARAM_CONN_SEND_BUFFERING,
&valueSize,
&value);
if (QUIC_FAILED(Status)) {
value = 0;
TEST_FAILURE("MsQuic->GetParam(CONN_SEND_BUFFERING) failed, 0x%x.", Status);
}
return value != FALSE;
}
QUIC_STATUS
TestConnection::SetUseSendBuffer(
bool value
)
{
BOOLEAN bValue = value ? TRUE : FALSE;
return
MsQuic->SetParam(
QuicConnection,
QUIC_PARAM_LEVEL_CONNECTION,
QUIC_PARAM_CONN_SEND_BUFFERING,
sizeof(bValue),
&bValue);
}
uint32_t
TestConnection::GetKeepAlive()
{
@ -826,6 +869,14 @@ TestConnection::HandleConnectionEvent(
case QUIC_CONNECTION_EVENT_PEER_STREAM_STARTED:
if (Event->PEER_STREAM_STARTED.Stream == nullptr) {
TEST_FAILURE("Null Stream");
break;
}
if (NewStreamCallback == nullptr) {
//
// Test is ignoring streams. Just close it.
//
MsQuic->StreamClose(Event->PEER_STREAM_STARTED.Stream);
break;
}
NewStreamCallback(
this,

Просмотреть файл

@ -54,7 +54,6 @@ class TestConnection
bool IsShutdown : 1;
bool ShutdownTimedOut : 1;
bool AutoDelete : 1;
bool UseSendBuffer : 1;
bool HasRandomLoss : 1;
bool ExpectedResumed : 1;
@ -100,17 +99,21 @@ class TestConnection
public:
TestConnection(
_In_ HQUIC Handle, // Client: SessionHandle; Server:ConnectionHandle
_In_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler,
_In_ bool Server,
_In_ bool AutoDelete = false,
_In_ bool UseSendBuffer = true
_In_ HQUIC Handle, // Server:ConnectionHandle
_In_opt_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler = nullptr
);
TestConnection(
_In_ MsQuicSession& Session,
_In_opt_ NEW_STREAM_CALLBACK_HANDLER NewStreamCallbackHandler = nullptr
);
~TestConnection();
bool IsValid() const { return QuicConnection != nullptr; }
void SetAutoDelete() { AutoDelete = true; }
QUIC_STATUS
Start(
_In_ QUIC_ADDRESS_FAMILY Family,
@ -228,6 +231,9 @@ public:
uint32_t GetCertValidationFlags();
QUIC_STATUS SetCertValidationFlags(uint32_t value);
bool GetUseSendBuffer();
QUIC_STATUS SetUseSendBuffer(bool value);
uint32_t GetKeepAlive(); // milliseconds
QUIC_STATUS SetKeepAlive(uint32_t value); // milliseconds

Просмотреть файл

@ -69,6 +69,10 @@ struct QuicAddr {
TEST_NOT_EQUAL(0xFFFF, QuicAddrGetPort(&SockAddr));
QuicAddrSetPort(&SockAddr, (uint16_t)1 + QuicAddrGetPort(&SockAddr));
}
void IncrementAddr() {
QuicAddrIncrement(&SockAddr);
}
uint16_t GetPort() const { return QuicAddrGetPort(&SockAddr); }
};
template<class T>
@ -276,6 +280,13 @@ struct MsQuicSession {
}
};
void
QuicTestPrimeResumption(
MsQuicSession& Session,
QUIC_ADDRESS_FAMILY Family,
bool& Success
);
struct ListenerScope {
HQUIC Handle;
ListenerScope() : Handle(nullptr) { }