Untitled
unknown
python
2 years ago
2.0 kB
17
Indexable
# for each file in student-high
# copy its content to p11.tf
# run the p11test
# store results in a folder
import os
import shutil
import subprocess
import json
import csv
def copy_file_contents(source_file, destination_file):
with open(source_file, 'r') as f:
content = f.read()
with open(destination_file, 'w') as f:
f.write(content)
directory = '/home/clouduser/s24-advcc-p11-Angela-CMU/student-high'
basic_directory = '/home/clouduser/s24-advcc-p11-Angela-CMU'
csv_file_path = '/home/clouduser/s24-advcc-p11-Angela-CMU/student-high/result/result.csv'
rps_list = []
capacity_list = []
combine_list = []
for filename in os.listdir(directory):
if filename.endswith('.tf'):
print("Find .tf file")
source_file = os.path.join(directory, filename)
destination_file = '/home/clouduser/s24-advcc-p11-Angela-CMU/p11.tf'
copy_file_contents(source_file, destination_file)
print("Running test for ", filename)
subprocess.run(['bin/p11test-new', '--pattern_names', 'test1']) # Modify testcase name
print("Running done for ", filename)
result_file = os.path.join(basic_directory, 'result', 'test_test1_score.log') # Modify testcase name
with open(result_file, 'r') as f:
result_data = json.load(f)
rps_score = result_data['rps_score']
capacity_score = result_data['capacity_score']
combine_score = (rps_score + capacity_score) / 2
print("rps_score = ", rps_score)
print("capacity_score = ", capacity_score)
print("combine_score = ", combine_score)
rps_list.append(rps_score)
capacity_list.append(capacity_score)
combine_list.append(combine_score)
print("Start saving results to csv file")
with open(csv_file_path, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['rps_score', 'capacity_score', 'combine_score']) # Write header
for rps_score, capacity_score, combine_score in zip(rps_list, capacity_list, combine_list):
writer.writerow([rps_score, capacity_score, combine_score])
print("Results saved to the csv file")
Editor is loading...
Leave a Comment