blob: 6996bee8c559411780a6a617e7e158624555141a [file] [log] [blame]
# Copyright (c) 2012 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.
import os, re, shutil, sys, time
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import constants, cros_ui_test, dns_server, httpd
GTALK_LOG_PATH = '/tmp/gtalkplugin.log'
class realtimecomm_GTalkPlayground(cros_ui_test.UITest):
version = 1
dep = 'realtimecomm_playground'
def setup(self):
self.playground = os.path.join(self.autodir, 'playground')
def initialize(self, creds=None):
self.dep_dir = os.path.join(self.autodir, 'deps', self.dep)
# Start local HTTP server to serve playground.
self._test_server = httpd.HTTPListener(
port=80, docroot=os.path.join(self.dep_dir, 'src'))
# We need the initialize call to use empty creds (a guest account)
# so that the auth service isn't started on port 80, preventing
# the server we are trying to run from binding to the same port.
super(realtimecomm_GTalkPlayground, self).initialize(creds=None)
# Since the DNS redirection is only activated implicitly when the
# auth service is used, start it up explicitly.
self._dnsServer = dns_server.LocalDns()
def cleanup(self):
super(realtimecomm_GTalkPlayground, self).cleanup()
def run_verification(self):
# TODO(zhurun): Add more checking and perf data collection.
if not os.path.exists(GTALK_LOG_PATH):
raise error.TestFail('GTalk log file not exist!')
content = utils.read_file(GTALK_LOG_PATH)
if not "Found V4L2 capture" in content:
raise error.TestFail('V4L2 not found!')
if not "video state, recv=1 send=1" in content:
raise error.TestFail('Error in Video send/recv!')
if not "voice state, recv=1 send=1" in content:
raise error.TestFail('Error in Audio send/recv!')
if not "Decoded framerate" in content:
raise error.TestFail('Error in Video upstream!')
if not "Rendered framerate" in content:
raise error.TestFail('Error in Video downstream!')
# Get framerate
def get_framerate(self, log):
d = {}
# We get two framerate reports every 10 seconds (one per stream).
# Expect at least that many frames over the SLEEP_DURATION. We should
# get frames during some portion of WARMUP_TIME, so we're being a bit
# generous about duration, but the camera startup + call connect can
# take a decent chunk of the warmup time.
expected_frame_count = SLEEP_DURATION / 10 * 2
l = re.findall(r'Rendered framerate \((.*)\): (\d+\.?\d*) fps', log)
if len(l) < expected_frame_count:
raise error.TestFail('Error in Video duration!')
# Ignore the first and last framerate since they are not accurate.
for i in range(1, len(l) - 1):
if d.has_key(l[i][0]):
d[l[i][0]] = d[l[i][0]] + float(l[i][1])
d[l[i][0]] = float(l[i][1])
if len(d) != 2:
raise error.TestFail('Number of video stream is NOT 2!')
# Get framerate for two streams.
fps = []
for k in d:
fps.insert(0, d[k] * 2 / (len(l) - 2))
self.performance_results['fps_gtalk_up'] = max(fps[0], fps[1])
self.performance_results['fps_gtalk_down'] = min(fps[0], fps[1])
# Very low framerate means something wrong. Video hang or crash.
if (min(fps[0], fps[1]) < 5.0):
raise error.TestFail('Error in Video framerate.')
def run_once(self):
import pgutil
self.performance_results = {}
os.path.join(self.dep_dir, 'src'), self.playground,
os.path.join(self.bindir, 'options'))
# Launch Playground
pyauto_timeout_changer = self.pyauto.ActionTimeoutChanger(
self.pyauto, 10000)
# This will be redirected to localhost, via DNS redirection
del pyauto_timeout_changer
# Collect ctime,stime for GoogleTalkPlugin
gtalk_s = pgutil.get_utime_stime(
chrome_s = pgutil.get_utime_stime(
gtalk_e = pgutil.get_utime_stime(
chrome_e = pgutil.get_utime_stime(
self.performance_results['ctime_gtalk'] = \
pgutil.get_cpu_usage(SLEEP_DURATION, gtalk_e[0] - gtalk_s[0])
self.performance_results['stime_gtalk'] = \
pgutil.get_cpu_usage(SLEEP_DURATION, gtalk_e[1] - gtalk_s[1])
self.performance_results['ctime_chrome'] = \
pgutil.get_cpu_usage(SLEEP_DURATION, chrome_e[0] - chrome_s[0])
self.performance_results['stime_chrome'] = \
pgutil.get_cpu_usage(SLEEP_DURATION, chrome_e[1] - chrome_s[1])
# Verify log
pgutil.cleanup_playground(self.playground, True)
# Report perf