# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

AUTHOR = "rohitbm@chromium.org, Chrome OS Audio"
NAME = "audio_PowerConsumption.mp3"
TIME = "MEDIUM"
TEST_CATEGORY = "Performance"
TEST_CLASS = "audio"
ATTRIBUTES = "suite:bvt-perbuild"
TEST_TYPE = "server"
DEPENDENCIES = "rpm, power:battery"
BUG_TEMPLATE = {
    "labels": ["OS-Chrome"],
    "components": ["OS>Kernel>Audio"],
}

DOC = """
The test outputs the power consumption for various audio formats.
"""

import logging

from autotest_lib.client.common_lib import error

VIDEO_NAME = "polka_crowd_128kbps_44_1khz.mp3"
CHECKSUM = "7171529bb34c6e17dd163b03aa2b7c9c"

def _run_client_test(machine):
    """Runs client test with battery actively discharging."""
    client = hosts.create_host(machine)
    if not client.has_power():
        raise error.TestError("This test requires RPM support.")

    try:
        client.power_off()
        client_at = autotest.Autotest(client)
        client_at.run_test("audio_PlaybackPower", test_file=VIDEO_NAME,
                           checksum=CHECKSUM)
    finally:
        client.power_on()


job.parallel_on_machines(_run_client_test, machines)