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