Beispiel #1
0
 def __init__(self, *, memorysize=10):
     self.time = 0  # This state's wall duration
     self.clock = 0  # The current wall clock
     self.mem = PhysicalMemory(memorysize)
     self.pagemngr = PageManager(self.mem)
     self.sched = Scheduler()
     self.pidcount = 0
     self.pid = None
Beispiel #2
0
def test_simple_free():
    mem = PhysicalMemory(2)
    mem.allocate_page = simple_alloc
    mem.free_page = simple_free
    mem.alloc(1)
    mem.free(0)
    assert mem.freelist == []
Beispiel #3
0
def test_process_run_two_segments():
    mem = PhysicalMemory(1)
    pm = PageManager(mem)
    proc = Process(pm, '../programs/two_fifties.process', 1)
    proc.run(100)
    assert proc.state == ProcessState.EXIT
    assert proc.program_counter == 2
Beispiel #4
0
def test_process_run():
    mem = PhysicalMemory(1)
    pm = PageManager(mem)
    proc = Process(pm, '../programs/100work.process', 1)
    proc.run(90)
    assert proc.unfinished_work == 90
    proc.run(10)
    assert proc.state == ProcessState.EXIT
Beispiel #5
0
class SimulationState:
    def __init__(self, *, memorysize=10):
        self.time = 0  # This state's wall duration
        self.clock = 0  # The current wall clock
        self.mem = PhysicalMemory(memorysize)
        self.pagemngr = PageManager(self.mem)
        self.sched = Scheduler()
        self.pidcount = 0
        self.pid = None

    def serialize(self):
        obj = {}
        obj['clock'] = self.clock
        obj['time'] = self.time
        obj['pid'] = self.pid
        obj['mem'] = self.mem.serialize()
        obj['pagemngr'] = self.pagemngr.serialize()
        obj['scheduler'] = self.sched.serialize()
        return obj
Beispiel #6
0
def test_raises_address_out_of_bounds():
    mem = PhysicalMemory(1)
    mem.allocate_page = simple_alloc
    with pytest.raises(exceptions.AddressInvalid):
        for i in range(5):
            mem.alloc(i + 1)
Beispiel #7
0
def test_simple_alloc():
    mem = PhysicalMemory(10)
    mem.allocate_page = simple_alloc
    for i in range(5):
        mem.alloc(i + 1)
    assert mem.state == [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
Beispiel #8
0
def test_make_page():
    mem = PhysicalMemory(1)
    pm = PageManager(mem)
    page = pm.make_page(32)
    assert pm.mem.get(page.addr) == 32