from unittest import (TestCase, main) from examples import (Q35Project_2_6_0) from common import ( RecursionError, notifier, ee, intervalmap, same, pygenerate, ) from traceback import (format_exc) from collections import (namedtuple) import qdt from os.path import (join, dirname) PYGEN_VERBOSE = ee("PYGEN_VERBOSE") verbose_dir = join(dirname(__file__), "pygen_code") class PyGeneratorTestHelper(object): def test(self): self._generator = gen = pygenerate(self._original) buf = gen.w code = buf.getvalue() res = {} try: exec(code, self._namespace, res) except: print("\nError in generated code:\n" + format_exc()) eq = False
from matplotlib import (pyplot as plt) from common import (git_find_commit, uname, Measurer, fast_repo_clone, ee, execfile, lazy, Persistent, Extensible) from argparse import (ArgumentTypeError, ArgumentParser, ArgumentDefaultsHelpFormatter) import qdt from traceback import (print_exc) from qemu import (qvd_get) from os import (makedirs, environ) from datetime import (datetime) from filecmp import (cmp) from collections import (defaultdict) from contextlib import (contextmanager) from math import (sqrt) TC_PRINT_COMMANDS = ee("TC_PRINT_COMMANDS") TC_MELD = not ee("TC_NO_MELD") TC_PRINT_STARTUP_ENVIRONMENT = ee("TC_PRINT_STARTUP_ENVIRONMENT") TEST_STARTUP_ENV = dict(environ) # Test environment is built basing on testing environment. # But some Python-related variables breaks operation of the tool being tested. for var in ["PYTHONPATH"]: try: del TEST_STARTUP_ENV[var] except: pass # no variable - no problem if TC_PRINT_STARTUP_ENVIRONMENT: print("\n".join(("%s=%s" % i) for i in TEST_STARTUP_ENV.items()))
from common import ( ee, LineNoStream, mlget as _, ) from widgets import ( add_scrollbars_native, TextCanvas, GUITk, Statusbar, ) from six.moves.tkinter_ttk import ( Sizegrip, ) DEBUG = ee("DEBUG_TEXTVIEW", "False") DEBUG_STREAM_SIZE = 100001 class TextViewerWindow(GUITk, object): def __init__(self): GUITk.__init__(self) self.title(_("Text Viewer")) self.columnconfigure(0, weight = 1) self.columnconfigure(1, weight = 0) row = 0 self.rowconfigure(row, weight = 1)
# Defining a lexer affects `ply.yacc.LRParser.parse` invocations without # explicit `lexer` argument value because a new lexer overwrites existing lexer # inside `ply` (it's a global reference). def t_ANY(t): ".+" return t t_error = lambda _: None tokens = ["ANY"] lex() TEST_CCONST_VERBOSE = ee("TEST_CCONST_VERBOSE") class CConstTest(object): if TEST_CCONST_VERBOSE: def setUp(self): print("== " + self.data + " ==") def test(self): self.parsed = CConst.parse(self.data) self.back = str(self.parsed) self.assertIsInstance(self.parsed, self.expected_type) self.assertEqual(self.back, self.data)
from unittest import (TestCase, main) from six import (StringIO) from source import (OpaqueCode, Type, Header, Source, Function, BodyTree, Declare, OpAssign, OpAdd, Label, Goto, Structure, Macro, Initializer, OpDeclareAssign, BranchSwitch, SwitchCase, Call, Pointer, Enumeration, add_base_types) from common import (ee) from os.path import (join, dirname) from difflib import (unified_diff) MODEL_VERBOSE = ee("MODEL_VERBOSE") SAVE_CHUNK_GRAPH = ee("SAVE_CHUNK_GRAPH") verbose_dir = join(dirname(__file__), "model_code") class SourceModelTestHelper(object): inherit_references = False def setUp(self): Type.reg = {} Header.reg = {} add_base_types() def test(self): for file_, content in self.files: kw = {} if isinstance(file_, Header): kw["inherit_references"] = self.inherit_references sf = file_.generate(**kw)
__all__ = ["SysBusDeviceType"] from .qom import (QemuTypeName, QOMDevice, QOMType) from source import (line_origins, Pointer, Macro, Initializer, Function, Type) from common import (ee, mlget as _) from collections import (OrderedDict) from .qom_desc import (describable) from copy import (deepcopy as dcp) from .machine_nodes import (MemoryLeafNode, MemoryRAMNode, MemoryROMNode) from itertools import (count) MACROS_2_HEADER = ee("QDT_SBD_MMIO_MACROS_TO_HEADER") @describable class SysBusDeviceType(QOMDevice): __attribute_info__ = OrderedDict([("out_irq_num", { "short": _("Output IRQ quantity"), "input": int }), ("in_irq_num", { "short": _("Input IRQ quantity"), "input": int }), ("mmio_num", { "short": _("MMIO quantity"), "input": int }), ("pio_num", { "short": _("PMIO (PIO) quantity"), "input": int })]) def __init__(self,
"OpGE", "OpLE", "OpGreater", "OpLess", "CaseRange" ] from ..c_const import (CConst, CINT) from ..model import (Type, TypeReference, Pointer, Macro, NodeVisitor, Function, Variable) from common import (ee, BreakVisiting, lazy) from six import (integer_types) # OpSDeref is automatically re-directed to definition of structure if # available. OPSDEREF_FROM_DEFINITION = ee("QDT_OPSDEREF_FROM_DEFINITION", "True") class DeclarationSearcher(NodeVisitor): def __init__(self, root): super(DeclarationSearcher, self).__init__(root) self.have_declaration = False def on_visit(self): if isinstance(self.cur, Declare): self.have_declaration = True raise BreakVisiting() class Node(object):
mlget as _ ) from six.moves import ( zip as izip, range as xrange, ) from qemu import ( QEMULog ) from time import ( time, ) # less value = more info DEBUG = ee("QLOG_DEBUG", "3") DEBUG_INST_TV = ee("QLOG_DEBUG_INSTRUCTIONS_TREE_VIEW", "False") # Instructions Treeview styles STYLE_DEFAULT = tuple() STYLE_DIFFERENCE = ("difference",) STYLE_FIRST = ("first",) # Instructions tree view shows only few instructions in backend Tk Treeview. # Showed instructions interval is called "window". # The window is automatically shifted when necessary by adding/removing rows # beyond the window. # Currently 1024 instructions are showed to user. TV_WINDOW_SIZE = 1 << 10
from common import (ee) from qemu import (QemuTypeName) from random import (randrange) QTN_AUTO_SEARCH = ee("QTN_AUTO_SEARCH") def names(qtn): return (qtn.for_id_name, qtn.for_header_name, qtn.for_struct_name, qtn.type_macro) def qtn_char(c): # low ["0"; "9"] middle0 ["A", "Z"] middle1 ["a"; "z"] high if c < "0": # low return False # ["0"; "9"] middle0 ["A", "Z"] middle1 ["a"; "z"] high if "z" < c: # high return False # ["0"; "9"] middle0 ["A", "Z"] middle1 ["a"; "z"] if c < "A": # ["0"; "9"] middle0 return c <= "9" # ["A", "Z"] middle1 ["a"; "z"] if "Z" < c: # middle1 ["a"; "z"] return "a" <= c # ["A", "Z"] return True
__all__ = ["QemuTypeName"] from common import (def_tokens, ee, pypath) with pypath("..ply"): from ply.yacc import (yacc) from ply.lex import (lex) from collections import (namedtuple as nt) QTN_DEBUG = ee("QTN_DEBUG") # Different character forms are used for generation of different entities. # I.e. name of function or variable must use lower case. A MACRO must use # upper case. A structure must have upper camel case name. qtnchar = nt("qtnchar", "id_char file_char struct_char macro_char") # Lexer. # Allowed characters. def t_NUMBER(t): r"[0-9]+" c = t.value t.value = qtnchar(c, c, c, c) return t def t_LOWER(t): r"[a-z]" c = t.value t.value = qtnchar(c, c, c, c.upper()) return t
__all__ = [ "InInstr", "TraceInstr", "TBCache", "QTrace", "QEMULog", ] from itertools import (count) from common import (pipeline, limit_stage, ee) from traceback import (print_exc) # less value = more info DEBUG = ee("QLOG_DEBUG", "3") def is_trace(l): # Looks like Chain is a fast jump to already translated TB (searched in # the cache) using non constant address (e.g. from a guest register), # while linking is a redirection to constant address (e.g. from an # instruction code immediate value) by translated code patching. # Chain message is printed _each time_. # Hence it's a "Trace" record analog for trace reconstruction algorithm. # Grep for: lookup_tb_ptr return l[:6] == "Trace " or l[:6] == "Chain " def is_linking(l): return l[:8] == "Linking "
__all__ = [ "TkCoDispatcher" ] from common import ( ee, CoDispatcher ) from time import ( time ) import sys PROFILE_COTASK = ee("QDT_PROFILE_COTASK") class TkCoDispatcher(CoDispatcher): """ The coroutine task dispatcher uses Tk.after method to spread task work peaces among Tkinter event driven GUI model. """ def __init__(self, tk, wait_msec = 500, **kw): disp_tk = {} for disp_arg in ("max_tasks"): try: disp_tk[disp_arg] = kw.pop(disp_arg) except KeyError: pass CoDispatcher.__init__(self, **disp_tk)