2018-02-04 19:07:49 +01:00
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
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",
|
|
|
|
kernel="builtin",
|
|
|
|
options=["-initrd", img])
|
|
|
|
self.emulator.login()
|
|
|
|
|
|
|
|
def build_test_prog(self):
|
|
|
|
hostdir = os.path.join(self.builddir, 'host')
|
|
|
|
env = os.environ.copy()
|
2018-04-29 00:14:13 +02:00
|
|
|
env["USER"] = "br-user"
|
2018-02-04 19:07:49 +01:00
|
|
|
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 = \
|
2018-11-16 23:21:47 +01:00
|
|
|
"""
|
|
|
|
BR2_arm=y
|
|
|
|
BR2_cortex_a9=y
|
|
|
|
BR2_ARM_ENABLE_NEON=y
|
|
|
|
BR2_ARM_ENABLE_VFP=y
|
|
|
|
BR2_TOOLCHAIN_EXTERNAL=y
|
|
|
|
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
|
|
|
|
BR2_SYSTEM_DHCP="eth0"
|
|
|
|
BR2_TARGET_ROOTFS_CPIO=y
|
|
|
|
# BR2_TARGET_ROOTFS_TAR is not set
|
|
|
|
BR2_PACKAGE_HOST_RUSTC=y
|
|
|
|
"""
|
2018-02-04 19:07:49 +01:00
|
|
|
|
2018-02-12 22:02:08 +01:00
|
|
|
def test_run(self):
|
|
|
|
self.build_test_prog()
|
|
|
|
self.login()
|
2021-06-26 15:32:38 +02:00
|
|
|
self.assertRunOk(self.crate)
|
2018-02-12 22:02:08 +01:00
|
|
|
|
2018-02-04 19:07:49 +01:00
|
|
|
|
|
|
|
class TestRust(TestRustBase):
|
|
|
|
config = \
|
2018-11-16 23:21:47 +01:00
|
|
|
"""
|
|
|
|
BR2_arm=y
|
|
|
|
BR2_cortex_a9=y
|
|
|
|
BR2_ARM_ENABLE_NEON=y
|
|
|
|
BR2_ARM_ENABLE_VFP=y
|
|
|
|
BR2_TOOLCHAIN_EXTERNAL=y
|
|
|
|
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
|
|
|
|
BR2_SYSTEM_DHCP="eth0"
|
|
|
|
BR2_TARGET_ROOTFS_CPIO=y
|
|
|
|
# BR2_TARGET_ROOTFS_TAR is not set
|
|
|
|
BR2_PACKAGE_HOST_RUSTC=y
|
|
|
|
BR2_PACKAGE_HOST_RUST=y
|
|
|
|
"""
|
2018-02-12 22:02:08 +01:00
|
|
|
|
|
|
|
def test_run(self):
|
|
|
|
self.build_test_prog()
|
|
|
|
self.login()
|
2021-06-26 15:32:38 +02:00
|
|
|
self.assertRunOk(self.crate)
|