import os
import shutil
import time, datetime
import tabulate

times = []
tests = [
    "test0", "test1", "test2", "test3", "test4", "test5", "test6", "test7", 
    "test9",  "test10", "test11", "test12", "test13", "test14", "test15"
]

dut_dir = "sec_taskBMC20_sodor5_lb_u"
mod_dir = "sec_taskBMC20_sodor5_model_lb_u"

for test in tests:
    print("Running test: " + test)
    shutil.copyfile(f"{os.getcwd()}/{test}/sodor5_lb_unified_bmc.v", f"{os.getcwd()}/sodor5_lb_unified_bmc.v")
    
    # Test with design
    pretime = time.time()
    os.system("time sby -f sec.sby taskBMC20_sodor5_lb_u")
    posttime = time.time()
    dut_time = posttime - pretime
    print(f"For test: {test} DUT time: {dut_time}")

    # Save the results
    os.system(f"cp -r {dut_dir} {test}/")

    # Test on model
    pretime = time.time()
    os.system("time sby -f sec.sby taskBMC20_sodor5_model_lb_u")
    posttime = time.time()
    model_time = posttime - pretime
    print(f"For test: {test} Model time: {model_time}")

    # Save the results
    os.system(f"cp -r {mod_dir} {test}/")

    # Save the times
    times.append([
        test, dut_time, model_time
    ])



with open("times.log", 'w') as f:
    f.write("// Generated by run_all.py at {}\n\n\n".format(datetime.datetime.now()))

    table = tabulate.tabulate(times, headers=["Test", "DUT Time", "Model Time"])
    f.write(table)