Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/clusterfuzz/_internal/bot/tasks/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _copy_testcase_to_device_and_setup_environment(testcase,
relative_testcase_file_path = (
testcase_file_path[len(local_testcases_directory) + 1:])
device_testcase_file_path = os.path.join(
android.constants.DEVICE_TESTCASES_DIR, relative_testcase_file_path)
android.app.get_testcases_directory(), relative_testcase_file_path)
android.adb.run_shell_command(['chmod', '0755', device_testcase_file_path])


Expand Down
4 changes: 2 additions & 2 deletions src/clusterfuzz/_internal/bot/testcase_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def convert_dependency_url_to_local_path(url):

# Convert remote to local path for android.
if environment.is_android():
remote_testcases_directory = android.constants.DEVICE_TESTCASES_DIR
remote_testcases_directory = android.app.get_testcases_directory()
local_testcases_directory = environment.get_value('FUZZ_INPUTS')
local_path = local_path.replace(remote_testcases_directory,
local_testcases_directory)
Expand Down Expand Up @@ -995,7 +995,7 @@ def get_command_line_for_application(file_to_run='',
apps_argument = environment.get_value('APPS_ARG')
crash_stacks_directory = environment.get_value('CRASH_STACKTRACES_DIR')
debugger = environment.get_value('DEBUGGER_PATH')
device_testcases_directory = android.constants.DEVICE_TESTCASES_DIR
device_testcases_directory = android.app.get_testcases_directory()
fuzzer_directory = environment.get_value('FUZZER_DIR')
extension_argument = environment.get_value('EXTENSION_ARG')
input_directory = environment.get_value('INPUT_DIR')
Expand Down
9 changes: 7 additions & 2 deletions src/clusterfuzz/_internal/platforms/android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from clusterfuzz._internal.system import environment

from . import adb
from . import constants

AAPT_CMD_TIMEOUT = 60
CHROME_CACHE_DIRS = [
Expand Down Expand Up @@ -53,7 +52,7 @@ def get_launch_command(app_args, testcase_path, testcase_file_url):
application_launch_command = application_launch_command.replace(
'%APP_ARGS%', app_args)
application_launch_command = application_launch_command.replace(
'%DEVICE_TESTCASES_DIR%', constants.DEVICE_TESTCASES_DIR)
'%DEVICE_TESTCASES_DIR%', get_testcases_directory())
application_launch_command = application_launch_command.replace(
'%PKG_NAME%', package_name)
application_launch_command = application_launch_command.replace(
Expand Down Expand Up @@ -93,6 +92,12 @@ def get_package_name(apk_path=None):
return match.group(1)


def get_testcases_directory():
"""Returns the testcases directory."""
package_name = get_package_name() or ''
return f'/sdcard/Android/data/{package_name}/files'
Comment thread
decoNR marked this conversation as resolved.


def install(package_apk_path: str, **kwargs):
"""Install a package from an apk path.

Expand Down
3 changes: 0 additions & 3 deletions src/clusterfuzz/_internal/platforms/android/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import re

DEVICE_DOWNLOAD_DIR = '/sdcard/Download'

DEVICE_TESTCASES_DIR = '/sdcard/fuzzer-testcases'

DEVICE_TMP_DIR = '/data/local/tmp'

# Directory to keep fuzzing artifacts for grey-box fuzzers e.g. corpus.
Expand Down
5 changes: 3 additions & 2 deletions src/clusterfuzz/_internal/platforms/android/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def clear_temp_directories():

def clear_testcase_directory():
"""Clears testcase directory."""
adb.remove_directory(constants.DEVICE_TESTCASES_DIR, recreate=True)
# Use wildcard to delete contents only, preserving the directory itself
adb.run_shell_command(f'rm -rf {app.get_testcases_directory()}/*', root=True)


def configure_device_settings():
Expand Down Expand Up @@ -442,7 +443,7 @@ def push_testcases_to_device():
return

adb.copy_local_directory_to_remote(local_testcases_directory,
constants.DEVICE_TESTCASES_DIR)
app.get_testcases_directory())


def reboot():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from clusterfuzz._internal.build_management import build_manager
from clusterfuzz._internal.crash_analysis.crash_result import CrashResult
from clusterfuzz._internal.datastore import data_types
from clusterfuzz._internal.platforms import android
from clusterfuzz._internal.protos import uworker_msg_pb2
from clusterfuzz._internal.system import environment
from clusterfuzz._internal.tests.test_libs import helpers as test_helpers
Expand Down Expand Up @@ -252,10 +253,11 @@ def setUp(self):
def test_file_match_android(self):
"""Tests matching a file URL."""
self.mock.platform.return_value = 'ANDROID'
testcases_dir = android.app.get_testcases_directory()
self.assertEqual(
'/mnt/scratch0/test.html',
testcase_manager.convert_dependency_url_to_local_path(
'file:///sdcard/fuzzer-testcases/test.html'))
f'file://{testcases_dir}/test.html'))
self.mock.normalize_path.assert_called_once_with('/mnt/scratch0/test.html')

def test_file_match_linux(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,23 @@ def test_install_with_valued_flags(self):
app.install('/path/to/app.apk', abi='x86', no_streaming=True)
self.mock_run_command.assert_called_once_with(
['install', '-r', '--abi', 'x86', '--no-streaming', '/path/to/app.apk'])


class GetTestcasesDirectoryTest(TestCase):
Comment thread
IvanBM18 marked this conversation as resolved.
"""Tests constants.get_testcases_directory."""

def setUp(self):
super().setUp()
helpers.patch_environ(self)

def test_get_testcases_directory(self):
"""Tests get_testcases_directory when package name is set."""
environment.set_value('PKG_NAME', 'com.google.chrome')
self.assertEqual(app.get_testcases_directory(),
'/sdcard/Android/data/com.google.chrome/files')

def test_get_testcases_directory_no_package_name(self):
"""Tests get_testcases_directory when package name is not set returns malformed string."""
environment.set_value('PKG_NAME', None)
self.assertEqual(app.get_testcases_directory(),
'/sdcard/Android/data//files')
Loading