Exemplo n.º 1
0
    def stress_test(self, setup_func=None, network_check_func=None, test_sms=False):
        if setup_func and not setup_func():
            self.log.error("Test setup %s failed", setup_func.__name__)
            return False
        fail_count = collections.defaultdict(int)
        for i in range(1, self.phone_call_iteration + 1):
            msg = "Stress Call Test %s Iteration: <%s> / <%s>" % (
                self.test_name, i, self.phone_call_iteration)
            self.log.info(msg)
            iteration_result = True
            ensure_phones_idle(self.log, self.android_devices)
            if not self._setup_phone_call():
                fail_count["dialing"] += 1
                iteration_result = False
                self.log.error("%s call dialing failure.", msg)

            if network_check_func and not network_check_func(self.log,
                                                             self.caller):
                fail_count["caller_network_check"] += 1
                iteration_result = False
                self.log.error("%s network check %s failure.", msg,
                               network_check_func.__name__)

            if network_check_func and not network_check_func(self.log,
                                                             self.callee):
                fail_count["callee_network_check"] += 1
                iteration_result = False
                self.log.error("%s network check failure.", msg)

            time.sleep(self.phone_call_duration)

            if not verify_incall_state(self.log, [self.caller, self.callee],
                                       True):
                self.log.error("%s call dropped.", msg)
                iteration_result = False
                fail_count["drop"] += 1

            self._hangup_call()

            if test_sms and not sms_send_receive_verify(
                    self.log, self.caller, self.callee, [rand_ascii_str(180)]):
                fail_count["sms"] += 1

            self.log.info("%s %s" % (msg, str(iteration_result)))
            if not iteration_result:
                self._take_bug_report("%s_%s" % (self.test_name, i), self.begin_time)

            if self.sleep_time_between_test_iterations:
                self.caller.droid.goToSleepNow()
                self.callee.droid.goToSleepNow()
                time.sleep(self.sleep_time_between_test_iterations)


        test_result = True
        for failure, count in fail_count.items():
            if count:
                self.log.error("%s: %s %s failures in %s iterations".format(
                    self.test_name, count, failure, self.phone_call_iteration))
                test_result = False
        return test_result
    def _power_test(self, phone_check_func_after_power_test=None, **kwargs):
        # Test passing criteria can be defined in test config file with the
        # maximum mA allowed for the test case in "pass_criteria"->test_name
        # field. By default it will set to 999.
        pass_criteria = self._get_pass_criteria(self.test_name)
        bug_report = True
        active_call = kwargs.get('active_call')
        average_current = 0
        result = None
        self.log.info("Test %s: %s" % (self.test_name, kwargs))
        if active_call:
            sample_rate = ACTIVE_CALL_TEST_SAMPLING_RATE
            sample_time = ACTIVE_CALL_TEST_SAMPLE_TIME
            offset_time = ACTIVE_CALL_TEST_OFFSET_TIME
        else:
            sample_rate = IDLE_TEST_SAMPLING_RATE
            sample_time = IDLE_TEST_SAMPLE_TIME
            offset_time = IDLE_TEST_OFFSET_TIME
        try:
            if not self._test_setup(**kwargs):
                self.log.error("DUT Failed to Set Up Properly.")
                return False

            if ((phone_check_func_after_power_test is not None)
                    and (not phone_check_func_after_power_test(
                        self.log, self.android_devices[0]))):
                self.log.error(
                    "Phone is not in correct status before power test.")
                return False

            result = self.mon.measure_power(sample_rate, sample_time,
                                            self.test_id, offset_time)
            average_current = result.average_current
            if ((phone_check_func_after_power_test is not None)
                    and (not phone_check_func_after_power_test(
                        self.log, self.android_devices[0]))):
                self.log.error(
                    "Phone is not in correct status after power test.")
                return False
            if active_call:
                if not verify_incall_state(
                        self.log,
                    [self.android_devices[0], self.android_devices[1]], True):
                    self.log.error("Call drop during power test.")
                    return False
                else:
                    hangup_call(self.log, self.android_devices[1])
            if (average_current <= pass_criteria):
                bug_report = False
                return True
        finally:
            self._save_logs_for_power_test(result, bug_report)
            self.log.info("{} Result: {} mA, pass criteria: {} mA".format(
                self.test_id, average_current, pass_criteria))
Exemplo n.º 3
0
 def _test_power_active_call(self,
                             test_name,
                             test_setup_func,
                             pass_criteria=DEFAULT_POWER_PASS_CRITERIA,
                             phone_check_func_after_power_test=None,
                             *args,
                             **kwargs):
     average_current = 0
     try:
         ensure_phone_default_state(self.log, self.android_devices[0])
         ensure_phone_default_state(self.log, self.android_devices[1])
         if not phone_setup_voice_general(self.log,
                                          self.android_devices[1]):
             self.log.error("PhoneB Failed to Set Up Properly.")
             return False
         if not test_setup_func(self.android_devices[0], *args, **kwargs):
             self.log.error("DUT Failed to Set Up Properly.")
             return False
         result = self.mon.measure_power(ACTIVE_CALL_TEST_SAMPLING_RATE,
                                         ACTIVE_CALL_TEST_SAMPLE_TIME,
                                         test_name,
                                         ACTIVE_CALL_TEST_OFFSET_TIME)
         self._save_logs_for_power_test(test_name, result)
         average_current = result.average_current
         if not verify_incall_state(
                 self.log,
             [self.android_devices[0], self.android_devices[1]], True):
             self.log.error("Call drop during power test.")
             return False
         if ((phone_check_func_after_power_test is not None)
                 and (not phone_check_func_after_power_test(
                     self.log, self.android_devices[0]))):
             self.log.error(
                 "Phone is not in correct status after power test.")
             return False
         return (average_current <= pass_criteria)
     finally:
         self.android_devices[1].droid.telecomEndCall()
         self.log.info("Result: {} mA, pass criteria: {} mA".format(
             average_current, pass_criteria))
Exemplo n.º 4
0
def swap_calls(log,
               ads,
               call_hold_id,
               call_active_id,
               num_swaps=1,
               check_call_status=True):
    """PhoneA in call with B and C. Swap active/holding call on PhoneA.

    Swap call and check status on PhoneA.
        (This step may have multiple times according to 'num_swaps'.)
    Check if all 3 phones are 'in-call'.

    Args:
        ads: list of ad object, at least three need to pass in.
            Swap operation will happen on ads[0].
            ads[1] and ads[2] are call participants.
        call_hold_id: id for the holding call in ads[0].
            call_hold_id should be 'STATE_HOLDING' when calling this function.
        call_active_id: id for the active call in ads[0].
            call_active_id should be 'STATE_ACTIVE' when calling this function.
        num_swaps: how many swap/check operations will be done before return.
        check_call_status: This is optional. Default value is True.
            If this value is True, then call status (active/hold) will be
            be checked after each swap operation.

    Returns:
        If no error happened, return True, otherwise, return False.
    """
    if check_call_status:
        # Check status before swap.
        if ads[0].droid.telecomCallGetCallState(
                call_active_id) != CALL_STATE_ACTIVE:
            log.error("Call_id:{}, state:{}, expected: STATE_ACTIVE".format(
                call_active_id,
                ads[0].droid.telecomCallGetCallState(call_active_id)))
            return False
        if ads[0].droid.telecomCallGetCallState(
                call_hold_id) != CALL_STATE_HOLDING:
            log.error("Call_id:{}, state:{}, expected: STATE_HOLDING".format(
                call_hold_id,
                ads[0].droid.telecomCallGetCallState(call_hold_id)))
            return False

    i = 1
    while (i <= num_swaps):
        log.info("swap_test: {}. {} swap and check call status.".format(
            i, ads[0].serial))
        ads[0].droid.telecomCallHold(call_active_id)
        time.sleep(WAIT_TIME_IN_CALL)
        # Swap object reference
        call_active_id, call_hold_id = call_hold_id, call_active_id
        if check_call_status:
            # Check status
            if ads[0].droid.telecomCallGetCallState(
                    call_active_id) != CALL_STATE_ACTIVE:
                log.error(
                    "Call_id:{}, state:{}, expected: STATE_ACTIVE".format(
                        call_active_id,
                        ads[0].droid.telecomCallGetCallState(call_active_id)))
                return False
            if ads[0].droid.telecomCallGetCallState(
                    call_hold_id) != CALL_STATE_HOLDING:
                log.error(
                    "Call_id:{}, state:{}, expected: STATE_HOLDING".format(
                        call_hold_id,
                        ads[0].droid.telecomCallGetCallState(call_hold_id)))
                return False
        # TODO: b/26296375 add voice check.

        i += 1

    #In the end, check all three phones are 'in-call'.
    if not verify_incall_state(log, [ads[0], ads[1], ads[2]], True):
        return False

    return True
    def stress_test(self,
                    setup_func=None,
                    network_check_func=None,
                    test_sms=False,
                    test_video=False):
        for ad in self.android_devices:
            #check for sim and service
            ensure_phone_subscription(self.log, ad)

        if setup_func and not setup_func():
            self.log.error("Test setup %s failed", setup_func.__name__)
            return False
        fail_count = collections.defaultdict(int)
        for i in range(1, self.phone_call_iteration + 1):
            msg = "Stress Call Test %s Iteration: <%s> / <%s>" % (
                self.test_name, i, self.phone_call_iteration)
            begin_time = get_current_epoch_time()
            self.log.info(msg)
            iteration_result = True
            ensure_phones_idle(self.log, self.android_devices)

            if not self._setup_phone_call(test_video, phone_call_duration=self.phone_call_duration):
                fail_count["dialing"] += 1
                iteration_result = False
                self.log.error("%s call dialing failure.", msg)
            else:
                if network_check_func and not network_check_func(
                        self.log, self.caller):
                    fail_count["caller_network_check"] += 1
                    last_call_drop_reason(self.caller, begin_time)
                    iteration_result = False
                    self.log.error("%s network check %s failure.", msg,
                                   network_check_func.__name__)

                if network_check_func and not network_check_func(
                        self.log, self.callee):
                    fail_count["callee_network_check"] += 1
                    last_call_drop_reason(self.callee, begin_time)
                    iteration_result = False
                    self.log.error("%s network check failure.", msg)

                if not verify_incall_state(self.log,
                                           [self.caller, self.callee], True):
                    self.log.error("%s call dropped.", msg)
                    iteration_result = False
                    fail_count["drop"] += 1

                self._hangup_call()

            if test_sms and not sms_send_receive_verify(
                    self.log, self.caller, self.callee, [rand_ascii_str(180)]):
                fail_count["sms"] += 1

            self.log.info("%s %s", msg, iteration_result)
            if not iteration_result:
                self._take_bug_report("%s_CallNo_%s" % (self.test_name, i),
                                      begin_time)
                start_qxdm_loggers(self.log, self.android_devices)

            if self.sleep_time_between_test_iterations:
                self.caller.droid.goToSleepNow()
                self.callee.droid.goToSleepNow()
                time.sleep(self.sleep_time_between_test_iterations)

        test_result = True
        for failure, count in fail_count.items():
            if count:
                self.log.error("%s: %s %s failures in %s iterations",
                               self.test_name, count, failure,
                               self.phone_call_iteration)
                test_result = False
        return test_result
def video_call_setup_teardown_for_subscription(
        log,
        ad_caller,
        ad_callee,
        subid_caller,
        subid_callee,
        ad_hangup=None,
        video_state=VT_STATE_BIDIRECTIONAL,
        verify_caller_func=None,
        verify_callee_func=None,
        wait_time_in_call=WAIT_TIME_IN_CALL,
        incall_ui_display=INCALL_UI_DISPLAY_FOREGROUND):
    """ Call process, including make a phone call from caller,
    accept from callee, and hang up. The call is on specified subscription

    In call process, call from <droid_caller> to <droid_callee>,
    accept the call, (optional)then hang up from <droid_hangup>.

    Args:
        ad_caller: Caller Android Device Object.
        ad_callee: Callee Android Device Object.
        subid_caller: Caller subscription ID
        subid_callee: Callee subscription ID
        ad_hangup: Android Device Object end the phone call.
            Optional. Default value is None, and phone call will continue.
        video_state: video state for VT call.
            Optional. Default value is VT_STATE_BIDIRECTIONAL
        verify_caller_func: func_ptr to verify caller in correct mode
            Optional. Default is None
        verify_callee_func: func_ptr to verify callee in correct mode
            Optional. Default is None
        wait_time_in_call: wait time during call.
            Optional. Default is WAIT_TIME_IN_CALL.
        incall_ui_display: after answer the call, bring in-call UI to foreground or
            background. Optional, default value is INCALL_UI_DISPLAY_FOREGROUND.
            if = INCALL_UI_DISPLAY_FOREGROUND, bring in-call UI to foreground.
            if = INCALL_UI_DISPLAY_BACKGROUND, bring in-call UI to background.
            else, do nothing.

    Returns:
        True if call process without any error.
        False if error happened.

    """
    CHECK_INTERVAL = 60

    class _CallSequenceException(Exception):
        pass

    caller_number = ad_caller.cfg['subscription'][subid_caller]['phone_num']
    callee_number = ad_callee.cfg['subscription'][subid_callee]['phone_num']

    log.info("Call from {} to {}".format(caller_number, callee_number))

    try:
        if not initiate_video_call(log, ad_caller, callee_number):
            raise _CallSequenceException("Initiate call failed.")

        if not wait_and_answer_video_call_for_subscription(
                log,
                ad_callee,
                subid_callee,
                incoming_number=caller_number,
                video_state=video_state,
                incall_ui_display=incall_ui_display):
            raise _CallSequenceException("Answer call fail.")

        # ensure that all internal states are updated in telecom
        time.sleep(WAIT_TIME_ACCEPT_VIDEO_CALL_TO_CHECK_STATE)

        # Check if caller/callee dropped call.
        if not verify_incall_state(log, [ad_callee, ad_caller], True):
            raise _CallSequenceException("Call Drop!")
        # Check Callee first
        # in case of VT call drop, it usually start from callee
        if verify_callee_func and not verify_callee_func(log, ad_callee):
            raise _CallSequenceException("Callee not in correct state!")
        if verify_caller_func and not verify_caller_func(log, ad_caller):
            raise _CallSequenceException("Caller not in correct state!")

        # TODO: b/26291165 Replace with reducing the volume as we want
        # to test route switching
        ad_caller.droid.telecomCallSetAudioRoute(AUDIO_ROUTE_EARPIECE)
        ad_callee.droid.telecomCallSetAudioRoute(AUDIO_ROUTE_EARPIECE)

        elapsed_time = 0
        while (elapsed_time < wait_time_in_call):
            CHECK_INTERVAL = min(CHECK_INTERVAL,
                                 wait_time_in_call - elapsed_time)
            time.sleep(CHECK_INTERVAL)
            elapsed_time += CHECK_INTERVAL

            # Check Callee first
            # in case of VT call drop, it usually start from callee
            if not verify_callee_func:
                callee_state_result = ad_callee.droid.telecomIsInCall()
            else:
                callee_state_result = verify_callee_func(log, ad_callee)
            if not callee_state_result:
                raise _CallSequenceException(
                    "Callee not in correct state at <{}>/<{}> seconds".format(
                        elapsed_time, wait_time_in_call))

            if not verify_caller_func:
                caller_state_result = ad_caller.droid.telecomIsInCall()
            else:
                caller_state_result = verify_caller_func(log, ad_caller)
            if not caller_state_result:
                raise _CallSequenceException(
                    "Caller not in correct state at <{}>/<{}> seconds".format(
                        elapsed_time, wait_time_in_call))

        if not ad_hangup:
            return True

        if not hangup_call(log, ad_hangup):
            raise _CallSequenceException("Error in Hanging-Up Call")
        return True

    except _CallSequenceException as e:
        log.error(e)
        return False
    finally:
        if ad_hangup:
            for ad in [ad_caller, ad_callee]:
                try:
                    if ad.droid.telecomIsInCall():
                        ad.droid.telecomEndCall()
                except Exception as e:
                    log.error(str(e))