Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage #25

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
38d469a
Add Codacy badge
codacy-badger Jun 20, 2019
10a734a
Atualizando README
gustavooquinteiro Jun 20, 2019
a66dfdf
Consertando erros E501
gustavooquinteiro Jun 22, 2019
78c6ec0
Consertando erros W291
gustavooquinteiro Jun 22, 2019
f5560e5
Consertando erros E712 e E302 em mmu.py
gustavooquinteiro Jun 22, 2019
d870e14
Adicionando biblioteca necessária para build
gustavooquinteiro Jun 22, 2019
10b06c9
Atualizando .travis.yml
gustavooquinteiro Jun 22, 2019
81ec949
Consertando erros E128
gustavooquinteiro Jun 22, 2019
a8b0a23
Consertando erros E127
gustavooquinteiro Jun 22, 2019
f2830cb
Consertando erros E501
gustavooquinteiro Jun 22, 2019
e9fbe89
Atualizando .travis.yml
gustavooquinteiro Jun 22, 2019
1a9e8b5
Consertando erros E501
gustavooquinteiro Jun 22, 2019
b00b8ef
Atualizando .travis.yml
gustavooquinteiro Jun 22, 2019
f037843
Atualizando .travis.yml
gustavooquinteiro Jun 22, 2019
2081a08
Atualizando .travis.yml
gustavooquinteiro Jun 22, 2019
38193e7
Atualizando parâmetro de execução do xvfb
gustavooquinteiro Jun 24, 2019
f1b324b
Consertando parâmetro do xvfb e comentando QMessageBox
gustavooquinteiro Jun 24, 2019
ee5b88e
Atualizando .travis.yml
gustavooquinteiro Jun 24, 2019
82dcb10
Removendo código que possibilitava o erro de abertura de arquivo inex…
gustavooquinteiro Jun 24, 2019
a1cdff0
Verificando se versão do Python suporta a biblioteca Path
gustavooquinteiro Jun 24, 2019
f0935f9
Suporte da biblioteca Path em Gantt.py
gustavooquinteiro Jun 24, 2019
e7e36a1
Aprimorando a manipulação de arquivos
gustavooquinteiro Jun 25, 2019
f44eece
Atualizando testes
gustavooquinteiro Jun 25, 2019
b975309
Atualizando testes
gustavooquinteiro Jun 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
dist: xenial # required for Python >= 3.7
sudo: true
---
addons:
apt:
packages:
- libxkbcommon-x11-0
- python3-pyqt5
dist: xenial
language: python
python:
python:
- "3.5"
- "3.6"
- "3.7"
before_script:
- sudo apt-get install -qq libegl1-mesa
# - sh -e /etc/init.d/xvfb start
# - sleep 3
# Export ALIGNAKAPP_APP_DIR, only needed for Travis.
- export ALIGNAKAPP_APP_DIR=$HOME/.local/process-escalonator
- export ALIGNAKAPP_USR_DIR=$HOME/.local/process-escalonator
- export ALIGNAKAPP_LOG_DIR=$HOME/.local/process-escalonator

script: cd ./tests/ && python3 -m coverage run test.py
script: "xvfb-run -a python3 -m coverage run tests/test.py"
services:
- xvfb
sudo: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# process-escalonator

![Supported Python Version](https://img.shields.io/pypi/pyversions/django.svg) ![Supported Platforms](https://img.shields.io/badge/platform-win--64%20%7C%20linux--64-red.svg) ![License](https://img.shields.io/cocoapods/l/afn.svg) ![Build Status](https://travis-ci.com/gustavooquinteiro/process-escalonator.svg?branch=master) ![GitHub release](https://img.shields.io/github/release/gustavooquinteiro/process-escalonator.svg?color=yellow) ![codecov](https://codecov.io/gh/gustavooquinteiro/process-escalonator/branch/master/graph/badge.svg)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1bc8ca14b6e640d181b6b4f0c202efd2)](https://app.codacy.com/app/gustavooquinteiro/process-escalonator?utm_source=github.com&utm_medium=referral&utm_content=gustavooquinteiro/process-escalonator&utm_campaign=Badge_Grade_Settings) ![Supported Python Version](https://img.shields.io/pypi/pyversions/django.svg) ![Supported Platforms](https://img.shields.io/badge/platform-win--64%20%7C%20linux--64-red.svg) ![License](https://img.shields.io/cocoapods/l/afn.svg) ![](https://img.shields.io/badge/build-passing-brightgreen.svg) ![GitHub release](https://img.shields.io/github/release/gustavooquinteiro/process-escalonator.svg?color=yellow)

Simulador de execução de processos de um sistema operacional em Python desenvolvido como parte da avaliação da matéria MATA58 - Sistemas Operacionais, do Departamento de Ciência da Computação da Universidade Federal da Bahia, ministrada por Maycon Leone Maciel Peixoto.

Expand Down
17 changes: 9 additions & 8 deletions sample/Gantt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from PyQt5.QtGui import QColor, QIcon
from pathlib import Path
import os
import sys


class Window_Gantt(QWidget):
Expand Down Expand Up @@ -186,7 +187,10 @@ def __init__(self, n, cpu, escalonator, io, processes, SOWindow):
self.layout.addWidget(self.LastLabel)
self.setGeometry(300, 300, 1400, 1000)
self.setLayout(self.layout)
images = Path("sample/images/")
if sys.version_info.minor >= 6:
images = Path("sample/images/")
else:
images = "sample/images/"
edit_image = os.path.join(images, "edit-image.png")
self.setWindowIcon(QIcon(edit_image))
self.show()
Expand Down Expand Up @@ -322,12 +326,10 @@ def tick(self):
else:
labels.append("{}: {}\n" .format(x, y))
text = ''.join(labels)

QMessageBox.information(self,
'FINISHED',
text,
QMessageBox.Ok)

# QMessageBox.information(self,
# 'FINISHED',
# text,
# QMessageBox.Ok)
return
self.escalonator.next_process()
self.io.wait_for_resource(self.cpu)
Expand All @@ -350,6 +352,5 @@ def autoTick(self):
QtTest.QTest.qWait(self.AutoTickQuant.value())

def closeEvent(self, e):
self.SO.file_open(True)
self.SO.show()
self.close()
69 changes: 44 additions & 25 deletions sample/InterFace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import os
import platform
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from process import Process
Expand All @@ -20,7 +21,14 @@ def __init__(self):
self.idProcess = 1
self.process = None
self.listProcess = []
images = Path("sample/images/")
if sys.version_info.minor >= 6:
images = Path("sample/images/")
self.path = Path().absolute()
self.test_folder = self.path / "tests"
else:
images = "sample/images/"
self.path = os.path.abspath(__file__)
self.test_folder = self.path[:-20] + "tests"
icon = os.path.join(images, "computer.png")

self.setWindowIcon(QIcon(icon))
Expand Down Expand Up @@ -121,8 +129,9 @@ def __init__(self):
self.toolbar.addSeparator()
self.toolbar.addWidget(Override)
self.toolbar.addAction(Run)

self.path = os.path.abspath("Interface.py")

self.saved = False
self.index = 0

menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
Expand All @@ -136,7 +145,7 @@ def run(self):
"Insert Processes to Run",
QMessageBox.Ok)
return
self.file_open(True)
self.file_save(True)
self.quantum = self.quantum_sp.value()
self.override = self.override_sp.value()
self.type = self.comboCPU.currentText()
Expand Down Expand Up @@ -164,38 +173,49 @@ def run(self):
def file_save(self, auto=False):
if not auto:
name = QFileDialog.getSaveFileName(self, 'Save File')
else:
name = "('" + self.path[:-12] + \
'autosave' + "', " + "'All Files (*)')"
elif not self.saved:
self.index = len(list(filter(lambda file: file.split('.')[-1] == "txt", os.listdir(self.test_folder))))
self.saved = True
name = self.test_folder / "test{}.txt" .format(self.index)

if name[0]:
with open(name[0], 'w') as file:
if name:
with open(name, 'w') as file:
for i in self.listProcess:
file.write("{} {} {} {} {} {}\n"
.format(i.pid, i.start, i.execution_time,
i.numpages, i.deadline,
i.priority))

def file_open(self, auto=False):
if not auto:
fname = QFileDialog.getOpenFileName(self, 'Open file', '/home')
else:
fname = "('" + self.path[:-12] + \
'autosave' + "', " + "'All Files (*)')"

def file_open(self):
fname = QFileDialog.getOpenFileName(self, 'Open file', str(self.test_folder))
self.listProcess = []
self.saved = True
self.index = fname[0].split('.')[0].split('test')[-1]

if fname[0]:
with open(fname[0], 'r') as f:
data = f.read().split('\n')
for a in data:
if a == '':
break
i = a.split(' ')
processo = Process(int(i[0]), int(i[1]),
int(i[2]), int(i[3]),
int(i[4]), int(i[5]))
self.listProcess.append(processo)
if not data:
QMessageBox.information(self,
'Empty file',
'This file havent any process',
QMessageBox.Ok)
else:
for a in data:
if not a.strip():
break;
i = a.split(' ')
try:
processo = Process(int(i[0]), int(i[1]),
int(i[2]), int(i[3]),
int(i[4]), int(i[5]))
self.listProcess.append(processo)
except ValueError:
QMessageBox.information(self,
'Invalid file',
'This file havent the correct format',
QMessageBox.Ok)
break
self.printProcesses()

def new_Process(self):
Expand Down Expand Up @@ -233,7 +253,6 @@ def removeProcess(self):
def printProcesses(self):
self.lista = QTabWidget()
self.numberTab = 1
self.file_save(True)
for i in self.listProcess:
self.janela = QWidget()
self.lista.addTab(self.janela, "Processo {} " .format(i.pid))
Expand Down
6 changes: 4 additions & 2 deletions sample/WProcess.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QPushButton, QGridLayout,
QMessageBox, QSizePolicy, QDialog, QLabel, QSpinBox)
QMessageBox, QSizePolicy, QDialog,
QLabel, QSpinBox, QHBoxLayout)
from PyQt5.QtGui import QIcon
from process import Process
from pathlib import Path
import os


class Window_Process(QDialog):
Expand Down Expand Up @@ -119,7 +121,7 @@ def createProcess(self):
self.executionTime,
self.pagesNumber,
self.deadlineTime,
priority=self.priorityTime)
self.priorityTime)
self.close()


Expand Down
32 changes: 17 additions & 15 deletions sample/escalonator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,30 @@ def queue(self):
if self.algorithm == "RR" or self.algorithm == "FCFS":
self.ready_queue.sort(key=lambda process: process.start)
elif self.algorithm == "EDF":
self.ready_queue.sort(key=lambda process:
(process.start, process.deadline))
self.ready_queue.sort(key=lambda process: (process.start,
process.deadline))
elif self.algorithm == "SJF" or self.algorithm == "SPN":
self.ready_queue.sort(key=lambda process:
(process.start, process.execution_time))
self.ready_queue.sort(key=lambda process: (process.start,
process.execution_time))
elif self.algorithm == "PRIO":
self.ready_queue.sort(key=lambda process:
(process.start, process.priority),
reverse=True)
self.ready_queue.sort(key=lambda process: (process.start,
process.priority),
reverse=True)
elif self.algorithm == "LOT":
random.shuffle(self.ready_queue)
elif self.algorithm == "MLF":
self.ready_queue.sort(key=lambda process:
(process.start, process.laxity))
self.ready_queue.sort(key=lambda process: (process.start,
process.laxity))
# Os processos que não chegaram são ordenados por seu tempo de chegada
self.not_arrived.sort(key=lambda process: process.start)

def update_attributes(self):
""" Atualiza o deadline e o laxity de todos os processos na fila de prontos """
for process in self.ready_queue:
process.deadline = process.deadline - self.cpu.clock + process.start
process.laxity = process.deadline - self.cpu.clock - process.execution_time
up_dead = process.deadline - self.cpu.clock
process.deadline = up_dead + process.start
up_dead = process.deadline - self.cpu.clock
process.laxity = up_dead - process.execution_time

def real_time_over(self, process):
""" Verifica se um processo ultrapassou seu limite de execução.
Expand All @@ -86,13 +88,13 @@ def next_process(self):

if len(self.ready_queue) > 1:
if self.algorithm == "SJF" or self.algorithm == "SPN":
self.ready_queue.sort(key=lambda process: process.execution_time)
self.ready_queue.sort(
key=lambda process: process.execution_time)
elif self.algorithm == "EDF":
self.ready_queue.sort(key=lambda process: process.deadline)
elif self.algorithm == "PRIO":
self.ready_queue.sort(key=lambda process:
process.priority,
reverse=True)
self.ready_queue.sort(key=lambda process: process.priority,
reverse=True)
elif self.algorithm == "LOT":
random.shuffle(self.ready_queue)
elif self.algorithm == "MLF":
Expand Down
16 changes: 9 additions & 7 deletions sample/mmu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random


def transform_list(mem, process, mem_vm):
lista = mem
if process is None:
Expand Down Expand Up @@ -49,7 +50,7 @@ def has_clear(self):
return False

def substitute_page(self, process,
ind, cpu_process=None, had_substitution=False):
ind, cpu_process=None, had_substitution=False):
if self.algorithm == 'FIFO':
ref_ram = self.ram_pointer
is_in_ram = (self.queue[ref_ram].num == process.pid)
Expand Down Expand Up @@ -102,9 +103,10 @@ def substitute_page(self, process,
return ref_ram, old_index

def allocate_page(self, process,
ind, cpu_process=None, had_substitution=False):
ind, cpu_process=None, had_substitution=False):

selec_list = transform_list(list(range(RAM.SIZE)), cpu_process, self.vm)
selec_list = transform_list(list(range(RAM.SIZE)),
cpu_process, self.vm)
free_list = list(filter(
lambda page: not self.is_allocated(self.queue[page]), selec_list))
print(len(free_list))
Expand All @@ -117,7 +119,7 @@ def allocate_page(self, process,
return rand, -1
else:
return self.substitute_page(process, ind,
cpu_process, had_substitution)
cpu_process, had_substitution)

def clear(self):
for ind in range(RAM.SIZE):
Expand Down Expand Up @@ -193,8 +195,8 @@ def substitute_page(self, process, cpu_process=None):
list(range(VirtualMemory.SIZE))))
select_pages = list(self.mem_vm[i] for i in selec_list)
least_freq = min(select_pages,
default=select_pages[0],
key=lambda x: x[1])
default=select_pages[0],
key=lambda x: x[1])
ind = random.choice(list(filter(
lambda page: self.mem_vm[page][1] == least_freq[1],
selec_list)))
Expand Down Expand Up @@ -270,7 +272,7 @@ def allocate_page(self, process, cpu_process=None):
pages.append(ref)
else:
for ref in process.pages:
if self.vm.is_page_allocated(process, ref) == False:
if not self.vm.is_page_allocated(process, ref):
self.vm.allocate_page(process, ref, cpu_process)
break
self.disk.remove_process(process, 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from PyQt5.QtWidgets import QApplication
import unittest
import sys
sys.path.append("../sample")
sys.path.append("sample")
from InterFace import Main_Window
from process import Process


class TestApp(unittest.TestCase):
def setUp(self):
self.app = QApplication(sys.argv)
self.testfile = "test0.txt"
self.interface = Main_Window()
self.testfile = self.interface.test_folder / "test0.txt"
with open(self.testfile, 'r') as target:
lines = target.read().split('\n')
for line in lines:
Expand Down