Bug 681238 part 2 - Test WindowsDllInterceptor on functions we intercept in our codebase. r=vlad
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 29 Aug 2011 13:23:45 +0200
changeset 76387 ce43a8644bc03efa037d5ea6b5b3da69b5977edc
parent 76386 38bbf1e8ae5d4eccbea1b8f330bd96764d3ed455
child 76388 1a29139e6bafb68172bebb92f4208762aa939367
child 76505 1c2522e75c04ed9cc66681dd4bd91f5c18f3e60f
push id1635
push usermh@glandium.org
push dateThu, 01 Sep 2011 16:24:37 +0000
treeherdermozilla-inbound@ce43a8644bc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs681238
milestone9.0a1
first release with
nightly linux32
ce43a8644bc0 / 9.0a1 / 20110902030838 / files
nightly linux64
ce43a8644bc0 / 9.0a1 / 20110902030838 / files
nightly mac
ce43a8644bc0 / 9.0a1 / 20110902030838 / files
nightly win32
ce43a8644bc0 / 9.0a1 / 20110902030838 / files
nightly win64
ce43a8644bc0 / 9.0a1 / 20110902030838 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 681238 part 2 - Test WindowsDllInterceptor on functions we intercept in our codebase. r=vlad
toolkit/xre/test/win/TestDllInterceptor.cpp
--- a/toolkit/xre/test/win/TestDllInterceptor.cpp
+++ b/toolkit/xre/test/win/TestDllInterceptor.cpp
@@ -64,16 +64,30 @@ static payload (*orig_rotatePayload)(pay
 
 static payload
 patched_rotatePayload(payload p)
 {
   patched_func_called = true;
   return orig_rotatePayload(p);
 }
 
+bool TestHook(const char *dll, const char *func)
+{
+  void *orig_func;
+  WindowsDllInterceptor TestIntercept;
+  TestIntercept.Init(dll);
+  if (TestIntercept.AddHook(func, 0, &orig_func)) {
+    printf("TEST-PASS | WindowsDllInterceptor | Could hook %s from %s\n", func, dll);
+    return true;
+  } else {
+    printf("TEST-UNEXPECTED-FAIL | WindowsDllInterceptor | Failed to hook %s from %s\n", func, dll);
+    return false;
+  }
+}
+
 int main()
 {
   payload initial = { 0x12345678, 0xfc4e9d31, 0x87654321 };
   payload p0, p1;
   ZeroMemory(&p0, sizeof(p0));
   ZeroMemory(&p1, sizeof(p1));
 
   p0 = rotatePayload(initial);
@@ -119,11 +133,24 @@ int main()
 
   if (p0 == p1) {
     printf("TEST-PASS | WindowsDllInterceptor | Original function worked properly\n");
   } else {
     printf("TEST-UNEXPECTED-FAIL | WindowsDllInterceptor | Original function didn't return the right information\n");
     return 1;
   }
 
-  printf("TEST-PASS | WindowsDllInterceptor | all checks passed\n");
-  return 0;
+  if (TestHook("user32.dll", "GetWindowInfo") &&
+#ifdef _WIN64
+      TestHook("user32.dll", "SetWindowLongPtrA") &&
+      TestHook("user32.dll", "SetWindowLongPtrW") &&
+#else
+      TestHook("user32.dll", "SetWindowLongA") &&
+      TestHook("user32.dll", "SetWindowLongW") &&
+#endif
+      TestHook("user32.dll", "TrackPopupMenu") &&
+      TestHook("ntdll.dll", "LdrLoadDll")) {
+    printf("TEST-PASS | WindowsDllInterceptor | all checks passed\n");
+    return 0;
+  }
+
+  return 1;
 }