~vcs-imports/distcc/trunk

« back to all changes in this revision

Viewing changes to test/testdistcc.py

  • Committer: mandyke at gmail
  • Date: 2013-05-27 08:10:06 UTC
  • Revision ID: svn-v4:01de4be4-8c4a-0410-9132-4925637da917:trunk:781
Improve reliability of tests

* test/testdistcc.py: Remove stale and duplicate TODO items.

  (_Touch): New function, acts like touch(1).
  (Compile_c_Case): makeFile is not sufficient to reliably update
  modification time on all systems (e.g. GNU/Hurd), so replace it with
  calls to _Touch.
  (Gdb_Case): Use _Touch.

  (SyntaxError_Case): Look for pattern anywhere in the output using
  re.search as warnings and other noise can be present.

* test/comfychair.py: Also set LC_ALL, which has a higher priority,
  and make it so LANG and LC_ALL are set after saving the environment.

  Clean up some stray import statements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
# abstract superclasses just provide methods that can be called,
51
51
# rather than establishing default behaviour.
52
52
 
53
 
# TODO: Run the server in a different directory from the clients
54
 
 
55
53
# TODO: Some kind of direct test of the host selection algorithm.
56
54
 
57
55
# TODO: Test host files containing \r.
84
82
 
85
83
# Check that without DISTCC_SAVE_TEMPS temporary files are cleaned up.
86
84
 
87
 
# TODO: Test compiling a really large source file that produces a
88
 
# large object file.  Perhaps need to generate it at run time -- just
89
 
# one big array?
90
 
 
91
85
# TODO: Perhaps redirect stdout, stderr to a temporary file while
92
86
# running?  Use os.open(), os.dup2().
93
87
 
94
 
# TODO: Test "distcc gcc -c foo.c bar.c".  gcc would actually compile
95
 
# both of them.  We could split it into multiple compiler invocations,
96
 
# but this is so rare that it's probably not worth the complexity.  So
97
 
# at the moment is just handled locally.
98
 
 
99
88
# TODO: Test crazy option arguments like "distcc -o -output -c foo.c"
100
89
 
101
 
# TODO: Test attempt to compile a nonexistent file.
102
 
 
103
90
# TODO: Add test harnesses that just exercise the bulk file transfer
104
91
# routines.
105
92
 
111
98
# TODO: Run "sleep" as a compiler, then kill the client and make sure
112
99
# that the server and "sleep" promptly terminate.
113
100
 
114
 
# TODO: Set umask 0, then check that the files are created with mode
115
 
# 0644.
116
 
 
117
101
# TODO: Perhaps have a little compiler that crashes.  Check that the
118
102
# signal gets properly reported back.
119
103
 
133
117
# TODO: Test a compiler that sleeps for a long time; try killing the
134
118
# server and make sure it goes away.
135
119
 
136
 
# TODO: Set LANG=C before running all tests, to try to make sure that
137
 
# localizations don't break attempts to parse error messages.  Is
138
 
# setting LANG enough, or do we also need LC_*?  (Thanks to Oscar
139
 
# Esteban.)
140
 
 
141
120
# TODO: Test scheduler.  Perhaps run really slow jobs to make things
142
121
# deterministic, and test that they're dispatched in a reasonable way.
143
122
 
168
147
 
169
148
# TODO: Test with DISTCC_DIR set, and not set.
170
149
 
 
150
# TODO: Using --lifetime does cause sporadic failures.  Ensure that
 
151
# teardown kills all daemon processes and then stop using --lifetime.
 
152
 
171
153
 
172
154
import time, sys, string, os, glob, re, socket
173
155
import signal, os.path
238
220
    contents = _FirstBytes(filename, 5)    
239
221
    return contents.startswith('MZ')
240
222
 
 
223
def _Touch(filename):
 
224
    '''Update the access and modification time of the given file,
 
225
    creating an empty file if it does not exist.
 
226
    '''
 
227
    f = open(filename, 'a')
 
228
    try:
 
229
        os.utime(filename, None)
 
230
    finally:
 
231
        f.close()
 
232
 
241
233
 
242
234
class SimpleDistCC_Case(comfychair.TestCase):
243
235
    '''Abstract base class for distcc tests'''
679
671
      assert m_obj, line
680
672
      return m_obj.group(1)
681
673
 
682
 
  def makeFile(self, f):
683
 
      fd = open(f, "w")
684
 
      fd.close()
685
 
 
686
 
  def makeFiles(self, files):
687
 
      for f in files:
688
 
          self.makeFile(f)
689
 
      
690
674
  def runtest(self):
691
675
 
692
676
      # Test dcc_discrepancy_filename
722
706
                    ]
723
707
 
724
708
      for dotd_contents, deps in dotd_cases:
725
 
          self.makeFiles(deps)
 
709
          for dep in deps:
 
710
              _Touch(dep)
726
711
          # Now postulate the time that is the beginning of build. This time
727
712
          # is after that of all the dependencies.
728
713
          time_ref = time.time() + 1
752
737
 
753
738
          # Let's try to touch, say the last dep file. Then, we should expect
754
739
          # the name of that very file as the output because there's a fresh
755
 
          # file. We'll have to advance real time beyond time_ref before doing
756
 
          # this.
757
 
          while time.time() <= time_ref:
758
 
              time.sleep(1)
 
740
          # file.
759
741
          if deps:
760
 
              self.makeFile(deps[-1])
 
742
              _Touch(deps[-1])
761
743
              out, err = self.runcmd(
762
744
                  "h_compile dcc_fresh_dependency_exists dotd '' %i" %
763
745
                  time_ref)
1232
1214
        # Create an empty .gdbinit, so that we insulate this test
1233
1215
        # from the ~/.gdbinit file of the user running it.
1234
1216
        filename = ".gdbinit"
1235
 
        f = open(filename, 'w')
1236
 
        f.close()
 
1217
        _Touch(filename)
1237
1218
 
1238
1219
    def compiler(self):
1239
1220
        """Command for compiling and linking."""
1847
1828
    def compile(self):
1848
1829
        rc, msgs, errs = self.runcmd_unchecked(self.compileCmd())
1849
1830
        self.assert_notequal(rc, 0)
1850
 
        self.assert_re_match(r'testtmp.c:1:.*error', errs)
 
1831
        self.assert_re_search(r'testtmp.c:1:.*error', errs)
1851
1832
        self.assert_equal(msgs, '')
1852
1833
 
1853
1834
    def runtest(self):