autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autotest function usage


From: Paolo Bonzini
Subject: Re: Autotest function usage
Date: Thu, 18 Oct 2007 10:27:43 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Or simpler, create all per-test sources in one go:

  /^#AT_START_27$/,/^#AT_STOP_27/w at-test-source-27
  /^#AT_START_44$/,/^#AT_STOP_44/w at-test-source-44
  ...

I have no idea how many `w' commands can portably be used in a sed
script

      GNU sed v3+:    no limit (but typical Unix is 253)
      ssed:           no limit (but typical Unix is 253)
      GNU sed v2.05:  total no. of r and w commands may not exceed 32
      sedmod v1.0:    10
      HHsed v1.5:     10

I have two patches that try to limit sed overhead. Both avoid that sed performs 80,000-odd regex matches per testgroup (instead, awk performs them once per testsuite run).

The first one caches the start and end line for each testgroup once at the beginning of the testsuite run. The second one applies the above idea in awk, like this:

BEGIN {
  print_test[27] = 1
  print_test[44] = 1
  print_test[81] = 1
}
/^#AT_START_/ { test = substr($1, 11); print_it = print_test[test] }
print_it && /^#AT_STOP_/ { print_it = 0 }
print_test[in_test] { print > ("testsuite.dir/at-test-source-" test) }

The second patch also avoids that sed reads in all the file once per testgroup -- you realized that the cost of sed-extraction is quadratic in the number of testgroups, RIGHT? :-)


For both patches, test time improves by ~5% for testsuite -10, and slows down slightly for running only one test.

./testsuite -1
pre:
user    0m3.041s
sys     0m2.266s

post first patch:
user    0m3.072s
sys     0m2.375s

post second patch:
user    0m3.042s
sys     0m2.455s


./testsuite -10
pre:
user    0m12.473s
sys     0m11.364s

post first patch:
user    0m10.919s
sys     0m11.461s

post second patch:
user    0m10.698s
sys     0m11.380s


I'm inclined to apply the second patch.  Anybody disagrees?

Paolo
2007-10-18  Paolo Bonzini  <address@hidden>

        * lib/autotest/general.m4 (at_func_test): Use cached line numbers
        to extract test scripts.
        (AT_INIT): Extract and cache test script line numbers.

diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index f94b10c..595a0c4 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -294,8 +294,8 @@ at_func_diff_devnull ()
 # Parse out test NUMBER from the tail of this file.
 at_func_test ()
 {
-  sed -n 
'/address@hidden:@AT_START_'$[1]'$/,/address@hidden:@AT_STOP_'$[1]'$/p' 
"$at_myself" \
-       > "$at_test_source"
+  eval at_sed=\$at_sed$[1]
+  sed "$at_sed" "$at_myself" > "$at_test_source"
 }
 
 # Load the config file.
@@ -711,6 +711,14 @@ else
 fi
 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
 
+# Extract the start and end lines of each test group at the tail
+# of this file
+awk '
+  /address@hidden:@AT_START_/ { start = NR }
+  /address@hidden:@AT_STOP_/ { print "at_sed" substr ($[1], 10) "=\"1," start 
"d;" NR "q\"" }
+' "$at_myself" > "$at_test_source"
+. "$at_test_source"
+
 # Banners and logs.
 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
 {
2007-10-18  Paolo Bonzini  <address@hidden>

        * lib/autotest/general.m4 (at_func_test): Remove.
        (AT_INIT): Pre-extract test groups into separate files.
        (AT_CLEANUP): Source pre-extracted file instead of calling at_func_test.

diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index f94b10c..8ed4da7 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -289,15 +289,6 @@ at_func_diff_devnull ()
   $at_diff "$at_devnull" "$[1]"
 }
 
-# at_func_test NUMBER
-# -------------------
-# Parse out test NUMBER from the tail of this file.
-at_func_test ()
-{
-  sed -n 
'/address@hidden:@AT_START_'$[1]'$/,/address@hidden:@AT_STOP_'$[1]'$/p' 
"$at_myself" \
-       > "$at_test_source"
-}
-
 # Load the config file.
 for at_file in atconfig atlocal
 do
@@ -369,7 +360,7 @@ at_status_file=$at_suite_dir/at-status
 at_stdout=$at_suite_dir/at-stdout
 at_stder1=$at_suite_dir/at-stder1
 at_stderr=$at_suite_dir/at-stderr
-# The file containing the function to run a test group.
+# The stem for files containing the function to run a test group.
 at_test_source=$at_suite_dir/at-test-source
 # The file containing dates.
 at_times_file=$at_suite_dir/at-times
@@ -805,6 +796,23 @@ else
   at_diff=diff
 fi
 
+[{
+  echo 'BEGIN {'
+  for at_group in $at_groups; do
+    echo "  print_test[\"$at_group\"] = 1"
+  done
+  echo '}
+!emit && /address@hidden:@AT_START_/ { test = substr($][1, 11); emit = 
print_test[test] }
+emit && /address@hidden:@AT_STOP_/ { emit = 0 }
+emit { print > ("'"$at_test_source"'-" test) }
+'
+}] > "$at_test_source"
+
+# Extract test group that will be run from the tail of this file
+if awk -f "$at_test_source" "$at_myself"; then :; else
+  AS_ECHO(["$as_me: unable to parse test groups"]) >&2
+  exit 1
+fi
 
 m4_text_box([Driver loop.])
 for at_group in $at_groups
@@ -1347,11 +1355,7 @@ at_status=`cat "$at_status_file"`
 [#AT_STOP_]AT_ordinal
 m4_divert_pop([TEST_FUNCTIONS])dnl Back to KILL.
 m4_divert_text([TESTS],
-[  AT_ordinal )
-    if at_func_test AT_ordinal && . "$at_test_source"; then :; else
-      AS_ECHO(["$as_me: unable to parse test group: $[1]"]) >&2
-      at_failed=:
-    fi ;;])
+[  AT_ordinal ) . "$at_test_source"-AT_ordinal ;; ])
 ])# AT_CLEANUP
 
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]