[Avida-cvs] [avida-svn] r742 - in development: consistencytests/Tests consistencytests/Tests/Default consistencytests/Tests/SMT support/utils/AvidaUtils

kaben@myxo.css.msu.edu kaben at myxo.css.msu.edu
Fri Jun 9 12:08:28 PDT 2006


Author: kaben
Date: 2006-06-09 15:08:28 -0400 (Fri, 09 Jun 2006)
New Revision: 742

Added:
   development/consistencytests/Tests/SMT/SConscript
   development/support/utils/AvidaUtils/TestUtil.py
Removed:
   development/support/utils/AvidaUtils/UnitTestUtil.py
Modified:
   development/consistencytests/Tests/Default/SConscript
   development/consistencytests/Tests/SConscript
   development/support/utils/AvidaUtils/__init__.py
Log:

Finished adding consistency check support to SCons-based build.



Modified: development/consistencytests/Tests/Default/SConscript
===================================================================
--- development/consistencytests/Tests/Default/SConscript	2006-06-09 14:08:02 UTC (rev 741)
+++ development/consistencytests/Tests/Default/SConscript	2006-06-09 19:08:28 UTC (rev 742)
@@ -1,143 +1,7 @@
-import os
-import os.path
-import shutil
-import sys
-import tempfile
 
+from AvidaUtils.TestUtil import ConsistencyCheck
 
-class TailChecker:
-  """
-  Class that uses Avida and an Avida configuration to produce a set of
-  last lines of Avida output files, and then compares them to a set of
-  corresponding expected last lines that were generated by the companion
-  class TailGenerator.
-  """
-  def __init__(self,
-    seed_set,
-    run_subdir_path_base,
-    output_file_name,
-    expectation_file_path_base,
-    expectation_file_name,
-    avida_exe_path,
-    avida_args
-  ):
-    self.seed_set = seed_set
-    self.run_subdir_path_base = run_subdir_path_base
-    self.output_file_name = output_file_name
-    self.expectation_file_path_base = expectation_file_path_base
-    self.expectation_file_name = expectation_file_name
-    self.avida_exe_path = avida_exe_path
-    self.avida_args = avida_args
 
-    self.failures_dict = {}
-
-  def _check_tail(self, seed):
-    run_subdir = self.run_subdir_path_base + str(seed)
-    expectation_file_path = self.expectation_file_path_base + str(seed) + '/' + self.expectation_file_name
-    avida_command = self.avida_exe_path + ' ' + self.avida_args % {'Seed': str(seed), 'DataDir': run_subdir}
-
-    old_cwd = os.getcwd()
-
-    os.system(avida_command)
-
-    detail_fd = file(os.path.join(run_subdir, self.output_file_name),"rU") 
-    next_detail_line = detail_fd.readline()
-    while next_detail_line != "":
-      last_detail_line = next_detail_line
-      next_detail_line = detail_fd.readline()
-    detail_fd.close()
-
-    print "last line of output file \"" + self.output_file_name + "\" : "
-    print last_detail_line
-    
-    expected_last_line_fd = file(expectation_file_path, "rU")
-    expected_last_detail_line = expected_last_line_fd.readline()
-    expected_last_line_fd.close()
-
-    if last_detail_line != expected_last_detail_line:
-      print "last line of output file doesn't match expected last line."
-      self.failures_dict[seed] = (last_detail_line, expected_last_detail_line)
-    else:
-      print "last line of output file matches expected last line."
-
-  def check_tails(self):
-    for seed in self.seed_set:
-      print 'trying seed', seed, 'of seed_set', self.seed_set
-      self._check_tail(seed)
-
-
-class TailGenerator:
-  """
-  Class that uses Avida to generate a set of expected last lines of output
-  files for a particular Avida configuration.
-  
-  The companion class TailChecker can subsequently use Avida with the same
-  configuration to generate a set of actual last lines of corresponding
-  output files, compare them to the expected last lines, and report the
-  result.
-  """
-  def __init__(self,
-    seed_set,
-    run_subdir_path_base,
-    genesis_file_path,
-    output_file_name,
-    expectation_file_path_base,
-    expectation_file_name,
-    avida_exe_path,
-    avida_args
-  ):
-    self.seed_set = seed_set
-    self.run_subdir_path_base = run_subdir_path_base
-    self.genesis_file_path = genesis_file_path
-    self.output_file_name = output_file_name
-    self.expectation_file_path_base = expectation_file_path_base
-    self.expectation_file_name = expectation_file_name
-    self.avida_exe_path = avida_exe_path
-    self.avida_args = avida_args
-
-  def _generate_tail(self, seed):
-    run_subdir = self.run_subdir_path_base + str(seed)
-    expectation_file_path = self.expectation_file_path_base + str(seed) + '/' + self.expectation_file_name
-    avida_command = self.avida_exe_path + ' ' + self.avida_args % seed
-
-    old_cwd = os.getcwd()
-
-    print "from run_subdir " + run_subdir + " : using command : " + avida_command + " :"
-
-    shutil.rmtree(run_subdir, True)
-    try:
-      os.makedirs(run_subdir)
-    except OSError:
-      pass
-    shutil.copy(self.genesis_file_path, run_subdir)
-    os.chdir(run_subdir)
-    avida_output_fd = os.popen(avida_command)
-    line = avida_output_fd.readline()
-    while line != "":
-      print line,
-      line = avida_output_fd.readline()
-    avida_output_fd.close()
-
-    detail_fd = file(self.output_file_name,"rU") 
-    next_detail_line = detail_fd.readline()
-    while next_detail_line != "":
-      last_detail_line = next_detail_line
-      next_detail_line = detail_fd.readline()
-    detail_fd.close()
-
-    print "last line of output file \"" + self.output_file_name + "\" : "
-    print last_detail_line
-    
-    expected_last_line_fd = file(expectation_file_path, "wU")
-    expected_last_line_fd.write(last_detail_line)
-    expected_last_line_fd.close()
-
-    os.chdir(old_cwd)
-
-  def generate_tails(self):
-    for seed in self.seed_set:
-      self._generate_tail(seed)
-
 Import('environment')
 e = environment
 
@@ -150,56 +14,31 @@
 EnvironmentFile = e.File('environment.cfg', ConfigDir)
 StartCreatureFile = e.File('organism.default', ConfigDir)
 
-AvidaArgs = "-c %(GenesisFile)s -seed %(Seed)s -set WORLD_X 40 -set WORLD_Y 40 -set INST_SET %(InstSetFile)s -set EVENT_FILE %(EventsFile)s -set ENVIRONMENT_FILE %(EnvironmentFile)s -set START_CREATURE %(StartCreatureFile)s -set DATA_DIR %(DataDir)s" % {
-  'Seed':'%(Seed)s',
-  'DataDir':'%(DataDir)s',
-  'EventsFile':'%(EventsFile)s',
+AvidaArgs = "-c %(GenesisFile)s -set WORLD_X 40 -set WORLD_Y 40 -set INST_SET %(InstSetFile)s -set ENVIRONMENT_FILE %(EnvironmentFile)s -set START_CREATURE %(StartCreatureFile)s -seed %(Seed)s -set EVENT_FILE %(EventsFile)s -set DATA_DIR %(DataDir)s" % {
   'GenesisFile':GenesisFile.path,
   'InstSetFile':InstSetFile.path,
   'EnvironmentFile':EnvironmentFile.path,
   'StartCreatureFile':StartCreatureFile.path,
+  'Seed':'%(Seed)s',
+  'EventsFile':'%(EventsFile)s',
+  'DataDir':'%(DataDir)s',
 }
 
 RunLength = '500'
 TestDirBase = e.Dir('Seed_')
 SeedSet = range(100,105)
-OutputFileBase = 'detail_pop'
-OutputFileName = '%s.%s' % (OutputFileBase, RunLength)
-ExpectationFileName = '%s.expected_last_line' % OutputFileName
-ExpectationFilePathBase = TestDirBase.srcnode().path
-DataDirBase = TestDirBase.path
+OutputFileName = 'detail_pop.%s' % RunLength
 
-def tail_checker_action(target, source, env):
-  events_file = tempfile.mkstemp('.cfg', 'events.')
-  os.write(events_file[0],
-'''
-u %(RunLength)s:%(RunLength)s detail_pop detail_pop.%(RunLength)s   # Save current state of population.
-u %(RunLength)s exit   # exit.
-''' % {'RunLength': RunLength}
-  )
-  os.close(events_file[0])
-  tail_checker = TailChecker(
-    seed_set = SeedSet,
-    run_subdir_path_base = DataDirBase,
-    output_file_name = OutputFileName,
-    expectation_file_path_base = ExpectationFilePathBase,
-    expectation_file_name = ExpectationFileName,
-    avida_exe_path = avida_exe[0].path,
-    avida_args = AvidaArgs % {'Seed':'%(Seed)s', 'DataDir':'%(DataDir)s', 'EventsFile':events_file[1]}
-  )
-  try:
-    tail_checker.check_tails()
-  finally:
-    os.remove(events_file[1])
+ConsistencyCheck(e, 'Default-CPU',
+  run_length = RunLength,
+  seed_set = SeedSet,
+  run_subdir_path_base = TestDirBase.path,
+  output_file_name = OutputFileName,
+  expectation_file_path_base = TestDirBase.srcnode().path,
+  expectation_file_name = '%s.expected_last_line' % OutputFileName,
+  avida_exe_path = avida_exe[0].path,
+  avida_args = AvidaArgs,
+)
 
-  for seed, lines in tail_checker.failures_dict.iteritems():
-    print 'Seed', seed, 'produced unexpected last line in file', output_file_name, ':'
-    print lines[0], 'Expected last line in file', expectation_file_name, ':'
-    print lines[1]
 
-  if 0 is not len(tail_checker.failures_dict):
-    return 1
-
-e.AlwaysBuild(e.Alias('Consistency-Check--%s' % TestsName, [avida_exe], tail_checker_action))
-
 # vim: set ft=python:

Modified: development/consistencytests/Tests/SConscript
===================================================================
--- development/consistencytests/Tests/SConscript	2006-06-09 14:08:02 UTC (rev 741)
+++ development/consistencytests/Tests/SConscript	2006-06-09 19:08:28 UTC (rev 742)
@@ -3,5 +3,6 @@
 e = environment
 
 e.SConscript('Default/SConscript')
+e.SConscript('SMT/SConscript')
 
 # vim: set ft=python:

Added: development/consistencytests/Tests/SMT/SConscript
===================================================================
--- development/consistencytests/Tests/SMT/SConscript	2006-06-09 14:08:02 UTC (rev 741)
+++ development/consistencytests/Tests/SMT/SConscript	2006-06-09 19:08:28 UTC (rev 742)
@@ -0,0 +1,44 @@
+
+from AvidaUtils.TestUtil import ConsistencyCheck
+
+
+Import('environment')
+e = environment
+
+Import('avida_exe')
+
+TestsName = 'Default-CPU'
+ConfigDir = e.Dir('$execPrefix')
+GenesisFile = e.File('avida-smt.cfg', ConfigDir)
+InstSetFile = e.File('inst_set.smt', ConfigDir)
+EnvironmentFile = e.File('environment.cfg', ConfigDir)
+StartCreatureFile = e.File('organism.smt', ConfigDir)
+
+AvidaArgs = "-c %(GenesisFile)s -set WORLD_X 40 -set WORLD_Y 40 -set INST_SET %(InstSetFile)s -set ENVIRONMENT_FILE %(EnvironmentFile)s -set START_CREATURE %(StartCreatureFile)s -seed %(Seed)s -set EVENT_FILE %(EventsFile)s -set DATA_DIR %(DataDir)s" % {
+  'GenesisFile':GenesisFile.path,
+  'InstSetFile':InstSetFile.path,
+  'EnvironmentFile':EnvironmentFile.path,
+  'StartCreatureFile':StartCreatureFile.path,
+  'Seed':'%(Seed)s',
+  'EventsFile':'%(EventsFile)s',
+  'DataDir':'%(DataDir)s',
+}
+
+RunLength = '500'
+TestDirBase = e.Dir('Seed_')
+SeedSet = range(100,105)
+OutputFileName = 'detail_pop.%s' % RunLength
+
+ConsistencyCheck(e, 'Default-SMT',
+  run_length = RunLength,
+  seed_set = SeedSet,
+  run_subdir_path_base = TestDirBase.path,
+  output_file_name = OutputFileName,
+  expectation_file_path_base = TestDirBase.srcnode().path,
+  expectation_file_name = '%s.expected_last_line' % OutputFileName,
+  avida_exe_path = avida_exe[0].path,
+  avida_args = AvidaArgs,
+)
+
+
+# vim: set ft=python:

Copied: development/support/utils/AvidaUtils/TestUtil.py (from rev 741, development/support/utils/AvidaUtils/UnitTestUtil.py)
===================================================================
--- development/support/utils/AvidaUtils/UnitTestUtil.py	2006-06-09 14:08:02 UTC (rev 741)
+++ development/support/utils/AvidaUtils/TestUtil.py	2006-06-09 19:08:28 UTC (rev 742)
@@ -0,0 +1,249 @@
+import os
+import os.path
+import shutil
+import sys
+import tempfile
+
+def PhonyTarget(alias, action, depends = None):
+  """Returns an alias to a command that performs the action.
+  Implementated by a Command with a nonexistant file target.  This command will
+  run on every build, and will never be considered 'up to date'. Acts like a
+  'phony' target in make.
+  """
+  phony_file = os.path.normpath(tempfile.mktemp(prefix="phony_%s_" % alias, dir="."))
+  Depends(phony_file, depends)
+  return Alias(alias, Command(target=phony_file, source=None, action=action))
+
+def Test(env, prg):
+  """Creates unit test from given program.
+  When unit test passes, a file stamp is made. If it ran successfully and there
+  is nothing changed, the unit test can be skipped next time.
+
+  Makes three alii: the name of program, force-test, and test-changed:
+  - First can be used to run individual unit test.
+  - Second is used to run changed unit tests.
+  - Third forces all unit tests to run.
+  """
+  name = str(prg[0])
+  stamp = name + '.passed'
+  env.UnitTest(stamp, prg)
+  alias = PhonyTarget(name, [prg], stamp)
+  env.Alias('force-test', name)
+  env.Alias('test-changed', stamp)
+    
+def TestList(env, name, list, *args, **kw):
+  """Creates a set of unit tests from given list of filename bases.
+    
+  For each filename base 'blah', tries to make unit test using filename
+  'blah.cc'.  Creates alias, of given name, to all tests in this set.
+  """
+  for i in list:
+    Test(e, e.Program(i, i + '.cc', *args, **kw))
+  Alias(name, list)
+
+
+
+class TailChecker:
+  """
+  Class that uses Avida and an Avida configuration to produce a set of
+  last lines of Avida output files, and then compares them to a set of
+  corresponding expected last lines that were generated by the companion
+  class TailGenerator.
+  """
+  def __init__(self,
+    seed_set,
+    run_subdir_path_base,
+    output_file_name,
+    expectation_file_path_base,
+    expectation_file_name,
+    avida_exe_path,
+    avida_args
+  ):
+    self.seed_set = seed_set
+    self.run_subdir_path_base = run_subdir_path_base
+    self.output_file_name = output_file_name
+    self.expectation_file_path_base = expectation_file_path_base
+    self.expectation_file_name = expectation_file_name
+    self.avida_exe_path = avida_exe_path
+    self.avida_args = avida_args
+
+    self.failures_dict = {}
+
+  def _check_tail(self, seed):
+    run_subdir = self.run_subdir_path_base + str(seed)
+    expectation_file_dir = self.expectation_file_path_base + str(seed)
+    expectation_file_path = expectation_file_dir + '/' + self.expectation_file_name
+    avida_command = self.avida_exe_path + ' ' + self.avida_args % {'Seed': str(seed), 'DataDir': run_subdir}
+
+    try:
+      os.makedirs(run_subdir)
+    except OSError:
+      pass
+
+    expected_last_line_fd = file(expectation_file_path, "rU")
+
+    os.system(avida_command)
+
+    detail_fd = file(os.path.join(run_subdir, self.output_file_name),"rU") 
+    next_detail_line = detail_fd.readline()
+    while next_detail_line != "":
+      last_detail_line = next_detail_line
+      next_detail_line = detail_fd.readline()
+    detail_fd.close()
+
+    print "last line of output file \"" + self.output_file_name + "\" : "
+    print last_detail_line
+    
+    expected_last_detail_line = expected_last_line_fd.readline()
+    expected_last_line_fd.close()
+
+    if last_detail_line != expected_last_detail_line:
+      print "last line of output file doesn't match expected last line."
+      self.failures_dict[seed] = (last_detail_line, expected_last_detail_line)
+    else:
+      print "last line of output file matches expected last line."
+
+  def check_tails(self):
+    for seed in self.seed_set:
+      print 'trying seed', seed, 'of seed_set', self.seed_set
+      self._check_tail(seed)
+
+
+def tail_checker_action(target, source, env):
+  """
+  An SCons Action used by ConsistencyCheck() to consistency-check Avida
+  using a TailChecker instance.
+  """
+  events_file = tempfile.mkstemp('.cfg', 'events.')
+  os.write(events_file[0],
+'''
+u %(run_length)s:%(run_length)s detail_pop %(output_file_name)s   # Save current state of population.
+u %(run_length)s exit   # exit.
+''' % {'run_length': env['run_length'], 'output_file_name': env['output_file_name']}
+  )
+  os.close(events_file[0])
+
+  tail_checker = TailChecker(
+    seed_set = env['seed_set'],
+    run_subdir_path_base = env['run_subdir_path_base'],
+    output_file_name = env['output_file_name'],
+    expectation_file_path_base = env['expectation_file_path_base'],
+    expectation_file_name = env['expectation_file_name'],
+    avida_exe_path = env['avida_exe_path'],
+    avida_args = env['avida_args'] % {'Seed':'%(Seed)s', 'DataDir':'%(DataDir)s', 'EventsFile':events_file[1]}
+  )
+  tail_checker.check_tails()
+
+  os.remove(events_file[1])
+
+  for seed, lines in tail_checker.failures_dict.iteritems():
+    print 'Seed', seed, 'produced unexpected last line in file', env['output_file_name'], ':'
+    print lines[0], 'Expected last line in file', env['expectation_file_name'], ':'
+    print lines[1]
+  if 0 is not len(tail_checker.failures_dict):
+    return 1
+
+
+class TailGenerator:
+  """
+  Class that uses Avida to generate a set of expected last lines of output
+  files for a particular Avida configuration.
+  
+  The companion class TailChecker can subsequently use Avida with the same
+  configuration to generate a set of actual last lines of corresponding
+  output files, compare them to the expected last lines, and report the
+  result.
+  """
+  def __init__(self,
+    seed_set,
+    run_subdir_path_base,
+    output_file_name,
+    expectation_file_path_base,
+    expectation_file_name,
+    avida_exe_path,
+    avida_args
+  ):
+    self.seed_set = seed_set
+    self.run_subdir_path_base = run_subdir_path_base
+    self.output_file_name = output_file_name
+    self.expectation_file_path_base = expectation_file_path_base
+    self.expectation_file_name = expectation_file_name
+    self.avida_exe_path = avida_exe_path
+    self.avida_args = avida_args
+
+  def _generate_tail(self, seed):
+    run_subdir = self.run_subdir_path_base + str(seed)
+    expectation_file_dir = self.expectation_file_path_base + str(seed)
+    expectation_file_path = expectation_file_dir + '/' + self.expectation_file_name
+    avida_command = self.avida_exe_path + ' ' + self.avida_args % {'Seed': str(seed), 'DataDir': run_subdir}
+
+    try:
+      os.makedirs(run_subdir)
+    except OSError:
+      pass
+    try:
+      os.makedirs(expectation_file_dir)
+    except OSError:
+      pass
+
+    expected_last_line_fd = file(expectation_file_path, "wU")
+
+    os.system(avida_command)
+
+    detail_fd = file(os.path.join(run_subdir, self.output_file_name),"rU")
+    next_detail_line = detail_fd.readline()
+    while next_detail_line != "":
+      last_detail_line = next_detail_line
+      next_detail_line = detail_fd.readline()
+    detail_fd.close()
+
+    print "last line of output file \"" + self.output_file_name + "\" : "
+    print last_detail_line
+    
+    expected_last_line_fd.write(last_detail_line)
+    expected_last_line_fd.close()
+
+  def generate_tails(self):
+    for seed in self.seed_set:
+      self._generate_tail(seed)
+
+
+def tail_generator_action(target, source, env):
+  """
+  An SCons Action used by ConsistencyCheck() to generate Avida
+  consistency-check expectation files, using a TailGenerator instance.
+  """
+  events_file = tempfile.mkstemp('.cfg', 'events.')
+  os.write(events_file[0],
+'''
+u %(run_length)s:%(run_length)s detail_pop %(output_file_name)s   # Save current state of population.
+u %(run_length)s exit   # exit.
+''' % {'run_length': env['run_length'], 'output_file_name': env['output_file_name']}
+  )
+  os.close(events_file[0])
+
+  tail_generator = TailGenerator(
+    seed_set = env['seed_set'],
+    run_subdir_path_base = env['run_subdir_path_base'],
+    output_file_name = env['output_file_name'],
+    expectation_file_path_base = env['expectation_file_path_base'],
+    expectation_file_name = env['expectation_file_name'],
+    avida_exe_path = env['avida_exe_path'],
+    avida_args = env['avida_args'] % {'Seed':'%(Seed)s', 'DataDir':'%(DataDir)s', 'EventsFile':events_file[1]}
+  )
+  tail_generator.generate_tails()
+
+  os.remove(events_file[1])
+
+
+def ConsistencyCheck(env, name, *args, **kw):
+  """
+  Creates SCons targets to run Avida consistency checks, or generate
+  consistency-check expectation files.
+  """
+  env.AlwaysBuild(env.Alias('Consistency-Check--' + name, [], tail_checker_action, *args, **kw))
+  env.AlwaysBuild(env.Alias('Consistency-Check', [], tail_checker_action, *args, **kw))
+
+  env.AlwaysBuild(env.Alias('Generate-Consistency-Check--' + name, [], tail_generator_action, *args, **kw))
+
+

Deleted: development/support/utils/AvidaUtils/UnitTestUtil.py
===================================================================
--- development/support/utils/AvidaUtils/UnitTestUtil.py	2006-06-09 14:08:02 UTC (rev 741)
+++ development/support/utils/AvidaUtils/UnitTestUtil.py	2006-06-09 19:08:28 UTC (rev 742)
@@ -1,38 +0,0 @@
-
-def PhonyTarget(alias, action, depends = None):
-  """Returns an alias to a command that performs the action.
-  Implementated by a Command with a nonexistant file target.  This command will
-  run on every build, and will never be considered 'up to date'. Acts like a
-  'phony' target in make.
-  """
-  phony_file = os.path.normpath(tempfile.mktemp(prefix="phony_%s_" % alias, dir="."))
-  Depends(phony_file, depends)
-  return Alias(alias, Command(target=phony_file, source=None, action=action))
-
-def Test(env, prg):
-  """Creates unit test from given program.
-  When unit test passes, a file stamp is made. If it ran successfully and there
-  is nothing changed, the unit test can be skipped next time.
-
-  Makes three alii: the name of program, force-test, and test-changed:
-  - First can be used to run individual unit test.
-  - Second is used to run changed unit tests.
-  - Third forces all unit tests to run.
-  """
-  name = str(prg[0])
-  stamp = name + '.passed'
-  env.UnitTest(stamp, prg)
-  alias = PhonyTarget(name, [prg], stamp)
-  env.Alias('force-test', name)
-  env.Alias('test-changed', stamp)
-    
-def TestList(env, name, list, *args, **kw):
-  """Creates a set of unit tests from given list of filename bases.
-    
-  For each filename base 'blah', tries to make unit test using filename
-  'blah.cc'.  Creates alias, of given name, to all tests in this set.
-  """
-  for i in list:
-    Test(e, e.Program(i, i + '.cc', *args, **kw))
-  Alias(name, list)
-

Modified: development/support/utils/AvidaUtils/__init__.py
===================================================================
--- development/support/utils/AvidaUtils/__init__.py	2006-06-09 14:08:02 UTC (rev 741)
+++ development/support/utils/AvidaUtils/__init__.py	2006-06-09 19:08:28 UTC (rev 742)
@@ -8,7 +8,7 @@
 
 import sys
 import SCons
-import CmdLineOpts, SConsOpts, StaticHelp
+import CmdLineOpts, SConsOpts, StaticHelp, TestUtil
 
 def Configure(args, env):
   env.Replace(AvidaUtils_path = __path__)




More information about the Avida-cvs mailing list