コード例 #1
0
def getLogFilesInDirectory(directory=None):

    testLogs.INFO(
        "FUNCTION : Getting Log files in directory : {}".format(directory))

    if directory == None:
        testLogs.ERROR("Kindly provide the directory to get log files")
        exit(1)
    try:
        files = os.listdir(directory)
    except Exception as E:
        testLogs.ERROR(
            "Could not get files from the directory : {}".format(directory))
        testLogs.ERROR(E)
        exit(1)
    filesDict = {}
    for file in files:
        if '_' not in file:
            continue
        angle = file.split('.')[0].split("_")[-1]
        try:
            angle = int(angle)
            filesDict[angle] = file
        except Exception as E:
            testLogs.ERROR(
                "This file is not is expected format : {}".format(file))
    #for ele in filesDict:
    #    print ("{} : {}".format(ele, filesDict[ele]))
    return filesDict
コード例 #2
0
def getAggregateValue():
    try:
        return data[-1].split(',')[aggregateColumn]
    except Exception as E:
        testLogs.ERROR("Could not get AGGREGATE value")
        testLogs.ERROR(E)
        exit(1)
コード例 #3
0
def writeXlFileColums(xlFile=None,
                      data=[1, 2, 3, 4, 5],
                      rowStart=wifiConfig.xlRowStart,
                      colStart=wifiConfig.xlColStart):

    if xlFile == None:
        testLogs.ERROR("Please provide XL file to parse")
        exit(1)

    testLogs.INFO(
        "FUNCTION : Writing colum data in XL file : {}".format(xlFile))

    fileExist = os.path.exists(xlFile)

    if fileExist != True:
        try:
            wb = openpyxl.Workbook()
            wb.create_sheet("sheet1", 0)
            wb.active = 0
        except Exception as E:
            testLogs.ERROR("Could not create XL file : {}".format(xlFile))
            testLogs.ERROR(E)
    else:
        wb = openpyxl.load_workbook(xlFile.strip(), data_only=True)

    currentSheet = wb.active

    rowEnd = rowStart + len(data)
    for index, row in enumerate(range(rowStart, rowEnd)):
        cellToModify = currentSheet.cell(row=row, column=colStart)
        cellToModify.value = data[index]

    wb.save(xlFile)
コード例 #4
0
def readXlFileRows(xlFile=None,
                   rowStart=wifiConfig.xlRowStart,
                   colStart=wifiConfig.xlColStart,
                   numberOfCols=wifiConfig.xlTotalCols):

    if xlFile == None:
        testLogs.ERROR("Please provide XL file to parse")
        exit(1)

    testLogs.INFO("FUNCTION : Reading row data in XL file : {}".format(xlFile))

    try:
        wb = openpyxl.load_workbook(xlFile.strip(), data_only=True)
        wb.active = 0
    except Exception as E:
        testLogs.ERROR("Could not open XL file : {}".format(xlFile))
        testLogs.ERROR(E)

    currentSheet = wb.active

    colEnd = colStart + numberOfCols
    # Read row values from XL file
    values = []
    for col in range(colStart, colEnd):
        testLogs.INFO("Row Col : {} {}".format(rowStart, col))
        cellToRead = currentSheet.cell(row=rowStart, column=col)
        testLogs.INFO(cellToRead.value)
        values.append(cellToRead.value)

    testLogs.INFO("Values of Row No {} is : {}".format(rowStart, values))
    return values
コード例 #5
0
def insertXlImage(xlFile=None, xlImage=None, row=1, col=1):

    if xlFile == None:
        testLogs.ERROR("Please provide XL file to parse")
        exit(1)

    if xlImage == None:
        testLogs.ERROR("Please provide Image file to insert")
        exit(1)

    testLogs.INFO("FUNCTION : Inser a Image {} file into XL file : {}".format(
        xlImage, xlFile))

    fileExist = os.path.exists(xlFile)

    if fileExist != True:
        try:
            wb = openpyxl.Workbook()
            wb.create_sheet("sheet1", 0)
            wb.active = 0
        except Exception as E:
            testLogs.ERROR("Could not create XL file : {}".format(xlFile))
            testLogs.ERROR(E)
    else:
        testLogs.INFO(xlFile)
        testLogs.INFO(xlFile.strip())
        wb = openpyxl.load_workbook(xlFile, data_only=True)

    ws = wb.active
    img = openpyxl.drawing.image.Image(xlImage)
    ws.add_image(img, '{}{}'.format(chr(col + 64), row))
    wb.save(xlFile)
コード例 #6
0
def getValues(row, col):
    try:
        return data[row].split(',')[col]
    except Exception as E:
        testLogs.ERROR("Could not get value from ROW : {}, COL : {}".format(
            row, col))
        testLogs.ERROR(E)
        exit(1)
コード例 #7
0
def createDirectory(directory=None):
    if directory == None:
        testLogs.ERROR("Please provide a directory name to create")
        exit(1)

    testLogs.INFO("Directory is about to create in : {}".format(directory))
    try:
        if os.path.exists(directory) == False:
            os.mkdir(directory)
            testLogs.SUCCESS("Directory created")
    except Exception as E:
        testLogs.ERROR(E)
        exit(1)
コード例 #8
0
def writeIntoTtSerialPort(data=None):
    if data == None:
        testLogs.ERROR(
            "Please provide data to write into Turn Table's serial port")
        exit(1)

    try:
        ser = serial.Serial(wifiConfig.ttPort, wifiConfig.ttBaudrate)
        ser.write(data)
        ser.close()
    except Exception as E:
        testLogs.ERROR("Could not write into Turn Table's serial port")
        testLogs.ERROR(E)
        exit(1)
コード例 #9
0
def readDataFromFile(file=None):
    if file == None:
        testLogs.ERROR("Kindly provide a file to read")
        exit(1)

    global data
    try:
        fd = open(file, 'r')
        data = fd.readlines()
        fd.close()
    except Exception as E:
        testLogs.ERROR("Could not open and read from file : {}".format(file))
        testLogs.ERROR(E)
        exit(1)
コード例 #10
0
def getTpInLogFiles(filesDict=None, logFolder=None):

    testLogs.INFO("FUNCTION : Reading Throughput from many files")

    if filesDict == None:
        testLogs.ERROR("Kindly provide data to parse...")
        exit(1)

    if logFolder != None:
        logDirectory = logFolder

    testLogs.INFO("----LOG FOLDER : {}".format(logDirectory))
    testLogs.INFO("----FILES : {}".format(filesDict))

    tpts = []
    # testLogs.INFO("File : {}".format(filesDict))
    for ang in range(10, 361, 10):
        file = logDirectory + filesDict[ang]
        fd = open(file, 'r')
        lines = fd.readlines()
        # prints.INFO("LINES : {}".format(lines))
        tp = int(float(lines[-1].split(' ')[-2]))
        fd.close()
        tpts.append(tp)

    return tpts
コード例 #11
0
def killLocalIperf():
    """
    To terminate all the iperf tasks running in backbone PC

    Arguments : None
    
    Returns : True, On successful termination of iperf tasks
              False, On failure of terminating iperf tasks
    """

    testLogs.INFO("FUNCTION : Terminating Local Iperf tasks")
    # Windows command to get all the running task
    ps = os.popen('wmic process get description').read()

    if wifiConfig.iperf in ps:
        # Windows command to kill all the running iperf task
        s = os.system("taskkill /f /im {}".format(wifiConfig.iperf))

        if s != 0:
            testLogs.ERROR("Could Not kill {}".format(wifiConfig.iperf))
            return False
        testLogs.SUCCESS("Terminated the process : {}".format(
            wifiConfig.iperf))
    else:
        testLogs.STATUS("Process {} Not found".format(wifiConfig.iperf))
    return True
コード例 #12
0
def generateIndividualTestReport():

    testLogs.INFO("FUNCTION : Generating individual test reports")

    if wifiConfig.test == 0 or wifiConfig.test == 1:
        log = "{}_{}_{}_{}".format(wifiConfig.streams[wifiConfig.stream],
                                   wifiConfig.bands[wifiConfig.band],
                                   wifiConfig.protocols[wifiConfig.protocol],
                                   wifiConfig.links[wifiConfig.link])
    elif wifiConfig.test == 2 or wifiConfig.test == 3:
        log = "{}_{}_{}".format(wifiConfig.streams[wifiConfig.stream],
                                wifiConfig.protocols[wifiConfig.protocol],
                                wifiConfig.links[wifiConfig.link])

    #### Generating report files from throughput files
    files = logParser.getLogFilesInDirectory(wifiConfig.iperfLogDirectory)
    throughputs = logParser.getTpInLogFiles(files,
                                            wifiConfig.iperfLogDirectory)
    logFile = wifiConfig.iperfLogDirectory + "throughputs.txt"
    testLogs.INFO("Log file is : {}".format(logFile))
    try:
        fd = open(logFile, 'w+')
        fd.write(' '.join([str(tp) for tp in throughputs]))
        fd.close()
    except Exception as E:
        testLogs.ERROR("Could not write throughputs in throughputs.txt file")
        testLogs.ERROR(E)
        exit(1)

    testLogs.INFO("Throughputs : {}".format(throughputs))

    graphName = wifiConfig.iperfLogDirectory + log
    graphs.createSingleRadarGraph(throughputs, graphName)
    throughputs = throughputs[:-1]
    graphs.createSingleBarGraph(throughputs, graphName)

    xlFileName = graphName + '.xlsx'
    createXlFile(xlFileName, throughputs)
    xlParser.insertXlImage(xlFileName, graphName + '_RADAR.png', 3, 5)
    xlParser.insertXlImage(xlFileName, graphName + '_BAR.png', 3, 15)
    return 0
コード例 #13
0
def runLocalIperfClient():
    """
    Running iperf client in backbone PC which is connected with AP

    Arguments : None
    
    Returns : True, On successful start of iperf client
              False, On failure in starting iperf client
    """

    testLogs.INFO("FUNCTION : Running Local Iperf Client")

    command = "{} -c {} -i 1 -f m -w {} -p {} -t {} ".format(
        wifiConfig.iperf, wifiConfig.remoteIP, wifiConfig.windowSize,
        wifiConfig.listeningPort, wifiConfig.executionTime)

    if wifiConfig.stream == 1:
        command += "-P {}".format(wifiConfig.numberOfStream)

    testLogs.INFO(command)
    try:
        p = subprocess.Popen(command.split(),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, err = p.communicate()
        out = str(out)
        err = str(err)

        if err == "b''":
            return out

        testLogs.ERROR(err)
        return False
    except Exception as E:
        testLogs.ERROR("Could not start the {} client...".format(
            wifiConfig.iperf))
        testLogs.ERROR(E)
        return False
コード例 #14
0
def runLocalIperfServer():
    """
    Running iperf server in backbone PC which is connected with AP

    Arguments : None
    
    Returns : True, On successful start of iperf server
              False, On failure in starting iperf server
    """

    testLogs.INFO("FUNCTION : Running Local Iperf Server")
    command = wifiConfig.iperfServer
    testLogs.INFO(command)
    try:
        p = subprocess.Popen(command.split(),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        return True
    except Exception as E:
        testLogs.ERROR("Could not start the {} server...".format(
            wifiConfig.iperf))
        testLogs.ERROR(E)
        return False
コード例 #15
0
def getTpInLogFile(file=None):

    testLogs.INFO(
        "FUNCTION : Reading Throughput in from single file : {}".format(file))

    if file == None:
        testLogs.ERROR("Kindly provide file to parse...")
        exit(1)

    tpts = []
    try:
        fd = open(file, 'r')
        lines = fd.readlines()
        for line in lines:
            if "Mbits/sec" in line:
                # print (line)
                tp = int(float(line.split(' ')[-2]))
                fd.close()
                tpts.append(tp)
    except Exception as E:
        testLogs.ERROR("Could not open given log file to parse")
        exit(1)

    return tpts
コード例 #16
0
def runTest():

    testLogs.INFO("FUNCTION : Run the AVM test")

    if wifiConfig.test == 0 or wifiConfig.test == 1:
        log = "{}_{}_{}_{}".format(wifiConfig.streams[wifiConfig.stream],
                                   wifiConfig.bands[wifiConfig.band],
                                   wifiConfig.protocols[wifiConfig.protocol],
                                   wifiConfig.links[wifiConfig.link])
    elif wifiConfig.test == 2 or wifiConfig.test == 3:
        log = "{}_{}_{}".format(wifiConfig.streams[wifiConfig.stream],
                                wifiConfig.protocols[wifiConfig.protocol],
                                wifiConfig.links[wifiConfig.link])

    if True:
        #### Terminate the iperf process which is running already in local PC
        status = iperf.killLocalIperf()
        testLogs.STATUS("Kill iperf in local PC status is : {}".format(status))

        #### Terminate the iperf process which is running already in remote Station
        status = iperf.killRemoteIperf(wifiConfig.remoteIP,
                                       wifiConfig.remoteUsername,
                                       wifiConfig.remotePassword)
        testLogs.STATUS(
            "Kill iperf in remote Station status is : {}".format(status))

        #### Start the iperf server
        if iperf.runIperfServer() == False:
            testLogs.ERROR("Could not start iperf server")
            exit(1)

        #### Calculating number of times to rotate the Turn table based on the degree per rotation
        steps = int(360 / wifiConfig.ttRotateAngle)

        #### Executing a loop for the given number of steps
        for step in range(1, steps + 1):
            testLogs.INFO("=============== RUNNING TEST IS : {}".format(log))
            #### Deriving log file name from the parameters
            testLogs.INFO("Rotate to angle : {}".format(
                step * wifiConfig.ttRotateAngle))
            iperfLogFile = wifiConfig.iperfLogDirectory + log + '_' + str(
                step * wifiConfig.ttRotateAngle) + ".txt"
            testLogs.INFO("Iperf Log File : {}".format(iperfLogFile))

            #### Rotate turn table to decided angle and wait for turn table to setteld in the position
            if turnTable.rotateTurnTable(wifiConfig.ttRotateAngle) == False:
                exit(1)
            time.sleep((wifiConfig.ttTimePerStep * wifiConfig.ttStepsPerAngle *
                        wifiConfig.ttRotateAngle) + .1)

            #### Run iperf client in local or remote station based on the command line argument
            status = iperf.runIperfClient()
            testLogs.STATUS(status)

            #### Write iperf client output into log file
            if status != False:
                try:
                    fd = open(iperfLogFile, 'w+')
                    fd.close()
                    fd = open(iperfLogFile, 'a')
                    fd.write(status)
                    fd.close()
                except Exception as E:
                    testLogs.ERROR(E)
                    exit(1)
            else:
                testLogs.ERROR("Could Not get output from iperf client")
                exit(1)