~aleteoryx/muditaos

ee65e0c5588c83212055e6d3985ca3fdc655aa69 — Maciej Gibowicz 4 years ago 7b8f171
[EGD-6082] Fix cellular start harness test

Improved cellular cold and hot start harness test
2 files changed, 28 insertions(+), 34 deletions(-)

M module-services/service-cellular/ServiceCellular.cpp
M test/pytest/test_cellular_start.py
M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +2 -1
@@ 253,7 253,8 @@ void ServiceCellular::SleepTimerHandler()
                                ? currentTime - lastCommunicationTimestamp
                                : std::numeric_limits<TickType_t>::max() - lastCommunicationTimestamp + currentTime;

    if (!ongoingCall.isValid() && timeOfInactivity >= constants::enterSleepModeTime.count()) {
    if (!ongoingCall.isValid() && state.get() == cellular::State::ST::Ready &&
        timeOfInactivity >= constants::enterSleepModeTime.count()) {
        cmux->EnterSleepMode();
        cpuSentinel->ReleaseMinimumFrequency();
    }

M test/pytest/test_cellular_start.py => test/pytest/test_cellular_start.py +26 -33
@@ 3,6 3,7 @@
import time
import pytest

from harness import log
from harness.interface.defs import SMSType
from harness.interface.defs import status
from test_send_message import get_message_by_text, compare_messages, prepare_sms, test_send_prepared_message as send_prepared_message


@@ 27,16 28,16 @@ cellular_states = {
}


def assert_that_prepare_sms_is_not_sent(harness, phone_number, sms_text):
    # send_message(harness, phone_number, sms_text)
    old_messages = get_message_by_text(harness, sms_text, str(phone_number))
    # prepare sms and send it (add sms to sending queue)
    prepare_sms(harness, sms_text, str(phone_number), SMSType.QUEUED.value)
    # time to send message
    time.sleep(3)
    # check whether message was sent - it shouldn't be sent in this case
    new_messages = get_message_by_text(harness, sms_text, str(phone_number))
    compare_messages(old_messages, new_messages, SMSType.FAILED)
def wait_for_cellular_state(harness, state, max_attempts = 10):
    for i in range(max_attempts):
        ret = request_cellular_state_info(harness)
        assert ret["status"] == status["OK"]
        if (ret["body"]["cellularState"] == state):
            return True
        else:
            log.info("cellular is not in " + state + " mode, waiting...")
            time.sleep(2)
    return False


@pytest.mark.rt1051


@@ 44,29 45,24 @@ def assert_that_prepare_sms_is_not_sent(harness, phone_number, sms_text):
@pytest.mark.usefixtures("usb_unlocked")

def test_cellular_cold_start(harness, phone_number, sms_text):
    # power up can take more then 12s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOn"])
    time.sleep(30)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"
    
    if (ret["body"]["cellularState"] != "Ready"):
        # power up can take more then 12s according to QUECTEL documentation
        request_cellular_power_state_change(harness, cellular_states["PowerOn"])
        time.sleep(30)
        assert wait_for_cellular_state(harness, "Ready") == True, "Cellular initialization failed!"

    # power down can take more then 29.5s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOff"])
    time.sleep(35)

    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "PowerDown"

    assert_that_prepare_sms_is_not_sent(harness, phone_number, sms_text)
    time.sleep(20)
    assert wait_for_cellular_state(harness, "PowerDown") == True, "Cellular shutdown failed!"

    # power up can take more then 12s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOn"])
    time.sleep(30)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"
    assert wait_for_cellular_state(harness, "Ready") == True, "Cellular initialization failed!"

    # send text message
    send_prepared_message(harness, phone_number, sms_text)


@@ 79,24 75,21 @@ def test_cellular_cold_start(harness, phone_number, sms_text):
@pytest.mark.usefixtures("usb_unlocked")

def test_cellular_hot_start(harness, phone_number, sms_text):
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]

    time.sleep(2)
    request_cellular_power_state_change(harness, cellular_states["HotStart"])

    # wait for changing state
    time.sleep(1)
    time.sleep(2)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is not "Ready"
    assert ret["body"]["cellularState"] != "Ready", "Cellular reset failed!"

    # power up can take more then 12s according to QUECTEL documentation
    time.sleep(35)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"
    time.sleep(30)
    assert wait_for_cellular_state(harness, "Ready") == True, "Cellular initialization failed!"

    # send text message
    send_prepared_message(harness, phone_number, sms_text)
    # try to make outgoing call
    call(harness, phone_number, 5)