Mercurial > ~astiob > upreckon > hgweb
comparison testcases.py @ 63:fb9d0223a871
Fixed negative run times reported on POSIX
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Wed, 22 Dec 2010 18:56:25 +0200 |
| parents | 593ad09cd69b |
| children | fcb5ab97f08e |
comparison
equal
deleted
inserted
replaced
| 62:593ad09cd69b | 63:fb9d0223a871 |
|---|---|
| 90 | 90 |
| 91 try: | 91 try: |
| 92 from signal import SIGCHLD, signal, SIG_DFL | 92 from signal import SIGCHLD, signal, SIG_DFL |
| 93 from select import select, error as select_error | 93 from select import select, error as select_error |
| 94 from errno import EINTR | 94 from errno import EINTR |
| 95 import pickle | |
| 95 except ImportError: | 96 except ImportError: |
| 96 try: | 97 try: |
| 97 from _subprocess import WAIT_OBJECT_0, STD_INPUT_HANDLE, INFINITE | 98 from _subprocess import WAIT_OBJECT_0, STD_INPUT_HANDLE, INFINITE |
| 98 except ImportError: | 99 except ImportError: |
| 99 WAIT_OBJECT_0 = 0 | 100 WAIT_OBJECT_0 = 0 |
| 182 signal(SIGCHLD, bury_child) | 183 signal(SIGCHLD, bury_child) |
| 183 | 184 |
| 184 # If you want this to work, don't set any stdio argument to PIPE | 185 # If you want this to work, don't set any stdio argument to PIPE |
| 185 def call_real(*args, **kwargs): | 186 def call_real(*args, **kwargs): |
| 186 bury_child.case = case = kwargs.pop('case') | 187 bury_child.case = case = kwargs.pop('case') |
| 188 preexec_fn_ = kwargs.get('preexec_fn', None) | |
| 189 read, write = os.pipe() | |
| 190 def preexec_fn(): | |
| 191 os.close(read) | |
| 192 if preexec_fn_: | |
| 193 preexec_fn_() | |
| 194 os.write(write, pickle.dumps(clock(), 1)) | |
| 195 kwargs['preexec_fn'] = preexec_fn | |
| 187 try: | 196 try: |
| 188 case.process = Popen(*args, **kwargs) | 197 case.process = Popen(*args, **kwargs) |
| 189 except OSError: | 198 except OSError: |
| 199 os.close(read) | |
| 190 raise CannotStartTestee(sys.exc_info()[1]) | 200 raise CannotStartTestee(sys.exc_info()[1]) |
| 191 case.time_started = clock() | 201 finally: |
| 192 if pause is None: | 202 os.close(write) |
| 193 if case.maxtime: | 203 try: |
| 194 time.sleep(case.maxtime) | 204 if pause is None: |
| 195 if case.process.poll() is None: | 205 if case.maxtime: |
| 196 raise TimeLimitExceeded | 206 time.sleep(case.maxtime) |
| 207 if case.process.poll() is None: | |
| 208 raise TimeLimitExceeded | |
| 209 else: | |
| 210 case.process.wait() | |
| 197 else: | 211 else: |
| 198 case.process.wait() | 212 if not case.maxtime: |
| 199 else: | 213 try: |
| 200 if not case.maxtime: | 214 while case.process.poll() is None: |
| 201 try: | 215 if select((sys.stdin,), (), ())[0]: |
| 202 while case.process.poll() is None: | |
| 203 if select((sys.stdin,), (), ())[0]: | |
| 204 if sys.stdin.read(1) == '\33': | |
| 205 raise CanceledByUser | |
| 206 except select_error: | |
| 207 if sys.exc_info()[1].args[0] != EINTR: | |
| 208 raise | |
| 209 else: | |
| 210 case.process.poll() | |
| 211 else: | |
| 212 time_end = clock() + case.maxtime | |
| 213 try: | |
| 214 while case.process.poll() is None: | |
| 215 remaining = time_end - clock() | |
| 216 if remaining > 0: | |
| 217 if select((sys.stdin,), (), (), remaining)[0]: | |
| 218 if sys.stdin.read(1) == '\33': | 216 if sys.stdin.read(1) == '\33': |
| 219 raise CanceledByUser | 217 raise CanceledByUser |
| 218 except select_error: | |
| 219 if sys.exc_info()[1].args[0] != EINTR: | |
| 220 raise | |
| 220 else: | 221 else: |
| 221 raise TimeLimitExceeded | 222 case.process.poll() |
| 222 except select_error: | 223 else: |
| 223 if sys.exc_info()[1].args[0] != EINTR: | 224 time_end = clock() + case.maxtime |
| 224 raise | 225 try: |
| 225 else: | 226 while case.process.poll() is None: |
| 226 case.process.poll() | 227 remaining = time_end - clock() |
| 227 del bury_child.case | 228 if remaining > 0: |
| 229 if select((sys.stdin,), (), (), remaining)[0]: | |
| 230 if sys.stdin.read(1) == '\33': | |
| 231 raise CanceledByUser | |
| 232 else: | |
| 233 raise TimeLimitExceeded | |
| 234 except select_error: | |
| 235 if sys.exc_info()[1].args[0] != EINTR: | |
| 236 raise | |
| 237 else: | |
| 238 case.process.poll() | |
| 239 finally: | |
| 240 case.time_started = pickle.loads(os.read(read, 512)) | |
| 241 os.close(read) | |
| 242 del bury_child.case | |
| 228 def call(*args, **kwargs): | 243 def call(*args, **kwargs): |
| 229 if 'preexec_fn' in kwargs: | 244 if 'preexec_fn' in kwargs: |
| 230 try: | 245 try: |
| 231 return call_real(*args, **kwargs) | 246 return call_real(*args, **kwargs) |
| 232 except MemoryError: | 247 except MemoryError: |
