Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.134
diff -u -p -r1.134 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	5 Aug 2009 15:58:35 -0000	1.134
+++ modules/simpletest/drupal_web_test_case.php	9 Aug 2009 07:26:03 -0000
@@ -30,8 +30,12 @@ abstract class DrupalTestCase {
 
   /**
    * Time limit for the test.
+   *
+   * The value is initialized in the constructor from a settings variable.
+   *
+   * @var integer
    */
-  protected $timeLimit = 180;
+  protected $timeLimit;
 
   /**
    * Current results of this test case.
@@ -69,6 +73,7 @@ abstract class DrupalTestCase {
    */
   public function __construct($test_id = NULL) {
     $this->testId = $test_id;
+    $this->timeLimit = variable_get('simpletest_time_limit', 180);
   }
 
   /**
Index: modules/simpletest/simpletest.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.install,v
retrieving revision 1.25
diff -u -p -r1.25 simpletest.install
--- modules/simpletest/simpletest.install	22 Jul 2009 04:45:35 -0000	1.25
+++ modules/simpletest/simpletest.install	9 Aug 2009 07:26:03 -0000
@@ -109,6 +109,7 @@ function simpletest_uninstall() {
   variable_del('simpletest_password');
   variable_del('simpletest_clear_results');
   variable_del('simpletest_verbose');
+  variable_del('simpletest_time_limit');
 
   // Uninstall schema.
   drupal_uninstall_schema('simpletest');
@@ -132,6 +133,7 @@ function simpletest_requirements($phase)
   $has_curl = function_exists('curl_init');
   $has_hash = function_exists('hash_hmac');
   $has_domdocument = class_exists('DOMDocument');
+  $can_set_time_limit = !ini_get('safe_mode') && strpos(ini_get('disable_functions'), 'set_time_limit') === FALSE;
 
   $requirements['curl'] = array(
     'title' => $t('cURL'),
@@ -156,7 +158,16 @@ function simpletest_requirements($phase)
   );
   if (!$has_domdocument) {
     $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
-    $requirements['php_domdocument']['description'] =t('SimpleTest requires the DOMDocument class to be available. Please check the configure command at the <a href="@link-phpinfo">PHP info page</a>.', array('@link-phpinfo' => url('admin/reports/status/php')));
+    $requirements['php_domdocument']['description'] = $t('SimpleTest requires the DOMDocument class to be available. Please check the configure command at the <a href="@link-phpinfo">PHP info page</a>.', array('@link-phpinfo' => url('admin/reports/status/php')));
+  }
+
+  $requirements['php_set_time_limit'] = array(
+    'title' => $t('Can call %f', array('%f' => 'set_time_limit()')),
+    'value' => $can_set_time_limit ? $t('Yes') : $t('No'),
+  );
+  if (!$can_set_time_limit) {
+    $requirements['php_set_time_limit']['severity'] = REQUIREMENT_ERROR;
+    $requirements['php_set_time_limit']['description'] = $t('Simpletest cannot run in safe_mode or with function set_time_limit() disable. Correct this in php.ini.');
   }
 
   return $requirements;
Index: modules/simpletest/simpletest.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.pages.inc,v
retrieving revision 1.11
diff -u -p -r1.11 simpletest.pages.inc
--- modules/simpletest/simpletest.pages.inc	4 Aug 2009 06:47:00 -0000	1.11
+++ modules/simpletest/simpletest.pages.inc	9 Aug 2009 07:26:03 -0000
@@ -264,8 +264,8 @@ function simpletest_result_form(&$form_s
       $form['result']['summary']['#' . $assertion->status]++;
     }
     $form['result']['results'][$group]['table'] = array(
-      '#theme' => 'table', 
-      '#header' => $header, 
+      '#theme' => 'table',
+      '#header' => $header,
       '#rows' => $rows,
     );
 
@@ -434,6 +434,13 @@ function simpletest_settings_form(&$form
     '#description' => t('The verbose data will be printed along with the standard assertions. Useful for debugging.'),
     '#default_value' => variable_get('simpletest_verbose', FALSE),
   );
+  $form['general']['simpletest_time_limit'] = array(
+    '#type' => 'textfield',
+    '#title' => t('PHP script execution time limit'),
+    '#description' => t('Simpletest calls set_time_limit() with this value to set the PHP script execution time limit to avoid possible timeout error, adjust this value upward if timeout error occur during test run. Set to zero for no limit.'),
+    '#default_value' => variable_get('simpletest_time_limit', 180),
+    '#size' => 5,
+  );
 
   $form['httpauth'] = array(
     '#type' => 'fieldset',
@@ -453,3 +460,15 @@ function simpletest_settings_form(&$form
 
   return system_settings_form($form);
 }
+
+
+/**
+ * Validate settings form value 'simpletest_time_limit' is an integer >= 0
+ */
+function simpletest_settings_form_validate($form, $form_state) {
+  $value = $form_state['values']['simpletest_time_limit'];
+  // ensure input value is an integer and not a float or non-integer
+  if ($value !== (string)(int)$value || $value < 0) {
+    form_error($form['general']['simpletest_time_limit'], t('Must be an integer >= 0.'));
+  }
+}
