apw | 6e55162 | 2006-04-04 08:50:53 +0000 | [diff] [blame] | 1 | import test |
| 2 | from autotest_utils import * |
| 3 | from error import * |
| 4 | |
| 5 | class selftest(test.test): |
apw | 3a4968d | 2006-04-25 10:10:49 +0000 | [diff] [blame] | 6 | version = 1 |
| 7 | |
apw | 6e55162 | 2006-04-04 08:50:53 +0000 | [diff] [blame] | 8 | def setup(self): |
| 9 | name = self.job.resultdir + '/sequence' |
| 10 | if (not os.path.exists(name)): |
| 11 | fd = file(name, 'w') |
| 12 | fd.write('0') |
| 13 | fd.close() |
| 14 | |
apw | 2f57123 | 2006-04-22 10:30:17 +0000 | [diff] [blame] | 15 | def __mark(self, checkpoint): |
apw | 6e55162 | 2006-04-04 08:50:53 +0000 | [diff] [blame] | 16 | name = self.job.resultdir + '/sequence' |
| 17 | fd = file(name, 'r') |
| 18 | current = int(fd.readline()) |
| 19 | fd.close() |
| 20 | |
| 21 | current += 1 |
| 22 | fd = file(name + '.new', 'w') |
| 23 | fd.write('%d' % current) |
| 24 | fd.close() |
| 25 | |
| 26 | os.rename(name + '.new', name) |
| 27 | |
| 28 | print "checkpoint %d %d" % (current, checkpoint) |
| 29 | |
| 30 | if (current != checkpoint): |
| 31 | raise JobError("selftest: sequence was " + |
| 32 | "%d when %d expected" % (current, checkpoint)) |
apw | 2f57123 | 2006-04-22 10:30:17 +0000 | [diff] [blame] | 33 | |
| 34 | def __throw(self): |
| 35 | __does_not_exist = __does_not_exist_either |
| 36 | |
apw | 1d99360 | 2006-04-25 14:26:55 +0000 | [diff] [blame^] | 37 | def __print(self, msg): |
| 38 | sys.stdout.write(msg) |
| 39 | |
| 40 | def __warn(self, msg): |
| 41 | sys.stderr.write(msg) |
| 42 | |
apw | 2f57123 | 2006-04-22 10:30:17 +0000 | [diff] [blame] | 43 | def execute(self, cmd, *args): |
| 44 | if cmd == 'mark': |
| 45 | self.__mark(*args) |
| 46 | elif cmd == 'throw': |
| 47 | self.__throw(*args) |
apw | 1d99360 | 2006-04-25 14:26:55 +0000 | [diff] [blame^] | 48 | elif cmd == 'print': |
| 49 | self.__print(*args) |
| 50 | elif cmd == 'warn': |
| 51 | self.__warn(*args) |