diff mbox series

[PATCHv2,1/2] support/testing: TestRust{Bin} use ripgrep package for testing

Message ID 20220224154513.220976-1-romain.naour@gmail.com
State Accepted
Headers show
Series [PATCHv2,1/2] support/testing: TestRust{Bin} use ripgrep package for testing | expand

Commit Message

Romain Naour Feb. 24, 2022, 3:45 p.m. UTC
TestRust and TestRustBin has been introduced at the time when there was
no cargo package infrastructure or any package using rust compiler
(Buildroot 2018.02).

Since then the ripgrep package has been introduced, initially using
the generic package infrastructure and converted later to the cargo
package infrastructure.

Due a recent change in rust/cargo removing the cargo config file [1]
the test TestRust and TestRustBin now fail to compile since they build
an hello-world crate outside of the cargo package infrastructure
without the correct environment for cross-compiling.

Replace the 'hello-world' crate by ripgrep package and check if it
can run properly in Qemu.

Fixes tests.package.test_rust.TestRustBin:
https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202545

But doesn't fixes tests.package.test_rust.TestRust due another bug:
https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202544

[1] b6378631c2609742382984f6f7b93c1d9d2cdb78

Signed-off-by: Romain Naour <romain.naour@gmail.com>
Cc: Eric Le Bihan <eric.le.bihan.dev@free.fr>
---
v2: no changes
---
 support/testing/tests/package/test_rust.py | 48 ++--------------------
 1 file changed, 4 insertions(+), 44 deletions(-)

Comments

Arnout Vandecappelle March 12, 2022, 8:30 p.m. UTC | #1
On 24/02/2022 16:45, Romain Naour wrote:
> TestRust and TestRustBin has been introduced at the time when there was
> no cargo package infrastructure or any package using rust compiler
> (Buildroot 2018.02).
>
> Since then the ripgrep package has been introduced, initially using
> the generic package infrastructure and converted later to the cargo
> package infrastructure.
>
> Due a recent change in rust/cargo removing the cargo config file [1]
> the test TestRust and TestRustBin now fail to compile since they build
> an hello-world crate outside of the cargo package infrastructure
> without the correct environment for cross-compiling.
>
> Replace the 'hello-world' crate by ripgrep package and check if it
> can run properly in Qemu.
>
> Fixes tests.package.test_rust.TestRustBin:
> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202545
>
> But doesn't fixes tests.package.test_rust.TestRust due another bug:
> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202544
>
> [1] b6378631c2609742382984f6f7b93c1d9d2cdb78
>
> Signed-off-by: Romain Naour <romain.naour@gmail.com>
> Cc: Eric Le Bihan <eric.le.bihan.dev@free.fr>
> ---
> v2: no changes
> ---
>   support/testing/tests/package/test_rust.py | 48 ++--------------------
>   1 file changed, 4 insertions(+), 44 deletions(-)
>
> diff --git a/support/testing/tests/package/test_rust.py b/support/testing/tests/package/test_rust.py
> index 884b40a4a3..a1abd20c09 100644
> --- a/support/testing/tests/package/test_rust.py
> +++ b/support/testing/tests/package/test_rust.py
> @@ -8,9 +8,6 @@ import infra.basetest
>   
>   class TestRustBase(infra.basetest.BRTest):
>   
> -    target = 'armv7-unknown-linux-gnueabihf'
> -    crate = 'hello-world'
> -
>       def login(self):
>           img = os.path.join(self.builddir, "images", "rootfs.cpio")
>           self.emulator.boot(arch="armv7",
> @@ -18,43 +15,6 @@ class TestRustBase(infra.basetest.BRTest):
>                              options=["-initrd", img])
>           self.emulator.login()
>   
> -    def build_test_prog(self):
> -        hostdir = os.path.join(self.builddir, 'host')
> -        env = os.environ.copy()
> -        env["USER"] = "br-user"
> -        env["PATH"] = "{}:".format(os.path.join(hostdir, 'bin')) + env["PATH"]
> -        env["CARGO_HOME"] = os.path.join(hostdir, 'usr', 'share', 'cargo')
> -        env["RUST_TARGET_PATH"] = os.path.join(hostdir, 'etc', 'rustc')
> -        cargo = os.path.join(hostdir, 'bin', 'cargo')
> -        workdir = os.path.join(tempfile.mkdtemp(suffix='-br2-testing-rust'),
> -                               self.crate)
> -        manifest = os.path.join(workdir, 'Cargo.toml')
> -        prog = os.path.join(workdir, 'target', self.target, 'debug', self.crate)
> -
> -        cmd = [cargo, 'init', '--bin', '--vcs', 'none', '-vv', workdir]
> -        ret = subprocess.call(cmd,
> -                              stdout=self.b.logfile,
> -                              stderr=self.b.logfile,
> -                              env=env)
> -        if ret != 0:
> -            raise SystemError("Cargo init failed")
> -
> -        cmd = [
> -            cargo, 'build', '-vv', '--target', self.target,
> -            '--manifest-path', manifest
> -        ]
> -        ret = subprocess.call(cmd,
> -                              stdout=self.b.logfile,
> -                              stderr=self.b.logfile,
> -                              env=env)
> -        if ret != 0:
> -            raise SystemError("Cargo build failed")
> -
> -        shutil.copy(prog, os.path.join(self.builddir, 'target', 'usr', 'bin'))
> -        self.b.build()
> -        shutil.rmtree(workdir)
> -
> -
>   class TestRustBin(TestRustBase):
>       config = \
>           """
> @@ -68,12 +28,12 @@ class TestRustBin(TestRustBase):
>           BR2_TARGET_ROOTFS_CPIO=y
>           # BR2_TARGET_ROOTFS_TAR is not set
>           BR2_PACKAGE_HOST_RUSTC=y
> +        BR2_PACKAGE_RIPGREP=y
>           """
>   
>       def test_run(self):
> -        self.build_test_prog()
>           self.login()
> -        self.assertRunOk(self.crate)
> +        self.assertRunOk("rg Buildroot /etc/issue")

  It now looks more like test_ripgrep than test_rust, but OK, we still have the 
rust-bin and full rust variants.


  Applied to master, thanks.

  Regards,
  Arnout

>   
>   
>   class TestRust(TestRustBase):
> @@ -90,9 +50,9 @@ class TestRust(TestRustBase):
>           # BR2_TARGET_ROOTFS_TAR is not set
>           BR2_PACKAGE_HOST_RUSTC=y
>           BR2_PACKAGE_HOST_RUST=y
> +        BR2_PACKAGE_RIPGREP=y
>           """
>   
>       def test_run(self):
> -        self.build_test_prog()
>           self.login()
> -        self.assertRunOk(self.crate)
> +        self.assertRunOk("rg Buildroot /etc/issue")
Arnout Vandecappelle March 15, 2022, 9:13 p.m. UTC | #2
On 24/02/2022 16:45, Romain Naour wrote:
> TestRust and TestRustBin has been introduced at the time when there was
> no cargo package infrastructure or any package using rust compiler
> (Buildroot 2018.02).
>
> Since then the ripgrep package has been introduced, initially using
> the generic package infrastructure and converted later to the cargo
> package infrastructure.
>
> Due a recent change in rust/cargo removing the cargo config file [1]
> the test TestRust and TestRustBin now fail to compile since they build
> an hello-world crate outside of the cargo package infrastructure
> without the correct environment for cross-compiling.
>
> Replace the 'hello-world' crate by ripgrep package and check if it
> can run properly in Qemu.
>
> Fixes tests.package.test_rust.TestRustBin:
> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202545
>
> But doesn't fixes tests.package.test_rust.TestRust due another bug:
> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202544
>
> [1] b6378631c2609742382984f6f7b93c1d9d2cdb78
>
> Signed-off-by: Romain Naour <romain.naour@gmail.com>
> Cc: Eric Le Bihan <eric.le.bihan.dev@free.fr>

  This introduced a few flake8 errors, which I fixed now. In the future: run 
flake8! (I also always forget :-))


  Regards,
  Arnout


> ---
> v2: no changes
> ---
>   support/testing/tests/package/test_rust.py | 48 ++--------------------
>   1 file changed, 4 insertions(+), 44 deletions(-)
>
> diff --git a/support/testing/tests/package/test_rust.py b/support/testing/tests/package/test_rust.py
> index 884b40a4a3..a1abd20c09 100644
> --- a/support/testing/tests/package/test_rust.py
> +++ b/support/testing/tests/package/test_rust.py
> @@ -8,9 +8,6 @@ import infra.basetest
>   
>   class TestRustBase(infra.basetest.BRTest):
>   
> -    target = 'armv7-unknown-linux-gnueabihf'
> -    crate = 'hello-world'
> -
>       def login(self):
>           img = os.path.join(self.builddir, "images", "rootfs.cpio")
>           self.emulator.boot(arch="armv7",
> @@ -18,43 +15,6 @@ class TestRustBase(infra.basetest.BRTest):
>                              options=["-initrd", img])
>           self.emulator.login()
>   
> -    def build_test_prog(self):
> -        hostdir = os.path.join(self.builddir, 'host')
> -        env = os.environ.copy()
> -        env["USER"] = "br-user"
> -        env["PATH"] = "{}:".format(os.path.join(hostdir, 'bin')) + env["PATH"]
> -        env["CARGO_HOME"] = os.path.join(hostdir, 'usr', 'share', 'cargo')
> -        env["RUST_TARGET_PATH"] = os.path.join(hostdir, 'etc', 'rustc')
> -        cargo = os.path.join(hostdir, 'bin', 'cargo')
> -        workdir = os.path.join(tempfile.mkdtemp(suffix='-br2-testing-rust'),
> -                               self.crate)
> -        manifest = os.path.join(workdir, 'Cargo.toml')
> -        prog = os.path.join(workdir, 'target', self.target, 'debug', self.crate)
> -
> -        cmd = [cargo, 'init', '--bin', '--vcs', 'none', '-vv', workdir]
> -        ret = subprocess.call(cmd,
> -                              stdout=self.b.logfile,
> -                              stderr=self.b.logfile,
> -                              env=env)
> -        if ret != 0:
> -            raise SystemError("Cargo init failed")
> -
> -        cmd = [
> -            cargo, 'build', '-vv', '--target', self.target,
> -            '--manifest-path', manifest
> -        ]
> -        ret = subprocess.call(cmd,
> -                              stdout=self.b.logfile,
> -                              stderr=self.b.logfile,
> -                              env=env)
> -        if ret != 0:
> -            raise SystemError("Cargo build failed")
> -
> -        shutil.copy(prog, os.path.join(self.builddir, 'target', 'usr', 'bin'))
> -        self.b.build()
> -        shutil.rmtree(workdir)
> -
> -
>   class TestRustBin(TestRustBase):
>       config = \
>           """
> @@ -68,12 +28,12 @@ class TestRustBin(TestRustBase):
>           BR2_TARGET_ROOTFS_CPIO=y
>           # BR2_TARGET_ROOTFS_TAR is not set
>           BR2_PACKAGE_HOST_RUSTC=y
> +        BR2_PACKAGE_RIPGREP=y
>           """
>   
>       def test_run(self):
> -        self.build_test_prog()
>           self.login()
> -        self.assertRunOk(self.crate)
> +        self.assertRunOk("rg Buildroot /etc/issue")
>   
>   
>   class TestRust(TestRustBase):
> @@ -90,9 +50,9 @@ class TestRust(TestRustBase):
>           # BR2_TARGET_ROOTFS_TAR is not set
>           BR2_PACKAGE_HOST_RUSTC=y
>           BR2_PACKAGE_HOST_RUST=y
> +        BR2_PACKAGE_RIPGREP=y
>           """
>   
>       def test_run(self):
> -        self.build_test_prog()
>           self.login()
> -        self.assertRunOk(self.crate)
> +        self.assertRunOk("rg Buildroot /etc/issue")
Romain Naour March 19, 2022, 2:33 p.m. UTC | #3
Le 15/03/2022 à 22:13, Arnout Vandecappelle a écrit :
> 
> On 24/02/2022 16:45, Romain Naour wrote:
>> TestRust and TestRustBin has been introduced at the time when there was
>> no cargo package infrastructure or any package using rust compiler
>> (Buildroot 2018.02).
>>
>> Since then the ripgrep package has been introduced, initially using
>> the generic package infrastructure and converted later to the cargo
>> package infrastructure.
>>
>> Due a recent change in rust/cargo removing the cargo config file [1]
>> the test TestRust and TestRustBin now fail to compile since they build
>> an hello-world crate outside of the cargo package infrastructure
>> without the correct environment for cross-compiling.
>>
>> Replace the 'hello-world' crate by ripgrep package and check if it
>> can run properly in Qemu.
>>
>> Fixes tests.package.test_rust.TestRustBin:
>> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202545
>>
>> But doesn't fixes tests.package.test_rust.TestRust due another bug:
>> https://gitlab.com/buildroot.org/buildroot/-/jobs/2116202544
>>
>> [1] b6378631c2609742382984f6f7b93c1d9d2cdb78
>>
>> Signed-off-by: Romain Naour <romain.naour@gmail.com>
>> Cc: Eric Le Bihan <eric.le.bihan.dev@free.fr>
> 
>  This introduced a few flake8 errors, which I fixed now. In the future: run
> flake8! (I also always forget :-))

This is completely unexpected, sorry for that.

Best regards,
Romain


> 
> 
>  Regards,
>  Arnout
>
diff mbox series

Patch

diff --git a/support/testing/tests/package/test_rust.py b/support/testing/tests/package/test_rust.py
index 884b40a4a3..a1abd20c09 100644
--- a/support/testing/tests/package/test_rust.py
+++ b/support/testing/tests/package/test_rust.py
@@ -8,9 +8,6 @@  import infra.basetest
 
 class TestRustBase(infra.basetest.BRTest):
 
-    target = 'armv7-unknown-linux-gnueabihf'
-    crate = 'hello-world'
-
     def login(self):
         img = os.path.join(self.builddir, "images", "rootfs.cpio")
         self.emulator.boot(arch="armv7",
@@ -18,43 +15,6 @@  class TestRustBase(infra.basetest.BRTest):
                            options=["-initrd", img])
         self.emulator.login()
 
-    def build_test_prog(self):
-        hostdir = os.path.join(self.builddir, 'host')
-        env = os.environ.copy()
-        env["USER"] = "br-user"
-        env["PATH"] = "{}:".format(os.path.join(hostdir, 'bin')) + env["PATH"]
-        env["CARGO_HOME"] = os.path.join(hostdir, 'usr', 'share', 'cargo')
-        env["RUST_TARGET_PATH"] = os.path.join(hostdir, 'etc', 'rustc')
-        cargo = os.path.join(hostdir, 'bin', 'cargo')
-        workdir = os.path.join(tempfile.mkdtemp(suffix='-br2-testing-rust'),
-                               self.crate)
-        manifest = os.path.join(workdir, 'Cargo.toml')
-        prog = os.path.join(workdir, 'target', self.target, 'debug', self.crate)
-
-        cmd = [cargo, 'init', '--bin', '--vcs', 'none', '-vv', workdir]
-        ret = subprocess.call(cmd,
-                              stdout=self.b.logfile,
-                              stderr=self.b.logfile,
-                              env=env)
-        if ret != 0:
-            raise SystemError("Cargo init failed")
-
-        cmd = [
-            cargo, 'build', '-vv', '--target', self.target,
-            '--manifest-path', manifest
-        ]
-        ret = subprocess.call(cmd,
-                              stdout=self.b.logfile,
-                              stderr=self.b.logfile,
-                              env=env)
-        if ret != 0:
-            raise SystemError("Cargo build failed")
-
-        shutil.copy(prog, os.path.join(self.builddir, 'target', 'usr', 'bin'))
-        self.b.build()
-        shutil.rmtree(workdir)
-
-
 class TestRustBin(TestRustBase):
     config = \
         """
@@ -68,12 +28,12 @@  class TestRustBin(TestRustBase):
         BR2_TARGET_ROOTFS_CPIO=y
         # BR2_TARGET_ROOTFS_TAR is not set
         BR2_PACKAGE_HOST_RUSTC=y
+        BR2_PACKAGE_RIPGREP=y
         """
 
     def test_run(self):
-        self.build_test_prog()
         self.login()
-        self.assertRunOk(self.crate)
+        self.assertRunOk("rg Buildroot /etc/issue")
 
 
 class TestRust(TestRustBase):
@@ -90,9 +50,9 @@  class TestRust(TestRustBase):
         # BR2_TARGET_ROOTFS_TAR is not set
         BR2_PACKAGE_HOST_RUSTC=y
         BR2_PACKAGE_HOST_RUST=y
+        BR2_PACKAGE_RIPGREP=y
         """
 
     def test_run(self):
-        self.build_test_prog()
         self.login()
-        self.assertRunOk(self.crate)
+        self.assertRunOk("rg Buildroot /etc/issue")