From cbe0e499df219ffffac56c106094d07a97f5d49b Mon Sep 17 00:00:00 2001
From: "Dimitrie O. Paun" <dpaun@rogers.com>
Date: Sat, 20 Mar 2004 19:21:39 +0000
Subject: [PATCH] Add revision support to winetest.exe.

---
 programs/winetest/Makefile.in |  3 ++
 programs/winetest/main.c      | 75 ++++++++++++++++++++++++++++++++++-
 programs/winetest/maketest    |  9 +++++
 3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/programs/winetest/Makefile.in b/programs/winetest/Makefile.in
index f6014baf6e8..df76fbad9c2 100644
--- a/programs/winetest/Makefile.in
+++ b/programs/winetest/Makefile.in
@@ -47,6 +47,9 @@ TESTBINS = $(TESTS:%=%_test.exe$(DLLEXT))
 winetest.rc: maketest Makefile.in
 	$(SRCDIR)/maketest $(TESTBINS) > $@ || ( $(RM) $@ && exit 1 )
 
+revision.info:
+	(cd $(TOPSRCDIR); for file in dlls/*/tests/*.c; do rev=`cvs stat "$$file" | grep "Working" | awk '{print $$3}'`; echo "$$file:$$rev"; done) > $@ || ( $(RM) $@ && exit 1 )
+
 winetest.res: $(TESTBINS)
 
 clean::
diff --git a/programs/winetest/main.c b/programs/winetest/main.c
index 6aa6b2e6c80..5390a3d8d80 100644
--- a/programs/winetest/main.c
+++ b/programs/winetest/main.c
@@ -49,7 +49,14 @@ struct wine_test
     char *exename;
 };
 
+struct rev_info
+{
+    const char* file;
+    const char* rev;
+};
+
 static struct wine_test *wine_tests;
+static struct rev_info *rev_infos;
 
 static const char *wineloader;
 
@@ -115,6 +122,65 @@ void remove_dir (const char *dir)
                 dir, GetLastError ());
 }
 
+const char* get_test_source_file(const char* test, const char* subtest)
+{
+    static const char* special_dirs[][2] = {
+	{ "gdi32", "gdi"}, { "kernel32", "kernel" },
+	{ "user32", "user" }, { "winspool.drv", "winspool" },
+	{ "ws2_32", "winsock" }, { 0, 0 }
+    };
+    static char buffer[MAX_PATH];
+    int i;
+
+    for (i = 0; special_dirs[i][0]; i++) {
+	if (strcmp(test, special_dirs[i][0]) == 0) {
+	    test = special_dirs[i][1];
+	    break;
+	}
+    }
+
+    snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
+    fprintf(stderr, "file=%s\n", buffer);
+    return buffer;
+}
+
+const char* get_file_rev(const char* file)
+{
+    const struct rev_info* rev;
+ 
+    for(rev = rev_infos; rev->file; rev++) {
+	fprintf(stderr, "  ?{%s:%s)\n", rev->file, rev->rev);
+	if (strcmp(rev->file, file) == 0) return rev->rev;
+    }
+
+    return "";
+}
+
+void extract_rev_infos ()
+{
+    char revinfo[256], *p;
+    int size = 0, i = 0, len;
+    HMODULE module = GetModuleHandle (NULL);
+
+    for (i = 0; TRUE; i++) {
+	if (i >= size) {
+	    size += 100;
+	    rev_infos = xrealloc(rev_infos, size);
+	}
+	memset(rev_infos + i, 0, sizeof(rev_infos[i]));
+
+        len = LoadStringA (module, i + 30000, revinfo, sizeof(revinfo));
+        if (len == 0) break; /* end of revision info */
+	if (len >= sizeof(revinfo)) 
+	    report (R_FATAL, "Revision info too long.");
+	if(!(p = strrchr(revinfo, ':')))
+	    report (R_FATAL, "Revision info malformed (i=%d)", i);
+	*p = 0;
+	rev_infos[i].file = strdup(revinfo);
+	rev_infos[i].rev = strdup(p + 1);
+    } while(1);
+}
+
 void* extract_rcdata (int id, DWORD* size)
 {
     HRSRC rsrc;
@@ -236,9 +302,11 @@ get_subtests (const char *tempdir, struct wine_test *test, int id)
 int run_test (struct wine_test* test, const char* subtest)
 {
     int status;
-    const char *argv[] = {"wine", test->exename, subtest, NULL};
+    const char* argv[] = {"wine", test->exename, subtest, NULL};
+    const char* file = get_test_source_file(test->name, subtest);
+    const char* rev = get_file_rev(file);
 
-    xprintf ("%s:%s start\n", test->name, subtest);
+    xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
     if (test->is_elf)
         status = spawnvp (_P_WAIT, wineloader, argv);
     else
@@ -386,6 +454,9 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
     char *tag = NULL, *cp;
     const char *submit = NULL;
 
+    /* initialize the revision information first */
+    extract_rev_infos();
+
     cmdLine = mystrtok (cmdLine);
     while (cmdLine) {
         if (*cmdLine == '-')
diff --git a/programs/winetest/maketest b/programs/winetest/maketest
index 59f9873777e..641ffa8621e 100755
--- a/programs/winetest/maketest
+++ b/programs/winetest/maketest
@@ -15,6 +15,15 @@ do
     i=`expr $i + 1`
     echo "$i \"$test\""
 done
+
+if [ -f revision.info ]; then
+    i=0
+    for line in `cat revision.info`; do
+        i=`expr $i + 1`
+	echo "$i+30000 \"$line\""
+    done
+fi
+
 echo "}"
 
 i=0