]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Enable rust cargo test in Samba make test
authorDavid Mulder <dmulder@samba.org>
Mon, 12 Aug 2024 15:39:06 +0000 (09:39 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:33 +0000 (14:21 +0000)
Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
python/samba/tests/rust.py [new file with mode: 0644]
rust/idmap/build.rs
rust/nss/build.rs
rust/pam/build.rs
rust/param/build.rs
selftest/tests.py

diff --git a/python/samba/tests/rust.py b/python/samba/tests/rust.py
new file mode 100644 (file)
index 0000000..e5624bb
--- /dev/null
@@ -0,0 +1,67 @@
+# Unix SMB/CIFS implementation.
+#
+# Tests for Rust
+#
+# Copyright (C) David Mulder <dmulder@samba.org> 2024
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""Cargo tests for Rust sources"""
+
+from samba.tests import BlackboxTestCase
+import os
+
+
+class RustCargoTests(BlackboxTestCase):
+    def setUp(self):
+        super().setUp()
+
+        # Locate the rust source directory
+        self.rust_dir = os.path.abspath(
+                os.path.join(
+                    os.path.realpath(
+                        os.path.dirname(__file__)
+                    ),
+                    '../../../../rust'
+                )
+            )
+
+        # Locate the bin directory
+        self.target_dir = os.path.abspath(
+                os.path.join(
+                    os.path.realpath(
+                        os.path.dirname(__file__)
+                    ),
+                    '../../..',
+                    'default/rust',
+                )
+            )
+
+    def check_cargo_test(self, crate_toml):
+        # Execute the cargo test command
+        cmd = 'cargo test --target-dir=%s --manifest-path=%s' % (self.target_dir, crate_toml)
+        return self.check_run(cmd, 'cargo test failed')
+
+    def test_rust(self):
+        crates = []
+        for root, dirs, files in os.walk(self.rust_dir):
+            for file in files:
+                if os.path.basename(file) == 'Cargo.toml':
+                    if root != self.rust_dir:
+                        crates.append(os.path.join(root, file))
+
+        for crate_toml in crates:
+            with self.subTest(crate_toml):
+                self.check_cargo_test(crate_toml)
index c24090c3a541094bede05c225c36d272594bc321..c1a9f35e31a30f32f6147c30c8f231cc3d6ad160 100644 (file)
@@ -29,4 +29,5 @@ fn main() {
         .write_to_file(out_path.join("bindings.rs"))
         .expect("Couldn't write bindings!");
     println!("cargo:rustc-link-lib=utf8proc");
+    println!("cargo:rustc-env=LD_LIBRARY_PATH=../../bin/shared/private/");
 }
index 4f5e414bf9a9703f13fd02e7dd71a94e711f940b..6fcc6b9f08e3ccea256ccce26a5cc9a0ec64cac9 100644 (file)
@@ -14,4 +14,5 @@ fn main() {
         "cargo:rustc-env=CARGO_PKG_VERSION_PATCH={}",
         version::SAMBA_VERSION_RELEASE
     );
+    println!("cargo:rustc-env=LD_LIBRARY_PATH=../../bin/shared:../../bin/shared/private/");
 }
index 3c23ee3f11456a2df7bdc1156476447cd7a27670..11313da3e5c9e83019caff1e820231a27e50b866 100644 (file)
@@ -6,4 +6,5 @@ fn main() {
     let _ = pkg_config::Config::new()
         .atleast_version("1.3.0")
         .probe("pam");
+    println!("cargo:rustc-env=LD_LIBRARY_PATH=../../bin/shared:../../bin/shared/private/");
 }
index 8fe81e1091b460ef968a055239d4eeaefadce3da..6d533e3b3dbf50de89f0dd96e713aef8ebb2196a 100644 (file)
@@ -14,6 +14,7 @@ fn main() {
         .clang_arg("-Doffset_t=loff_t")
         .clang_arg("-I../../bin/default")
         .clang_arg("-I../../lib/talloc")
+        .generate_comments(false)
         .clang_arg("-includestdint.h")
         .header("../../lib/param/param.h")
         .header("../../lib/param/loadparm.h")
@@ -22,6 +23,9 @@ fn main() {
         .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
         .generate()
         .expect("Unable to generate bindings");
+    println!("cargo:rerun-if-changed=../../lib/param/param.h");
+    println!("cargo:rerun-if-changed=../../lib/param/loadparm.h");
+    println!("cargo:rerun-if-changed=../../source3/param/loadparm.h");
     println!(
         "cargo:rerun-if-changed=../../bin/default/lib/param/param_functions.h"
     );
index e894a3594a498a0ac0ed6eca2305dfea57e0e9bc..f55c90750c860f66e0511eb919de5e70008124ad 100644 (file)
@@ -615,3 +615,6 @@ plantestsuite("samba.unittests.claim_conversion", "none",
               [os.path.join(bindir(), "test_claim_conversion")])
 plantestsuite("samba.unittests.cmdline", "none",
               [os.path.join(bindir(), "test_cmdline")])
+
+# Run the Rust cargo tests
+planpythontestsuite("none", "samba.tests.rust")