Ejemplo n.º 1
0
 def test_normalize_case(self):
     """Tests normalize case for windows."""
     if sys.platform.startswith('win'):
         self.assertEqual(
             utils.normalize_path('C:\\test\\test2\\test3'),
             # Notice that the path starts with a lowercase c.
             utils.normalize_path('c:\\test\\test2\\test3'))
     else:
         self.assertEqual('/mnt/Test', utils.normalize_path('/mnt/Test'))
Ejemplo n.º 2
0
def get_testcases_from_directories(directories):
    """Returns all testcases from testcase directories."""
    testcase_paths = []
    max_testcases = environment.get_value('MAX_TESTCASES')

    generators = []
    for directory in directories:
        if not directory.strip():
            continue

        generators.append(shell.walk(directory))

    for generator in generators:
        for structure in generator:
            base_directory = structure[0]
            for filename in structure[2]:
                if not filename.startswith(FUZZ_PREFIX):
                    continue

                if filename.endswith(COVERAGE_SUFFIX):
                    continue

                file_path = os.path.join(base_directory, filename)
                if not os.path.getsize(file_path):
                    continue

                testcase_paths.append(utils.normalize_path(file_path))
                if len(testcase_paths) == max_testcases:
                    return testcase_paths

    return testcase_paths
Ejemplo n.º 3
0
def convert_dependency_url_to_local_path(url):
    """Convert a dependency URL to a corresponding local path."""
    # Bot-specific import.
    from clusterfuzz._internal.bot.webserver import http_server

    logs.log('Process dependency: %s.' % url)
    file_match = FILE_URL_REGEX.search(url)
    http_match = HTTP_URL_REGEX.search(url)
    platform = environment.platform()

    local_path = None
    if file_match:
        file_path = file_match.group(1)
        logs.log('Detected file dependency: %s.' % file_path)
        if platform == 'WINDOWS':
            local_path = file_path
        else:
            local_path = '/' + file_path

            # Convert remote to local path for android.
            if environment.is_android():
                remote_testcases_directory = android.constants.DEVICE_TESTCASES_DIR
                local_testcases_directory = environment.get_value(
                    'FUZZ_INPUTS')
                local_path = local_path.replace(remote_testcases_directory,
                                                local_testcases_directory)

    elif http_match:
        relative_http_path = os.path.sep + http_match.group(2)
        logs.log('Detected http dependency: %s.' % relative_http_path)
        local_path = http_server.get_absolute_testcase_file(relative_http_path)
        if not local_path:
            # This needs to be a warning since in many cases, it is actually a
            # non-existent path. For others, we need to add the directory aliases in
            # file http_server.py.
            logs.log_warn('Unable to find server resource %s, skipping.' %
                          relative_http_path)

    if local_path:
        local_path = utils.normalize_path(local_path)

    return local_path
Ejemplo n.º 4
0
 def test_redundant_path(self):
     """Tests redundant paths."""
     self.assertEqual('/test/test2/test3',
                      utils.normalize_path('/test/./test2/test3'))
     self.assertEqual('/test/test2/test3',
                      utils.normalize_path('/test//test2/test3'))