Ejemplo n.º 1
0
    def test_shell(self):
        '''
        Test shell.
        '''
        # test running command and the command success (retcode 0)
        str_ret = textwrap.dedent('''\
                                  test_result
                                  0''')
        expected_ret = 'test_result'
        excepted_retcode = 0
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret, retcode = AdbWrapper.adb_shell('b2g-test')
        self.assertEqual(ret, expected_ret,
                         'The result should be {}, not {}.'.format(expected_ret, ret))
        self.assertEqual(retcode, excepted_retcode,
                         'The return code should be {}, not {}.'.format(excepted_retcode, retcode))

        # test running command and the command failed (retcode 1)
        str_ret = textwrap.dedent('''\
                                  test_result
                                  1''')
        expected_ret = 'test_result'
        not_excepted_retcode = 0
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret, retcode = AdbWrapper.adb_shell('b2g-test')
        self.assertEqual(ret, expected_ret,
                         'The result should be {}, not {}.'.format(expected_ret, ret))
        self.assertNotEqual(retcode, not_excepted_retcode,
                         'The return code cannot be {}, but it is.'.format(not_excepted_retcode))
Ejemplo n.º 2
0
    def get_crash(self):
        crash_info = self.fetch_crash_info()
        submitted = crash_info['submitted']
        pending = crash_info['pending']
        processed = set()
        for pendi in set(pending):
            # Get pending dump and submit
            dmp = pendi + ".dmp"
            extra = pendi + ".extra"
            AdbWrapper.adb_pull(PENDING_DIR + "/" + dmp, dmp, self.serial)
            AdbWrapper.adb_pull(PENDING_DIR + "/" + extra, extra, self.serial)

            ret = cli([dmp])
            if ret:
                processed.add(pendi)
                submitted.append(ret[0])
                AdbWrapper.adb_shell("rm \"" + PENDING_DIR + "/" + dmp + "\"",
                                     self.serial)
                AdbWrapper.adb_shell(
                    "rm \"" + PENDING_DIR + "/" + extra + "\"", self.serial)
                AdbWrapper.adb_shell("rm -r \"" + SUBMITTED_DIR + "\"",
                                     self.serial)
            os.remove(dmp)
            os.remove(extra)
        return {
            'crash_info': {
                'submitted': submitted,
                'pending': list(set(pending) - processed)
            }
        }
 def launch_execute_file(self):
     working_dir = os.path.join(self.DEFAULT_ROOT_TMP_DIR, self.DEFAULT_ROOT_OUTPUT_DIR, self.fuzzer_name)
     cmd_format = "cd %s; bash %s 2>&1 > %s"
     execution_log_dir = os.path.join(self.working_dir, self.DEFAULT_ROOT_LOG_DIR, self.fuzzer_name)
     if os.path.exists(execution_log_dir) is False:
         os.makedirs(execution_log_dir)
     execution_log_path = os.path.join(execution_log_dir, self.DEFAULT_EXEC_LOG_NAME)
     cmd_str = cmd_format % (working_dir, self.DEFAULT_LAUNCH_SCRIPT_FILE_NAME, execution_log_path)
     adb_obj = AdbWrapper()
     adb_obj.adb_forward(local="tcp:2828", remote="tcp:2828")
     os.system(cmd_str)
Ejemplo n.º 4
0
 def test_wait_for_device(self):
     """
     test wait-fot-device.
     """
     # wait 1 second
     def func():
         import time
         time.sleep(1)
         return ['', None]
     self.mock_obj.communicate = func
     self.mock_popen.return_value = self.mock_obj
     # test timeout is 0.1, should raise exception
     with self.assertRaises(Exception) as cm:
         ret = AdbWrapper.adb_wait_for_device(timeout=0.1)
     # test timeout is 10, should pass
     ret = AdbWrapper.adb_wait_for_device(timeout=10)
     self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 5
0
 def test_root_faile(self):
     """
     Test root fail.
     """
     str_ret = 'adbd cannot run as root in production builds'
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_root()
     self.assertFalse(ret, 'The result should be False.')
Ejemplo n.º 6
0
 def test_forward_remove(self):
     """
     test remove a forward
     """
     str_ret = textwrap.dedent('')
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_forward(command='remove', local='tcp:2828')
     self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 7
0
 def test_root_faile(self):
     '''
     Test root fail.
     '''
     str_ret = 'adbd cannot run as root in production builds'
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_root()
     self.assertFalse(ret, 'The result should be False.')
Ejemplo n.º 8
0
 def launch_execute_file(self):
     working_dir = os.path.join(self.DEFAULT_ROOT_TMP_DIR,
                                self.DEFAULT_ROOT_OUTPUT_DIR,
                                self.fuzzer_name)
     cmd_format = "cd %s; bash %s 2>&1 > %s"
     execution_log_dir = os.path.join(self.working_dir,
                                      self.DEFAULT_ROOT_LOG_DIR,
                                      self.fuzzer_name)
     if os.path.exists(execution_log_dir) is False:
         os.makedirs(execution_log_dir)
     execution_log_path = os.path.join(execution_log_dir,
                                       self.DEFAULT_EXEC_LOG_NAME)
     cmd_str = cmd_format % (working_dir,
                             self.DEFAULT_LAUNCH_SCRIPT_FILE_NAME,
                             execution_log_path)
     adb_obj = AdbWrapper()
     adb_obj.adb_forward(local="tcp:2828", remote="tcp:2828")
     os.system(cmd_str)
Ejemplo n.º 9
0
 def test_forward_remove_no_dest(self):
     """
     test remove a forward by wrong argv
     """
     str_ret = textwrap.dedent('')
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_forward(command='remove', remote='tcp:2828')
     self.assertFalse(ret, 'The result should be False.')
Ejemplo n.º 10
0
    def test_remount_fail(self):
        """
        Test remount fail.
        """
        str_ret = textwrap.dedent("""\
                                  error: device offline
                                  """)
        # return code is 0, but no "remount succeeded" message will return False.
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_remount()
        self.assertFalse(ret, 'The result should be False.')

        # return code is not 0 will raise exception
        with self.assertRaises(Exception) as cm:
            self.mock_obj.returncode = 1
            self.mock_obj.communicate.return_value = [str_ret, None]
            self.mock_popen.return_value = self.mock_obj
            ret = AdbWrapper.adb_remount()
Ejemplo n.º 11
0
 def test_push_fail(self):
     """
     Test push fail.
     """
     str_ret = 'failed to copy \'foo\' to \'bar\': No such file or directory'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_push('foo', 'bar')
Ejemplo n.º 12
0
    def test_remount_fail(self):
        """
        Test remount fail.
        """
        str_ret = textwrap.dedent("""\
                                  error: device offline
                                  """)
        # return code is 0, but no "remount succeeded" message will return False.
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_remount()
        self.assertFalse(ret, 'The result should be False.')

        # return code is not 0 will raise exception
        with self.assertRaises(Exception) as cm:
            self.mock_obj.returncode = 1
            self.mock_obj.communicate.return_value = [str_ret, None]
            self.mock_popen.return_value = self.mock_obj
            ret = AdbWrapper.adb_remount()
Ejemplo n.º 13
0
 def test_shell_fail(self):
     '''
     Test shell fail.
     '''
     str_ret = 'error: device not found'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_shell('foo')
Ejemplo n.º 14
0
    def test_wait_for_device(self):
        """
        test wait-fot-device.
        """

        # wait 1 second
        def func():
            import time
            time.sleep(1)
            return ['', None]

        self.mock_obj.communicate = func
        self.mock_popen.return_value = self.mock_obj
        # test timeout is 0.1, should raise exception
        with self.assertRaises(Exception) as cm:
            ret = AdbWrapper.adb_wait_for_device(timeout=0.1)
        # test timeout is 10, should pass
        ret = AdbWrapper.adb_wait_for_device(timeout=10)
        self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 15
0
 def test_shell_fail(self):
     """
     Test shell fail.
     """
     str_ret = 'error: device not found'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_shell('foo')
Ejemplo n.º 16
0
 def test_pull_fail(self):
     '''
     Test pull fail.
     '''
     str_ret = 'remote object \'foo\' does not exist'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_pull('foo', '')
Ejemplo n.º 17
0
 def test_pull_fail(self):
     """
     Test pull fail.
     """
     str_ret = 'remote object \'foo\' does not exist'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_pull('foo', '')
Ejemplo n.º 18
0
 def test_push_fail(self):
     '''
     Test push fail.
     '''
     str_ret = 'failed to copy \'foo\' to \'bar\': No such file or directory'
     with self.assertRaises(Exception) as cm:
         self.mock_obj.returncode = 1
         self.mock_obj.communicate.return_value = [str_ret, None]
         self.mock_popen.return_value = self.mock_obj
         ret = AdbWrapper.adb_push('foo', 'bar')
Ejemplo n.º 19
0
 def test_remount(self):
     """
     Test remount.
     """
     str_ret = textwrap.dedent("""\
                               remount succeeded
                               """)
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_remount()
     self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 20
0
    def test_root(self):
        """
        Test root.
        """
        # test adb already running as root
        str_ret = 'adbd is already running as root'
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_root()
        self.assertTrue(ret, 'The result should be True')

        # test adb not running, then running as root
        str_ret = textwrap.dedent("""\
                                  * daemon not running. starting it now on port 5037 *
                                  * daemon started successfully *
                                  adbd is already running as root""")
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_root()
        self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 21
0
 def test_push(self):
     '''
     Test push.
     '''
     str_ret = '2 KB/s (104 bytes in 0.040s)'
     expected_ret = '2 KB/s (104 bytes in 0.040s)'
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_push('mozilla.test', '/b2g/mozilla.test')
     self.assertEqual(ret, expected_ret,
                      'The result should be {}, not {}.'.format(expected_ret, ret))
Ejemplo n.º 22
0
 def test_remount(self):
     """
     Test remount.
     """
     str_ret = textwrap.dedent("""\
                               remount succeeded
                               """)
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_remount()
     self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 23
0
 def test_no_device(self):
     '''
     Test no device.
     '''
     str_ret = 'List of devices attached\n\r'
     expected_ret = {}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(devices, expected_ret,
                      'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 24
0
    def test_root(self):
        '''
        Test root.
        '''
        # test adb already running as root
        str_ret = 'adbd is already running as root'
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_root()
        self.assertTrue(ret, 'The result should be True')

        # test adb not running, then running as root
        str_ret = textwrap.dedent('''\
                                  * daemon not running. starting it now on port 5037 *
                                  * daemon started successfully *
                                  adbd is already running as root''')
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret = AdbWrapper.adb_root()
        self.assertTrue(ret, 'The result should be True.')
Ejemplo n.º 25
0
 def test_push(self):
     """
     Test push.
     """
     str_ret = '2 KB/s (104 bytes in 0.040s)'
     expected_ret = '2 KB/s (104 bytes in 0.040s)'
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     ret = AdbWrapper.adb_push('mozilla.test', '/b2g/mozilla.test')
     self.assertEqual(
         ret, expected_ret,
         'The result should be {}, not {}.'.format(expected_ret, ret))
Ejemplo n.º 26
0
 def test_no_device(self):
     """
     Test no device.
     """
     str_ret = 'List of devices attached\n\r'
     expected_ret = {}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(
         devices, expected_ret,
         'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 27
0
 def test_one_device(self):
     '''
     Test one device.
     '''
     str_ret = textwrap.dedent('''\
                               List of devices attached
                               foo\tbar''')
     expected_ret = {'foo': 'bar'}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(devices, expected_ret,
                      'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 28
0
 def test_two_device(self):
     """
     Test two device.
     """
     str_ret = textwrap.dedent("""\
                               List of devices attached
                               foo\tbar
                               askeing\tcool""")
     expected_ret = {'foo': 'bar', 'askeing': 'cool'}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(devices, expected_ret,
                      'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 29
0
 def test_one_device(self):
     """
     Test one device.
     """
     str_ret = textwrap.dedent("""\
                               List of devices attached
                               foo\tbar""")
     expected_ret = {'foo': 'bar'}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(
         devices, expected_ret,
         'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 30
0
    def test_shell(self):
        """
        Test shell.
        """
        # test running command and the command success (retcode 0)
        str_ret = textwrap.dedent("""\
                                  test_result
                                  0""")
        expected_ret = 'test_result'
        excepted_retcode = 0
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret, retcode = AdbWrapper.adb_shell('b2g-test')
        self.assertEqual(
            ret, expected_ret,
            'The result should be {}, not {}.'.format(expected_ret, ret))
        self.assertEqual(
            retcode, excepted_retcode,
            'The return code should be {}, not {}.'.format(
                excepted_retcode, retcode))

        # test running command and the command failed (retcode 1)
        str_ret = textwrap.dedent("""\
                                  test_result
                                  1""")
        expected_ret = 'test_result'
        not_excepted_retcode = 0
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        ret, retcode = AdbWrapper.adb_shell('b2g-test')
        self.assertEqual(
            ret, expected_ret,
            'The result should be {}, not {}.'.format(expected_ret, ret))
        self.assertNotEqual(
            retcode, not_excepted_retcode,
            'The return code cannot be {}, but it is.'.format(
                not_excepted_retcode))
Ejemplo n.º 31
0
    def get_crash(self):
        crash_info = self.fetch_crash_info()
        submitted = crash_info['submitted']
        pending = crash_info['pending']
        processed = set()
        for pendi in set(pending):
            # Get pending dump and submit
            dmp = pendi + ".dmp"
            extra = pendi + ".extra"
            AdbWrapper.adb_pull(PENDING_DIR + "/" + dmp,
                                dmp,
                                self.serial)
            AdbWrapper.adb_pull(PENDING_DIR + "/" + extra,
                                extra,
                                self.serial)

            ret = cli([dmp])
            if ret:
                processed.add(pendi)
                submitted.append(ret[0])
                AdbWrapper.adb_shell("rm \""
                                     + PENDING_DIR
                                     + "/" + dmp + "\"",
                                     self.serial)
                AdbWrapper.adb_shell("rm \""
                                     + PENDING_DIR
                                     + "/" + extra + "\"",
                                     self.serial)
                AdbWrapper.adb_shell("rm -r \""
                                     + SUBMITTED_DIR + "\"",
                                     self.serial)
            os.remove(dmp)
            os.remove(extra)
        return {'crash_info': {
                'submitted': submitted,
                'pending': list(set(pending) - processed)}}
Ejemplo n.º 32
0
 def test_two_device(self):
     '''
     Test two device.
     '''
     str_ret = textwrap.dedent('''\
                               List of devices attached
                               foo\tbar
                               askeing\tcool''')
     expected_ret = {'foo': 'bar', 'askeing': 'cool'}
     self.mock_obj.communicate.return_value = [str_ret, None]
     self.mock_popen.return_value = self.mock_obj
     devices = AdbWrapper.adb_devices()
     self.assertEqual(
         devices, expected_ret,
         'The result should be {}, not {}.'.format(expected_ret, devices))
Ejemplo n.º 33
0
    def test_forward_list(self):
        """
        test forward --list
        """
        str_ret = textwrap.dedent("""\
e481d888 tcp:49662 tcp:2828
e479da98 tcp:57988 tcp:2828
e47cd830 tcp:45784 tcp:2828
e47cd887 tcp:41946 tcp:2828
7ed3ca11 tcp:39961 tcp:2828
""")
        expected_ret = {'e481d888': {'source': 'tcp:49662', 'dest': 'tcp:2828'},
                        'e479da98': {'source': 'tcp:57988', 'dest': 'tcp:2828'},
                        'e47cd830': {'source': 'tcp:45784', 'dest': 'tcp:2828'},
                        'e47cd887': {'source': 'tcp:41946', 'dest': 'tcp:2828'},
                        '7ed3ca11': {'source': 'tcp:39961', 'dest': 'tcp:2828'}}
        self.mock_obj.communicate.return_value = [str_ret, None]
        self.mock_popen.return_value = self.mock_obj
        fwd_list = AdbWrapper.adb_forward(command='list')
        self.assertEqual(fwd_list, expected_ret,
                         'The result should be {}, not {}.'.format(expected_ret, fwd_list))
Ejemplo n.º 34
0
    'serial': "",
    'job_info': {
        'jobname': 'flamekk.vmaster.moztwlab01.512',
        'seriesname': 'mtbf',
        'pid': 18845,
        'program': "chrome",
        'host_name': "mtbf-10",
        'port_no': 8086,
        'user_name': "xxxxxx",
        'pwd': "xxxxxx",
        'database_name': "raptor"
    }
}

# FIXME: with following workaround we still need at least one device connected
devices = AdbWrapper.adb_devices().keys()
testdata['serial'] = devices[0]
mini = MtbfToRaptorMinion(**testdata)


def test_generate_raptor_mtbf_data():
    data = mini.output_data['mtbf']['data'] = mini.generate_raptor_mtbf_data()
    assert (data['mtbf'][0]['deviceId'] == testdata['serial'])


def test_generate_raptor_event_data():
    mini.output_data['events']['data'] = mini.generate_raptor_event_data(
        mini.output_data['mtbf']['data'])
    data = mini.output_data['events']['data']
    assert (data['events'][0]['device'] == testdata['job_info']
            ['jobname'].split(".")[0])
Ejemplo n.º 35
0
                       'file': "unittest"},
            'serial': "",
            'job_info': {
                'jobname': 'flamekk.vmaster.moztwlab01.512',
                'seriesname': 'mtbf',
                'pid': 18845,
                'program': "chrome",
                'host_name': "mtbf-10",
                'port_no': 8086,
                'user_name': "xxxxxx",
                'pwd': "xxxxxx",
                'database_name': "raptor"
            }}

# FIXME: with following workaround we still need at least one device connected
devices = AdbWrapper.adb_devices().keys()
testdata['serial'] = devices[0]
mini = MtbfToRaptorMinion(**testdata)


def test_generate_raptor_mtbf_data():
    data = mini.output_data['mtbf']['data'] = mini.generate_raptor_mtbf_data()
    assert(data['mtbf'][0]['deviceId'] == testdata['serial'])


def test_generate_raptor_event_data():
    mini.output_data['events']['data'] = mini.generate_raptor_event_data(
        mini.output_data['mtbf']['data'])
    data = mini.output_data['events']['data']
    assert(data['events'][0]['device']
           == testdata['job_info']['jobname'].split(".")[0])