[v4,2/2] selftests: add tests for INCOMPATIBLE_LICENSE

Submitted by Quentin Schulz on June 11, 2019, 2:26 p.m. | Patch ID: 162107

Details

Message ID 20190611142607.18038-2-quentin.schulz@streamunlimited.com
State New
Headers show

Commit Message

Quentin Schulz June 11, 2019, 2:26 p.m.
One bug went unnoticed without these selftests: an INCOMPATIBLE_LICENSE
with a non-SPDX license for a package with that non-SPDX license wasn't
enforcing the denial of build for said package.

While adding a test for that particular case, let's add a few more so
that we cover a handful more use cases of INCOMPATIBLE_LICENSE.

Signed-off-by: Quentin Schulz <quentin.schulz@streamunlimited.com>
---

added in v4

 .../license/incompatible-license-alias.bb     |  3 ++
 .../license/incompatible-license.bb           |  3 ++
 .../license/incompatible-nonspdx-license.bb   |  3 ++
 .../oeqa/selftest/cases/incompatible_lic.py   | 42 +++++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 meta-selftest/recipes-test/license/incompatible-license-alias.bb
 create mode 100644 meta-selftest/recipes-test/license/incompatible-license.bb
 create mode 100644 meta-selftest/recipes-test/license/incompatible-nonspdx-license.bb
 create mode 100644 meta/lib/oeqa/selftest/cases/incompatible_lic.py

Patch hide | download patch | download mbox

diff --git a/meta-selftest/recipes-test/license/incompatible-license-alias.bb b/meta-selftest/recipes-test/license/incompatible-license-alias.bb
new file mode 100644
index 0000000000..e0b4e13c26
--- /dev/null
+++ b/meta-selftest/recipes-test/license/incompatible-license-alias.bb
@@ -0,0 +1,3 @@ 
+SUMMARY = "Recipe with an alias of an SPDX license"
+DESCRIPTION = "Is licensed with an alias of an SPDX license to be used for testing"
+LICENSE = "GPLv3"
diff --git a/meta-selftest/recipes-test/license/incompatible-license.bb b/meta-selftest/recipes-test/license/incompatible-license.bb
new file mode 100644
index 0000000000..1728ad76b7
--- /dev/null
+++ b/meta-selftest/recipes-test/license/incompatible-license.bb
@@ -0,0 +1,3 @@ 
+SUMMARY = "Recipe with an SPDX license"
+DESCRIPTION = "Is licensed with an SPDX license to be used for testing"
+LICENSE = "GPL-3.0"
diff --git a/meta-selftest/recipes-test/license/incompatible-nonspdx-license.bb b/meta-selftest/recipes-test/license/incompatible-nonspdx-license.bb
new file mode 100644
index 0000000000..35af0966ef
--- /dev/null
+++ b/meta-selftest/recipes-test/license/incompatible-nonspdx-license.bb
@@ -0,0 +1,3 @@ 
+SUMMARY = "Recipe with a non-SPDX license"
+DESCRIPTION = "Is licensed with a non-SPDX license to be used for testing"
+LICENSE = "FooLicense"
diff --git a/meta/lib/oeqa/selftest/cases/incompatible_lic.py b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
new file mode 100644
index 0000000000..4e0d1f53d3
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
@@ -0,0 +1,42 @@ 
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake
+from oeqa.core.decorator.oeid import OETestID
+
+class IncompatibleLicenseTests(OESelftestTestCase):
+
+    def test_lic(self, pn, pn_lic, lic):
+        error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has an incompatible license: %s' % (pn, pn, pn_lic)
+
+        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
+
+        result = bitbake(pn, ignore_status=True)
+        if error_msg not in result.output:
+            raise AssertionError(result.output)
+
+    # Verify that a package with an SPDX license (from SRC_DISTRIBUTE_LICENSES)
+    # cannot be built when INCOMPATIBLE_LICENSE contains this SPDX license
+    def test_incompatible_spdx_license(self):
+        self.test_lic('incompatible-license', 'GPL-3.0', 'GPL-3.0')
+
+    # Verify that a package with an SPDX license (from SRC_DISTRIBUTE_LICENSES)
+    # cannot be built when INCOMPATIBLE_LICENSE contains an alias (in
+    # SPDXLICENSEMAP) of this SPDX license
+    def test_incompatible_alias_spdx_license(self):
+        self.test_lic('incompatible-license', 'GPL-3.0', 'GPLv3')
+
+    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
+    # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
+    # license
+    def test_incompatible_spdx_license_alias(self):
+        self.test_lic('incompatible-license-alias', 'GPLv3', 'GPL-3.0')
+
+    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
+    # license cannot be built when INCOMPATIBLE_LICENSE contains this alias
+    def test_incompatible_alias_spdx_license_alias(self):
+        self.test_lic('incompatible-license-alias', 'GPLv3', 'GPLv3')
+
+    # Verify that a package with a non-SPDX license (neither in
+    # SRC_DISTRIBUTE_LICENSES nor in SPDXLICENSEMAP) cannot be built when
+    # INCOMPATIBLE_LICENSE contains this license
+    def test_incompatible_nonspdx_license(self):
+        self.test_lic('incompatible-nonspdx-license', 'FooLicense', 'FooLicense')

Comments

Ross Burton June 11, 2019, 2:49 p.m.
On Tue, 11 Jun 2019 at 15:27, Quentin Schulz
<quentin.schulz@streamunlimited.com> wrote:
> +from oeqa.core.decorator.oeid import OETestID

This was removed a while ago, can you rebase the patches on top of
master please?

In this case you can just remove the import, but please verify the
behaviour with master.

Ross
Quentin Schulz June 11, 2019, 2:52 p.m.
Hi Ross,

On Tue, Jun 11, 2019 at 03:49:31PM +0100, Burton, Ross wrote:
> On Tue, 11 Jun 2019 at 15:27, Quentin Schulz
> <quentin.schulz@streamunlimited.com> wrote:
> > +from oeqa.core.decorator.oeid import OETestID
> 
> This was removed a while ago, can you rebase the patches on top of
> master please?
> 
> In this case you can just remove the import, but please verify the
> behaviour with master.
> 

Sorry for the noise, apparently forgot to pull master and didn't even
see my patch was already there *sigh*.

I'll remove the import and test on master with and without the patch you
already merged.

Do you want me to send a v5 or a separate patch series is better for
you?

Quentin
Ross Burton June 11, 2019, 2:55 p.m.
On Tue, 11 Jun 2019 at 15:52, Quentin Schulz
<quentin.schulz@streamunlimited.com> wrote:
> Sorry for the noise, apparently forgot to pull master and didn't even
> see my patch was already there *sigh*.
>
> I'll remove the import and test on master with and without the patch you
> already merged.
>
> Do you want me to send a v5 or a separate patch series is better for
> you?

Either is fine.  Note that in the broken case - where the recipe isn't
skipped - the test goes ahead and compiles stuff.  Can you also try
using --dry-run to see if that results in the same test behaviour, but
without attempting compilation.

Ross
Quentin Schulz June 11, 2019, 2:56 p.m.
On Tue, Jun 11, 2019 at 04:52:16PM +0200, Quentin Schulz wrote:
> Hi Ross,
> 
> On Tue, Jun 11, 2019 at 03:49:31PM +0100, Burton, Ross wrote:
> > On Tue, 11 Jun 2019 at 15:27, Quentin Schulz
> > <quentin.schulz@streamunlimited.com> wrote:
> > > +from oeqa.core.decorator.oeid import OETestID
> > 
> > This was removed a while ago, can you rebase the patches on top of
> > master please?
> > 
> > In this case you can just remove the import, but please verify the
> > behaviour with master.
> > 
> 
> Sorry for the noise, apparently forgot to pull master and didn't even
> see my patch was already there *sigh*.
> 
> I'll remove the import and test on master with and without the patch you
> already merged.
> 
> Do you want me to send a v5 or a separate patch series is better for
> you?
> 

Also, I factored out everything into a function that shouldn't be run as
a test but when doing:
oe-selftest --run-tests incompatible_lic.IncompatibleLicenseTests
it tries to run the function and thus fails the test. Is that okay? if
not, how do you usually proceed?

Quentin
Ross Burton June 11, 2019, 2:57 p.m.
On Tue, 11 Jun 2019 at 15:56, Quentin Schulz
<quentin.schulz@streamunlimited.com> wrote:
> Also, I factored out everything into a function that shouldn't be run as
> a test but when doing:
> oe-selftest --run-tests incompatible_lic.IncompatibleLicenseTests
> it tries to run the function and thus fails the test. Is that okay? if
> not, how do you usually proceed?

So Python unittest's behaviour is that any function called test_*() is
a test case and is executed, so just don't name any helper functions
like this test_*.

Ross
Ross Burton June 11, 2019, 2:59 p.m.
On Tue, 11 Jun 2019 at 15:55, Burton, Ross <ross.burton@intel.com> wrote:
> Either is fine.  Note that in the broken case - where the recipe isn't
> skipped - the test goes ahead and compiles stuff.  Can you also try
> using --dry-run to see if that results in the same test behaviour, but
> without attempting compilation.

FWIW:

-        result = bitbake(pn, ignore_status=True)
+        result = bitbake("%s --dry-run" % pn, ignore_status=True)

Still results in the nonspdx case failing as expected without the fix,
but without any compilation attempted.

Ross
Quentin Schulz June 11, 2019, 3:06 p.m.
On Tue, Jun 11, 2019 at 03:57:23PM +0100, Burton, Ross wrote:
> On Tue, 11 Jun 2019 at 15:56, Quentin Schulz
> <quentin.schulz@streamunlimited.com> wrote:
> > Also, I factored out everything into a function that shouldn't be run as
> > a test but when doing:
> > oe-selftest --run-tests incompatible_lic.IncompatibleLicenseTests
> > it tries to run the function and thus fails the test. Is that okay? if
> > not, how do you usually proceed?
> 
> So Python unittest's behaviour is that any function called test_*() is
> a test case and is executed, so just don't name any helper functions
> like this test_*.
> 

Ah, that's what I was missing. Thanks.

Quentin