test01.py 4.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#******************************************************************************

#  Eurecom OpenAirInterface
#  Copyright(c) 1999 - 2013 Eurecom

#  This program is free software; you can redistribute it and/or modify it
#  under the terms and conditions of the GNU General Public License,
#  version 2, as published by the Free Software Foundation.

#  This program is distributed in the hope it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.

#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

#  The full GNU General Public License is included in this distribution in
#  the file called "COPYING".

#  Contact Information
#  Openair Admin: openair_admin@eurecom.fr
#  Openair Tech : openair_tech@eurecom.fr
#  Forums       : http://forums.eurecom.fsr/openairinterface
#  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France

#*****************************************************************************

# \file test01.py
# \brief test 01 for OAI
# \author Navid Nikaein
# \date 2013
# \version 0.1
# @ingroup _test


import sys
import wave
import os
import time
import datetime
import getpass
44
import math #from time import clock 
45 46 47 48

import log
import case01
import case02
49
import case03
50 51
import case04
import case05
52

53 54 55
from  openair import *

debug = 0
Navid Nikaein's avatar
Navid Nikaein committed
56
prompt2 = '$'
57 58
pw =''
i = 0
59 60
dlsim=0

61 62 63 64 65 66
for arg in sys.argv:
    if arg == '-d':
        debug = 1
    elif arg == '-dd':
        debug = 2
    elif arg == '-p' :
Navid Nikaein's avatar
Navid Nikaein committed
67
        prompt2 = sys.argv[i+1]
68 69
    elif arg == '-w' :
        pw = sys.argv[i+1]
70 71
    elif arg == '-P' :
        dlsim = 1
72 73 74 75 76 77 78 79
    elif arg == '-h' :
        print "-d:  low debug level"
        print "-dd: high debug level"
        print "-p:  set the prompt"
        print "-w:  set the password for ssh to localhost"
        sys.exit()
    i= i + 1     

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
try:  
   os.environ["OPENAIR1_DIR"]
except KeyError: 
   print "Please set the environment variable OPENAIR1_DIR in the .bashrc"
   sys.exit(1)

try:  
   os.environ["OPENAIR2_DIR"]
except KeyError: 
   print "Please set the environment variable OPENAIR2_DIR in the .bashrc"
   sys.exit(1)

try:  
   os.environ["OPENAIR_TARGETS"]
except KeyError: 
   print "Please set the environment variable OPENAIR_TARGETS in the .bashrc"
   sys.exit(1)

98
# get the oai object
99
host = os.uname()[1]
100
oai = openair('localdomain','localhost')
101
#start_time = time.time()  # datetime.datetime.now()
102 103
try: 
    user = getpass.getuser()
104 105
    print '\n******* Note that the user <'+user+'> should be a sudoer *******\n'
    print '******* Connecting to the localhost to perform the test *******\n'
106
   
107 108 109 110 111 112 113
   
    if not pw :
        print "username: " + user 
        pw = getpass.getpass() 
    else :
        print "username: " + user 
        #print "password: " + pw 
Navid Nikaein's avatar
Navid Nikaein committed
114
    
115 116 117 118 119
    try:
        prompt = os.getenv("PS1")[-2]
    except : 
        #prompt = input('set your shell prompt: ') 
        prompt = '$'
120
    print "your prompt is:   " + prompt
121 122 123 124 125 126 127 128 129 130 131
    
    oai.connect(user,pw,prompt)
    #oai.get_shell()
except :
    print 'Fail to connect to the local host'
    sys.exit(1)


test = 'test01'
ctime=datetime.datetime.utcnow().strftime("%Y-%m-%d.%Hh%M")
logfile = user+'.'+test+'.'+ctime+'.txt'  
132 133 134 135 136
logdir = os.getcwd() + '/pre-ci-logs-'+host;
oai.create_dir(logdir,debug)    
print 'log dir: ' + logdir
#oai.send_nowait('mkdir -p -m 755' + logdir + ';')

137
#print '=================start the ' + test + ' at ' + ctime + '=================\n'
138
#print 'Results will be reported in log file : ' + logfile
139 140 141 142
log.writefile(logfile,'====================start'+test+' at ' + ctime + '=======================\n')
log.set_debug_level(debug)

oai.kill(user, pw)   
143 144
oai.rm_driver(oai,user,pw)

145
# start te test cases 
Navid Nikaein's avatar
 
Navid Nikaein committed
146 147
rv=case01.execute(oai, user, pw, host,logfile,logdir,debug)
if rv != 0 :
Navid Nikaein's avatar
 
Navid Nikaein committed
148 149 150 151 152 153
    case02.execute(oai, user, pw, host, logfile,logdir,debug)
    case03.execute(oai, user, pw, host, logfile,logdir,debug)
    case04.execute(oai, user, pw, host, logfile,logdir,debug)
    #case05.execute(oai, user, pw, host, logfile,logdir,debug)
else :
    print 'Compilation error: skip test case 02,03,04,05'
154 155

oai.kill(user, pw) 
156
oai.rm_driver(oai,user,pw)
157 158 159 160 161 162 163 164 165 166

# perform the stats
log.statistics(logfile)


oai.disconnect()

ctime=datetime.datetime.utcnow().strftime("%Y-%m-%d_%Hh%M")
log.writefile(logfile,'====================end the '+ test + ' at ' + ctime +'====================')
print 'Test results can be found in : ' + logfile 
167 168
#print '\nThis test took %f minutes\n' % math.ceil((time.time() - start_time)/60) 

169
#print '\n=====================end the '+ test + ' at ' + ctime + '====================='