mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 10:45:45 +00:00
Repair MSVC-CRT leakage detector and enable this detection with Appveyor-CI (#5105)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
38bf4cfc03
commit
3f388ec747
@@ -2463,13 +2463,6 @@ void CreateSharedStringTest() {
|
||||
|
||||
int FlatBufferTests() {
|
||||
// clang-format off
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF
|
||||
// For more thorough checking:
|
||||
//| _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF
|
||||
);
|
||||
#endif
|
||||
|
||||
// Run our various test suites:
|
||||
|
||||
@@ -2563,9 +2556,8 @@ int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
|
||||
if (!testing_fails) {
|
||||
TEST_OUTPUT_LINE("ALL TESTS PASSED");
|
||||
return 0;
|
||||
} else {
|
||||
TEST_OUTPUT_LINE("%d FAILED TESTS", testing_fails);
|
||||
return 1;
|
||||
}
|
||||
return CloseTestEngine();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include "test_assert.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <crtdbg.h>
|
||||
#endif
|
||||
@@ -27,13 +28,9 @@ void TestEqStr(const char *expval, const char *val, const char *exp,
|
||||
if (strcmp(expval, val) != 0) { TestFail(expval, val, exp, file, line); }
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Without this hook function the message box not suppressed.
|
||||
int msvc_no_dialog_box_on_assert(int rpt_type, char *msg, int *ret_val) {
|
||||
(void)ret_val;
|
||||
TEST_OUTPUT_LINE("TEST ASSERTED: %d: %s", rpt_type, msg);
|
||||
return 1;
|
||||
}
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#define FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC
|
||||
#endif
|
||||
|
||||
void InitTestEngine(TestFailEventListener listener) {
|
||||
@@ -46,14 +43,37 @@ void InitTestEngine(TestFailEventListener listener) {
|
||||
// clang-format off
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Suppress pop-up message box on assertion (MSVC2010, MSVC2012).
|
||||
// This message box hangs CI-test on the hour until timeout expired.
|
||||
// Default mode is file, file is stderr.
|
||||
// Send all reports to STDOUT.
|
||||
// CrtDebug reports to _CRT_WARN channel.
|
||||
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
||||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
|
||||
// The assert from <assert.h> reports to _CRT_ERROR channel
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
|
||||
// Internal CRT assert channel?
|
||||
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
||||
_CrtSetReportHook(msvc_no_dialog_box_on_assert);
|
||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
|
||||
#endif
|
||||
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
||||
// For more thorough checking:
|
||||
// _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF
|
||||
auto flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
_CrtSetDbgFlag(flags | _CRTDBG_ALLOC_MEM_DF);
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
fail_listener_ = listener;
|
||||
}
|
||||
|
||||
int CloseTestEngine(bool force_report) {
|
||||
if (!testing_fails || force_report) {
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
||||
auto flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
flags &= ~_CRTDBG_DELAY_FREE_MEM_DF;
|
||||
flags |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flags);
|
||||
#endif
|
||||
}
|
||||
return (0 != testing_fails);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef TEST_ASSERT_H
|
||||
#define TEST_ASSERT_H
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
// clang-format off
|
||||
@@ -42,6 +43,12 @@ typedef bool (*TestFailEventListener)(const char *expval, const char *val,
|
||||
// listener - this function will be notified on each TestFail call.
|
||||
void InitTestEngine(TestFailEventListener listener = nullptr);
|
||||
|
||||
// Release all test-engine resources.
|
||||
// Prints or schedule a debug report if all test passed.
|
||||
// Returns 0 if all tests passed or 1 otherwise.
|
||||
// Memory leak report: FLATBUFFERS_MEMORY_LEAK_TRACKING && _MSC_VER && _DEBUG.
|
||||
int CloseTestEngine(bool force_report = false);
|
||||
|
||||
// Write captured state to a log and terminate test run.
|
||||
void TestFail(const char *expval, const char *val, const char *exp,
|
||||
const char *file, int line, const char *func = 0);
|
||||
|
||||
Reference in New Issue
Block a user