From: Mark Wooding Date: Fri, 6 Sep 2024 20:53:59 +0000 (+0100) Subject: soak: Pull sync state out into a separate variable. X-Git-Tag: 0.99.0~101 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/xyla/commitdiff_plain/f41dfcf459befd2edbd4ea645a284f152007bc48?ds=sidebyside soak: Pull sync state out into a separate variable. --- diff --git a/soak b/soak index 83645db..7953608 100755 --- a/soak +++ b/soak @@ -225,6 +225,7 @@ def choices(): OPTS = Options() ST = State(OPTS) KID = SUB.Popen(OPTS.testprog, stdin = SUB.PIPE, stdout = SUB.PIPE) +SYNC = OPTS.sync def fail(msg): SYS.stderr.write("%s: FAILED: %s\n" % (PROG, msg)) @@ -238,17 +239,17 @@ def fail(msg): def put(msg, echo = True): try: KID.stdin.write(msg.encode()); KID.stdin.flush() except OSError as err: fail("write failed: %s" % err) - if OPTS.sync and echo: SYS.stdout.write("$ " + msg); SYS.stdout.flush() + if SYNC and echo: SYS.stdout.write("$ " + msg); SYS.stdout.flush() def get(echo = True): try: line = KID.stdout.readline().decode() except OSError as err: fail("read failed: %s" % err) if line == "": fail("unexpected end of file") - if OPTS.sync and echo: SYS.stdout.write(line) + if SYNC and echo: SYS.stdout.write(line) if line[-1] == "\n": return line[:-1] else: return line def dump_tree(): - if OPTS.sync: + if SYNC: put("D\n:;;END DUMP\n", echo = False) while True: line = get(echo = False) @@ -279,7 +280,7 @@ dump_tree() STEP = CSTEP = 0 ch = choices() while OPTS.nsteps is None or STEP < OPTS.nsteps: - if OPTS.sync: SYS.stdout.write("\n;; step %d\n" % CSTEP) + if SYNC: SYS.stdout.write("\n;; step %d\n" % CSTEP) op = ch.choose(ST.rand) if op == "addrm1": @@ -393,11 +394,11 @@ while OPTS.nsteps is None or STEP < OPTS.nsteps: STEP += 1; CSTEP += 1 dump_tree() - if OPTS.sync or CSTEP == OPTS.ckpt_steps: check_tree() + if SYNC or CSTEP == OPTS.ckpt_steps: check_tree() if CSTEP == OPTS.ckpt_steps: snapshot() ST.write_ckpt() - CSTEP = 0; OPTS.sync = False + CSTEP = 0; SYNC = False while True: check_tree()