]> granicus.if.org Git - check/commitdiff
* Added code and tests for timeout scaling via environment variable.
authorhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Fri, 6 Mar 2009 23:29:20 +0000 (23:29 +0000)
committerhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Fri, 6 Mar 2009 23:29:20 +0000 (23:29 +0000)
   Feature requested in tracker item #1549835 on sourceforge. Docs
   coming later.

git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@538 64e312b2-a51f-0410-8e61-82d0ca0eb02a

src/check.c
tests/check_check_master.c
tests/check_check_sub.c

index 49f1b686b86b7322bea2d11eed9e2bc2d4efdadc..41b9e793cd8c0e85261c1537bc10ad7aec7cb375 100644 (file)
@@ -89,7 +89,15 @@ TCase *tcase_create (const char *name)
       timeout = tmp;
     }
   }
-  
+
+  env = getenv("CK_TIMEOUT_MULTIPLIER");
+  if (env != NULL) {
+    int tmp = atoi(env);
+    if (tmp >= 0) {
+      timeout = timeout * tmp;
+    }
+  }  
+
   tc->timeout = timeout;
   tc->tflst = check_list_create();
   tc->unch_sflst = check_list_create();
@@ -180,8 +188,16 @@ static void tcase_add_fixture (TCase *tc, SFun setup, SFun teardown,
 
 void tcase_set_timeout (TCase *tc, int timeout)
 {
-  if (timeout >= 0)
+  if (timeout >= 0) {
+    char *env = getenv("CK_TIMEOUT_MULTIPLIER");
+    if (env != NULL) {
+      int tmp = atoi(env);
+      if (tmp >= 0) {
+        timeout = timeout * tmp;
+      }
+    }
     tc->timeout = timeout;
+  }
 }
 
 void tcase_fn_start (const char *fname CK_ATTRIBUTE_UNUSED, const char *file, int line)
index cc7013509fbd6ef877859550d419215473f78ed6..056d933f0af4d899f53b27185d24d05a7b92b1da 100644 (file)
@@ -59,10 +59,12 @@ static master_test_t master_tests[] = {
   { "Signal Tests", CK_ERROR,   signal_8_str },
 
 #if TIMEOUT_TESTS_ENABLED
+#if HAVE_WORKING_SETENV
   { "Environment Timeout Tests", CK_ERROR,  "Test timeout expired" },
   { "Environment Timeout Tests", CK_PASS,   "Passed" },
   { "Environment Timeout Tests", CK_PASS,   "Passed" },
   { "Environment Timeout Tests", CK_ERROR,  "Test timeout expired" },
+#endif
   { "Timeout Tests", CK_ERROR,  "Test timeout expired" },
   { "Timeout Tests", CK_PASS,   "Passed" },
   { "Timeout Tests", CK_ERROR,  "Test timeout expired" },
@@ -76,6 +78,20 @@ static master_test_t master_tests[] = {
   { "Timeout Tests", CK_PASS,   "Passed" },
   { "Timeout Tests", CK_ERROR,  "Test timeout expired" },
   { "Timeout Tests", CK_ERROR,  "Test timeout expired" },
+#if HAVE_WORKING_SETENV
+  { "Environment Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+  { "Environment Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "Environment Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "Environment Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+  { "Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+  { "Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+  { "User Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+  { "User Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "User Timeout Scaling Tests", CK_PASS,   "Passed" },
+  { "User Timeout Scaling Tests", CK_ERROR,  "Test timeout expired" },
+#endif
 #endif
 
   { "Limit Tests", CK_ERROR,   "Early exit with return value 1" },
index bd30b073eee1d1e416f7be082cff652553f19895..76e594a630a0bb55bbef542772528d7baa1f4d08 100644 (file)
@@ -246,10 +246,17 @@ START_TEST(test_sleep5)
 }
 END_TEST
 
-START_TEST(test_sleep8)
-  #define LINENO_sleep8 _STR(__LINE__)
+START_TEST(test_sleep9)
+  #define LINENO_sleep9 _STR(__LINE__)
 {
-  sleep(8);
+  sleep(9);
+}
+END_TEST
+
+START_TEST(test_sleep14)
+  #define LINENO_sleep14 _STR(__LINE__)
+{
+  sleep(14);
 }
 END_TEST
 #endif
@@ -472,22 +479,38 @@ void init_master_tests_lineno(void) {
 
 #if TIMEOUT_TESTS_ENABLED
 /* Timeout Tests */
+#if HAVE_WORKING_SETENV
     LINENO_eternal,
     "-1",
     "-1",
-    LINENO_sleep8,
+    LINENO_sleep9,
+#endif
     LINENO_eternal,
     "-1",
     LINENO_sleep5,
-    LINENO_sleep8,
+    LINENO_sleep9,
     LINENO_eternal,
     "-1",
     "-1",
-    LINENO_sleep8,
+    LINENO_sleep9,
     LINENO_eternal,
     "-1",
     LINENO_sleep5,
-    LINENO_sleep8,
+    LINENO_sleep9,
+#if HAVE_WORKING_SETENV
+    LINENO_eternal,
+    "-1",
+    "-1",
+    LINENO_sleep14,
+    LINENO_eternal,
+    "-1",
+    "-1",
+    LINENO_sleep9,
+    LINENO_eternal,
+    "-1",
+    "-1",
+    LINENO_sleep14,
+#endif
 #endif
 
 /* Limit Tests */
@@ -527,6 +550,11 @@ Suite *make_sub_suite(void)
 #endif /* HAVE_WORKING_SETENV */
   TCase *tc_timeout;
   TCase *tc_timeout_usr;
+#if HAVE_WORKING_SETENV
+  TCase *tc_timeout_env_scale;
+  TCase *tc_timeout_scale;
+  TCase *tc_timeout_usr_scale;
+#endif /* HAVE_WORKING_SETENV */
 #endif
   TCase *tc_limit;
   TCase *tc_messaging_and_fork;
@@ -543,6 +571,15 @@ Suite *make_sub_suite(void)
 #endif /* HAVE_WORKING_SETENV */
   tc_timeout = tcase_create("Timeout Tests");
   tc_timeout_usr = tcase_create("User Timeout Tests");
+#if HAVE_WORKING_SETENV
+  setenv("CK_TIMEOUT_MULTIPLIER", "2", 1);
+  tc_timeout_scale = tcase_create("Timeout Scaling Tests");
+  tc_timeout_usr_scale = tcase_create("User Timeout Scaling Tests");
+  setenv("CK_DEFAULT_TIMEOUT", "6", 1);
+  tc_timeout_env_scale = tcase_create("Environment Timeout Scaling Tests");
+  unsetenv("CK_DEFAULT_TIMEOUT");
+  unsetenv("CK_TIMEOUT_MULTIPLIER");
+#endif
 #endif
   tc_limit = tcase_create("Limit Tests");
   tc_messaging_and_fork = tcase_create("Msg and fork Tests");
@@ -557,6 +594,11 @@ Suite *make_sub_suite(void)
   suite_add_tcase (s, tc_timeout_usr);
   /* Add a second time to make sure tcase_set_timeout doesn't contaminate it. */
   suite_add_tcase (s, tc_timeout);
+#if HAVE_WORKING_SETENV
+  suite_add_tcase (s, tc_timeout_env_scale);
+  suite_add_tcase (s, tc_timeout_scale);
+  suite_add_tcase (s, tc_timeout_usr_scale);
+#endif
 #endif
   suite_add_tcase (s, tc_limit);
   suite_add_tcase (s, tc_messaging_and_fork);
@@ -605,19 +647,36 @@ Suite *make_sub_suite(void)
   tcase_add_test (tc_timeout_env, test_eternal);
   tcase_add_test (tc_timeout_env, test_sleep2);
   tcase_add_test (tc_timeout_env, test_sleep5);
-  tcase_add_test (tc_timeout_env, test_sleep8);
+  tcase_add_test (tc_timeout_env, test_sleep9);
 #endif /* HAVE_WORKING_SETENV */
 
   tcase_add_test (tc_timeout, test_eternal);
   tcase_add_test (tc_timeout, test_sleep2);
   tcase_add_test (tc_timeout, test_sleep5);
-  tcase_add_test (tc_timeout, test_sleep8);
+  tcase_add_test (tc_timeout, test_sleep9);
 
   tcase_set_timeout (tc_timeout_usr, 6);
   tcase_add_test (tc_timeout_usr, test_eternal);
   tcase_add_test (tc_timeout_usr, test_sleep2);
   tcase_add_test (tc_timeout_usr, test_sleep5);
-  tcase_add_test (tc_timeout_usr, test_sleep8);
+  tcase_add_test (tc_timeout_usr, test_sleep9);
+#if HAVE_WORKING_SETENV
+  tcase_add_test (tc_timeout_env_scale, test_eternal);
+  tcase_add_test (tc_timeout_env_scale, test_sleep5);
+  tcase_add_test (tc_timeout_env_scale, test_sleep9);
+  tcase_add_test (tc_timeout_env_scale, test_sleep14);
+  tcase_add_test (tc_timeout_scale, test_eternal);
+  tcase_add_test (tc_timeout_scale, test_sleep2);
+  tcase_add_test (tc_timeout_scale, test_sleep5);
+  tcase_add_test (tc_timeout_scale, test_sleep9);
+  setenv("CK_TIMEOUT_MULTIPLIER", "2", 1);
+  tcase_set_timeout (tc_timeout_usr_scale, 6);
+  unsetenv("CK_TIMEOUT_MULTIPLIER");
+  tcase_add_test (tc_timeout_usr_scale, test_eternal);
+  tcase_add_test (tc_timeout_usr_scale, test_sleep5);
+  tcase_add_test (tc_timeout_usr_scale, test_sleep9);
+  tcase_add_test (tc_timeout_usr_scale, test_sleep14);
+#endif
 #if 0
   tcase_set_timeout (tc_timeout_kill, 2);
   tcase_add_test (tc_timeout_kill, test_sleep);