mirror of
https://github.com/jopohl/urh.git
synced 2026-03-20 15:07:02 +01:00
get fuzzing profile tests working
This commit is contained in:
@@ -853,9 +853,10 @@ class CompareFrameController(QFrame):
|
||||
@pyqtSlot(int)
|
||||
def show_protocol_labels(self, preselected_index: int):
|
||||
view_type = self.ui.cbProtoView.currentIndex()
|
||||
block = next(block for block in self.proto_analyzer.blocks if self.active_labelset.id == block.labelset.id)
|
||||
label_controller = ProtocolLabelController(preselected_index=preselected_index, labelset=self.active_labelset,
|
||||
max_end=numpy.max([len(block) for block in self.proto_analyzer.blocks]),
|
||||
viewtype=view_type,
|
||||
viewtype=view_type, block=block,
|
||||
parent=self)
|
||||
label_controller.exec_()
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from urh import constants
|
||||
from urh.models.PLabelTableModel import PLabelTableModel
|
||||
from urh.signalprocessing.LabelSet import LabelSet
|
||||
from urh.signalprocessing.ProtocolAnalyzer import ProtocolAnalyzer
|
||||
from urh.signalprocessing.ProtocolBlock import ProtocolBlock
|
||||
from urh.signalprocessing.ProtocolGroup import ProtocolGroup
|
||||
from urh.ui.delegates.CheckBoxDelegate import CheckBoxDelegate
|
||||
from urh.ui.delegates.ComboBoxDelegate import ComboBoxDelegate
|
||||
@@ -15,11 +16,11 @@ from urh.ui.ui_properties_dialog import Ui_DialogLabels
|
||||
|
||||
|
||||
class ProtocolLabelController(QDialog):
|
||||
def __init__(self, preselected_index, labelset: LabelSet, viewtype: int, max_end: int, parent=None):
|
||||
def __init__(self, preselected_index, labelset: LabelSet, viewtype: int, max_end: int, block:ProtocolBlock, parent=None):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_DialogLabels()
|
||||
self.ui.setupUi(self)
|
||||
self.model = PLabelTableModel(labelset)
|
||||
self.model = PLabelTableModel(labelset, block=block)
|
||||
self.preselected_index = preselected_index
|
||||
|
||||
self.ui.tblViewProtoLabels.setItemDelegateForColumn(1, SpinBoxDelegate(1, max_end, self))
|
||||
|
||||
@@ -3,6 +3,7 @@ from PyQt5.QtCore import QAbstractTableModel, pyqtSignal, Qt, QModelIndex
|
||||
from urh.signalprocessing.LabelSet import LabelSet
|
||||
from urh.signalprocessing.ProtocoLabel import ProtocolLabel
|
||||
from urh.signalprocessing.ProtocolAnalyzer import ProtocolAnalyzer
|
||||
from urh.signalprocessing.ProtocolBlock import ProtocolBlock
|
||||
from urh.signalprocessing.ProtocolGroup import ProtocolGroup
|
||||
|
||||
|
||||
@@ -11,7 +12,7 @@ class PLabelTableModel(QAbstractTableModel):
|
||||
|
||||
label_removed = pyqtSignal(ProtocolLabel)
|
||||
|
||||
def __init__(self, labelset: LabelSet, parent=None):
|
||||
def __init__(self, labelset: LabelSet, block: ProtocolBlock, parent=None):
|
||||
super().__init__(parent)
|
||||
self.row_count = len(labelset)
|
||||
self.proto_view = 0
|
||||
@@ -45,9 +46,9 @@ class PLabelTableModel(QAbstractTableModel):
|
||||
if j == 0:
|
||||
return lbl.name
|
||||
elif j == 1:
|
||||
return self.labelset.get_label_range(lbl, self.proto_view, True)[0] + 1
|
||||
return self.block.get_label_range(lbl, self.proto_view, True)[0] + 1
|
||||
elif j == 2:
|
||||
return self.labelset.get_label_range(lbl, self.proto_view, True)[1]
|
||||
return self.block.get_label_range(lbl, self.proto_view, True)[1]
|
||||
elif j == 3:
|
||||
return lbl.color_index
|
||||
elif j == 4:
|
||||
|
||||
@@ -4,7 +4,7 @@ import string
|
||||
from urh import constants
|
||||
from urh.signalprocessing.ProtocoLabel import ProtocolLabel
|
||||
from urh.util.Logger import logger
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
class LabelSet(list):
|
||||
def __init__(self, name: str, iterable=None, id=None):
|
||||
@@ -15,21 +15,6 @@ class LabelSet(list):
|
||||
self.__id = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(50)) if id is None else id
|
||||
|
||||
|
||||
def get_label_range(self):
|
||||
pass # TODO
|
||||
|
||||
def find_overlapping_labels(self, start: int, end: int, proto_view):
|
||||
ostart = self.convert_index(start, proto_view, 0, True)[0]
|
||||
oend = self.convert_index(end, proto_view, 0, True)[1]
|
||||
|
||||
|
||||
overlapping_labels = [lbl for lbl in self.labels
|
||||
if any(i in range(lbl.start, lbl.end) for i in range(ostart, oend))]
|
||||
|
||||
return overlapping_labels
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
return self.__id
|
||||
@@ -85,4 +70,19 @@ class LabelSet(list):
|
||||
logger.warning(lbl.name + " is not in set, so cant be removed")
|
||||
|
||||
def __getitem__(self, index) -> ProtocolLabel:
|
||||
return super().__getitem__(index)
|
||||
return super().__getitem__(index)
|
||||
|
||||
def to_xml(self) -> ET.Element:
|
||||
result = ET.Element("labelset", attrib={"name": self.name, "id": self.id})
|
||||
for lbl in self:
|
||||
result.append(lbl.to_xml(-1))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def from_xml(tag: ET.Element):
|
||||
name = tag.get("name", "blank")
|
||||
id = tag.get("id", None)
|
||||
labels = []
|
||||
for lbl_tag in tag.findall("label"):
|
||||
labels.append(ProtocolLabel.from_xml(lbl_tag))
|
||||
return LabelSet(name=name, iterable=labels, id=id)
|
||||
@@ -638,10 +638,4 @@ class ProtocolAnalyzer(object):
|
||||
return "ProtoAnalyzer " + self.name
|
||||
|
||||
def set_labels(self, val):
|
||||
self._protocol_labels = val
|
||||
|
||||
|
||||
def get_label_range(self, lbl, viewtype, decoded: bool):
|
||||
# TODO
|
||||
start, end = self.proto_analyzer.get_label_range(lbl, self.ui.cbProtoView.currentIndex())
|
||||
|
||||
self._protocol_labels = val
|
||||
@@ -253,14 +253,8 @@ class ProtocolAnalyzerContainer(ProtocolAnalyzer):
|
||||
self.blocks[:] = []
|
||||
self.protocol_labels[:] = []
|
||||
|
||||
|
||||
def get_label_range(self, lbl: ProtocolLabel, view: int, decode: bool):
|
||||
return self.__group.get_label_range(lbl, view, decode)
|
||||
|
||||
def create_fuzzing_label(self, start, end, refblock) -> ProtocolLabel:
|
||||
fuz_lbl = self.__group.add_protocol_label(start, end, refblock, 0, False)
|
||||
for block in self.blocks:
|
||||
block.labelset.append(fuz_lbl)
|
||||
fuz_lbl = self.blocks[refblock].labelset.add_protocol_label(start=start, end=end, type_index= 0)
|
||||
return fuz_lbl
|
||||
|
||||
def remove_label(self, label: ProtocolLabel):
|
||||
@@ -301,10 +295,9 @@ class ProtocolAnalyzerContainer(ProtocolAnalyzer):
|
||||
# Save data
|
||||
data_tag = ET.SubElement(root, "data")
|
||||
for i, block in enumerate(self.blocks):
|
||||
block_tag = ET.SubElement(data_tag, "block", attrib={"modulator_index": str(block.modulator_indx),
|
||||
"decoding_index": str(decoders.index(block.decoder)),
|
||||
"pause": str(block.pause),"index": str(i)})
|
||||
block_tag.text = block.plain_bits_str
|
||||
block_tag = block.to_xml(decoders=decoders, include_labelset=True)
|
||||
block_tag.set("bits", block.plain_bits_str)
|
||||
data_tag.append(block_tag)
|
||||
|
||||
# Save labels
|
||||
if len(self.protocol_labels) > 0:
|
||||
@@ -352,20 +345,13 @@ class ProtocolAnalyzerContainer(ProtocolAnalyzer):
|
||||
self.used_symbols.add(s)
|
||||
|
||||
block_tags = root.find("data").findall("block")
|
||||
self.blocks[:] = [None] * len(block_tags)
|
||||
self.blocks[:] = []
|
||||
|
||||
for block_tag in block_tags:
|
||||
block = ProtocolBlock.from_plain_bits_str(block_tag.text, {s.name: s for s in self.used_symbols})
|
||||
block = ProtocolBlock.from_plain_bits_str(bits=block_tag.get("bits"), symbols={s.name: s for s in self.used_symbols},
|
||||
labelset=None)
|
||||
block.from_xml(tag=block_tag, participants=None, decoders=decoders)
|
||||
block.modulator_indx = Formatter.str2val(block_tag.get("modulator_index"), int, 0)
|
||||
block.decoder = decoders[Formatter.str2val(block_tag.get("decoding_index"), int, 0)]
|
||||
self.blocks[Formatter.str2val(block_tag.get("index"), int)] = block
|
||||
block.pause = Formatter.str2val(block_tag.get("pause"), int)
|
||||
|
||||
# Todo read labelsets instead labels
|
||||
self.protocol_labels[:] = []
|
||||
labels_tag = root.find("labels")
|
||||
if labels_tag:
|
||||
label_tags = labels_tag.findall("label")
|
||||
self.protocol_labels = [None] * len(label_tags)
|
||||
for label_tag in label_tags:
|
||||
self.protocol_labels[int(label_tag.get("index"))] = ProtocolLabel.from_xml(label_tag)
|
||||
self.blocks.append(block)
|
||||
|
||||
@@ -534,16 +534,27 @@ class ProtocolBlock(object):
|
||||
|
||||
return ProtocolBlock(plain_bits=plain_bits, pause=0, bit_alignment_positions=[], labelset=labelset)
|
||||
|
||||
def to_xml(self) -> ET.Element:
|
||||
def to_xml(self, decoders=None, include_labelset=False) -> ET.Element:
|
||||
root = ET.Element("block")
|
||||
root.set("labelset_id", self.labelset.id)
|
||||
root.set("modulator_index", str(self.modulator_indx))
|
||||
root.set("pause", str(self.pause))
|
||||
if decoders:
|
||||
root.set("decoding_index", str(decoders.index(self.decoder)))
|
||||
if self.participant is not None:
|
||||
root.set("participant_id", self.participant.id)
|
||||
if include_labelset:
|
||||
root.append(self.labelset.to_xml())
|
||||
return root
|
||||
|
||||
def from_xml(self, tag: ET.Element, participants, labelsets):
|
||||
def from_xml(self, tag: ET.Element, participants, decoders=None, labelsets=None):
|
||||
part_id = tag.get("participant_id", None)
|
||||
labelset_id = tag.get("labelset_id", None)
|
||||
self.modulator_indx = int(tag.get("modulator_index", self.modulator_indx))
|
||||
self.pause = int(tag.get("pause", self.pause))
|
||||
decoding_index = tag.get("decoding_index", None)
|
||||
if decoding_index:
|
||||
self.decoder = decoders[int(decoding_index)]
|
||||
|
||||
if part_id:
|
||||
for participant in participants:
|
||||
@@ -553,12 +564,16 @@ class ProtocolBlock(object):
|
||||
if self.participant is None:
|
||||
logger.warning("No participant matched the id {0} from xml".format(part_id))
|
||||
|
||||
if labelset_id:
|
||||
if labelset_id and labelsets:
|
||||
for labelset in labelsets:
|
||||
if labelset.id == labelset_id:
|
||||
self.labelset = labelset
|
||||
break
|
||||
|
||||
labelset_tag = tag.find("labelset")
|
||||
if labelset_tag:
|
||||
self.labelset = LabelSet.from_xml(labelset_tag)
|
||||
|
||||
|
||||
def get_label_range(self, lbl: ProtocolLabel, view: int, decode: bool):
|
||||
start = self.convert_index(index=lbl.start, from_view=0, to_view=view, decoded=decode)[0]
|
||||
|
||||
@@ -49,13 +49,13 @@ class TestFuzzing(unittest.TestCase):
|
||||
self.assertEqual(self.cframe.protocol_model.display_data[0][-4:], "0000")
|
||||
|
||||
# Serial Part 1: Bits 207-226 (Dezimal: 91412) (20 Bits)
|
||||
self.cframe.add_protocol_label(206, 225, 0, 0, False, edit_label_name = False)
|
||||
self.cframe.add_protocol_label(206, 225, 0, 0, edit_label_name = False)
|
||||
|
||||
# Zeros: Bits 227-244 (18 Bits)
|
||||
self.cframe.add_protocol_label(226, 243, 0, 0, False, edit_label_name = False)
|
||||
self.cframe.add_protocol_label(226, 243, 0, 0, edit_label_name = False)
|
||||
|
||||
# Serial Part 2: Bit 245 - 264 (Dezimal: 1034678) (20 Bits)
|
||||
self.cframe.add_protocol_label(244, 263, 0, 0, False, edit_label_name = False)
|
||||
self.cframe.add_protocol_label(244, 263, 0, 0, edit_label_name = False)
|
||||
QTest.qWait(10)
|
||||
|
||||
self.form.ui.tabWidget.setCurrentIndex(2)
|
||||
|
||||
@@ -20,8 +20,8 @@ class TestFuzzing(unittest.TestCase):
|
||||
decoders = [encoding(["NRZ"]), encoding(["NRZ-I", constants.DECODING_INVERT])]
|
||||
|
||||
pac = ProtocolAnalyzerContainer([mod1, mod2])
|
||||
pac.blocks.append(ProtocolBlock([True, False, False, True, "A"], 100, [], decoder=decoders[0]))
|
||||
pac.blocks.append(ProtocolBlock([False, False, False, False, "A"], 200, [], decoder=decoders[1]))
|
||||
pac.blocks.append(ProtocolBlock([True, False, False, True, "A"], 100, [], decoder=decoders[0], labelset=pac.default_labelset))
|
||||
pac.blocks.append(ProtocolBlock([False, False, False, False, "A"], 200, [], decoder=decoders[1], labelset=pac.default_labelset))
|
||||
pac.used_symbols.add(Symbol("A", 1, 1, 100))
|
||||
pac.create_fuzzing_label(1, 10, 0)
|
||||
pac.to_xml_file(filename)
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestGeneratorTable(unittest.TestCase):
|
||||
t = time.time()
|
||||
self.gframe.table_model.data(indx, role = role)
|
||||
microseconds = (time.time() - t) * 10 ** 6
|
||||
self.assertLessEqual(microseconds, 1.5 * time_for_display, msg=self.__role_to_str(role))
|
||||
self.assertLessEqual(microseconds, 1.75 * time_for_display, msg=self.__role_to_str(role))
|
||||
if role == Qt.DisplayRole:
|
||||
time_for_display = microseconds
|
||||
print("{0}: {1} µs".format(self.__role_to_str(role), microseconds))
|
||||
@@ -60,7 +60,7 @@ class TestGeneratorTable(unittest.TestCase):
|
||||
def __build_protocol(self):
|
||||
result = ProtocolAnalyzer(signal = None)
|
||||
for _ in range(self.NUM_BLOCKS):
|
||||
b = ProtocolBlock([True] * self.BITS_PER_BLOCK, pause = 1000, bit_alignment_positions = [])
|
||||
b = ProtocolBlock([True] * self.BITS_PER_BLOCK, pause = 1000, bit_alignment_positions = [], labelset=result.default_labelset)
|
||||
result.blocks.append(b)
|
||||
return result
|
||||
|
||||
@@ -68,7 +68,7 @@ class TestGeneratorTable(unittest.TestCase):
|
||||
start = 0
|
||||
label_len = 3
|
||||
for i in range(self.NUM_LABELS):
|
||||
self.cframe.add_protocol_label(start, start + label_len, 0, 0, False, edit_label_name = False)
|
||||
self.cframe.add_protocol_label(start, start + label_len, 0, 0, edit_label_name = False)
|
||||
start += label_len + 1
|
||||
|
||||
def __role_to_str(self, role):
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestProtocolTable(unittest.TestCase):
|
||||
def __build_protocol(self):
|
||||
result = ProtocolAnalyzer(signal=None)
|
||||
for _ in range(self.NUM_BLOCKS):
|
||||
b = ProtocolBlock([True] * self.BITS_PER_BLOCK, pause=1000, bit_alignment_positions=[])
|
||||
b = ProtocolBlock([True] * self.BITS_PER_BLOCK, pause=1000, bit_alignment_positions=[], labelset=result.default_labelset)
|
||||
result.blocks.append(b)
|
||||
return result
|
||||
|
||||
@@ -58,7 +58,7 @@ class TestProtocolTable(unittest.TestCase):
|
||||
start = 0
|
||||
label_len = 3
|
||||
for i in range(self.NUM_LABELS):
|
||||
self.cframe.add_protocol_label(start, start+label_len, 0, 0, False, edit_label_name=False)
|
||||
self.cframe.add_protocol_label(start, start+label_len, 0, 0, edit_label_name=False)
|
||||
start += label_len +1
|
||||
|
||||
def __role_to_str(self, role):
|
||||
|
||||
Reference in New Issue
Block a user