1##########################################################################
2# Copyright (c) 2009, ETH Zurich.
3# All rights reserved.
4#
5# This file is distributed under the terms in the attached LICENSE file.
6# If you do not find this file, copies can be found by writing to:
7# ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8##########################################################################
9
10import re, socket, httplib, traceback, os, subprocess, select, datetime, glob, time
11import tests, debug, siteconfig
12from shutil import copyfile
13from common import TestCommon, TimeoutError, select_timeout
14from results import ResultsBase, PassFailResult, RowResults
15
16
17WEBSERVER_TEST_FILES=['index.html', 'barrelfish.gif', 'barrelfish_sosp09.pdf']
18WEBSERVER_TIMEOUT=5 # seconds
19TEST_LOG_NAME = 'testlog.txt'
20TRACE_LOG_NAME = 'tracelog.txt'
21
22HTTPERF_BASE_ARGS='--hog --close-with-reset --timeout 2 '
23HTTPERF_URI = '/index.html'
24
25# desired duration of an httperf test run (seconds)
26HTTPERF_DURATION = 20
27
28# sleep time between runs (seconds)
29HTTPERF_SLEEPTIME = 20
30
31# timeout for a complete run, including setup etc.
32HTTPERF_TIMEOUT = datetime.timedelta(seconds=(HTTPERF_DURATION + 30))
33
34# connection rates across all client machines
35HTTPERF_STARTRATE = 1000 # initial rate
36HTTPERF_RATEINCREMENT = 1000 # amount to increment by for each new run
37
38
39class NetCommon(TestCommon):
40
41    def setup(self, build, machine, testdir):
42        super(NetCommon, self).setup(build, machine, testdir)
43        self.testdir = testdir
44        self.ip = None
45        self.traceLogsON = False
46        self.traceLogs = []
47        self.build_path = build.build_dir
48
49    def get_modules(self, build, machine):
50        cardName = "e1000"
51        modules = super(NetCommon, self).get_modules(build, machine)
52        modules.add_module("e1000n", ["auto"])
53        modules.add_module("net_sockets_server", ["auto"])
54        nfsip = socket.gethostbyname(siteconfig.get('WEBSERVER_NFS_HOST'))
55        modules.add_module("webserver", ["core=%d" % machine.get_coreids()[0], #2
56				cardName, nfsip,
57                                siteconfig.get('WEBSERVER_NFS_TEST_PATH')])
58
59        return modules
60
61    def process_line(self, line):
62        m = re.match(r'Interface up! IP address (\d+\.\d+\.\d+\.\d+)', line)
63        if m:
64            self.ip = m.group(1)
65
66        if line.startswith('dump trac buffers: Start') :
67            self.traceLogsON = True
68        elif line.startswith('dump trac buffers: Stop') :
69            self.traceLogsON = False
70        elif  self.traceLogsON :
71            self.traceLogs.append(line);
72
73    def get_finish_string(self):
74        return 'dump trac buffers: Stop'
75
76@tests.add_test
77class NetdTraceTest(NetCommon):
78    '''tests netd and generates tracing output'''
79    name = "netdTrace"
80
81    def setup(self, *args):
82        super(NetdTraceTest, self).setup(*args)
83        self.testlog = None
84
85
86    def process_data(self, testdir, rawiter):
87
88        tracelogFilePath = os.path.join(self.testdir, TRACE_LOG_NAME)
89        tracelogFile = open(tracelogFilePath, 'w')
90
91        passed = None
92        traceLogsStarted = False
93        traceLogsFinished = False
94        #testlog = open(os.path.join(testdir, TEST_LOG_NAME), 'r')
95        for line in rawiter:
96            if line.startswith('dump trac buffers: Start') :
97                traceLogsStarted = True
98            elif line.startswith('dump trac buffers: Stop') :
99                traceLogsStarted = False
100            elif traceLogsStarted :
101                tracelogFile.write(line);
102                passed = True
103        #testlog.close()
104        tracelogFile.close()
105        print "Tracefile: " +  tracelogFilePath
106        JASONFILENAME = 'trace_defs.json'
107        # copy trace_defs.json files
108        jsonFilePath = os.path.join(self.build_path,
109                "x86_64", "trace_definitions", JASONFILENAME)
110        print "json file is at " + jsonFilePath
111        destFile =  os.path.join(self.testdir, JASONFILENAME)
112        copyfile(jsonFilePath, destFile)
113
114        return PassFailResult(passed == True)
115
116
117
118