#!/usr/bin/env python3 """Runs the earlier tick-loop program and rr.cpp on random workloads where every process arrives at time 0 (the only case the old program can express) and compares waiting times.""" import random, subprocess, sys random.seed(2015) TRIALS, mismatches = 500, 0 for _ in range(TRIALS): n = random.randint(1, 7) bursts = [random.randint(1, 15) for _ in range(n)] q = random.randint(1, 9) old_in = f"{n}\n" + "\n".join(map(str, bursts)) + f"\n{q}\n" new_in = f"{n}\n" + "\n".join(f"0 {b}" for b in bursts) + f"\n{q}\n" old = subprocess.run(["build/old"], input=old_in, capture_output=True, text=True).stdout new = subprocess.run(["build/rr"], input=new_in, capture_output=True, text=True).stdout old_wt = [int(l.split()[2]) for l in old.split("PNo")[1].splitlines()[1:1 + n]] new_wt = [int(l.split("\t")[5]) for l in new.splitlines()[3:3 + n]] if old_wt != new_wt: mismatches += 1 print(f"random workloads (all arrivals at 0, seed 2015): {TRIALS}") print(f"waiting-time mismatches, legacy vs rr.cpp : {mismatches}")