Skip to content

Commit

Permalink
Replace QUIC_TEST_MODE with DEBUG (microsoft#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Apr 23, 2020
1 parent 819517b commit be5d771
Show file tree
Hide file tree
Showing 25 changed files with 85 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ QuicConnAlloc(
}
QuicZeroMemory(Connection, sizeof(QUIC_CONNECTION));

#if QUIC_TEST_MODE
#if DEBUG
InterlockedIncrement(&MsQuicLib.ConnectionCount);
#endif

Expand All @@ -91,7 +91,7 @@ QuicConnAlloc(
QuicTraceEvent(ConnCreated, Connection, IsServer, Connection->Stats.CorrelationId);

Connection->RefCount = 1;
#if QUIC_TEST_MODE
#if DEBUG
Connection->RefTypeCount[QUIC_CONN_REF_HANDLE_OWNER] = 1;
#endif
Connection->PartitionID = PartitionId;
Expand Down Expand Up @@ -361,7 +361,7 @@ QuicConnFree(
&MsQuicLib.PerProc[QuicLibraryGetCurrentPartition()].ConnectionPool,
Connection);

#if QUIC_TEST_MODE
#if DEBUG
InterlockedDecrement(&MsQuicLib.ConnectionCount);
#endif
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ typedef struct QUIC_CONNECTION {
//
long RefCount;

#if QUIC_TEST_MODE
#if DEBUG
short RefTypeCount[QUIC_CONN_REF_COUNT];
#endif

Expand Down Expand Up @@ -823,7 +823,7 @@ QuicConnOnShutdownComplete(
_In_ QUIC_CONNECTION* Connection
);

#if QUIC_TEST_MODE
#if DEBUG
_IRQL_requires_max_(DISPATCH_LEVEL)
inline
void
Expand All @@ -850,7 +850,7 @@ QuicConnAddRef(
{
QuicConnValidate(Connection);

#if QUIC_TEST_MODE
#if DEBUG
InterlockedIncrement16((volatile short*)&Connection->RefTypeCount[Ref]);
#else
UNREFERENCED_PARAMETER(Ref);
Expand All @@ -875,7 +875,7 @@ QuicConnRelease(
{
QuicConnValidate(Connection);

#if QUIC_TEST_MODE
#if DEBUG
QUIC_TEL_ASSERT(Connection->RefTypeCount[Ref] > 0);
uint16_t result = (uint16_t)InterlockedDecrement16((volatile short*)&Connection->RefTypeCount[Ref]);
QUIC_TEL_ASSERT(result != 0xFFFF);
Expand All @@ -885,7 +885,7 @@ QuicConnRelease(

QUIC_DBG_ASSERT(Connection->RefCount > 0);
if (InterlockedDecrement((volatile long*)&Connection->RefCount) == 0) {
#if QUIC_TEST_MODE
#if DEBUG
for (uint32_t i = 0; i < QUIC_CONN_REF_COUNT; i++) {
QUIC_TEL_ASSERT(Connection->RefTypeCount[i] == 0);
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ QuicConnFatalError(
_In_opt_z_ const char* ErrorMsg
);

#if DEBUG
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicConnValidate(
_In_ QUIC_CONNECTION* Connection
);
#endif

_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicConnRelease(
Expand Down
2 changes: 1 addition & 1 deletion src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ MsQuicLibraryUninitialize(
MsQuicLib.WorkerPool = NULL;
}

#if QUIC_TEST_MODE
#if DEBUG
//
// If you hit this assert, MsQuic API is trying to be unloaded without
// first cleaning up all connections.
Expand Down
2 changes: 1 addition & 1 deletion src/core/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef struct QUIC_LIBRARY {
//
uint8_t PartitionMask;

#if QUIC_TEST_MODE
#if DEBUG
//
// Number of connections current allocated.
//
Expand Down
12 changes: 6 additions & 6 deletions src/core/operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QuicOperationAlloc(
{
QUIC_OPERATION* Oper = (QUIC_OPERATION*)QuicPoolAlloc(&Worker->OperPool);
if (Oper != NULL) {
#if QUIC_TEST_MODE
#if DEBUG
Oper->Link.Flink = NULL;
#endif
Oper->Type = Type;
Expand Down Expand Up @@ -87,7 +87,7 @@ QuicOperationFree(
_In_ QUIC_OPERATION* Oper
)
{
#if QUIC_TEST_MODE
#if DEBUG
QUIC_DBG_ASSERT(Oper->Link.Flink == NULL);
#endif
QUIC_DBG_ASSERT(Oper->FreeAfterProcess);
Expand Down Expand Up @@ -129,7 +129,7 @@ QuicOperationEnqueue(
{
BOOLEAN StartProcessing;
QuicDispatchLockAcquire(&OperQ->Lock);
#if QUIC_TEST_MODE
#if DEBUG
QUIC_DBG_ASSERT(Oper->Link.Flink == NULL);
#endif
StartProcessing = QuicListIsEmpty(&OperQ->List) && !OperQ->ActivelyProcessing;
Expand All @@ -147,7 +147,7 @@ QuicOperationEnqueueFront(
{
BOOLEAN StartProcessing;
QuicDispatchLockAcquire(&OperQ->Lock);
#if QUIC_TEST_MODE
#if DEBUG
QUIC_DBG_ASSERT(Oper->Link.Flink == NULL);
#endif
StartProcessing = QuicListIsEmpty(&OperQ->List) && !OperQ->ActivelyProcessing;
Expand All @@ -172,7 +172,7 @@ QuicOperationDequeue(
Oper =
QUIC_CONTAINING_RECORD(
QuicListRemoveHead(&OperQ->List), QUIC_OPERATION, Link);
#if QUIC_TEST_MODE
#if DEBUG
Oper->Link.Flink = NULL;
#endif
}
Expand All @@ -198,7 +198,7 @@ QuicOperationQueueClear(
while (!QuicListIsEmpty(&OldList)) {
QUIC_OPERATION* Oper =
QUIC_CONTAINING_RECORD(QuicListRemoveHead(&OldList), QUIC_OPERATION, Link);
#if QUIC_TEST_MODE
#if DEBUG
Oper->Link.Flink = NULL;
#endif
if (Oper->FreeAfterProcess) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ QuicRangeGetMaxSafe(
}
}

#if QUIC_TEST_MODE
#if DEBUG

_IRQL_requires_max_(DISPATCH_LEVEL)
void
Expand Down
2 changes: 1 addition & 1 deletion src/core/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ QuicRangeGetMaxSafe(
// Use for debugging purposes.
//

#if QUIC_TEST_MODE
#if DEBUG

//
// Some simple heuristics to try to make sure the range is valid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ QuicSendQueueFlushForStream(
}
}

#if QUIC_TEST_MODE
#if DEBUG
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicSendValidate(
Expand Down
2 changes: 1 addition & 1 deletion src/core/send.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ QuicSendUninitialize(
_In_ QUIC_SEND* Send
);

#if QUIC_TEST_MODE
#if DEBUG
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicSendValidate(
Expand Down
2 changes: 1 addition & 1 deletion src/core/send_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ QuicSendBufferFill(
QUIC_STREAM* Stream = QUIC_CONTAINING_RECORD(Entry, QUIC_STREAM, SendLink);
Entry = Entry->Flink;

#if QUIC_TEST_MODE
#if DEBUG
//
// Sanity check: SendBufferBookmark should always point to the
// first unbuffered send request (if there is one), and no requests
Expand Down
2 changes: 1 addition & 1 deletion src/core/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ QuicStreamInitialize(
Stream->SendRequestsTail = &Stream->SendRequests;
QuicDispatchLockInitialize(&Stream->ApiSendRequestLock);
QuicRefInitialize(&Stream->RefCount);
#if QUIC_TEST_MODE
#if DEBUG
Stream->RefTypeCount[QUIC_STREAM_REF_APP] = 1;
#endif

Expand Down
8 changes: 4 additions & 4 deletions src/core/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ typedef struct QUIC_STREAM {
//
QUIC_REF_COUNT RefCount;

#if QUIC_TEST_MODE
#if DEBUG
short RefTypeCount[QUIC_STREAM_REF_COUNT];
#endif

Expand Down Expand Up @@ -580,7 +580,7 @@ QuicStreamAddRef(
QUIC_DBG_ASSERT(Stream->Connection);
QUIC_DBG_ASSERT(Stream->RefCount > 0);

#if QUIC_TEST_MODE
#if DEBUG
InterlockedIncrement16((volatile short*)&Stream->RefTypeCount[Ref]);
#else
UNREFERENCED_PARAMETER(Ref);
Expand All @@ -605,7 +605,7 @@ QuicStreamRelease(
QUIC_DBG_ASSERT(Stream->Connection);
QUIC_TEL_ASSERT(Stream->RefCount > 0);

#if QUIC_TEST_MODE
#if DEBUG
QUIC_TEL_ASSERT(Stream->RefTypeCount[Ref] > 0);
uint16_t result = (uint16_t)InterlockedDecrement16((volatile short*)&Stream->RefTypeCount[Ref]);
QUIC_TEL_ASSERT(result != 0xFFFF);
Expand All @@ -614,7 +614,7 @@ QuicStreamRelease(
#endif

if (QuicRefDecrement(&Stream->RefCount)) {
#if QUIC_TEST_MODE
#if DEBUG
for (uint32_t i = 0; i < QUIC_STREAM_REF_COUNT; i++) {
QUIC_TEL_ASSERT(Stream->RefTypeCount[i] == 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/stream_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QuicStreamCompleteSendRequest(
_In_ BOOLEAN Canceled
);

#if QUIC_TEST_MODE
#if DEBUG

_IRQL_requires_max_(PASSIVE_LEVEL)
void
Expand Down
2 changes: 1 addition & 1 deletion src/core/stream_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "stream_set.tmh"
#endif

#if QUIC_TEST_MODE
#if DEBUG
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicStreamSetValidate(
Expand Down
4 changes: 2 additions & 2 deletions src/core/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ QuicWorkerGetNextOperation(
Operation =
QUIC_CONTAINING_RECORD(
QuicListRemoveHead(&Worker->Operations), QUIC_OPERATION, Link);
#if QUIC_TEST_MODE
#if DEBUG
Operation->Link.Flink = NULL;
#endif
Worker->OperationCount--;
Expand Down Expand Up @@ -596,7 +596,7 @@ QUIC_THREAD_CALLBACK(QuicWorkerThread, Context)
QUIC_OPERATION* Operation =
QUIC_CONTAINING_RECORD(
QuicListRemoveHead(&Worker->Operations), QUIC_OPERATION, Link);
#if QUIC_TEST_MODE
#if DEBUG
Operation->Link.Flink = NULL;
#endif
QuicOperationFree(Worker, Operation);
Expand Down
19 changes: 12 additions & 7 deletions src/inc/quic_platform_winkernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ ZwSetInformationThread(
extern "C" {
#endif

#if DBG
#define DEBUG 1
#endif

#if _WIN64
#define QUIC_64BIT 1
#else
Expand Down Expand Up @@ -178,13 +182,14 @@ QuicPlatformLogAssert(
#define QUIC_ANALYSIS_ASSUME(_exp) _Analysis_assume_(_exp)
#else // _PREFAST_
// QUIC_ANALYSIS_ASSUME ensures that _exp is parsed in non-analysis compile.
// On DBG, it's guaranteed to be parsed as part of the normal compile, but with
// non-DBG, use __noop to ensure _exp is parseable but without code generation.
#if DBG
// On DEBUG, it's guaranteed to be parsed as part of the normal compile, but
// with non-DEBUG, use __noop to ensure _exp is parseable but without code
// generation.
#if DEBUG
#define QUIC_ANALYSIS_ASSUME(_exp) ((void) 0)
#else // DBG
#else // DEBUG
#define QUIC_ANALYSIS_ASSUME(_exp) __noop(_exp)
#endif // DBG
#endif // DEBUG
#endif // _PREFAST_

//
Expand All @@ -196,15 +201,15 @@ QuicPlatformLogAssert(
// QUIC_FRE_ASSERT - Asserts that must always crash the system.
//

#if DBG || QUIC_TEST_MODE
#if DEBUG
#define QUIC_DBG_ASSERT(_exp) (QUIC_ANALYSIS_ASSUME(_exp), QUIC_ASSERT_ACTION(_exp))
#define QUIC_DBG_ASSERTMSG(_exp, _msg) (QUIC_ANALYSIS_ASSUME(_exp), QUIC_ASSERTMSG_ACTION(_msg, _exp))
#else
#define QUIC_DBG_ASSERT(_exp) (QUIC_ANALYSIS_ASSUME(_exp), 0)
#define QUIC_DBG_ASSERTMSG(_exp, _msg) (QUIC_ANALYSIS_ASSUME(_exp), 0)
#endif

#if DBG || QUIC_TEST_MODE
#if DEBUG
#define QUIC_TEL_ASSERT(_exp) (QUIC_ANALYSIS_ASSUME(_exp), QUIC_ASSERT_ACTION(_exp))
#define QUIC_TEL_ASSERTMSG(_exp, _msg) (QUIC_ANALYSIS_ASSUME(_exp), QUIC_ASSERTMSG_ACTION(_msg, _exp))
#define QUIC_TEL_ASSERTMSG_ARGS(_exp, _msg, _origin, _bucketArg1, _bucketArg2) \
Expand Down
Loading

0 comments on commit be5d771

Please sign in to comment.