예제 #1
0
    def invoke(self, engine: Engine, macro_expansion: MacroExpansion):
        file = macro_expansion.file
        line = macro_expansion.line

        type_and_level = engine.read_byte()
        args = macro_expansion.args[3:]

        level = level_t[(type_and_level[0] & 0b11100000) >> 5]
        type_ = type_t[type_and_level[0] & 0b11111]

        cond_or_length = engine.read_int()
        condition = bool(cond_or_length)
        func = getattr(self.reporter, type_)

        if type_ == "checkpoint":
            func(file, line)
        elif type_ == "log":
            func(file, line, args[0])
        elif type_ in ["message", "plain"]:
            func(file, line, level, condition, args[0])
        elif type_ in ["equal", "not_equal", "ge", "le", "greater", "lesser"]:
            func(file, line, level, condition, args[0], args[1])
        elif type_ in ["close", "close_relative"]:
            func(file, line, level, condition, args[0], args[1], args[2])
        elif type_ in ["close", "close_relative"]:
            func(file, line, level, condition, args[0], args[1], args[2])
        elif type_ == "report":
            func(file, line, condition)
        elif type_ == "critical":
            func(file, line, level)
        elif type_ == "call":
            name = args[1][3:-8] if args[1] else args[0]
            func(file, line, level, condition, name)
        elif type_ == 'loop':
            func(file, line, level)
        elif type_ == 'ranged':
            func(file, line, level, cond_or_length, args)
        elif type_ == 'predicate':
            args_a = [arg.strip() for arg in str(args[1][2:-2]).split(',')
                      ] if args else None
            func(file, line, level, cond_or_length, args[0], args_a)
        else:
            raise Exception("Unknown check type {}".format(type_))
예제 #2
0
serial_info = generate(args.binary, args.define, args.include)

p = Popen(args.binary,
          stdin=PIPE,
          stdout=PIPE,
          stderr=sys.stdout.buffer,
          close_fds=True)

engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info)

assert engine.init_marker.file.endswith('write.c')
assert engine.init_marker.line == 25

engine.write_byte(b'0')
assert engine.read_byte() == b'9'

engine.write_int(22)
assert engine.read_int() == 44

assert engine.write_string("str") == 3
assert engine.read_string() == "tr"

engine.write_int(11)
assert engine.read_int() == 33

assert engine.write_string("overflow") == 6
assert engine.read_string() == "erfl"

engine.write_int(4)
assert engine.read_int() == 16