]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
oe-selftest: devtool: add test for multiple source trees
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Tue, 28 Nov 2017 02:16:26 +0000 (15:16 +1300)
committerPaul Eggleton <paul.eggleton@linux.intel.com>
Tue, 5 Dec 2017 01:39:24 +0000 (14:39 +1300)
Add two synthetic tests for devtool modify + devtool finish: first with
multiple source trees side-by-side, and second to test with one as a
subdirectory of the main source tree. These also test devtool finish's
recently added dry-run option and that detects and errors on uncommitted
changes without being forced.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
meta-selftest/recipes-test/devtool/devtool-test-multisrc-subdir_1.0.bb [new file with mode: 0644]
meta-selftest/recipes-test/devtool/devtool-test-multisrc/example-files.tar.gz [new file with mode: 0644]
meta-selftest/recipes-test/devtool/devtool-test-multisrc/example.patch [new file with mode: 0644]
meta-selftest/recipes-test/devtool/devtool-test-multisrc/mypackage-1.0.tar.gz [new file with mode: 0644]
meta-selftest/recipes-test/devtool/devtool-test-multisrc_1.0.bb [new file with mode: 0644]
meta/lib/oeqa/selftest/cases/devtool.py

diff --git a/meta-selftest/recipes-test/devtool/devtool-test-multisrc-subdir_1.0.bb b/meta-selftest/recipes-test/devtool/devtool-test-multisrc-subdir_1.0.bb
new file mode 100644 (file)
index 0000000..0430382
--- /dev/null
@@ -0,0 +1,13 @@
+SUMMARY = "Recipe to test multiple source trees"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://settings-daemon.c;beginline=1;endline=26;md5=8d77ba1c7a55df48d8d06c5f3d86b49d"
+
+SRC_URI = "git://git.yoctoproject.org/xsettings-daemon;name=xsettings-daemon \
+           git://git.yoctoproject.org/libfakekey;name=libfakekey;destsuffix=git/libfakekey \
+"
+
+SRCREV_xsettings-daemon = "b2e5da502f8c5ff75e9e6da771372ef8e40fd9a2"
+SRCREV_libfakekey = "7ad885912efb2131e80914e964d5e635b0d07b40"
+
+S = "${WORKDIR}/git"
+
diff --git a/meta-selftest/recipes-test/devtool/devtool-test-multisrc/example-files.tar.gz b/meta-selftest/recipes-test/devtool/devtool-test-multisrc/example-files.tar.gz
new file mode 100644 (file)
index 0000000..fdab4b7
Binary files /dev/null and b/meta-selftest/recipes-test/devtool/devtool-test-multisrc/example-files.tar.gz differ
diff --git a/meta-selftest/recipes-test/devtool/devtool-test-multisrc/example.patch b/meta-selftest/recipes-test/devtool/devtool-test-multisrc/example.patch
new file mode 100644 (file)
index 0000000..2e48bf1
--- /dev/null
@@ -0,0 +1,7 @@
+diff -udNr example-files/test2 example-files2/test2
+--- example-files/test2        2017-11-22 10:29:11.766891385 +1300
++++ example-files2/test2       2017-11-22 10:30:08.920094705 +1300
+@@ -1 +1,3 @@
+ Another example file
++
++More content added here
diff --git a/meta-selftest/recipes-test/devtool/devtool-test-multisrc/mypackage-1.0.tar.gz b/meta-selftest/recipes-test/devtool/devtool-test-multisrc/mypackage-1.0.tar.gz
new file mode 100644 (file)
index 0000000..b513b28
Binary files /dev/null and b/meta-selftest/recipes-test/devtool/devtool-test-multisrc/mypackage-1.0.tar.gz differ
diff --git a/meta-selftest/recipes-test/devtool/devtool-test-multisrc_1.0.bb b/meta-selftest/recipes-test/devtool/devtool-test-multisrc_1.0.bb
new file mode 100644 (file)
index 0000000..2b81f83
--- /dev/null
@@ -0,0 +1,11 @@
+SUMMARY = "Recipe to test multiple source trees"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = "file://mypackage-${PV}.tar.gz \
+           file://example-files.tar.gz \
+           file://example.patch;patchdir=../example-files \
+"
+
+S = "${WORKDIR}/mypackage-${PV}"
+
index 96072be189c858ab1363adad82f0190439bfb4f6..b051b7c97b32eaf37affd7bd19bf40ad250c6e0b 100644 (file)
@@ -1568,6 +1568,115 @@ class DevtoolTests(DevtoolBase):
         if files:
             self.fail('Unexpected file(s) copied next to bbappend: %s' % ', '.join(files))
 
+    def test_devtool_finish_modify_multisrc(self):
+        # Check preconditions
+        self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
+        # Try modifying a recipe
+        self.track_for_cleanup(self.workspacedir)
+        recipe = 'devtool-test-multisrc'
+        recipefile = get_bb_var('FILE', recipe)
+        recipedir = os.path.dirname(recipefile)
+        result = runCmd('git status --porcelain .', cwd=recipedir)
+        if result.output.strip():
+            self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
+        tempdir = tempfile.mkdtemp(prefix='devtoolqa')
+        self.track_for_cleanup(tempdir)
+        self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
+        result = runCmd('devtool modify %s %s' % (recipe, tempdir))
+        mainsrc = os.path.join(tempdir, 'mypackage-1.0')
+        extrasrc = os.path.join(tempdir, 'example-files')
+        self.assertExists(os.path.join(mainsrc, 'mainfile.c'), 'Extracted main source tree could not be found')
+        self.assertExists(os.path.join(extrasrc, 'test2'), 'Extracted extra source tree could not be found')
+        # Try dry-run finishing without changes
+        result = runCmd('devtool finish %s meta-selftest -N' % recipe)
+        self.assertIn('No patches or files need updating', result.output)
+        # Make some changes to both the main and extra source trees
+        with open(os.path.join(mainsrc, 'mainfile.c'), 'a') as f:
+            f.write('\n/* Additional comment */\n')
+        result = runCmd('git commit -a -m "Add a comment"', cwd=mainsrc)
+        with open(os.path.join(extrasrc, 'test2'), 'a') as f:
+            f.write('\nAnother line\n')
+        result = runCmd('git commit -a -m "Add another line"', cwd=extrasrc)
+        # Try finishing now with dry-run to see if it reports what we expect
+        result = runCmd('devtool finish %s meta-selftest -N' % recipe)
+        self.assertNotIn('No patches or files need updating', result.output)
+        self.assertIn('+           file://0001-Add-a-comment.patch \\', result.output)
+        self.assertIn('+           file://0001-Add-another-line.patch;patchdir=../example-files \\', result.output)
+        self.assertNotIn('Removing', result.output)
+        # Now really finish
+        self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
+        result = runCmd('devtool finish %s meta-selftest' % recipe)
+        expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
+                           ('??', '.*/.*-Add-a-comment.patch$'),
+                           ('??', '.*/.*-Add-another-line.patch$')]
+        self._check_repo_status(recipedir, expected_status)
+
+    def test_devtool_finish_modify_multisrc_subdir(self):
+        # Check preconditions
+        self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
+        # Try modifying a recipe
+        self.track_for_cleanup(self.workspacedir)
+        recipe = 'devtool-test-multisrc-subdir'
+        recipefile = get_bb_var('FILE', recipe)
+        recipedir = os.path.dirname(recipefile)
+        result = runCmd('git status --porcelain .', cwd=recipedir)
+        if result.output.strip():
+            self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
+        tempdir = tempfile.mkdtemp(prefix='devtoolqa')
+        self.track_for_cleanup(tempdir)
+        self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
+        result = runCmd('devtool modify %s %s' % (recipe, tempdir))
+        mainsrc = tempdir
+        extrasrc = os.path.join(tempdir, 'libfakekey')
+        self.assertExists(os.path.join(mainsrc, 'xsettings-client.c'), 'Extracted main source tree could not be found')
+        self.assertExists(os.path.join(extrasrc, 'configure.ac'), 'Extracted extra source tree could not be found')
+        # Try dry-run finishing without changes
+        result = runCmd('devtool finish %s meta-selftest -N' % recipe)
+        self.assertIn('No patches or files need updating', result.output)
+        # Make some changes to both the main and extra source trees
+        with open(os.path.join(mainsrc, 'xsettings-client.c'), 'a') as f:
+            f.write('\n/* Additional comment */\n')
+        result = runCmd('git commit -a -m "Add a comment"', cwd=mainsrc)
+        with open(os.path.join(extrasrc, 'README'), 'a') as f:
+            f.write('\nAnother line\n')
+        result = runCmd('git commit -a -m "Add another line to README"', cwd=extrasrc)
+        # Try finishing now with dry-run to see if it reports what we expect
+        # However, the first time it will fail because git treats sub-repositories
+        # the same as submodules, so the parent will appear to have uncommitted changes
+        failed = False
+        try:
+            result = runCmd('devtool finish %s meta-selftest -N' % recipe, assert_error=False)
+        except CommandError as err:
+            if err.retcode != 1:
+                self.fail('Unexpected failure from devtool finish:\n%s' % err.output)
+            lines = []
+            collecting = False
+            for line in err.output.splitlines():
+                if collecting:
+                    if line:
+                        lines.append(line)
+                elif line.startswith('ERROR: Source tree %s is not clean' % mainsrc):
+                    collecting = True
+            lines = lines[:-1]
+            self.assertEqual(lines, [' M libfakekey'], 'Unexpected modifications to main source tree')
+            if not collecting:
+                self.fail('devtool finish did not report uncommitted changes as expected:\n%s' % err.output)
+            failed = True
+        if not failed:
+            self.fail('devtool finish was expected to fail but did not:\n%s' % result.output)
+        result = runCmd('devtool finish %s meta-selftest -N -f' % recipe)
+        self.assertNotIn('No patches or files need updating', result.output)
+        self.assertIn('+           file://0001-Add-a-comment.patch \\', result.output)
+        self.assertIn('+           file://0001-Add-another-line-to-README.patch;patchdir=libfakekey \\', result.output)
+        self.assertNotIn('Removing', result.output)
+        self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
+        result = runCmd('devtool finish %s -f meta-selftest' % recipe)
+        expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
+                           ('??', '.*/%s/$' % recipe)]
+        self._check_repo_status(recipedir, expected_status)
+        self.assertExists(os.path.join(os.path.dirname(recipefile), recipe, '0001-Add-a-comment.patch'))
+        self.assertExists(os.path.join(os.path.dirname(recipefile), recipe, '0001-Add-another-line-to-README.patch'))
+
     @OETestID(1626)
     def test_devtool_rename(self):
         # Check preconditions