cros: Upload command stats in parallel.

Add background command stats uploading functionality to CrosCommand
instances.

The functionality is disabled by default, and can be enabled by
overriding the 'upload_stats' property.  Also adds a
'upload_stats_timeout' property to allow customization of the timeout.

The timeout for stats uploading is set at 1 second, which provides for a
fair bit of margin.  From manual timing, upload_command_stats takes
between 0.35s-0.45s in MTV.

BUG=None
TEST=Ran 'cros chrome-sdk' and verified stats were uploading.

Change-Id: I09cf4c005c80aa2464981266d44c0055e0e295ab
Reviewed-on: https://gerrit.chromium.org/gerrit/47088
Commit-Queue: Ryan Cui <rcui@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Ryan Cui <rcui@chromium.org>
diff --git a/scripts/cros_unittest.py b/scripts/cros_unittest.py
new file mode 100755
index 0000000..42b967b
--- /dev/null
+++ b/scripts/cros_unittest.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+# Copyright (c) 2013 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
+import sys
+
+sys.path.insert(0, os.path.abspath('%s/../..' % os.path.dirname(__file__)))
+from chromite.lib import cros_test_lib
+from chromite.lib import stats
+from chromite.lib import stats_unittest
+from chromite.scripts import cros
+
+
+# pylint: disable=W0212
+
+
+class RunScriptTest(cros_test_lib.MockTempDirTestCase):
+  """Test the main functionality."""
+
+  def setUp(self):
+    self.StartPatcher(stats_unittest.StatsModuleMock())
+    self.PatchObject(cros, '_RunSubCommand', autospec=True)
+
+  def testStatsUpload(self):
+    """Test stats uploading."""
+    return_value = cros.main(['chrome-sdk', '--board', 'lumpy'])
+    self.assertEquals(stats.StatsUploader._Upload.call_count, 1)
+    self.assertEquals(return_value, 0)
+
+
+if __name__ == '__main__':
+  cros_test_lib.main()