Example #1
0
def CommonSetup():
    if not v.failure_detected:
        try:
            tch_auto.log_h1('Load Testbed file')
            args = get_args()
            v.topo = tch_auto.load_topology(args.topo)
        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

    tch_auto.log_info('Connect to devices')
    if not v.failure_detected:
        try:
            v.lnx1 = connect(v.topo.lnx1)
            v.lnx2 = connect(v.topo.lnx2)
            v.linphone1 = connect(v.topo.lnx1)
            v.linphone2 = connect(v.topo.lnx2)
            v.lnxs = [v.lnx1, v.lnx2]
            v.linphones = [v.linphone1, v.linphone2]
            v.linphone1.IP = v.topo.lnx1.interface.onboardEthernet.ip
            v.linphone2.IP = v.topo.lnx2.interface.onboardEthernet.ip

            for linphone in v.linphones:
                linphone.prompt = linphone.conn.get_prompt()
                #changing the prompt
                linphone.conn.set_prompt(re.compile(r'.*[$]|linphonec>'))
        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))
Example #2
0
def copy_wave_file(v):
    ExeServer = v.topo.ExeServer
    os.system('rm -f received.wav')
    cmd = "sshpass -p %s scp -o StrictHostKeyChecking=no received.wav %s@%s:~/received.wav"\
    %(ExeServer.password, ExeServer.username, ExeServer.interface.controlBridge.ip )
    v.lnx2.execute(cmd)
    if not os.path.isfile('received.wav'):
        v.failure_detected = True
        tch_auto.log_error('File transferred failed from %s' %
                           v.linphone1.Hostname)
    else:
        tch_auto.log_info('File transferred successfully from %s' %
                          v.linphone1.Hostname)
    return
Example #3
0
    def setUp(self):
        tch_auto.log_h1('Common Setup')
        try:
            log_h1('Load Testbed file')
            args = get_args()
            v.topo = load_topology(args.topo)

        except:
            v.failure_detected = True
            tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_info('Connect to devices')
        if not v.failure_detected:
            try:
                v.lnx1 = connect(v.topo.lnx1)
                v.lnx2 = connect(v.topo.lnx2)
                v.linphone1 = connect(v.topo.lnx1)
                v.linphone2 = connect(v.topo.lnx2)
                v.lnxs = [v.lnx1, v.lnx2]
                v.linphones = [v.linphone1, v.linphone2]
                v.linphone1.IP = v.topo.lnx1.interface.pciEthernet1.ip
                v.linphone2.IP = v.topo.lnx2.interface.pciEthernet2.ip
            except:
                v.failure_detected = True
                tch_auto.log_error(traceback.format_exc(6))

        tch_auto.log_h1('Check validations in two linux machines')

        if not v.failure_detected:
            voip_test.create_null_sinks(v)
        if not v.failure_detected:
            cmds = []
            cmds.append('pactl load-module module-null-sink sink_name=fakemic')
            cmds.append(
                'pactl load-module module-null-sink sink_name=fakespeaker')

            for cmd in cmds:
                for lnx in v.linphones:
                    lnx.execute(cmd)

            validation = munch.munchify({'present': [], 'absent': []})
            cmd = 'pactl list short sources'
            validation.present.append(r'fakemic.monitor')
            validation.present.append(r'fakespeaker.monitor')
            if not v.lnx1.cmd_check(cmd, validation) or not v.lnx2.cmd_check(
                    cmd, validation):
                v.failure_detected = True

        self.assertEqual(v.failure_detected, False)
Example #4
0
 def tearDown(self):
     tch_auto.log_h1('Common CleanUP - Start')
     if v.failure_detected:
         voip_test.end_calls(v)
     for lnx in v.linphones:
         lnx.execute('killall pulseaudio')
     try:
         tch_auto.log_info('Clear all ssh console sessions')
         for linphone in v.linphones:
             linphone.close()
         for lnx in v.lnxs:
             lnx.close()
     except:
         tch_auto.log_error(traceback.format_exc(6))
     tch_auto.report(v)
     tch_auto.log_h1('Voip_test TestCase End')
Example #5
0
    def testTestRun(self):
        v.failure_detected = False
        tch_auto.log_h1('TestRun - Start')
        v.calls = False
        if not v.failure_detected:
            voip_test.start_linphones(v)

        if not v.failure_detected:
            duration = v.lnx1.execute('sox --i -D %s' % v.topo.lnx1.wavFile)
            voip_test.call_play_recored_wav(v)

        if not v.failure_detected:
            v.duration = float(duration) + time.time() + 60
            cmd = 'ls -l received.wav'
            buffer = []
            while v.duration > time.time():
                out = v.lnx2.execute(cmd)
                match = re.search(r'[-rwx]*\s+\w+\s+\w+\s+(\d+).*received.wav',
                                  out)
                if match:
                    buffer.append(match.group(1))
                if len(buffer) >= 3:
                    if len(set(buffer)) == 1:
                        tch_auto.log_info('Playback and recording completed')
                        v.failure_detected = False
                        voip_test.end_calls(v)
                        break
                    else:
                        buffer.pop(0)
                        tch_auto.log_info('Playback and recording in progress')

                else:
                    v.failure_detected = True
                time.sleep(10)

        if v.failure_detected:
            tch_auto.log_error(
                'Playback and recording was not completed in expected time')
            voip_test.end_calls(v)
        else:
            voip_test.validate_wav_files(v)
Example #6
0
def validate_wav_files(v):
    copy_wave_file(v)
    if not v.failure_detected:
        v.wav1 = thinkdsp.read_wave(v.topo.lnx2.wavFile)
        v.wav1.normalize()
        temp = thinkdsp.read_wave('received.wav')
        temp1 = temp.segment(start=temp.duration - v.wav1.duration,
                             duration=v.wav1.duration)
        filename = os.path.join(os.getcwd(), 'received1.wav')
        temp1.write(filename)
        v.wav2 = thinkdsp.read_wave(filename)
        v.wav2.normalize()
        if v.wav1.duration == v.wav2.duration:
            if v.wav1.duration > 20:
                v.start = 15
            else:
                v.start = 2
            v.time_frame = corr_time_frame(v)
            if not v.failure_detected:
                start_time = v.time_frame + v.start
                duration = v.wav1.duration - start_time
                seg1 = v.wav1.segment(start=v.start, duration=duration)
                seg2 = v.wav2.segment(start=start_time, duration=duration)
                corr = seg1.corr(seg2)
                v.correation = format(corr, '.2f')
                v.correation = float(v.correation) * 100
                tch_auto.log_info('Corelation of %s%% with lag - %s' %
                                  (v.correation, v.time_frame))
                v.deviated = 100 - v.correation
                tch_auto.log_info(
                    'Deviated found between played and recorded wave file - %s%%'
                    % v.deviated)
                return
            else:
                if v.time_frame is False:
                    return False
        else:
            tch_auto.log_error('Wave files duration mis-match')
            v.failure_detected = True
Example #7
0
def start_linphones(v):
    for linphone in v.linphones:
        linphone.execute('rm -f received.wav')
        linphone.execute('killall linphone linphonec')
        # linphone.execute('killall linphonec')
        out = linphone.execute('linphonec')
        if 'Could not start udp' not in out:
            tch_auto.log_info('Linphone started successfully in %s' %
                              linphone.Hostname)
        else:
            tch_auto.log_error('Linphone failed to start in %s' %
                               linphone.Hostname)
            v.failure_detected = True
        out = linphone.execute('soundcard use files')
        if 'Using wav files instead of soundcard' in out:
            tch_auto.log_info(
                'Linphone started Using wav files instead of soundcard in %s' %
                linphone.Hostname)
        else:
            tch_auto.log_error(
                'Linphone failed to use wav files instead of soundcard in %s' %
                linphone.Hostname)
            v.failure_detected = True
Example #8
0
def corr_time_frame(v, duration=1):

    mcor = 0.9
    match_val = {}
    while mcor > 0.5:
        time_frame1 = 0.00
        time_frame = v.start + time_frame1
        while time_frame <= v.start + 1:
            time_frame = v.start + time_frame1
            seg1 = v.wav1.segment(start=v.start, duration=duration)
            seg2 = v.wav2.segment(start=time_frame, duration=duration)
            match = seg1.corr(seg2)
            if match > 6:
                tch_auto.log_info('Corelation - %s' % (match))
            if match > mcor:
                match_val.update({time_frame1: match})
                tch_auto.log_info('Corelation Match - %s, With Time Lag = %s' %
                                  (match, time_frame1))
            time_frame1 += 0.00001
        if len(match_val) == 0:
            mcor -= 0.1
        else:
            break
    if len(match_val) == 0:
        tch_auto.log_error('No Corelation found between two samples')
        v.failure_detected = True
        return False
    else:
        max_match = max(match_val.values())
        tch_auto.log_info('MAX Match - %s' % (max_match))
        time_s = []
        for key, val in match_val.items():
            if max_match == val:
                time_s.append(key)
        tch_auto.log_info('MAX-Time-lag - %s' % (time_s))
        time_s = np.array(time_s)
        return time_s.mean()
Example #9
0
def TestRun():
    tch_auto.log_h1('TestRun - Start')
    if not v.failure_detected:
        for linphone in v.linphones:
            linphone.execute('killall linphone linphonec parecord paplay')
            # linphone.execute('killall linphonec')
            out = linphone.execute('linphonec')
            if 'Could not start udp' not in out:
                tch_auto.log_info('Linphone started successfully in %s' %
                                  linphone.Hostname)
            else:
                tch_auto.log_error('Linphone failed to start in %s' %
                                   linphone.Hostname)
                v.failure_detected = True

    if not v.failure_detected:
        if 'Auto answer enabled.' in v.linphone1.execute('autoanswer enable'):
            tch_auto.log_info('Auto answer enabled successfully in %s' %
                              v.linphone1.Hostname)

        pattern = 'Establishing call id to <sip:%s>, assigned id \d+.' % v.linphone1.IP
        cmd = 'call sip:%s' % v.linphone1.IP
        out = v.linphone2.execute(cmd)
        if pattern in out:
            tch_auto.log_info('Call getting established for %s' %
                              v.linphone1.Hostname)

        cmd = 'calls'
        validation = munch.munchify({'present': [], 'absent': []})
        validation.present.append(r'.*<sip:%s>.*StreamsRunning' %
                                  v.linphone1.IP)
        # validation.present.append(r'9  __PIPE__ <sip:10.78.192.120>                 __PIPE__ StreamsRunning  __PIPE__')
        if v.linphone2.cmd_check(cmd, validation, 6):
            cmds = []
            cmds.append('killall parecord paplay')
            cmds.append(
                'parecord --device=fakespeaker.monitor --file-format=wav received1.wav &'
            )
            cmds.append('paplay --device=fakemic Thendral.wav &')
            pid = {}
            for cmd in cmds:
                for lnx in v.lnxs:
                    if 'paplay' in cmd:
                        key = 'paplay'
                    else:
                        key = 'parecord'
                    out = lnx.execute(cmd)
                    m = re.search(r'\[\d\]+\s+(\d+)', out)
                    if m:
                        if lnx.Hostname in pid.keys():
                            pid[lnx.Hostname].update({key: m.group(1)})
                        else:
                            pid.update({lnx.Hostname: {key: m.group(1)}})
            cmd = 'pgrep paplay'
            while True:
                for lnx in v.lnxs:
                    tch_auto.log_info(lnx.Hostname)
                    out = lnx.execute(cmd)
                    if pid[lnx.Hostname]['paplay'] not in out:
                        lnx.execute('killall parecord')
                        pid[lnx.Hostname].update({'paplay': 'Done'})
                if pid[v.lnx1.Hostname]['paplay'] and pid[
                        v.lnx1.Hostname]['paplay'] != 'Done':
                    time.sleep(30)
                if pid[v.lnx1.Hostname]['paplay'] and pid[
                        v.lnx1.Hostname]['paplay'] == 'Done':
                    break
                if not v.failure_detected:
                    for linphone in v.linphones:
                        linphone.execute('terminate')
                        linphone.execute('quit')