~aleteoryx/muditaos

ref: cf75cfc01250ea019aabfa22f59d9c2bb8c1afb7 muditaos/test/pytest/service-desktop/test_bluetooth.py -rw-r--r-- 2.2 KiB
cf75cfc0 — Marcin Smoczyński [EGD-5973] Reduce audio stack usage 4 years 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
69
70
71
72
73
74
75
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

import pytest
from harness.interface.defs import status
from harness import log
import time


@pytest.mark.rt1051
@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("usb_unlocked")
def test_bluetooth_on_off(harness):
    body = {"state": True}
    ret = harness.endpoint_request("bluetooth", "get", body)
    print(ret)
    assert ret["status"] == status["OK"]
    if ret["body"]["state"] == 0:
        log.info("BT turned off, turning on...")
        body = {"state": "on"}
        ret = harness.endpoint_request("bluetooth", "put", body)

        time.sleep(5)
        body = {"state": True}
        ret = harness.endpoint_request("bluetooth", "get", body)

        assert ret["status"] == status["OK"]

    assert ret["body"]["state"] == 1

    log.info("BT turning off...")
    body = {"state": "off"}
    ret = harness.endpoint_request("bluetooth", "put", body)

    body = {"state": True}
    ret = harness.endpoint_request("bluetooth", "get", body)
    assert ret["body"]["state"] == 0


@pytest.mark.rt1051
@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("usb_unlocked")
def test_bluetooth_scan(harness):
    body = {"state": True}
    ret = harness.endpoint_request("bluetooth", "get", body)
    print(ret)
    assert ret["status"] == status["OK"]
    if ret["body"]["state"] == 0:
        log.info("BT turned off, turning on...")
        body = {"state": "on"}
        ret = harness.endpoint_request("bluetooth", "put", body)

        time.sleep(5)
        body = {"state": True}
        ret = harness.endpoint_request("bluetooth", "get", body)

        assert ret["status"] == status["OK"]

    assert ret["body"]["state"] == 1

    body = {"command": "scanOn"}
    ret = harness.endpoint_request("bluetooth", "put", body)
    assert ret["body"]["scan"] == "on"

    time.sleep(1)
    body = {"command": "scanOff"}
    ret = harness.endpoint_request("bluetooth", "put", body)
    assert ret["body"]["scan"] == "off"

    body = {"state": "off"}
    ret = harness.endpoint_request("bluetooth", "put", body)

    body = {"state": True}
    ret = harness.endpoint_request("bluetooth", "get", body)
    assert ret["body"]["state"] == 0