From 57def3460af9cd3992626d6a39f4e5b93a7d3fc0 Mon Sep 17 00:00:00 2001 From: Ed Day Date: Sat, 11 Jun 2011 00:49:24 -0400 Subject: [PATCH 1/2] Fix tinytest invocation from windows shell Original post: This post is in response to a posting last December on a Windows regression fork failure ([Libevent-users] Re: Libevent 2.0.10-stable is released by Dongsheng Song). I noticed the question was not answered and I recently experienced the same error myself when trying to run the Windows regression tests myself. I checked the return status from the CreateProcess call and found it was "file not found". This led me to look at the command-line I was using which was .\regress in a Visual Studio 2008 command prompt window. Windows could not find the file because it did not have the .exe extension on the end. The code that builds the command should be modified to ensure the extension is present. --- test/tinytest.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/tinytest.c b/test/tinytest.c index d0b77f74..87d1fc3b 100644 --- a/test/tinytest.c +++ b/test/tinytest.c @@ -67,7 +67,7 @@ const char *cur_test_name = NULL; #ifdef WIN32 /** Pointer to argv[0] for win32. */ -static const char *commandname = NULL; +static char *commandname = NULL; #endif static void usage(struct testgroup_t *groups, int list_groups) @@ -291,7 +291,19 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) int i, j, n=0; #ifdef WIN32 - commandname = v[0]; + const char* sp = strrchr (v[0], '.'); + if (0 != sp) { + if (0 != stricmp (sp, ".exe")) { /* not exe extension */ + sp = 0; + } + } + if (0 == sp) { + commandname = (char*) malloc (strlen(v[0]) + 5); + strcpy (commandname, v[0]); + strcat (commandname, ".exe"); + } + else + commandname = strdup (v[0]); #endif for (i=1; i= 1) printf("%d tests ok. (%d skipped)\n", n_ok, n_skipped); + free (commandname); + return (n_bad == 0) ? 0 : 1; } From 812d42e8863a7b9ccba8b03c5a7e32b31a1e4155 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 11 Jun 2011 01:26:54 -0400 Subject: [PATCH 2/2] Simplify windows commandname logic in tinytest Instead of using a dup'd pointer, let's use a static array, so we don't need to free it. This patch also makes tinytest build on non-windows again. --- test/tinytest.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/test/tinytest.c b/test/tinytest.c index 87d1fc3b..76376de0 100644 --- a/test/tinytest.c +++ b/test/tinytest.c @@ -66,8 +66,8 @@ const char *cur_test_prefix = NULL; /**< prefix of the current test group */ const char *cur_test_name = NULL; #ifdef WIN32 -/** Pointer to argv[0] for win32. */ -static char *commandname = NULL; +/* Copy of argv[0] for win32. */ +static char commandname[MAX_PATH+1]; #endif static void usage(struct testgroup_t *groups, int list_groups) @@ -291,19 +291,12 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) int i, j, n=0; #ifdef WIN32 - const char* sp = strrchr (v[0], '.'); - if (0 != sp) { - if (0 != stricmp (sp, ".exe")) { /* not exe extension */ - sp = 0; - } - } - if (0 == sp) { - commandname = (char*) malloc (strlen(v[0]) + 5); - strcpy (commandname, v[0]); - strcat (commandname, ".exe"); - } - else - commandname = strdup (v[0]); + const char *sp = strrchr(v[0], '.'); + const char *extension = ""; + if (!sp || stricmp(sp, ".exe")) + extension = ".exe"; /* Add an exe so CreateProcess will work */ + snprintf(commandname, sizeof(commandname), "%s%s", v[0], extension); + commandname[MAX_PATH]='\0'; #endif for (i=1; i= 1) printf("%d tests ok. (%d skipped)\n", n_ok, n_skipped); - free (commandname); - return (n_bad == 0) ? 0 : 1; }