예제 #1
0
 def test___init__python27_binary(self, mock_find_executable, mock_isfile,
                                  mock_os_environ):
     # pylint: disable=unused-argument
     python_dir = os.path.join("/root", "python27_dir")
     python27_path = os.path.join(python_dir, "python2")
     adb = adb_monitor.Adb(python27=python27_path)
     self.assertEqual(adb.python27, python27_path)
예제 #2
0
 def test_battery(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb.battery("myfile")
     battery_cmd = mock_runcmd.RunCommand.call_args_list[0][0][0]
     self.assertIn("--checkin", battery_cmd)
     self.assertNotIn("--reset", battery_cmd)
예제 #3
0
 def test_devices(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb.devices()
     mock_runcmd.RunCommand.assert_called_once_with("adb devices -l",
                                                    unittest.mock.ANY,
                                                    unittest.mock.ANY)
예제 #4
0
 def test_memory(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     memory_cmd = "shell dumpsys meminfo -c -d"
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb.memory("myfile")
     mock_runcmd.RunCommand.assert_called_once_with("adb " + memory_cmd,
                                                    unittest.mock.ANY,
                                                    unittest.mock.ANY)
예제 #5
0
 def test___init__adb_binary(self, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     adb_dir = os.path.join("/root", "adb_dir")
     adb_path = os.path.join(adb_dir, "adb")
     mock_os.environ = {"PATH": os.environ["PATH"]}
     mock_os.path.pathsep = os.path.pathsep
     mock_os.path.dirname = lambda x: x
     adb = adb_monitor.Adb(adb_binary=adb_path)
     self.assertTrue(adb.systrace_script.startswith(adb_dir))
     self.assertIn(os.path.pathsep + adb_dir, mock_os.environ["PATH"])
예제 #6
0
 def test__battery_cmd(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     option = "myopt"
     battery_cmd = "shell dumpsys batterystats " + option
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb._battery_cmd(option)
     mock_runcmd.RunCommand.assert_called_once_with("adb " + battery_cmd,
                                                    unittest.mock.ANY,
                                                    unittest.mock.ANY)
예제 #7
0
 def test_pull(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     files = "myfile"
     local_dir = "/localdir"
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb.pull(files, local_dir)
     pull_cmd = mock_runcmd.RunCommand.call_args_list[0][0][0]
     self.assertIn(files, pull_cmd)
     self.assertIn(local_dir, pull_cmd)
     self.assertNotIn("--sync", pull_cmd)
예제 #8
0
 def test___init__(self, mock_find_executable, mock_isfile):
     # pylint: disable=unused-argument
     os_path = os.environ["PATH"]
     adb = adb_monitor.Adb()
     self.assertTrue(
         adb.systrace_script.startswith(
             os.path.join("systrace", "systrace.py")))
     self.assertEqual(adb.logger, adb_monitor.LOGGER)
     self.assertEqual(adb.python27, adb_monitor.DEFAULT_PYTHON27)
     self.assertEqual(adb.logger, adb_monitor.LOGGER)
     self.assertEqual(os.environ["PATH"], os_path)
예제 #9
0
 def test_push_list(self, mock_runcmd, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     files = ["myfile", "file2"]
     remote_dir = "/remotedir"
     mock_os.path.dirname.return_value = "adb_dir"
     adb = adb_monitor.Adb()
     adb.push(files, remote_dir)
     push_cmd = mock_runcmd.RunCommand.call_args_list[0][0][0]
     self.assertIn(" ".join(files), push_cmd)
     self.assertIn(remote_dir, push_cmd)
     self.assertNotIn("--sync", push_cmd)
예제 #10
0
 def test_systrace_stop(self, mock_find_executable, mock_os):
     # pylint: disable=unused-argument
     mock_os.path.dirname.return_value = "adb_dir"
     systrace_script = "systrace.py"
     systrace_output = "Systrace: Wrote trace"
     mock_os.path.join.return_value = systrace_script
     adb = adb_monitor.Adb()
     adb._cmd = MagicMock()
     with patch(ADB_MONITOR + ".open",
                mock_open(read_data=systrace_output)):
         adb.systrace_stop()
     adb._cmd.send_to_process.assert_called_once_with(b"bye")
     mock_os.remove.assert_called_once_with(adb._tempfile)
예제 #11
0
    def __init__(self, logger, mongoebench_config_file, program_options=None):
        """Initialize the BenchrunEmbeddedTestCase with the executable to run."""

        interface.ProcessTestCase.__init__(self, logger,
                                           "Benchmark embedded test",
                                           mongoebench_config_file)
        parser.validate_benchmark_options()

        self.benchrun_config_file = mongoebench_config_file

        # Command line options override the YAML configuration.
        self.benchrun_executable = utils.default_if_none(
            _config.MONGOEBENCH_EXECUTABLE,
            _config.DEFAULT_MONGOEBENCH_EXECUTABLE)
        self.benchrun_repetitions = utils.default_if_none(
            _config.BENCHMARK_REPETITIONS,
            _config.DEFAULT_BENCHMARK_REPETITIONS)
        self.suite_benchrun_options = program_options
        self.benchrun_threads = 1
        if program_options and "threads" in program_options:
            self.benchrun_threads = program_options["threads"]
        self.report_root = _config.BENCHRUN_REPORT_ROOT
        self.benchrun_options = {}

        # Set the dbpath.
        dbpath = utils.default_if_none(_config.DBPATH_PREFIX,
                                       _config.DEFAULT_DBPATH_PREFIX)
        self.dbpath = os.path.join(dbpath, "mongoebench")

        self.android_device = _config.BENCHRUN_DEVICE == "Android"
        # If Android device, then the test runs via adb shell.
        if self.android_device:
            self.adb = adb_monitor.Adb()
            self.android_benchrun_root = _config.BENCHRUN_EMBEDDED_ROOT
            self.device_report_root = posixpath.join(
                self.android_benchrun_root, "results")
            self.dbpath = posixpath.join(self.android_benchrun_root, "db")
            self.benchrun_config_file = posixpath.join(
                self.android_benchrun_root, "testcases",
                os.path.basename(self.benchrun_config_file))
            ld_library_path = "LD_LIBRARY_PATH={}".format(
                posixpath.join(self.android_benchrun_root, "sdk"))
            mongoebench = posixpath.join(self.android_benchrun_root, "sdk",
                                         "mongoebench")
            self.benchrun_executable = "adb shell {} {}".format(
                ld_library_path, mongoebench)
예제 #12
0
 def __init__(self,
              hook_logger,
              fixture,
              sample_interval_ms=500,
              threads=1):
     """Initialize CollectEmbeddedResources."""
     interface.Hook.__init__(self, hook_logger, fixture,
                             CollectEmbeddedResources.DESCRIPTION)
     self.hook_logger = hook_logger
     self.adb = None
     self.adb_control = None
     if _config.BENCHRUN_DEVICE == "Android":
         self.report_root = _config.BENCHRUN_REPORT_ROOT
         self.sample_interval_ms = sample_interval_ms
         self.threads = threads
         self.battery_file = "battery.csv"
         self.cpu_file = "cpu.json"
         self.memory_file = "memory.csv"
         self.adb = adb_monitor.Adb(logger=hook_logger)
예제 #13
0
 def test_systrace_start(self, mock_runcmd, mock_find_executable, mock_os,
                         mock_tempfile):
     # pylint: disable=unused-argument
     mock_os.path.dirname.return_value = "adb_dir"
     systrace_script = "systrace.py"
     mock_os.path.join.return_value = systrace_script
     adb = adb_monitor.Adb()
     adb.systrace_start()
     mock_runcmd.RunCommand.assert_called_once_with(
         output_file=mock_tempfile().name, propagate_signals=False)
     self.assertEqual(adb.systrace_script, systrace_script)
     self.assertEqual(mock_runcmd.RunCommand().add_file.call_count, 3)
     mock_runcmd.RunCommand().add_file.assert_any_call(
         adb_monitor.DEFAULT_PYTHON27)
     mock_runcmd.RunCommand().add_file.assert_any_call(systrace_script)
     self.assertEqual(mock_runcmd.RunCommand().add.call_count, 3)
     mock_runcmd.RunCommand().add.assert_any_call("--json")
     mock_runcmd.RunCommand().add.assert_any_call("-o")
     mock_runcmd.RunCommand().add.assert_any_call(
         "dalvik sched freq idle load")
     mock_runcmd.RunCommand().start_process.assert_called_once()
예제 #14
0
def main():
    """Execute Main program."""

    logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s",
                        level=logging.INFO)
    logging.Formatter.converter = time.gmtime

    benchrun_root = "/data/local/tmp/benchrun_embedded"

    parser = optparse.OptionParser()
    program_options = optparse.OptionGroup(parser, "Program Options")
    device_options = optparse.OptionGroup(parser, "Device Options")
    sdk_options = optparse.OptionGroup(parser, "Embedded Test SDK Options")
    json_options = optparse.OptionGroup(parser, "JSON benchrun file Options")

    program_options.add_option(
        "--adbBinary",
        dest="adb_binary",
        help="The path for adb. Defaults to '%default', which is in $PATH.",
        default="adb")

    device_options.add_option(
        "--rootRemoteDir",
        dest="embedded_root_dir",
        help=
        "The remote root directory to store the files. Defaults to '%default'.",
        default=benchrun_root)

    device_options.add_option(
        "--dbDir",
        dest="db_dir",
        help=(
            "The remote dbpath directory used by mongoebench."
            " Will be created if it does not exist. Defaults to '%default'."),
        default=posixpath.join(benchrun_root, "db"))

    device_options.add_option(
        "--resultsDir",
        dest="results_dir",
        help=(
            "The remote directory to store the mongoebench results."
            " Will be created if it does not exist. Defaults to '%default'."),
        default=posixpath.join(benchrun_root, "results"))

    device_options.add_option(
        "--sdkRemoteDir",
        dest="sdk_remote_dir",
        help=
        "The remote directory to store the embedded SDK files. Defaults to '%default'.",
        default=posixpath.join(benchrun_root, "sdk"))

    device_options.add_option(
        "--benchrunJsonRemoteDir",
        dest="json_remote_dir",
        help="The remote directory to store the benchrun JSON files."
        " Defaults to '%default'.",
        default=posixpath.join(benchrun_root, "testcases"))

    sdk_url = "https://s3.amazonaws.com/mciuploads/mongodb-mongo-v4.0/embedded-sdk-test/embedded-sdk-android-arm64-latest.tgz"
    sdk_options.add_option(
        "--sdkUrl",
        dest="sdk_url",
        help=
        ("The embedded SDK test URL. This tarball must contain mongoebench and"
         " any required shared object (.so) libraries. Defaults to '%default'."
         ),
        default=sdk_url)

    sdk_options.add_option(
        "--sdkLocalDir",
        dest="sdk_local_dir",
        help="The local directory of embedded SDK files to be copied."
        "If specified, overrides --sdkUrl.",
        default=None)

    sdk_options.add_option(
        "--sdkSaveLocalDir",
        dest="sdk_save_local_dir",
        help=
        ("The local directory to save the downloaded embedded SDK as an unzipped tarball."
         " Only used if the embedded SDK tarball is downloaded. Note - this will delete"
         " the existing directory."),
        default=None)

    json_url = "https://s3.amazonaws.com/mciuploads/mongodb-mongo-v4.0/benchrun_embedded/benchrun_json_files.tgz"
    json_options.add_option(
        "--benchrunJsonUrl",
        dest="json_url",
        help=
        ("The benchrun JSON files URL. This tarball must contain all the JSON"
         " files to be used in the benchrun embedded test."
         " Defaults to '%default'."),
        default=json_url)

    json_options.add_option(
        "--benchrunJsonLocalDir",
        dest="json_local_dir",
        help="The local directory of benchrun JSON files to be copied."
        "If specified, overrides --benchrunJsonUrl.",
        default=None)

    json_options.add_option(
        "--benchrunJsonSaveLocalDir",
        dest="json_save_local_dir",
        help=
        ("The local directory to save the downloaded benchrun JSON as an unzipped tarball."
         " Only used if the benchrun JSON files tarball is downloaded. Note - this will"
         " delete the existing directory.  Defaults to '%default'."),
        default=os.path.join("benchrun_embedded", "testcases"))

    json_options.add_option(
        "--noBenchrunJsonSaveLocal",
        action="store_true",
        dest="no_json_save_local_dir",
        help=(
            "Disable saving downloaded benchrun JSON as an unzipped tarball."),
        default=False)

    parser.add_option_group(program_options)
    parser.add_option_group(device_options)
    parser.add_option_group(sdk_options)
    parser.add_option_group(json_options)
    options, _ = parser.parse_args()

    if options.no_json_save_local_dir:
        options.json_save_local_dir = None

    adb = adb_monitor.Adb(options.adb_binary)
    adb.device_available()
    LOGGER.info("Detected devices by adb:\n%s%s", adb.devices(),
                adb.device_available())

    # Create/empty remote directories.
    create_empty_remote_dirs(adb, [
        options.embedded_root_dir, options.db_dir, options.results_dir,
        options.sdk_remote_dir, options.json_remote_dir
    ])

    # Download, untar and push Embedded SDK Tests & Benchrun JSON files.
    # Unfortunately gunzip may not exist on the Android device, so we cannot use this remote command:
    #   curl URL | tar -xzv -C LOCAL_DIR

    if options.sdk_local_dir:
        push_directory_contents(adb, options.sdk_local_dir,
                                options.sdk_remote_dir)
    else:
        download_and_push(adb, options.sdk_url, options.sdk_remote_dir,
                          options.sdk_save_local_dir)
    move_sdk_files(adb, options.sdk_remote_dir)

    if options.json_local_dir:
        push_directory_contents(adb, options.json_local_dir,
                                options.json_remote_dir)
    else:
        download_and_push(adb, options.json_url, options.json_remote_dir,
                          options.json_save_local_dir)
예제 #15
0
 def setUpClass(cls):
     cls.temp_dir = tempfile.mkdtemp()
     mock_adb_and_systrace(cls.temp_dir)
     cls.adb = adb_monitor.Adb()
예제 #16
0
 def test___init__bad_systrace(self, mock_find_executable, mock_isfile,
                               mock_os_environ):
     # pylint: disable=unused-argument
     with self.assertRaises(EnvironmentError):
         adb_monitor.Adb()
예제 #17
0
 def test_bad_adb(self):
     self.assertRaises(EnvironmentError, lambda: adb_monitor.Adb("bad_adb"))