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): |
| 6 | def setup(self): |
| 7 | name = self.job.resultdir + '/sequence' |
| 8 | if (not os.path.exists(name)): |
| 9 | fd = file(name, 'w') |
| 10 | fd.write('0') |
| 11 | fd.close() |
| 12 | |
apw | 2f57123 | 2006-04-22 10:30:17 +0000 | [diff] [blame] | 13 | def __mark(self, checkpoint): |
apw | 6e55162 | 2006-04-04 08:50:53 +0000 | [diff] [blame] | 14 | name = self.job.resultdir + '/sequence' |
| 15 | fd = file(name, 'r') |
| 16 | current = int(fd.readline()) |
| 17 | fd.close() |
| 18 | |
| 19 | current += 1 |
| 20 | fd = file(name + '.new', 'w') |
| 21 | fd.write('%d' % current) |
| 22 | fd.close() |
| 23 | |
| 24 | os.rename(name + '.new', name) |
| 25 | |
| 26 | print "checkpoint %d %d" % (current, checkpoint) |
| 27 | |
| 28 | if (current != checkpoint): |
| 29 | raise JobError("selftest: sequence was " + |
| 30 | "%d when %d expected" % (current, checkpoint)) |
apw | 2f57123 | 2006-04-22 10:30:17 +0000 | [diff] [blame] | 31 | |
| 32 | def __throw(self): |
| 33 | __does_not_exist = __does_not_exist_either |
| 34 | |
| 35 | def execute(self, cmd, *args): |
| 36 | if cmd == 'mark': |
| 37 | self.__mark(*args) |
| 38 | elif cmd == 'throw': |
| 39 | self.__throw(*args) |