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 -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	13 Aug 2009 15:33:54 -0000
@@ -30,8 +30,12 @@
 
   /**
    * 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 @@
    */
   public function __construct($test_id = NULL) {
     $this->testId = $test_id;
+    $this->timeLimit = variable_get('simpletest_time_limit', 180);
   }
 
   /**
Index: modules/simpletest/simpletest.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.pages.inc,v
retrieving revision 1.12
diff -u -r1.12 simpletest.pages.inc
--- modules/simpletest/simpletest.pages.inc	13 Aug 2009 11:31:26 -0000	1.12
+++ modules/simpletest/simpletest.pages.inc	13 Aug 2009 15:33:54 -0000
@@ -264,8 +264,8 @@
       $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 @@
     '#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,14 @@
 
   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'];
+  if (!is_numeric($value) || $value != (int) $value || $value < 0) {
+    form_error($form['general']['simpletest_time_limit'], t('PHP script execution time limit must be an integer greater then or equal to zero.'));
+  }
+}
Index: modules/simpletest/simpletest.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.install,v
retrieving revision 1.25
diff -u -r1.25 simpletest.install
--- modules/simpletest/simpletest.install	22 Jul 2009 04:45:35 -0000	1.25
+++ modules/simpletest/simpletest.install	13 Aug 2009 15:33:54 -0000
@@ -109,6 +109,7 @@
   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 @@
   $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 @@
   );
   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 %function', array('%function' => '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;
