Exemple #1
0
def runCMDtoCOMPort(ser, runcmds):
    global newCon
    global logFileP
    global testResult

    if (ser == None):
        print("Please check console port if open")
        return None
    else:
        #print('Enter console commands after >>\r\nEnter "quit" to leave program.')
        logFileP = foxfile.isLogfileOpen()

        #check bootmode terminator
        terminator = getTerminator()

        try:
            for i in range(len(runcmds)):
                ss = runcmds[i]
                cmdstr = ""

                for j in range(len(ss)):
                    cmdstr = cmdstr + ss[j] + " "

                ser.flushInput()
                ser.flushOutput()
                sys.stdin.flush()
                sys.stdout.flush()
                #print(cmdstr)

                if cmdstr == "" or cmdstr == " ":
                    cmdstr = '\r\n'
                else:
                    cmdstr = cmdstr + '\n'

                ser.write(cmdstr.encode())
                out = ""
                ser.timeout = 10

                data = ser.read_until(terminator.encode())
                out += data.decode()
                print(out[len(cmdstr):], end="")

                if (out.find("FAIL") > -1) or (out.find("FAILED") > -1):
                    testResult.append([cmdstr[:-2], "FAIL"])
                elif (out.find("PASS") > -1) or (out.find("PASSED") > -1):
                    testResult.append([cmdstr[:-2], "PASS"])
                else:
                    testResult.append([cmdstr[:-2], "    "])

                #Save log file
                if (logFileP != None):
                    foxfile.writelogtofile(">>" + out)

                if (newCon != None):
                    toConsole(newCon, out)

        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print("(runCMDtoCOMPort) Error to communicating serial port ")
Exemple #2
0
def command(con, flag, str_=""):
    global newCon
    global logFileP

    try:
        logFileP = foxfile.isLogfileOpen()

        con.write(str_.encode() + b"\n")
        data = con.read_until(flag.encode(), timeout=10)

        #if(log_lvl == 1):
        print(data.decode(errors='ignore')[len(str_):], end="")

        #Display output message to another console
        if (newCon != None):
            toConsole(newCon, data.decode(errors='ignore'))

        #save log to file
        if (logFileP != None):
            foxfile.writelogtofile(data.decode(errors='ignore'))

    except KeyboardInterrupt:
        print("Press Keyboard Interrupt (CTRL+C)")
    except:
        print("function command error")
    return data
Exemple #3
0
def console_cmd(con, flag, str_=""):
    global newCon
    global logFileP
    global testResult

    try:
        logFileP = foxfile.isLogfileOpen()

        if (con == None):
            print("Please check console port if open")
            return None

        #print(str_)
        con.write(str_.encode() + b"\n")
        data = con.read_until(flag.encode(), timeout=60)
        print(data.decode(errors='ignore'), end="")

        out = ""
        out = out + data.decode()

        if out.find("FAIL") > -1:
            testResult.append([str_, "FAIL"])
        elif out.find("PASS") > -1:
            testResult.append([str_, "PASS"])
        else:
            testResult.append([str_, "    "])

        #save log to file
        if (logFileP != None):
            foxfile.writelogtofile(data.decode(errors='ignore'))

        #return data
        if (newCon != None):
            toConsole(newCon, data.decode(errors='ignore'))

    except KeyboardInterrupt:
        print("Press Keyboard Interrupt (CTRL+C)")
    except:
        print("console_cmd error")
Exemple #4
0
def readMoreData(ser, match, out):
    global newCon
    global logFileP

    try:
        if ser == None or match == None:
            print("read More data is None")
            return True
        elif len(out) <= 0 or out == " ":
            return True
        else:
            i = out.find(match)

            if i > -1:
                ser.write("\x20".encode())
                out = ""
                time.sleep(2)

                while ser.inWaiting() > 0:
                    data = ser.read(1)
                    out = out + data.decode()

                print("Console>>" + out)

                #Save log File
                if (logFileP != None):
                    foxfile.writelogtofile("Console>>" + out)

                if (newCon != None):
                    toConsole(newCon, out)

                readMoreData(ser, match, out)
            else:
                out = ""
                return True

    except:
        print("Read more console output data error")
Exemple #5
0
def runCMDtoLinuxShell(ser, runcmds):
    global diagprompt
    global linuxshell
    global logFileP

    firstime = True

    if (ser == None):
        print("Please check com port if open")
        return None
    else:

        logFileP = foxfile.isLogfileOpen()

        try:

            if (firstime == True):
                firstime = False
                ss = "linux_shell" + '\n'
                ser.timeout = 3
                ser.write(ss.encode())
                out = ""
                out = ser.read_until(linuxshell.encode())
                print(out.decode(), end="")

            for i in range(len(runcmds)):
                ss = runcmds[i]
                ss = ss + '\n'

                ser.flushInput()
                ser.flushOutput()
                sys.stdin.flush()
                sys.stdout.flush()

                ser.write(ss.encode())
                out = ""
                ser.timeout = 30

                if (ss[0:4] == "exit"):
                    out = ser.read_until(diagprompt.encode())
                    print(out.decode(), end="")
                    break
                else:
                    out = ser.read_until(linuxshell.encode())
                    print(out.decode(), end="")

                #Save log file
                if (logFileP != None) and (out.decode() != ""):
                    foxfile.writelogtofile(linuxshell + out.decode())

            if (ss[0:4] == "exit"):
                print("Got linux shell command is exit.")
                #Save log file
                if (logFileP != None) and (out.decode() != ""):
                    foxfile.writelogtofile(linuxshell + out.decode())
            else:
                #read if lastest cmd succeed
                if (len(out) > 0):
                    ss = "exit" + "\n"
                    ser.timeout = 5
                    ser.write(ss.encode())
                    out = ""
                    out = ser.read_until(diagprompt.encode())
                    print(out.decode(), end="")

                else:
                    ss = "\n"
                    ser.timeout = 2
                    ser.write(ss.encode())
                    out = ""
                    out = ser.read_until(linuxshell.encode())
                    print(out.decode(), end="")

        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print("error communicating serial port (runCMDtoLinuxShell) ")
Exemple #6
0
def runEmphasisCMDtoBCMShell(ser, runcmds):
    global diagprompt
    global bcmshell
    global logFileP

    firstime = True

    if (ser == None):
        print("Please check com port if open")
        return None
    else:

        logFileP = foxfile.isLogfileOpen()

        try:

            ser.flushInput()
            ser.flushOutput()
            sys.stdin.flush()
            sys.stdout.flush()

            if (firstime == True):
                firstime = False
                ss = "bcm_shell" + '\n'
                ser.timeout = 30
                ser.write(ss.encode())
                out = ""
                out = ser.read_until(bcmshell.encode())
                print(out.decode(), end="")

            for i in range(len(runcmds)):
                ss = runcmds[i]
                ss = ss + '\n'
                print(ss)

                ser.flushInput()
                ser.flushOutput()
                sys.stdin.flush()
                sys.stdout.flush()

                ser.write(ss.encode())
                out = ""
                ser.timeout = 60

                if (ss[0:4] == "exit"):
                    out = ser.read_until(diagprompt.encode())
                    print(out.decode()[len(ss):], end="")
                    break
                else:
                    out = ser.read_until(bcmshell.encode())
                    print(out.decode()[len(ss):], end="")

                #Save log file
                if (logFileP != None) and (out.decode() != ""):
                    foxfile.writelogtofile(bcmshell + out.decode())

            time.sleep(1)

            #If bcmshell cmd is "exit", then return to DIAG> already
            if (ss[0:4] == "exit"):
                print("Got bcmshell command is exit. ")
                #Save log file
                if (logFileP != None) and (out.decode() != ""):
                    foxfile.writelogtofile(bcmshell + out.decode())
            else:
                #always exit bcmshell
                ss = "exit" + "\n"
                ser.timeout = 10
                ser.write(ss.encode())
                out = ""
                out = ser.read_until(diagprompt.encode())
                print(out.decode(), end="")

                #Save log file
                if (logFileP != None) and (out.decode() != ""):
                    foxfile.writelogtofile(out.decode())

        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print(
                "error communicating serial port (runEmphasisCMDtoBCMShell) ")
Exemple #7
0
def runCMDtoCOMPortPrompt(ser, runcmds, prompt):
    global newCon
    global logFileP
    global testResult
    global iosprompt

    bcmshellcmd = False
    linuxshellcmd = False

    if (ser == None):
        print("Please check console port if open")
        return None
    else:

        logFileP = foxfile.isLogfileOpen()

        try:

            ser.flushInput()
            ser.flushOutput()
            sys.stdin.flush()
            sys.stdout.flush()

            if prompt == iosprompt:
                ss = '\r\n'
                ser.write(ss.encode())
                out = ""

                ser.timeout = 5
                out = ser.read_until(iosprompt.encode())

                if out.decode() == "":
                    ss = '\r\n'
                    ser.write(ss.encode())
                    out = ""

                    ser.timeout = 5
                    out = ser.read_until(iosen.encode())
                    print(out.decode(), end="")
                    ser.write("en\n".encode())
                    out = ser.read_until(iosprompt.encode())
                    print(out.decode(), end="")
                else:
                    print(out.decode(), end="")

            for i in range(len(runcmds)):
                ss = runcmds[i]
                cmdstr = ""

                linuxshellcmd = bcmshellcmd = False

                for j in range(len(ss)):
                    if j == 0:
                        if ss[0] == bcmshell:
                            bcmshellcmd = True
                            continue
                        elif ss[0][-1:] == linuxshell:
                            linuxshellcmd = True
                            continue
                        else:
                            cmdstr = cmdstr + ss[j] + " "
                    else:
                        cmdstr = cmdstr + ss[j] + " "

                #Check if testcmd is a bcmshell or linuxshell command
                #call sub function
                if bcmshellcmd == True:
                    #print(cmdstr)
                    runEmphasisCMDtoBCMShell(ser, [cmdstr])
                    testResult.append([cmdstr[:-2], "   "])
                    continue
                elif linuxshellcmd == True:
                    #print(cmdstr)
                    runCMDtoLinuxShell(ser, [cmdstr])
                    testResult.append([cmdstr[:-2], "    "])
                    continue

                print(prompt, cmdstr)

                ser.flushInput()
                ser.flushOutput()
                sys.stdin.flush()
                sys.stdout.flush()

                if cmdstr == "" or cmdstr == " ":
                    cmdstr = '\r\n'
                else:
                    cmdstr = cmdstr + '\n'

                ser.write(cmdstr.encode())
                out = ""

                ser.timeout = 60

                data = ser.read_until(prompt.encode())
                out += data.decode()

                print(out[len(cmdstr):-(len(prompt))])

                if out.find("FAIL") > -1:
                    testResult.append([cmdstr[:-2], "FAIL"])
                elif out.find("PASS") > -1:
                    testResult.append([cmdstr[:-2], "PASS"])
                else:
                    testResult.append([cmdstr[:-2], "    "])

                #Save log file
                if (logFileP != None):
                    foxfile.writelogtofile(out)

                if (newCon != None):
                    toConsole(newCon, out)

            #print("Closed runCMDtoCOMPort")
        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print("error communicating serial port ")
Exemple #8
0
def runTestCmdToCOMPort(ser, testcmds, terminator, wait_time, option):
    global logFileP
    global testResult
    ret = None

    if (ser == None):
        print("Please check com port if open")
        return None
    else:

        logFileP = foxfile.isLogfileOpen()

        try:
            sys.stdin.flush()
            sys.stdout.flush()
            ser.flushInput()
            ser.flushOutput()

            for i in range(len(testcmds)):
                testcmd = testcmds[i]

                if (len(testcmd) == 0):
                    testcmd = "\n"
                    return ret
                else:
                    testcmd = testcmd + '\n'

                print(testcmd)
                ser.write(testcmd.encode())
                out = ""
                ser.timeout = wait_time

                data = ser.read_until(terminator.encode())
                out += data.decode()
                print(out[len(testcmd):], end="")

                if (out == ""):
                    print("runTestCmdToCOMPort is timeout!")
                    ret = "Timeout"

                if (logFileP != None) and (len(out) > 0):
                    foxfile.writelogtofile(terminator + out)

                tempidx = -1

                if testcmd.find("linespeed") > -1:
                    tempidx = out.find("100 %")

                # Add temperature result
                if (tempidx > -1):
                    #print(out[tempidx+10:tempidx+14])

                    if (out.find("FAIL") > -1) or (out.find("FAILED") > -1):
                        testResult.append([
                            testcmd[:-1],
                            str(option), out[tempidx + 10:tempidx + 15], "FAIL"
                        ])
                    elif (out.find("PASS") > -1) or (out.find("PASSED") > -1):
                        testResult.append([
                            testcmd[:-1],
                            str(option), out[tempidx + 10:tempidx + 15], "PASS"
                        ])
                    else:
                        testResult.append(
                            [testcmd[:-1],
                             str(option), "     ", "      "])
                else:
                    if (out.find("FAIL") > -1) or (out.find("FAILED") > -1):
                        testResult.append([testcmd[:-1], str(option), "FAIL"])
                    elif (out.find("PASS") > -1) or (out.find("PASSED") > -1):
                        testResult.append([testcmd[:-1], str(option), "PASS"])
                    else:
                        testResult.append(
                            [testcmd[:-1], str(option), "      "])

        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print("error communicating serial port (runTestCmdToCOMPort)")

        return ret
Exemple #9
0
def consoleToCOMPort(ser):
    global matchMore
    global newCon
    global logFileP
    global timeout
    global diagprompt
    global iosen
    global iosprompt
    global rommonprompt
    global bcmshell

    firsttime = False
    #check bootmode terminator
    terminator = getTerminator()

    if (ser == None):
        print("Please check console port if open")
        return None
    else:
        print('Enter any commands after {0}\r\nEnter "quit" to leave program.'.
              format(terminator))

        logFileP = foxfile.isLogfileOpen()

        try:

            while True:
                ser.flushInput()
                ser.flushOutput()
                sys.stdin.flush()
                sys.stdout.flush()

                if (firsttime == False):
                    s = input(terminator)
                    firsttime = True
                else:
                    s = input("")

                if s == "quit":
                    print("quit console program")
                    break
                else:

                    if s == "" or s == " ":
                        s = '\n'
                    else:
                        s = s + '\n'

                    ser.write(s.encode())
                    out = ""
                    ser.timeout = 10

                    data = ser.read_until(terminator.encode())
                    out += data.decode()
                    print(out[len(s):], end="")

                    #Save log file
                    if (logFileP != None):
                        foxfile.writelogtofile(">>" + out)

                    if (newCon != None):
                        toConsole(newCon, out)

                    #read more data if match "--More--"
                    #readMoreData(ser, matchMore, out)

        except KeyboardInterrupt:
            print("Press Keyboard Interrupt (CTRL+C)")
        except:
            print("error communicating serial port ")
Exemple #10
0
def showTestResult(showstr, heads, verbose):
    global testResult
    global logFileP

    total_pass = 0
    total_fail = 0
    out = "\n"

    logFileP = foxfile.isLogfileOpen()

    #print("\n*********************************************************")
    #out += "\n*********************************************************\n"

    if (showstr == ""):
        print("\nShow autotest run all result ")
        out += "Show autotest run all result\n"
    else:
        print("\n" + showstr)
        out += showstr + "\n"

    resban = "===================="
    s = 0

    for res in testResult:
        s = len(res)
        resban = s * resban
        out += resban + "\n"
        break

    print(resban)

    #Show result tilte
    if (heads != "") and len(heads) > 0:
        for i, head in enumerate(heads):
            if i == 0:
                print("{0:35}".format(head), end="")
                out += "{0:35}".format(head)
            elif i == 1:
                print("{0:30}".format(head), end="")
                out += "{0:30}".format(head)
            else:
                print("{0:10}".format(head), end="")
                out += "{0:10}".format(head)

    subban = "--------------------"
    subban *= s

    print("\n" + subban)
    out += "\n" + subban + "\n"

    for res in testResult:

        s = len(res)
        if res[s - 1] == "PASS":
            total_pass += 1
        elif res[s - 1] == "FAIL":
            total_fail += 1
        else:
            pass
        #else:se
        #    continue

        for i in range(len(res)):
            if i == 0:
                if len(res[i]) > 35:
                    print("{0:55}".format(res[i]), end="")
                    out += "{0:55}".format(res[i])
                else:
                    print("{0:35}".format(res[i]), end="")
                    out += "{0:35}".format(res[i])
            elif i == 1:
                print("{0:30}".format(res[i]), end="")
                out += "{0:30}".format(res[i])
            else:
                print("{0:10}".format(res[i]), end="")
                out += "{0:10}".format(res[i])

        print("")
        out += "\n"

    print(resban)
    out += "\n" + resban + "\n"

    print("Total of PASSED {0:4}, FAILED {1:4}".format(total_pass, total_fail))
    out += "Total of PASSED {0:4}, FAILED {1:4}\n".format(
        total_pass, total_fail)
    #print("*********************************************************")
    #out += "*********************************************************\n"
    #Save log file
    if (logFileP != None):
        foxfile.writelogtofile(out)

    if (verbose == "en"):
        print("Debug test result for detail")
        for res in testResult:
            print(res)

    testResult = []