Example #1
0
 def test_get_src_files(self):
     """
     Check filenames are extracted from the patches and also if it
     raises the UnrecognizedPatchFormat execption when the patch is not a
     git diff output.
     """
     patches_dir = os.path.join(self.db_dir, 'patches')
     patches = []
     for patch in sorted(os.listdir(patches_dir)):
         patches.append(os.path.join(patches_dir, patch))
     expected_value = {
         'fs/ext4/ext4.h',
         'fs/ext4/ext4_jbd2.h',
         'fs/ext4/inode.c',
         'fs/ext4/ioctl.c',
         'fs/xfs/xfs_log.c',
     }
     self.assertSequenceEqual(
         expected_value,
         targeted.get_src_files(patches),
     )
     with tempfile.NamedTemporaryFile() as tmpfile:
         tmpfile.write(b'Unrecognized format patch')
         tmpfile.flush()
         patches = [tmpfile.name]
         self.assertRaises(
             targeted.UnrecognizedPatchFormat,
             targeted.get_src_files,
             patches,
         )
Example #2
0
def get_test_cases(patches, dbdir):
    """
    Return test cases by querying layout according list of patch files.
    Args:
        patches: List of patches, they can be local files or remote urls
        dbdir:   Path to the kpet-db
    """
    tmpdir = tempfile.mkdtemp(suffix='kpet')
    try:
        patches = utils.patch2localfile(patches, tmpdir)
        src_files = targeted.get_src_files(patches)
        return sorted(targeted.get_test_cases(src_files, dbdir))
    finally:
        shutil.rmtree(tmpdir)
Example #3
0
def get_src_files(patches, pw_cookie=None):
    """
    Get the set of files modified by a list of patches.

    Args:
        patches:   List of patches, they can be local files or remote urls
        pw_cookie: Session cookie to Patchwork instance if login is required,
                   None otherwise
    """
    tmpdir = tempfile.mkdtemp(suffix='kpet')
    try:
        patches = misc.patch2localfile(patches, tmpdir, pw_cookie)
        return targeted.get_src_files(patches)
    finally:
        shutil.rmtree(tmpdir)
Example #4
0
def get_test_cases(patches, dbdir, pw_cookie=None):
    """
    Return test cases by querying layout according list of patch files.
    Args:
        patches:   List of patches, they can be local files or remote urls
        dbdir:     Path to the kpet-db
        pw_cookie: Session cookie to Patchwork instance if login is required,
                   None otherwise
    """
    tmpdir = tempfile.mkdtemp(suffix='kpet')
    try:
        patches = utils.patch2localfile(patches, tmpdir, pw_cookie)
        src_files = targeted.get_src_files(patches)
        return sorted(targeted.get_test_cases(src_files, dbdir))
    finally:
        shutil.rmtree(tmpdir)
Example #5
0
    def test_get_src_files(self):
        """
        Check filenames are extracted from the patches and also if it
        raises the UnrecognizedPatchFormat execption when the patch is not a
        git diff output.
        """
        patches_dir = os.path.join(os.path.dirname(__file__),
                                   'assets/patches/format_assortment')
        patches = []
        for patch in sorted(os.listdir(patches_dir)):
            patches.append(os.path.join(patches_dir, patch))
        expected_value = {
            'Kconfig',
            'fs/ext4/ext4.h',
            'fs/ext4/ext4_jbd2.h',
            'fs/ext4/inode.c',
            'fs/ext4/ioctl.c',
            'fs/xfs/xfs_log.c',
            'block/blk-core.c',
            'drivers/scsi/scsi_lib.c',
            'drivers/s390/scsi/zfcp_dbf.h',
            'drivers/s390/scsi/zfcp_fc.h',
            'drivers/s390/scsi/zfcp_fsf.h',
            'drivers/s390/scsi/zfcp_qdio.h',
            'drivers/s390/scsi/zfcp_reqlist.h',
            'lib/iomap.c',
            'lib/llist.c',
            'new_file',
            'Documentation/video-output.txt',
            'Documentation/video_output.txt',
        }
        self.assertSequenceEqual(
            expected_value,
            targeted.get_src_files(patches),
        )
        bad_patch_map = {
            # Empty
            b'':
            targeted.UnrecognizedPatchFormat,

            # No diff headers
            b'text':
            targeted.UnrecognizedPatchFormat,

            # Both files /dev/null
            b'--- /dev/null\n'
            b'+++ /dev/null':
            targeted.UnrecognizedPatchFormat,

            # Headers without files
            b'--- \n'
            b'+++ /dev/null':
            targeted.UnrecognizedPatchFormat,
            b'--- /dev/null\n'
            b'+++ ':
            targeted.UnrecognizedPatchFormat,

            # No directory
            b'--- abc\n'
            b'+++ ghi/jkl':
            targeted.UnrecognizedPatchPathFormat,
            b'--- abc/def\n'
            b'+++ jkl':
            targeted.UnrecognizedPatchPathFormat,

            # Directory diff
            b'--- abc/def\n'
            b'+++ ghi/jkl/':
            targeted.UnrecognizedPatchPathFormat,
            b'--- abc/def/\n'
            b'+++ ghi/jkl':
            targeted.UnrecognizedPatchPathFormat,

            # An absolute path to a file
            b'--- /abc/def\n'
            b'+++ ghi/jkl':
            targeted.UnrecognizedPatchPathFormat,
            b'--- abc/def\n'
            b'+++ /ghi/jkl':
            targeted.UnrecognizedPatchPathFormat,
        }
        for bad_patch, exception in bad_patch_map.items():
            with tempfile.NamedTemporaryFile() as bad_patch_file:
                bad_patch_file.write(bad_patch)
                bad_patch_file.flush()
                self.assertRaises(
                    exception,
                    targeted.get_src_files,
                    [bad_patch_file.name],
                )