def test(self): """Tests copy_local_directory_to_remote.""" utils.write_data_to_file('a', os.path.join(self.local_temp_dir, 'a')) shell.create_directory(os.path.join(self.local_temp_dir, 'b')) utils.write_data_to_file('c', os.path.join(self.local_temp_dir, 'b', 'c')) adb.copy_local_directory_to_remote(self.local_temp_dir, self.device_temp_dir) self.assertTrue(adb.file_exists(os.path.join(self.device_temp_dir, 'a'))) self.assertFalse( adb.directory_exists(os.path.join(self.device_temp_dir, 'a'))) self.assertEqual( adb.get_file_size(os.path.join(self.device_temp_dir, 'a')), 1) self.assertTrue( adb.directory_exists(os.path.join(self.device_temp_dir, 'b'))) self.assertFalse(adb.file_exists(os.path.join(self.device_temp_dir, 'b'))) self.assertTrue( adb.file_exists(os.path.join(self.device_temp_dir, 'b', 'c'))) self.assertFalse( adb.directory_exists(os.path.join(self.device_temp_dir, 'b', 'c'))) self.assertEqual( adb.get_file_size(os.path.join(self.device_temp_dir, 'b', 'c')), 1)
def test_regular_file(self): """Test that checksum is properly calculated for regular files.""" adb.write_data_to_file('abcd', '/sdcard/file1') self.assertTrue(adb.file_exists('/sdcard/file1')) self.assertEqual( adb.get_file_checksum('/sdcard/file1'), 'e2fc714c4727ee9395f324cd2e7f331f')
def test(self): """Test that ASan instrumentation can be successfully set up on device.""" adb.revert_asan_device_setup_if_needed() environment.reset_current_memory_tool_options() sanitizer.setup_asan_if_needed() self.assertEqual(0, self.mock.log_error.call_count) self.assertTrue(adb.file_exists("/system/bin/asanwrapper"))
def test_copy_local_directory_to_remote(self): """Tests copy_local_directory_to_remote.""" utils.write_data_to_file('a', os.path.join(self.local_temp_dir, 'a')) shell.create_directory_if_needed(os.path.join(self.local_temp_dir, 'b')) utils.write_data_to_file('c', os.path.join(self.local_temp_dir, 'b', 'c')) adb.copy_local_directory_to_remote(self.local_temp_dir, self.device_temp_dir) self.assertTrue( adb.file_exists(os.path.join(self.device_temp_dir, 'a'))) self.assertTrue( adb.directory_exists(os.path.join(self.device_temp_dir, 'b'))) self.assertTrue( adb.file_exists(os.path.join(self.device_temp_dir, 'b', 'c')))
def test_file_exists(self): """Tests file_exists.""" utils.write_data_to_file('a', os.path.join(self.local_temp_dir, 'a')) shell.create_directory(os.path.join(self.local_temp_dir, 'b')) utils.write_data_to_file('c', os.path.join(self.local_temp_dir, 'b', 'c')) adb.copy_local_directory_to_remote(self.local_temp_dir, self.device_temp_dir) existent_file_path_remote = os.path.join(self.device_temp_dir, 'a') existent_directory_path_remote = os.path.join(self.device_temp_dir, 'b') non_existent_file_path_remote = os.path.join(self.device_temp_dir, 'd') non_existent_directory_path_remote = os.path.join(self.device_temp_dir, 'e') self.assertTrue(adb.file_exists(existent_file_path_remote)) self.assertFalse(adb.file_exists(existent_directory_path_remote)) self.assertFalse(adb.file_exists(non_existent_file_path_remote)) self.assertFalse(adb.file_exists(non_existent_directory_path_remote))
def setup_memory_monitor_script_if_needed(): """Run check_process_mem.sh to monitor the memory usage""" # The script should only start if this is a low end device. device_codename = environment.get_value('DEVICE_CODENAME', get_codename()) if device_codename not in MEMORY_CONSTRAINED_DEVICES: return adb.run_as_root() if get_pid_for_script(MEMORY_MONITOR_SCRIPT): # The script is already running, no work to do. return android_directory = environment.get_platform_resources_directory() script_host_path = os.path.join(android_directory, MEMORY_MONITOR_SCRIPT) script_device_path = os.path.join(adb.DEVICE_TMP_DIR, MEMORY_MONITOR_SCRIPT) # Push memory monitor script onto device and make it executable (if needed). if not adb.file_exists(script_device_path): adb.run_adb_command(['push', script_host_path, adb.DEVICE_TMP_DIR]) adb.run_adb_shell_command(['chmod', '0755', script_device_path]) # Run the memory monitor script. adb.run_adb_shell_command('sh %s 2>/dev/null 1>/dev/null &' % script_device_path) # Wait one second to allow the script to run. time.sleep(1) # Change the priority of the process so that it will not be easily killed # by lowmemorykiller. pid = get_pid_for_script(MEMORY_MONITOR_SCRIPT) if not pid: logs.log_error('Memory monitor script failed to run.') return adb.run_adb_shell_command('echo -1000 \\> /proc/%s/oom_score_adj' % pid) adb.run_adb_shell_command('echo 0 \\> /proc/%s/oom_score' % pid) adb.run_adb_shell_command('echo -17 \\> /proc/%s/oom_adj' % pid)
def test_nonexistent_file(self): """Tests that checksum is None for a non-existent file.""" self.assertFalse(adb.file_exists('/sdcard/non-existent')) self.assertIsNone(adb.get_file_checksum('/sdcard/non-existent'))
def test_regular_file(self): """Test that file size is properly calculated for regular files.""" adb.write_data_to_file('abcd', '/sdcard/file1') self.assertTrue(adb.file_exists('/sdcard/file1')) self.assertEqual(adb.get_file_size('/sdcard/file1'), 4)
def test_unsupported(self): """Test that options are not set with an unsupported sanitizer e.g. UBSan, MSan, etc.""" sanitizer.set_options("UBSAN", "a=b:c=d") self.assertFalse(adb.file_exists("/data/local/tmp/ubsan.options")) self.assertEqual(1, self.mock.log_error.call_count)