Exemplo n.º 1
0
class TestKernel(unittest.TestCase):
    def setUp(self):
        self.memory = Memory(50)
        self.scheduler = Scheduler()
        self.scheduler.set_as_fifo()
        self.a_kernel = Kernel(None)
        self.pcb_table = PCBTable()
        self.a_kernel.set_pcb_table(self.pcb_table)
        interruption_manager = InterruptionHandler(self.a_kernel.cpu)
        self.a_kernel.set_interruption_handler(interruption_manager)
        load_in_interruption_manager = Handle_Loaders()
        load_in_interruption_manager.load_handlers(self, interruption_manager)

    def write_program(self,program,memory):
        pos = 0
        for instruction in program.obtain_instructions():
            memory.put(pos,instruction)

    def load_a_instruction_in_a_program(self):
        program = Program("SIN-IO")
        instruction = Instruction("Texto")
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program,self.memory)
        self.setup_load_of_a_program_in_memory(2,program,2)

    def load_a_io_instruction_in_a_program(self):
        program = Program("IO")
        self.a_kernel.set_scheduler(self.scheduler)
        instruction = InstructionIO()
        program.addInstruction(instruction)
        program.addInstruction(instruction)
        self.write_program(program, self.memory)
        self.setup_load_of_a_program_in_memory(2,program,2)

    def setup_load_of_a_program_in_memory(self, amount_instructions, program, pcb_id):
        block_holder = BlockHolder(program)
        block_holder.set_representation([0,1])
        pcb = PCB(amount_instructions, pcb_id, block_holder)
        self.pcb_table.add(pcb)
        self.scheduler.policy.add_pcb(pcb)
        memory_admin = ToyMemoryAdmin(self.memory)
        self.a_kernel.cpu.set_actual_pcb(pcb)
        self.a_kernel.cpu.set_memory_manager(memory_admin)

    def test_given_pcb_when_cpu_complete_instruction_cycle_then_increments_pc(self):
        '''
        Compare the initial state of PCB's PC with final state
        '''
        self.load_a_instruction_in_a_program()
        self.assertEqual(0, self.a_kernel.cpu.actual_pcb.get_pc())
        self.a_kernel.cpu.complete_instruction_cycle()
        self.assertEqual(1, self.a_kernel.cpu.actual_pcb.get_pc())

    def test_given_pcb_when_cpu_complete_instruction_cycle_then_IO_Manager_captures_interruption_and_increments_pc(self):
        self.load_a_io_instruction_in_a_program()
        self.assertEqual(0, self.a_kernel.cpu.actual_pcb.get_pc())
        self.a_kernel.cpu.complete_instruction_cycle()
        self.assertEqual(1, self.a_kernel.cpu.actual_pcb.get_pc())
class TestScheduler(unittest.TestCase):

    def setUp(self):
        program1 = Program('D')
        program2 = Program('E')
        program3 = Program('H')
        program4 = Program('S')

        self.pcb1 = PCB(1, 20, PageHolder(program1))
        self.pcb1.set_priority(PCBPriorities.HIGH)

        self.pcb2 = PCB(2, 25, PageHolder(program2))
        self.pcb2.set_priority(PCBPriorities.MEDIUM)

        self.pcb3 = PCB(3, 15, PageHolder(program3))
        self.pcb3.set_priority(PCBPriorities.LOW)

        self.pcb4 = PCB(4, 6, PageHolder(program4))
        self.pcb4.set_priority(PCBPriorities.LOW)

        self.scheduler = Scheduler()

    def test_scheduler_with_fifo(self):
        self.fifo = FifoPolicy(self.scheduler)
        self.fifo.add_pcb(self.pcb1)
        self.fifo.add_pcb(self.pcb2)
        self.fifo.add_pcb(self.pcb3)
        self.fifo.add_pcb(self.pcb4)
        result = self.scheduler.next_process()
        self.assertEquals(self.pcb1.get_pid, result.get_pid)

    def test_scheduler_with_round_robin(self):
        quantum = 1
        self.round_robin = RoundRobinPolicy(self.scheduler, quantum)
        self.round_robin.add_pcb(self.pcb1)
        self.round_robin.add_pcb(self.pcb2)
        self.round_robin.add_pcb(self.pcb3)
        self.round_robin.add_pcb(self.pcb4)
        expected_elements = [self.pcb1, self.pcb2, self.pcb3, self.pcb4]
        for expected_element in expected_elements:
            self.assertEqual(expected_element.get_pid, self.round_robin.next_process().get_pid)

    def test_scheduler_with_priority(self):
        self.priority_policy = PriorityPolicy(self.scheduler)
        self.priority_policy.add_pcb(self.pcb1)
        self.priority_policy.add_pcb(self.pcb2)
        self.priority_policy.add_pcb(self.pcb3)
        self.priority_policy.add_pcb(self.pcb4)
        expected_elems = [self.pcb1, self.pcb2, self.pcb3, self.pcb4]
        for expected_elem in expected_elems:
            self.assertEqual(expected_elem.get_pid, self.scheduler.next_process().get_pid)
class TestCPUWithClock(unittest.TestCase):
    def setUp(self):
        self.memory = Memory(50)
        self.a_kernel = Kernel(None)
        self.cpu = Cpu(self.a_kernel)
        self.scheduler = Scheduler()
        self.scheduler.set_as_fifo()
        self.clock = Clock(self.cpu)
        self.a_kernel.clock = self.clock
        self.pcb_table = PCBTable()

    def test_the_clock_makes_a_tick_and_the_cpu_fetch_a_single_instruction_to_decode(self):
        CpuArrangements().load_a_instruction_in_a_program(self.a_kernel,self.scheduler,self.pcb_table,self.cpu,self.memory)
        self.a_kernel.clock.tick()
        self.assertTrue(self.cpu.get_actual_pcb().get_pc() == 1)
Exemplo n.º 4
0
def main0():
    instruction1 = BasicInstruction()
    instruction2 = IO_Instruction()
    instruction3 = Priority_Instruction()
    program = Program('a')
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    programb = Program('b')
    programb.addInstruction(instruction3)
    programc = Program('c')
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    timer = Timer(2)
    memory = Memory()
    memory.buildMemory(9)
    frame1 = Frame(memory,0,9)
    mmu = MMU()
    mmu.addEmptyFrame(frame1)
    cpu = CPU(None,mmu,None,timer)
    scheduler = Scheduler(PFIFO())
    ioqueue = IOQueue(scheduler)
    disk = Disk(None)
    kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk)
    disk.setKernel(kernel)
    cpu.setKernel(kernel)
    kernel.saveProgram(program)
    kernel.saveProgram(programb)
    kernel.saveProgram(programc)
    kernel.start()
    cpu.start()
    ioqueue.start()
Exemplo n.º 5
0
def main1():
    instruction1 = BasicInstruction()
    instruction3 = Priority_Instruction()
    logger = Logger("../resource/log.txt")
    program = Program('a')
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    programb = Program('b')
    programb.addInstruction(instruction3)
    programc = Program('c')
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    timer = Timer(2)
    memory = Memory()
    memory.buildMemory(9)
    frame1 = Frame(memory,0,9)
    mmu = MMU()
    mmu.addEmptyFrame(frame1)
    cpu = CPU(None,mmu,None,timer,logger)
    scheduler = Scheduler(PFIFO())
    ioqueue = IOQueue(scheduler,logger)
    disk = Disk(None)
    kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk,logger)
    disk.setKernel(kernel)
    disk.save(program)
    disk.save(programb)
    disk.save(programc)
    cpu.setKernel(kernel)
    kernel.executeProgram('a')   
 def setUp(self):
     self.pcb1 = PCB(5, 20, 4)
     self.pcb2 = PCB(4, 21, 3)
     self.a_kernel = Kernel(None)
     self.scheduler = Scheduler(None)
     self.a_kernel.set_scheduler(self.scheduler)
     self.cpu = Cpu(self.a_kernel)
 def setUp(self):
     self.memory = Memory(50)
     self.a_kernel = Kernel(None)
     self.cpu = Cpu(self.a_kernel)
     self.scheduler = Scheduler()
     self.scheduler.set_as_fifo()
     self.clock = Clock(self.cpu)
     self.a_kernel.clock = self.clock
     self.pcb_table = PCBTable()
Exemplo n.º 8
0
 def test__start_scheduler(self, mock_start):
     mock_start.return_value = True
     expected = True
     # act
     actual = Scheduler.start(operations={'do_mutate_fasta': True}, path_input=TPLS.MC_TESTS_INPUT.value,
                              path_output=TPLS.MC_TESTS_OUTPUT, pdb_list=['RepairPDB_1.pdb'],
                              fastafile_list=['1_A.fasta'], amino_acids=['A'], use_multithread=False,
                              write_1_fasta_only=True, write_fasta_per_mut=True)
     # assert
     self.assertEqual(expected, actual)
Exemplo n.º 9
0
 def setUp(self):
     self.memory = Memory(50)
     self.scheduler = Scheduler()
     self.scheduler.set_as_fifo()
     self.a_kernel = Kernel(None)
     self.pcb_table = PCBTable()
     self.a_kernel.set_pcb_table(self.pcb_table)
     interruption_manager = InterruptionHandler(self.a_kernel.cpu)
     self.a_kernel.set_interruption_handler(interruption_manager)
     load_in_interruption_manager = Handle_Loaders()
     load_in_interruption_manager.load_handlers(self, interruption_manager)
Exemplo n.º 10
0
 def __init__(self, operations: dict, use_multithread: bool,
              path_input: str, path_output: str, path_pdbfiles: list,
              path_fastafiles: list, specific_fxmutants: list,
              amino_acids: list,
              write_to_csv_dumpfile_after_each_mutant: bool):
     """
     All algorithmic analyses start from here. IdentifyProtein.py which runs Blast analyses is the only program that
     currently runs independently.
     :param write_to_csv_dumpfile_after_each_mutant:
     :param operations: Operations flagged True to run, False to not run.
     :param use_multithread: True if program(s) should be spawned on separate threads/processes.
     :param path_input: Abs path to input root dir
     :param path_output: Abs path to output root dir
     :param path_pdbfiles: Abs path to repo of pdbfiles.
     :param path_fastafiles: Abs path to repo of fastafiles.
     :param amino_acids: All amino acids that mutation operations will mutate residues to.
     :param write_to_csv_dumpfile_after_each_mutant: True to extract desired values to write to a single csv file (for
     database dump).
     """
     if operations == {} or Main._all_ops_are_false(operations):
         raise ValueError(
             "All options in 'operations' were either set to FALSE or some typographical error. "
             "Check /config/global_options/global_options.txt was written correctly"
         )
     elif operations[Str.OPER_RUN_MUT_FSTA.value] or operations[Str.OPER_RUN_AGDR.value] or \
             operations[Str.OPER_RUN_FX_RPR.value] or operations[Str.OPER_RUN_FX_BM.value] or \
             operations[Str.OPER_RUN_FX_STAB.value] or operations[Str.OPER_RUN_FX_AC.value]:
         Scheduler.start(operations,
                         use_multithread,
                         path_input,
                         path_output,
                         path_pdbfiles,
                         path_fastafiles,
                         specific_fxmutants,
                         amino_acids,
                         write_1_fasta_only=True,
                         write_fasta_per_mut=False,
                         write_to_csv_dumpfile_after_each_mutant=
                         write_to_csv_dumpfile_after_each_mutant)
Exemplo n.º 11
0
def main():
    args = parse_arguments()
    translation = TranslationFactory.get_translation(args.lang)
    scheduler = Scheduler(args.path)

    app = wx.App()

    # Fix datetime.strptime issue
    locale.setlocale(locale.LC_ALL, 'C')

    _ = WhatsAppAutomationFrame(translation, scheduler)

    app.MainLoop()
Exemplo n.º 12
0
    def setUp(self):
        program1 = Program('D')
        program2 = Program('E')
        program3 = Program('H')
        program4 = Program('S')

        self.pcb1 = PCB(1, 20, PageHolder(program1))
        self.pcb1.set_priority(PCBPriorities.HIGH)

        self.pcb2 = PCB(2, 25, PageHolder(program2))
        self.pcb2.set_priority(PCBPriorities.MEDIUM)

        self.pcb3 = PCB(3, 15, PageHolder(program3))
        self.pcb3.set_priority(PCBPriorities.LOW)

        self.pcb4 = PCB(4, 6, PageHolder(program4))
        self.pcb4.set_priority(PCBPriorities.LOW)

        self.scheduler = Scheduler()
Exemplo n.º 13
0
def main3():
    if(1==1):
        instruction1 = BasicInstruction()
        instruction2 = BasicInstruction()      
        memory = Memory()
        memory.buildMemory(5)
        frame1 = Frame(memory,0,1)
        frame2 = Frame(memory,1,2)
        frame3 = Frame(memory,3,1)
        frame4 = Frame(memory,4,1)
        mmu = MMU()
        mmu.fullFrames.append(frame1)
        mmu.fullFrames.append(frame3)
        mmu.emptyFrames.append(frame2)
        mmu.emptyFrames.append(frame4)
        program = Program('a')
        program.addInstruction(instruction1)
        pcbA = PCB('a',0,0,1)
        programb = Program('b')
        pcbB = PCB('b',0,3,1)
        programb.addInstruction(instruction1)
        frame1.load(pcbA,program)
        frame3.load(pcbB,programb)
        programc = Program('c')
        programc.addInstruction(instruction1)
        programc.addInstruction(instruction1)
        programc.addInstruction(instruction1)
        programd = Program('d')
        programd.addInstruction(instruction2)
        programd.addInstruction(instruction2)
        programd.addInstruction(instruction2)
        scheduler = Scheduler(PFIFO())
        disk = Disk(None)
        kernel = Kernel (None,None,scheduler,mmu,disk)
        disk.setKernel(kernel)
        memory.printMemory()
        kernel.saveProgram(programc)
        print( "     ")
        memory.printMemory()
        kernel.saveProgram(programd)
        print( "     ")
        memory.printMemory()
        print(len(disk.programList))
Exemplo n.º 14
0
def main():
    instruction1 = BasicInstruction()
    instruction2 = IO_Instruction()
    instruction3 = Priority_Instruction()
    program = Program('a')
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    program.addInstruction(instruction1)
    programd = Program('d')
    programd.addInstruction(instruction1)
    programd.addInstruction(instruction1)
    programd.addInstruction(instruction1)
    programd.addInstruction(instruction1)
    programd.addInstruction(instruction1)
    programb = Program('b')
    programb.addInstruction(instruction3)
    programc = Program('c')
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    programc.addInstruction(instruction1)
    timer = Timer(2)
    memory = Memory()
    memory.buildMemory(9)
    frame1 = Frame(memory,0,9)
    logger = Logger("/home/matlock/Escritorio/Sistemas Operativos/OSProyect/resource/log.txt")
    mmu = MMU(logger)
    mmu.addEmptyFrame(frame1)
    cpu = CPU(None,mmu,None,timer,logger)
    scheduler = Scheduler(PFIFO())
    ioqueue = IOQueue(scheduler,logger)
    disk = Disk(None)
    kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk,logger)
    disk.setKernel(kernel)
    cpu.setKernel(kernel)
    x = []
    x.append(program)
    x.append(programb)
    x.append(programc)
    x.append(programd)
    kernel.saveOnDisk(x)
    kernel.executeProgram('a')
Exemplo n.º 15
0
#!/usr/bin/env python3
import os
from src.Scheduler import Scheduler
import logging

logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
logger = logging.getLogger(__name__)
if __name__ == '__main__':
    scheduler = Scheduler()
    scheduler.main()
class TestSchedulerInteractions(unittest.TestCase):
    '''
    Testing Scheduler and CPU interactions...
    '''

    def setUp(self):
        self.pcb1 = PCB(5, 20, 4)
        self.pcb2 = PCB(4, 21, 3)
        self.a_kernel = Kernel(None)
        self.scheduler = Scheduler(None)
        self.a_kernel.set_scheduler(self.scheduler)
        self.cpu = Cpu(self.a_kernel)

    def test_when_given_scheduler_with_priority_and_cpu_then_scheduler_sends_next_process_to_cpu(self):
        queue = PriorityQueue()
        scheduler_priority = Scheduler(None, ready_queue=queue)
        self.a_kernel.set_scheduler(scheduler_priority)
        scheduler_priority.set_cpu(self.cpu)
        scheduler_priority.set_as_priority()
        self.pcb1.set_priority(1)
        scheduler_priority.push_to_queue(self.pcb1)
        self.pcb2.set_priority(2)
        scheduler_priority.push_to_queue(self.pcb2)
        expected_pcb = scheduler_priority.next_process()
        scheduler_priority.send_next_to_cpu()
        self.assertEqual(self.pcb2, self.cpu.get_actual_pcb())
        
    def test_when_given_scheduler_with_round_robin_and_a_cpu_then_scheduler_sends_next_process_to_cpu(self):
        self.scheduler.set_cpu(self.cpu)
        quantum = 1
        self.scheduler.set_as_round_robin(quantum)
        self.scheduler.push_to_queue(self.pcb1)
        self.scheduler.send_next_to_cpu()
        self.assertEqual(self.pcb1, self.cpu.get_actual_pcb())

    def test_when_given_scheduler_with_fifo_and_a_cpu_then_scheduler_sends_next_process_to_cpu(self):
        self.scheduler.set_cpu(self.cpu)
        self.scheduler.set_as_fifo()
        self.scheduler.push_to_queue(self.pcb1)
        self.scheduler.send_next_to_cpu()
        self.assertEqual(self.pcb1, self.cpu.get_actual_pcb())
Exemplo n.º 17
0
class ENA():
    HOME = expanduser("~")
    # Booleans
    running = False
    # Objects
    edit_users = Edit_Users()
    commands = Commands()
    deploy = Deploy()
    scheduler = Scheduler()

    main_user = None
    ena = None
    # edit_users = None
    # commands = None
    # deploy = None
    # scheduler = None
    id = None
    # Strings
    conn_string = "host='localhost' dbname='enabrain' user='******' password='******'"
    # Array for users
    users = []

    #constructor
    def ena(self, ena):
        self.running = True
        self.ena = ena
        #Creates the commands
        self.edit_users.Edit_Users(ena)
        self.commands.commands(self.ena, self.deploy, self.scheduler)
        try:
            #Checks if there is a table, if so, it loads the users
            self.id = self.edit_users.load_users()
        except:
            #Creates tables then loads empty users and sets the user id to 0
            Create_Tables = create_tables()
            Create_Tables.create_tables(ena)
            self.id = self.edit_users.load_users()
        self.ena.run()

    #this command is used in Commands.py
    def ena_help(self):
        print("=======================================")
        if (self.main_user == None):
            for command in self.commands.commands_array:
                print(command)
        else:
            for command in self.commands.commands_array:
                print(command)
        print("=======================================")

    #Admin function
    def show_users(self):
        for user in self.users:
            print("=======================================")
            user.show_info()
            print("=======================================")

    def change_user_level(self):
        selected_user = input(
            "please enter the user you want to change their level: ")
        real_user = False
        for user in self.users:
            if (user.username == selected_user):
                real_user = True
                check = input("Are you sure you want to change " +
                              selected_user + "'s level: ")
                level = int(input("please enter the user's new level: "))
                if (check.lower() == "yes" or check.lower() == "y"):
                    user.level = level
                    print(user.username + " is now a level " + str(user.level))
                else:
                    print("Authorization cancled")
        if (not real_user):
            print("There is no user with that username.")

    def login(self):
        testing_username = input("username: "******"Password: "******"----ADMIN----")
            print(self.main_user.username + ", You are now logged in")
        #this lets the user know that their password or username is incorrect
        else:
            if (not authenticate):
                false_pass = getpass.getpass("Password: "******"username or password is incorrect")

    def logout(self):
        #this logs them out, as the functions name implies
        for user in self.users:
            user.logged_in = False
        self.main_user = None
        self.commands.load_commands_abstract_user()
        print("You are now logged out")

    def clear(self):
        #check if the user is using windows
        if os.name == 'nt':
            os.system('cls')
        #else it uses linux termianls 'clear'
        else:
            os.system('clear')

    def run(self):
        self.clear()
        #gets commands
        command = input("Hello, my name is Ena, how may I assist you today: ")
        #main running loop
        while (self.running):
            self.commands.test_commands(command)
            command = input("How may I assist you today: ")
Exemplo n.º 18
0
def main():
    scheduler = Scheduler()
    scheduler.run()
Exemplo n.º 19
0
import sys

from src.Scheduler import Scheduler

if __name__ == '__main__':
    scheduler = Scheduler(sys.argv[1:2])  # chrome path as an argument.
    scheduler.schedule("22/05/2020-23:48:40", "test", "Selenium-Test")  # TODO - change it.

    # try to cancel the scheduled task.
    scheduler.cancel_scheduled_msg("22/05/2020-23:48:40", "Selenium-Test")
 def test_when_given_scheduler_with_priority_and_cpu_then_scheduler_sends_next_process_to_cpu(self):
     queue = PriorityQueue()
     scheduler_priority = Scheduler(None, ready_queue=queue)
     self.a_kernel.set_scheduler(scheduler_priority)
     scheduler_priority.set_cpu(self.cpu)
     scheduler_priority.set_as_priority()
     self.pcb1.set_priority(1)
     scheduler_priority.push_to_queue(self.pcb1)
     self.pcb2.set_priority(2)
     scheduler_priority.push_to_queue(self.pcb2)
     expected_pcb = scheduler_priority.next_process()
     scheduler_priority.send_next_to_cpu()
     self.assertEqual(self.pcb2, self.cpu.get_actual_pcb())