~aleteoryx/muditaos

ref: sign_test muditaos/test/make_a_call.py -rw-r--r-- 2.0 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

import sys
import time

from harness import log
from harness.harness import Harness
from harness.interface.defs import key_codes, endpoint, method
from harness.interface.error import TestError, Error


def call(harness, phone_number: str, duration: int):
    @harness.with_phone_unlocked
    def do_it(connection):
        # enter number
        harness.send_number(phone_number)
        # call
        connection.send_key_code(key_codes["fnLeft"])

        time.sleep(duration)
        connection.send_key_code(key_codes["fnRight"])


def get_calllog_count(harness):
    body = {"count": True}
    return harness.endpoint_request("calllog", "get", body)["body"]["count"]


def main():
    if len(sys.argv) == 1 or "/dev" not in sys.argv[1]:
        log.warning("Port name not passed, trying port name filename from simulator...")
        try:
            file = open("/tmp/purephone_pts_name", "r")
        except FileNotFoundError as err:
            raise TestError(Error.PORT_FILE_NOT_FOUND)

        port_name = file.readline()
        if port_name.isascii():
            log.debug("found {} entry!".format(port_name))
        else:
            print(f'Please pass port name as the parameter: python {sys.argv[0]} /dev/ttyACM0 number duration')
            raise TestError(Error.PORT_NOT_FOUND)
    else:
        port_name = sys.argv[1]

    harness = Harness(sys.argv[1])
    harness.unlock_phone()
    number = str(sys.argv[2])
    duration = int(sys.argv[3])
    count_before = get_calllog_count(harness)
    call(harness, number, duration)
    count_after = get_calllog_count(harness)

    if count_after == count_before + 1:
        print("Success!")
    else:
        print("Error!")
        raise TestError(Error.TEST_FAILED)


if __name__ == "__main__":
    try:
        main()
    except TestError as err:
        log.error(err)
        exit(err.get_error_code())