示例#1
0
    def setUp(self):
        self.program0 = Program("p.exe", [CPUInstruction(3)])
        self.program1 = Program("t.exe", [CPUInstruction(5)])
        self.program2 = Program("t.exe", [
            IOInstruction(1),
            CPUInstruction(5),
        ])
        self.program3 = Program("f.exe", [
            CPUInstruction(3),
            IOInstruction(1),
        ])

        self.hardware = Hardware(memorySize=32)
        self.kernel = Kernel(
            self.hardware,
            RoundRobin(3, self.hardware.clock(), self.hardware.irqVector()),
            Pagination(self.hardware.memory(),
                       self.hardware.mmu(),
                       frameSize=2))
        self.fileSystem = self.kernel.fileSystem()

        # Load programs
        self.fileSystem.save("home/nicolas/program0", self.program0)
        self.fileSystem.save("home/nicolas/program1", self.program1)
        self.fileSystem.save("home/nicolas/program2", self.program2)
        self.fileSystem.save("home/nicolas/program3", self.program3)
示例#2
0
    def setUp(self):
        self.program0 = Program("t.exe", [CPUInstruction(10)])
        self.program1 = Program("p.exe", [CPUInstruction(5)])
        self.program2 = Program("x.exe", [
            IOInstruction(1),
            CPUInstruction(2),
        ])

        self.hardware = Hardware(memorySize=64)
        self.kernel = Kernel(
            self.hardware, FCFS(),
            Pagination(self.hardware.memory(),
                       self.hardware.mmu(),
                       frameSize=2))
        self.fileSystem = self.kernel.fileSystem()

        # Load programs
        self.fileSystem.save("home/nicolas/program0", self.program0)
        self.fileSystem.save("home/nicolas/program1", self.program1)
        self.fileSystem.save("home/nicolas/program2", self.program2)

        self.scheduler = self.kernel.scheduler()
        self.pcbTable = self.kernel.pcbTable()
        self.cpu = self.kernel.hardware().cpu()
        self.waitingQueue = self.kernel.hardware().IOdevice().getWaitingQueue()
 def test_python_success(self):
     code = '''print("hello world")'''
     expected_out = "hello world"
     inp = ""
     pgm = Program(code, 'python3', self.sandbox)
     pgm.compile()
     out = pgm.execute(inp)
     assert expected_out == out.strip()
 def test_c_compilation_error(self):
     code = '''
     #include<stdio.h>
     int main(){
         printf("hello world")
         return 0;
     }
     '''
     pgm = Program(code, 'C', self.sandbox)
     pgm.compile()
示例#5
0
    def setUp(self):
        self.program0 = Program("t.exe", [CPUInstruction(9)])
        self.program2 = Program("s.exe", [CPUInstruction(5), IOInstruction(1)])

        self.hardware = Hardware(memorySize = 32)
        self.kernel = Kernel(self.hardware, FCFS(), Pagination(self.hardware.memory(), self.hardware.mmu(), frameSize=2))
        self.fileSystem = self.kernel.fileSystem()

        # Load programs
        self.fileSystem.save("home/nicolas/program0", self.program0)
        self.fileSystem.save("home/nicolas/program2", self.program2)
 def test_c_success(self):
     code = '''
     #include<stdio.h>
     int main(){
         printf("hello world");
         return 0;
     }
     '''
     expected_out = "hello world"
     inp = ""
     pgm = Program(code, 'C', self.sandbox)
     pgm.compile()
     out = pgm.execute(inp)
     assert expected_out == out
示例#7
0
def main2():

        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)
        memory.printMemory()
        print(memory.getEmptyCells())
        mmu.compact()
        memory.printMemory()
示例#8
0
    def setUp(self):
        self.program0 = Program("t.exe", [CPUInstruction(3)])
        self.program1 = Program("p.exe", [CPUInstruction(5)])
        self.program2 = Program("t.exe", [CPUInstruction(7)])

        self.hardware = Hardware(memorySize=64)
        self.kernel = Kernel(
            self.hardware, PreemptivePriority(5),
            Pagination(self.hardware.memory(),
                       self.hardware.mmu(),
                       frameSize=2))
        self.fileSystem = self.kernel.fileSystem()

        # Load programs
        self.fileSystem.save("home/nicolas/program0", self.program0)
        self.fileSystem.save("home/nicolas/program1", self.program1)
        self.fileSystem.save("home/nicolas/program2", self.program2)
    def setUp(self):
        self.program0 = Program("t.exe", [CPUInstruction(3)])
        self.program1 = Program("p.exe", [CPUInstruction(5)])
        self.program2 = Program("e.exe", [CPUInstruction(10)])

        self.hardware = Hardware(memorySize=32)
        self.kernel = Kernel(
            self.hardware, Priority(5),
            Pagination(self.hardware.memory(),
                       self.hardware.mmu(),
                       frameSize=2))
        self.fileSystem = self.kernel.fileSystem()

        # Load programs
        self.fileSystem.save("home/nicolas/program0", self.program0)
        self.fileSystem.save("home/nicolas/program1", self.program1)
        self.fileSystem.save("home/nicolas/program2", self.program2)

        self.scheduler = self.kernel.scheduler()
        self.pcbTable = self.kernel.pcbTable()
        self.cpu = self.kernel.hardware().cpu()
示例#10
0
    def test_network_access(self):
        code = '''import http
conn = http.client.HTTPConnection('www.python.org')
conn.request("HEAD","/index.html")
'''
        pgm = Program(code, 'python3', self.sandbox)
        pgm.compile()
        pgm.execute('')
 def test_c_error(self):
     code = '''
     #include<stdio.h>
     int main(){
         int a,b;
         scanf("%d",&b);
         a = 10/b;
         return 0;
     }
     '''
     inp = "0"
     pgm = Program(code, 'C', self.sandbox)
     pgm.compile()
     pgm.execute(inp)
示例#12
0
    def test_file_access(self):
        code = '''f = open('../a.txt','w')
f.write("hello world")
f.close()
'''
        pgm = Program(code, 'python3', self.sandbox)
        pgm.compile()
        pgm.execute('')
        file_path = path.join(path.dirname(pgm.file_location), '../a.txt')
        if path.exists(file_path):
            with open(file_path, 'r') as fileObj:
                assert "hello world" != fileObj.read().strip()
        else:
            assert True
示例#13
0
 def test_runtime_limit(self):
     code = '''while(True):
 pass'''
     pgm = Program(code, 'python3', self.sandbox)
     pgm.compile()
     pgm.execute('')
示例#14
0
#A CLI script to run the library
from  src.sandbox.no_sandbox import NoSandBox
from src.Program import Program
pgm = Program('''
#include<stdio.h>
#include<stdlib.h>
int main(){
    char a[10];
    scanf("%s",a);
    printf("hello %s",a);
}
''','C',NoSandBox())
pgm.compile()
print(pgm.execute('johnabraqw'))
示例#15
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')   
示例#16
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))
示例#17
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')
示例#18
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()
 def test_python_error(self):
     code = '''a = 1/0'''
     inp = ""
     pgm = Program(code, 'python3', self.sandbox)
     pgm.compile()
     pgm.execute(inp)
示例#20
0
 def test_memory_limit(self):
     code = '''a = [i for i in range(1024*1024*1024)]'''
     pgm = Program(code, 'python3', self.sandbox)
     pgm.compile()
     pgm.execute('')