RTSA-lab02-SchedTest/SchedTest.py

99 lines
3.0 KiB
Python
Raw Normal View History

2022-06-01 16:11:48 +02:00
import argparse
import numpy as np
2022-06-02 10:29:04 +02:00
from tabulate import tabulate
2022-06-01 16:11:48 +02:00
import schedTests.LiuAndLaylandBound as LLB
import schedTests.TimeDemandAnalysis as TDA
import schedTests.HyperbolicBound as HB
import include.TasksHelper as TH
2022-06-02 10:29:04 +02:00
import task_sets.TaskSetGenerator as gen
2022-06-01 16:11:48 +02:00
# This function Parses the Input Arguments
def parse_args():
# Instantiate the parser
parser = argparse.ArgumentParser(
description='A small Scheduling test Framework.')
# Required argument
parser.add_argument('--i', type=str, required=True,
help='Path to the file containing task sets.')
# Required argument
parser.add_argument('--n', type=int, required=False, default=10,
help='Number of tasks per set.')
return parser.parse_args()
# Read Tasksets in to numpy array from text files
def get_tasksets(filename: str, NrSets: int):
input = np.genfromtxt(filename, dtype=float, delimiter=",", comments=";")
shape = input.shape
tasksets = input.reshape(int(shape[0]/NrSets), NrSets, 3)
return tasksets
def main():
# Parse Arguments
args = parse_args()
print(args.i)
2022-06-02 10:29:04 +02:00
np.set_printoptions(threshold=np.inf)
2022-06-01 16:11:48 +02:00
# Read Tasksets from txt files
tasksets = get_tasksets(args.i, args.n)
2022-06-02 10:29:04 +02:00
#tasksets = gen.gen_np_taskset(100)
2022-06-01 16:11:48 +02:00
print("Successfully parsed Task Sets")
shape = tasksets.shape
print("Nr. of Task Sets: " + str(shape[0]))
print("Nr. of Tasks per Set: " + str(shape[1]))
# Starting the analysis
print("Starting Liu and Layland bound analysis!")
stubLLB = []
2022-06-02 10:29:04 +02:00
stubU = []
for k in range(shape[0]):
2022-06-01 16:11:48 +02:00
stubLLB.append(False)
2022-06-02 10:29:04 +02:00
stubU.append(TH.getTotalUtilization(tasksets[k], shape[1]))
2022-06-01 16:11:48 +02:00
LLBresults = np.array(stubLLB)
2022-06-02 10:29:04 +02:00
U = np.array(stubU)
2022-06-01 16:11:48 +02:00
for i in range(shape[0]):
if LLB.test(tasksets[i]):
LLBresults[i] = True
2022-06-02 10:29:04 +02:00
# print("Task Set: " + str(i) +
# " fulfills necessary the Liu and Layland Bound!")
#print()
2022-06-01 16:11:48 +02:00
print("Starting Hyperbolic bound analysis!")
stubHB = []
for _ in range(shape[0]):
stubHB.append(False)
HBresults = np.array(stubHB)
for i in range(shape[0]):
if HB.test(tasksets[i]):
HBresults[i] = True
2022-06-02 10:29:04 +02:00
# print("Task Set: " + str(i) +
# " fulfills the sufficient Hyperbolic Bound!")
#print()
2022-06-01 16:11:48 +02:00
print("Starting Time Demand Analysis!")
stubTDA = []
for _ in range(shape[0]):
stubTDA.append(False)
TDAresults = np.array(stubTDA)
for i in range(shape[0]):
if TDA.test(tasksets[i]) > 0:
TDAresults[i] = True
2022-06-02 10:29:04 +02:00
#print("Task Set: " + str(i) + " is feasible by TDA analysis!")
#print results
headers = ["#", "U", "LLB", "HB", "TDA"]
# Generate the table in fancy format.
results = np.array((np.arange(shape[0]), U, LLBresults, HBresults, TDAresults)).T
table = tabulate(results, headers, tablefmt="fancy_grid")
print(table)
2022-06-01 16:11:48 +02:00
if __name__ == "__main__":
main()