From ff4f3a3e5a69b95e4ce596403c663c1d46acce6f Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 29 Jul 2026 16:06:08 -0700 Subject: [PATCH] Add fflush calls in pdfium_test to prevent buffered output truncation Bot hypothesis about flakey windows component build tests. In pdfium_test.cc, call fflush(stdout) after printf calls in example embedder callbacks (such as ExampleAppAlert and ExampleAppResponse) and call fflush(stdout) and fflush(stderr) at the end of main(). On Windows MSVC CRT, block-buffered piped streams can be truncated if the process terminates before the buffer is flushed. Explicitly flushing stdout prevents truncation in text diff tests. TAG=agy CONV=8e1e302a-cea2-4f5a-972f-5b3625f86d6d Change-Id: Iea9180efccf3ec4b4db329c88c24efb83aca0466 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153630 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- testing/pdfium_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/pdfium_test.cc b/testing/pdfium_test.cc index 9a27e721bc..fbce83e9ad 100644 --- a/testing/pdfium_test.cc +++ b/testing/pdfium_test.cc @@ -330,11 +330,13 @@ int ExampleAppAlert(IPDF_JSPLATFORM*, printf("[icon=%d,type=%d]", icon, type); } printf(": %ls\n", GetPlatformWString(msg).c_str()); + fflush(stdout); return 0; } void ExampleAppBeep(IPDF_JSPLATFORM*, int type) { printf("BEEP!!! %d\n", type); + fflush(stdout); } int ExampleAppResponse(IPDF_JSPLATFORM*, @@ -350,6 +352,7 @@ int ExampleAppResponse(IPDF_JSPLATFORM*, GetPlatformWString(question).c_str(), GetPlatformWString(default_value).c_str(), GetPlatformWString(label).c_str(), is_password, length); + fflush(stdout); // UTF-16, always LE regardless of platform. auto* ptr = static_cast(response); @@ -384,6 +387,7 @@ void ExampleDocMail(IPDF_JSPLATFORM*, GetPlatformWString(To).c_str(), GetPlatformWString(CC).c_str(), GetPlatformWString(BCC).c_str(), GetPlatformWString(Subject).c_str(), GetPlatformWString(Msg).c_str()); + fflush(stdout); } void ExampleDocPrint(IPDF_JSPLATFORM*, @@ -397,6 +401,7 @@ void ExampleDocPrint(IPDF_JSPLATFORM*, FPDF_BOOL bAnnotations) { printf("Doc Print: %d, %d, %d, %d, %d, %d, %d, %d\n", bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); + fflush(stdout); } void ExampleDocSubmitForm(IPDF_JSPLATFORM*, @@ -410,10 +415,12 @@ void ExampleDocSubmitForm(IPDF_JSPLATFORM*, printf(" %02x", UNSAFE_TODO(ptr[i])); } printf("\n"); + fflush(stdout); } void ExampleDocGotoPage(IPDF_JSPLATFORM*, int page_number) { printf("Goto Page: %d\n", page_number); + fflush(stdout); } int ExampleFieldBrowse(IPDF_JSPLATFORM*, void* file_path, int length) { @@ -434,12 +441,14 @@ FPDF_BOOL ExamplePopupMenu(FPDF_FORMFILLINFO* pInfo, float x, float y) { printf("Popup: x=%2.1f, y=%2.1f, flags=0x%x\n", x, y, flags); + fflush(stdout); return true; } #endif // PDF_ENABLE_XFA void ExampleNamedAction(FPDF_FORMFILLINFO* pInfo, FPDF_BYTESTRING name) { UNSAFE_TODO(printf("Execute named action: %s\n", name)); + fflush(stdout); } void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) {