Exemplo n.º 1
0
def test_usage_with_output():
    with mock.patch("mozdevice.adb.ADBDevice") as device:
        with mock.patch(
                "control_server.RaptorControlServer") as control_server:
            # Override the shell output with sample CPU usage details
            filepath = os.path.abspath(os.path.dirname(__file__)) + "/files/"
            with open(filepath + "top-info.txt", "r") as f:
                test_data = f.read()
            device.shell_output.side_effect = ["8.0.0", test_data]
            device._verbose = True

            # Create a control server
            control_server.cpu_test = True
            control_server.test_name = "cpuunittest"
            control_server.device = device
            control_server.app_name = "org.mozilla.geckoview_example"
            raptor = WebExtensionAndroid("geckoview",
                                         "org.mozilla.geckoview_example")
            raptor.device = device
            raptor.config["cpu_test"] = True
            raptor.control_server = control_server

            cpu_profiler = cpu.AndroidCPUProfiler(raptor)
            cpu_profiler.polls.append(cpu_profiler.get_app_cpu_usage())
            cpu_profiler.polls.append(0)

            # Verify the response contains our expected CPU % of 93.7
            avg_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_integer_cpu_info_output-avg",
                "unit": "%",
                "values": {
                    "avg": 93.7 / 2
                },
            }
            min_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_integer_cpu_info_output-min",
                "unit": "%",
                "values": {
                    "min": 0
                },
            }
            max_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_integer_cpu_info_output-max",
                "unit": "%",
                "values": {
                    "max": 93.7
                },
            }

            cpu_profiler.generate_android_cpu_profile(
                "usage_with_integer_cpu_info_output")
            control_server.submit_supporting_data.assert_has_calls([
                mock.call(avg_cpuinfo_data),
                mock.call(min_cpuinfo_data),
                mock.call(max_cpuinfo_data),
            ])
Exemplo n.º 2
0
def test_androidos_baseline_power():
    if not os.getenv("MOZ_UPLOAD_DIR"):
        os.environ["MOZ_UPLOAD_DIR"] = tempfile.mkdtemp()

    with mock.patch("mozdevice.adb.ADBDevice") as device:
        with mock.patch(
                "control_server.RaptorControlServer") as control_server:
            # Override the shell output with sample CPU usage details
            filepath = os.path.abspath(os.path.dirname(__file__)) + "/files/"
            f = open(filepath + "batterystats-android-8.txt", "r")
            batterystats_return_value = f.read()

            # Multiple shell output calls are performed
            # and only those with non-None output are required
            device.shell_output.return_value = None
            device.shell_output.side_effect = [
                None,
                None,
                "Test value",
                "Test value",
                batterystats_return_value,
                "8.0.0",
            ]

            device._verbose = True
            device.version = 8

            # Create a control server
            control_server.power_test = True
            control_server.test_name = "gve-pytest"
            control_server.device = device
            control_server.app_name = "org.mozilla.geckoview_example"
            web_extension = WebExtensionAndroid(
                "geckoview", "org.mozilla.geckoview_example", power_test=True)
            web_extension.device = device
            web_extension.config["power_test"] = True
            web_extension.control_server = control_server

            # Expected OS baseline calculation result
            os_baseline_data = {
                "type": "power",
                "test": "gve-pytest",
                "unit": "mAh",
                "values": {
                    "cpu": float(10.786654),
                    "wifi": float(2.26132),
                    "screen": float(51.66),
                    "proportional": float(11.294805199999999),
                },
            }

            # Verify the response contains our expected calculations
            power.finish_android_power_test(web_extension,
                                            "gve-pytest",
                                            os_baseline=True)

            assert web_extension.os_baseline_data == os_baseline_data
Exemplo n.º 3
0
def test_no_device():
    raptor = WebExtensionAndroid(
        "geckoview",
        "org.mozilla.org.mozilla.geckoview_example",
        cpu_test=True,
    )
    raptor.device = None
    resp = cpu.start_android_cpu_profiler(raptor)
    assert resp is None
Exemplo n.º 4
0
def test_usage_with_fallback():
    with mock.patch("mozdevice.adb.ADBDevice") as device:
        with mock.patch("control_server.RaptorControlServer") as control_server:
            device._verbose = True

            # Return what our shell call to dumpsys would give us
            shell_output = (
                " 31093 u0_a196  10 -10   8% S    "
                + "66 1392100K 137012K  fg org.mozilla.geckoview_example"
            )

            # We set the version to be less than Android 8
            device.shell_output.side_effect = ["7.0.0", shell_output]

            # Create a control server
            control_server.cpu_test = True
            control_server.test_name = "cpuunittest"
            control_server.device = device
            control_server.app_name = "org.mozilla.geckoview_example"
            raptor = WebExtensionAndroid("geckoview", "org.mozilla.geckoview_example")
            raptor.device = device
            raptor.config["cpu_test"] = True
            raptor.control_server = control_server

            cpu_profiler = cpu.AndroidCPUProfiler(raptor)
            cpu_profiler.polls.append(cpu_profiler.get_app_cpu_usage())
            cpu_profiler.polls.append(0)

            # Verify the response contains our expected CPU % of 8
            avg_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_fallback-avg",
                "unit": "%",
                "values": {"avg": 8 / 2},
            }
            min_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_fallback-min",
                "unit": "%",
                "values": {"min": 0},
            }
            max_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_fallback-max",
                "unit": "%",
                "values": {"max": 8},
            }

            cpu_profiler.generate_android_cpu_profile("usage_with_fallback")
            control_server.submit_supporting_data.assert_has_calls(
                [
                    mock.call(avg_cpuinfo_data),
                    mock.call(min_cpuinfo_data),
                    mock.call(max_cpuinfo_data),
                ]
            )
Exemplo n.º 5
0
def test_usage_with_invalid_data_returns_zero():
    with mock.patch("mozdevice.adb.ADBDevice") as device:
        with mock.patch(
                "control_server.RaptorControlServer") as control_server:
            # Create a device that returns invalid data
            device.shell_output.side_effect = ["8.0.0", "geckoview"]
            device._verbose = True

            # Create a control server
            control_server.cpu_test = True
            control_server.device = device
            raptor = WebExtensionAndroid("geckoview",
                                         "org.mozilla.geckoview_example")
            raptor.config["cpu_test"] = True
            raptor.control_server = control_server
            raptor.device = device

            cpu_profiler = cpu.AndroidCPUProfiler(raptor)
            cpu_profiler.get_app_cpu_usage()

            # Verify the call to submit data was made
            avg_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_invalid_data_returns_zero-avg",
                "unit": "%",
                "values": {
                    "avg": 0
                },
            }
            min_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_invalid_data_returns_zero-min",
                "unit": "%",
                "values": {
                    "min": 0
                },
            }
            max_cpuinfo_data = {
                "type": "cpu",
                "test": "usage_with_invalid_data_returns_zero-max",
                "unit": "%",
                "values": {
                    "max": 0
                },
            }

            cpu_profiler.generate_android_cpu_profile(
                "usage_with_invalid_data_returns_zero")
            control_server.submit_supporting_data.assert_has_calls([
                mock.call(avg_cpuinfo_data),
                mock.call(min_cpuinfo_data),
                mock.call(max_cpuinfo_data),
            ])
Exemplo n.º 6
0
def test_android7_power():
    if not os.getenv("MOZ_UPLOAD_DIR"):
        os.environ["MOZ_UPLOAD_DIR"] = tempfile.mkdtemp()

    with mock.patch("mozdevice.adb.ADBDevice") as device:
        with mock.patch(
                "control_server.RaptorControlServer") as control_server:
            # Override the shell output with sample CPU usage details
            filepath = os.path.abspath(os.path.dirname(__file__)) + "/files/"
            f = open(filepath + "batterystats-android-7.txt", "r")
            batterystats_return_value = f.read()

            # Multiple shell output calls are performed
            # and only those with non-None output are required
            device.shell_output.return_value = None
            device.shell_output.side_effect = [
                None,
                None,
                "Test value",
                "Test value",
                batterystats_return_value,
                "7.0.0",
            ]

            device._verbose = True
            device.version = 7

            # Create a control server
            control_server.power_test = True
            control_server.test_name = "gve-pytest"
            control_server.device = device
            control_server.app_name = "org.mozilla.geckoview_example"
            web_extension = WebExtensionAndroid(
                "geckoview", "org.mozilla.geckoview_example", power_test=True)
            web_extension.device = device
            web_extension.config["power_test"] = True
            web_extension.control_server = control_server
            web_extension.power_test_time = 20  # minutes
            web_extension.os_baseline_data = {
                "type": "power",
                "test": "gve-pytest",
                "unit": "mAh",
                "values": {
                    "cpu": float(5),
                    "wifi": float(5),
                    "screen": float(5)
                },
            }

            # Verify the response contains our expected calculations
            # (no proportional measure on android 7)
            power_data = {
                "type": "power",
                "test": "gve-pytest",
                "unit": "mAh",
                "values": {
                    "cpu": float(14.5),
                    "wifi": float(0.132),
                    "screen": float(70.7),
                },
            }

            pc_data = {
                "type": "power",
                "test": "gve-pytest-%change",
                "unit": "%",
                "values": {
                    "cpu": float(14.5),
                    "wifi": float(0.132000000000005),
                    "screen": float(70.70000000000002),
                },
            }

            power.finish_android_power_test(web_extension, "gve-pytest")

            control_server.submit_supporting_data.assert_has_calls([
                mock.call(power_data),
                mock.call(pc_data),
                mock.call(web_extension.os_baseline_data),
            ])