aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Windows/report_globals_reload_dll.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/Windows/report_globals_reload_dll.cc')
-rw-r--r--test/asan/TestCases/Windows/report_globals_reload_dll.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/asan/TestCases/Windows/report_globals_reload_dll.cc b/test/asan/TestCases/Windows/report_globals_reload_dll.cc
new file mode 100644
index 000000000000..8b050975aac1
--- /dev/null
+++ b/test/asan/TestCases/Windows/report_globals_reload_dll.cc
@@ -0,0 +1,51 @@
+// Make sure we can handle reloading the same DLL multiple times.
+// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe
+// RUN: env ASAN_OPTIONS=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+
+extern "C" {
+#if defined(EXE)
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ printf("Usage: %s [client].dll\n", argv[0]);
+ return 101;
+ }
+ const char *dll_name = argv[1];
+
+// CHECK: time to load DLL
+ printf("time to load DLL\n");
+ fflush(0);
+
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+ for (int i = 0; i < 30; ++i) {
+ HMODULE dll = LoadLibrary(dll_name);
+ if (dll == NULL)
+ return 3;
+
+ if (!FreeLibrary(dll))
+ return 4;
+ }
+
+// CHECK: All OK!
+ printf("All OK!\n");
+ fflush(0);
+}
+#elif defined(DLL)
+BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
+ printf("in DLL(reason=%d)\n", (int)reason);
+ fflush(0);
+ return TRUE;
+}
+#else
+# error oops!
+#endif
+}