Esempio n. 1
0
def start_test(server,
               server_ctl,
               host,
               clients,
               resultsdir,
               test_duration=60,
               sessions_rr="50 100 250 500",
               sessions="1 2 4",
               sizes_rr="64 256 512 1024 2048",
               sizes="64 256 512 1024 2048 4096",
               protocols="TCP_STREAM TCP_MAERTS TCP_RR TCP_CRR",
               netserver_port=None,
               params=None,
               server_cyg=None,
               test=None):
    """
    Start to test with different kind of configurations

    :param server: netperf server ip for data connection
    :param server_ctl: ip to control netperf server
    :param host: localhost ip
    :param clients: netperf clients' ip
    :param resultsdir: directory to restore the results
    :param test_duration: test duration
    :param sessions_rr: sessions number list for RR test
    :param sessions: sessions number list
    :param sizes_rr: request/response sizes (TCP_RR, UDP_RR)
    :param sizes: send size (TCP_STREAM, UDP_STREAM)
    :param protocols: test type
    :param netserver_port: netserver listen port
    :param params: Dictionary with the test parameters.
    :param server_cyg: shell session for cygwin in windows guest
    """
    if params is None:
        params = {}

    fd = open("%s/netperf-result.%s.RHS" % (resultsdir, time.time()), "w")
    netperf_base.record_env_version(test, params, host, server_ctl, fd,
                                    test_duration)

    record_list = [
        'size', 'sessions', 'throughput', 'trans.rate', 'CPU', 'thr_per_CPU',
        'rx_pkts', 'tx_pkts', 'rx_byts', 'tx_byts', 're_pkts', 'exits',
        'tpkt_per_exit'
    ]

    for i in range(int(params.get("queues", 0))):
        record_list.append('rx_intr_%s' % i)
    record_list.append('rx_intr_sum')
    for i in range(int(params.get("queues", 0))):
        record_list.append('tx_intr_%s' % i)
    record_list.append('tx_intr_sum')
    base = params.get("format_base", "12")
    fbase = params.get("format_fbase", "2")

    output = netperf_base.ssh_cmd(host, "mpstat 1 1 |grep CPU")
    mpstat_head = re.findall(r"CPU\s+.*", output)[0].split()
    mpstat_key = params.get("mpstat_key", "%idle")
    if mpstat_key in mpstat_head:
        mpstat_index = mpstat_head.index(mpstat_key) + 1
    else:
        mpstat_index = 0

    for protocol in protocols.split():
        error_context.context("Testing %s protocol" % protocol, logging.info)
        if protocol in ("TCP_RR", "TCP_CRR"):
            sessions_test = sessions_rr.split()
            sizes_test = sizes_rr.split()
            protocol_log = protocol
        else:
            sessions_test = sessions.split()
            sizes_test = sizes.split()
            if protocol == "TCP_STREAM":
                protocol_log = protocol + " (RX)"
            elif protocol == "TCP_MAERTS":
                protocol_log = protocol + " (TX)"
        fd.write("Category:" + protocol_log + "\n")

        record_header = True
        for i in sizes_test:
            for j in sessions_test:
                if protocol in ("TCP_RR", "TCP_CRR"):
                    nf_args = "-t %s -v 1 -- -r %s,%s" % (protocol, i, i)
                elif (protocol == "TCP_MAERTS"):
                    nf_args = "-C -c -t %s -- -m ,%s" % (protocol, i)
                else:
                    nf_args = "-C -c -t %s -- -m %s" % (protocol, i)

                ret = launch_client(j, server, server_ctl, host, clients,
                                    test_duration, nf_args, netserver_port,
                                    params, server_cyg, test)
                if ret:
                    thu = float(ret['thu'])
                    cpu = 100 - float(ret['mpstat'].split()[mpstat_index])
                    normal = thu / cpu
                    if ret.get('tx_pkt') and ret.get('exits'):
                        ret['tpkt_per_exit'] = float(ret['tx_pkts']) / float(
                            ret['exits'])

                    ret['size'] = int(i)
                    ret['sessions'] = int(j)
                    if protocol in ("TCP_RR", "TCP_CRR"):
                        ret['trans.rate'] = thu
                    else:
                        ret['throughput'] = thu
                    ret['CPU'] = cpu
                    ret['thr_per_CPU'] = normal
                    row, key_list = netperf_base.netperf_record(
                        ret,
                        record_list,
                        header=record_header,
                        base=base,
                        fbase=fbase)
                    if record_header:
                        record_header = False
                        category = row.split('\n')[0]

                    test.write_test_keyval({'category': category})
                    prefix = '%s--%s--%s' % (protocol, i, j)
                    for key in key_list:
                        test.write_test_keyval(
                            {'%s--%s' % (prefix, key): ret[key]})

                    logging.info(row)
                    fd.write(row + "\n")

                    fd.flush()

                    logging.debug("Remove temporary files")
                    process.system_output("rm -f /tmp/netperf.%s.nf" %
                                          ret['pid'],
                                          verbose=False,
                                          ignore_status=True,
                                          shell=True)
                    logging.info("Netperf thread completed successfully")
                else:
                    logging.debug(
                        "Not all netperf clients start to work, please enlarge"
                        " '%s' number or skip this tests", int(j))
                    continue
    fd.close()
Esempio n. 2
0
def start_test(server, server_ctl, host, client, resultsdir,
               test_duration="20",
               burst_time="1",
               numbers_per_burst="1000 1500 2000 2500 3000",
               params=None, test=None):
    """
    Start to test with different combination of burst_time and numbers_per_burst

    """
    if params is None:
        params = {}

    fd = open("%s/netperf-udp-perf.result.%s.RHS" % (
              resultsdir, time.time()), "w")
    netperf_base.record_env_version(test, params, host, server_ctl,
                                    fd, test_duration)

    error_context.context("Start Netserver on guest", logging.info)
    netperf_version = params.get("netperf_version", "2.6.0")
    client_path = "/tmp/netperf-%s/src/netperf" % netperf_version
    server_path = "/tmp/netperf-%s/src/netserver" % netperf_version
    logging.info("Netserver start cmd is '%s'" % server_path)
    netperf_base.ssh_cmd(server_ctl, "pidof netserver || %s" % server_path)

    base = params.get("format_base", "18")
    fbase = params.get("format_fbase", "2")
    pid = str(os.getpid())
    fname = "/tmp/netperf.%s.nf" % pid
    numa_enable = params.get("netperf_with_numa", "yes") == "yes"

    def thread_cmd(params, numa_enable, burst_time, numbers_per_burst,
                   client, server, test_duration, fname):
        option = "%s -t UDP_STREAM -w %s -b %s -H %s -l %s" % (
                 client_path, burst_time, numbers_per_burst,
                 server, test_duration)
        netperf_base.netperf_thread(params, numa_enable, client, option, fname)

    def thu_result(fname):
        with open(fname, 'rt') as filehandle:
            file = filehandle.readlines()[5:]
        results = []
        for thu in file:
            thu_tmp = thu.rstrip('\n').split(" ")
            thu_result = thu_tmp[-1]
            results.append(thu_result)
        return results

    record_header = True
    record_list = ['burst_time', 'numbers_per_burst', 'send_throughput',
                   'receive_throughput', 'drop_ratio']

    for i in burst_time.split():
        for j in numbers_per_burst.split():
            client_thread = threading.Thread(target=thread_cmd, args=(
                params, numa_enable, i, j, client, server, test_duration, fname))
            client_thread.start()
            time.sleep(test_duration+1)
            client_thread.join()

            ret = {}
            ret['burst_time'] = int(i)
            ret['numbers_per_burst'] = int(j)

            finished_result = netperf_base.ssh_cmd(client, "cat %s" % fname)
            f = open(fname, "w")
            f.write(finished_result)
            f.close()
            thu_all = thu_result(fname)
            ret['send_throughput'] = float(thu_all[0])
            ret['receive_throughput'] = float(thu_all[1])
            ret['drop_ratio'] = float(ret['receive_throughput'] /
                                      ret['send_throughput'])

            row, key_list = netperf_base.netperf_record(
                                           ret, record_list,
                                           header=record_header,
                                           base=base,
                                           fbase=fbase)
            if record_header:
                record_header = False
            prefix = '%s--%s' % (i, j)
            for key in key_list:
                test.write_test_keyval(
                    {'%s--%s' % (prefix, key): ret[key]})

            logging.info(row)
            fd.write(row + "\n")
            fd.flush()
            logging.debug("Remove temporary files")
            process.system_output("rm -f %s" % fname, verbose=False,
                                  ignore_status=True, shell=True)
            netperf_base.ssh_cmd(client, "rm -f %s" % fname)

    fd.close()