]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/tests/package/test_rust.py
8035f8b83af8fd7eaeba64ae38b8cbc0b946a197
[coffee/buildroot.git] / support / testing / tests / package / test_rust.py
1 import os
2 import tempfile
3 import subprocess
4 import shutil
5
6 import infra.basetest
7
8
9 class TestRustBase(infra.basetest.BRTest):
10
11     target = 'armv7-unknown-linux-gnueabihf'
12     crate = 'hello-world'
13
14     def login(self):
15         img = os.path.join(self.builddir, "images", "rootfs.cpio")
16         self.emulator.boot(arch="armv7",
17                            kernel="builtin",
18                            options=["-initrd", img])
19         self.emulator.login()
20
21     def build_test_prog(self):
22         hostdir = os.path.join(self.builddir, 'host')
23         env = os.environ.copy()
24         env["PATH"] = "{}:".format(os.path.join(hostdir, 'bin')) + env["PATH"]
25         env["CARGO_HOME"] = os.path.join(hostdir, 'usr', 'share', 'cargo')
26         env["RUST_TARGET_PATH"] = os.path.join(hostdir, 'etc', 'rustc')
27         cargo = os.path.join(hostdir, 'bin', 'cargo')
28         workdir = os.path.join(tempfile.mkdtemp(suffix='-br2-testing-rust'),
29                                self.crate)
30         manifest = os.path.join(workdir, 'Cargo.toml')
31         prog = os.path.join(workdir, 'target', self.target, 'debug', self.crate)
32
33         cmd = [cargo, 'init', '--bin', '--vcs', 'none', '-vv', workdir]
34         ret = subprocess.call(cmd,
35                               stdout=self.b.logfile,
36                               stderr=self.b.logfile,
37                               env=env)
38         if ret != 0:
39             raise SystemError("Cargo init failed")
40
41         cmd = [
42             cargo, 'build', '-vv', '--target', self.target,
43             '--manifest-path', manifest
44         ]
45         ret = subprocess.call(cmd,
46                               stdout=self.b.logfile,
47                               stderr=self.b.logfile,
48                               env=env)
49         if ret != 0:
50             raise SystemError("Cargo build failed")
51
52         shutil.copy(prog, os.path.join(self.builddir, 'target', 'usr', 'bin'))
53         self.b.build()
54         shutil.rmtree(workdir)
55
56     def test_run(self):
57         self.build_test_prog()
58         self.login()
59         _, exit_code = self.emulator.run(self.crate)
60         self.assertEqual(exit_code, 0)
61
62
63 class TestRustBin(TestRustBase):
64     config = \
65              """
66              BR2_arm=y
67              BR2_cortex_a9=y
68              BR2_ARM_ENABLE_NEON=y
69              BR2_ARM_ENABLE_VFP=y
70              BR2_TOOLCHAIN_EXTERNAL=y
71              BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
72              BR2_SYSTEM_DHCP="eth0"
73              BR2_LINUX_KERNEL=y
74              BR2_LINUX_KERNEL_CUSTOM_VERSION=y
75              BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.11.3"
76              BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
77              BR2_LINUX_KERNEL_DTS_SUPPORT=y
78              BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
79              BR2_TARGET_ROOTFS_CPIO=y
80              # BR2_TARGET_ROOTFS_TAR is not set
81              BR2_PACKAGE_HOST_CARGO=y
82              BR2_PACKAGE_HOST_RUSTC=y
83              """
84
85
86 class TestRust(TestRustBase):
87     config = \
88              """
89              BR2_arm=y
90              BR2_cortex_a9=y
91              BR2_ARM_ENABLE_NEON=y
92              BR2_ARM_ENABLE_VFP=y
93              BR2_TOOLCHAIN_EXTERNAL=y
94              BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
95              BR2_SYSTEM_DHCP="eth0"
96              BR2_LINUX_KERNEL=y
97              BR2_LINUX_KERNEL_CUSTOM_VERSION=y
98              BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.11.3"
99              BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
100              BR2_LINUX_KERNEL_DTS_SUPPORT=y
101              BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
102              BR2_TARGET_ROOTFS_CPIO=y
103              # BR2_TARGET_ROOTFS_TAR is not set
104              BR2_PACKAGE_HOST_CARGO=y
105              BR2_PACKAGE_HOST_RUSTC=y
106              BR2_PACKAGE_HOST_RUST=y
107              """