示例#1
0
def tryOpenOcd(verbose, boxpath, interactive, board_id, sleep):
    path = boxpath + "/interface/openocd.py"
    with tempfile.TemporaryFile() as logfile:
        with toolwrapper.ToolWrapper(path, list(board_id), logfile,
                                     5) as wrapper:
            if interactive:
                input("done? press return... ")
            else:
                time.sleep(sleep)
            wrapper.comm(data="\n".encode('ascii'), timeout=2)
        print("=" * 20)
        # check for successful output
        logfile.seek(0)
        found = 0
        for line in logfile:
            line = line.decode('ascii')
            if verbose:
                print(line, end='')
            if "tap/device found" in line:
                found = found + 1
            if "Listening on port" in line:
                found = found + 1
            if "no device found" in line:
                return false
    return found == 7
示例#2
0
def test_toolwrapper_read_write_when_closed():
    tool = toolwrapper.ToolWrapper(["cat"], start=False)
    with pytest.raises(toolwrapper.ToolException):
        tool.writeline("hello")
    with pytest.raises(toolwrapper.ToolException):
        tool.readline()
    tool.start()
    tool.writeline("hello")
    assert "hello" == tool.readline()
    tool.close()
    with pytest.raises(toolwrapper.ToolException):
        tool.writeline("hello")
    with pytest.raises(toolwrapper.ToolException):
        tool.readline()
示例#3
0
def test_toolwrapper_start_stop_restart():
    tool = toolwrapper.ToolWrapper(["cat"], start=False)
    assert tool.proc is None
    tool.start()
    pid = tool.proc.pid
    with pytest.raises(toolwrapper.ToolException):
        tool.start()
    tool.close()
    assert tool.closed
    tool.start()
    assert pid != tool.proc.pid
    pid = tool.proc.pid
    tool.restart()
    assert pid != tool.proc.pid
    tool.close()
示例#4
0
def tryComm(verbose, boxpath, interactive, board_id, board_type, sleep):
    path = boxpath + "/interface/comm.py"
    with tempfile.TemporaryFile() as logfile:
        with toolwrapper.ToolWrapper(path,
                                     list(board_id) + ["-i", "-it", "output"],
                                     logfile, 5) as wrapper:
            if interactive:
                input("done? press return... ")
            else:
                time.sleep(sleep)
            wrapper.comm(data="\n".encode('ascii'), timeout=2)
        print("=" * 20)
        # check for successful output
        logfile.seek(0)
        if board_type == "rpi3" or board_type == "rpi4":
            found = 0
            for line in logfile:
                line = line.decode('ascii')
                if verbose:
                    print(line, end='')
                if "Init complete" in line:
                    found = found + 1
            return found == 4
        elif board_type == "rpi2":
            found = 0
            for line in logfile:
                line = line.decode('ascii')
                if verbose:
                    print(line, end='')
                if "U-Boot 2016.09.01-dirty" in line:
                    found = found + 1
                if "RPI 2 Model B (0xa01041)" in line:
                    found = found + 1
                if "reading uboot.env" in line:
                    found = found + 1
            return found == 3
        else:
            raise Exception(f"unknown board type {board_type}")
示例#5
0
def test_toolwrapper():
    with toolwrapper.ToolWrapper(["cat"]) as cat:
        for line in sample_lines:
            cat.writeline(line)
            assert cat.readline() == line
示例#6
0
def test_toolwrapper_str():
    x = toolwrapper.ToolWrapper(["a", "b"])
    assert str(x) == '''ToolWrapper'''
示例#7
0
def test_toolwrapper_repr():
    x = toolwrapper.ToolWrapper(["a", "b"], start=False, cwd="d")
    assert repr(x) == '''ToolWrapper(['a', 'b'], encoding='utf-8', cwd='d')'''
示例#8
0
def test_toolwrapper_no_stdbuf():
    with toolwrapper.ToolWrapper(["cat"], stdbuf=False) as cat:
        for line in sample_lines:
            cat.writeline(line)
            assert cat.readline() == line