summaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2023-06-27 23:57:13 +0300
committerGitHub <noreply@github.com>2023-06-27 23:57:13 +0300
commita4fb8dcc4111575c670c384e52bf1abb119879b9 (patch)
treebdf995d017f7452d7b96f17829d022a208243aba /test cases
parent8946bc05f7f9cdd16dce3613c481a66f7835fc7f (diff)
parent6bfb47a455af60dc975e21dd82943d5baa2bea83 (diff)
downloadmeson-a4fb8dcc4111575c670c384e52bf1abb119879b9.tar.gz
Merge pull request #11902 from dcbaker/submit/rust-module-enhancements
Rust module enhancements for mesa
Diffstat (limited to 'test cases')
-rw-r--r--test cases/rust/20 rust and cpp/lib.cpp18
-rw-r--r--test cases/rust/20 rust and cpp/lib.hpp8
-rw-r--r--test cases/rust/20 rust and cpp/main.rs19
-rw-r--r--test cases/rust/20 rust and cpp/meson.build14
-rw-r--r--test cases/rust/20 rust and cpp/test.json15
-rw-r--r--test cases/rust/9 unit tests/helper.rs3
-rw-r--r--test cases/rust/9 unit tests/meson.build10
-rw-r--r--test cases/rust/9 unit tests/test3.rs23
8 files changed, 107 insertions, 3 deletions
diff --git a/test cases/rust/20 rust and cpp/lib.cpp b/test cases/rust/20 rust and cpp/lib.cpp
new file mode 100644
index 000000000..b08f870e2
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/lib.cpp
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+#include "lib.hpp"
+
+#include <string>
+
+namespace {
+
+uint64_t priv_length(const std::string & str) {
+ return str.length();
+}
+
+}
+
+extern "C" uint64_t lib_length(const char * str) {
+ return priv_length(str);
+}
diff --git a/test cases/rust/20 rust and cpp/lib.hpp b/test cases/rust/20 rust and cpp/lib.hpp
new file mode 100644
index 000000000..63093c4c1
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/lib.hpp
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+#include <cstddef>
+#include <cstdint>
+
+extern "C" uint64_t lib_length(const char * str);
+
diff --git a/test cases/rust/20 rust and cpp/main.rs b/test cases/rust/20 rust and cpp/main.rs
new file mode 100644
index 000000000..b048cac2b
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/main.rs
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+use std::ffi::CString;
+use std::os::raw::c_char;
+
+extern "C" {
+ fn lib_length(s: *const c_char) -> u64;
+}
+
+fn main() {
+ let len: u64;
+ unsafe {
+ let c_str = CString::new("Hello, world!").unwrap();
+ len = lib_length(c_str.as_ptr());
+ }
+
+ std::process::exit(if len == 13 { 0 } else { 1 })
+}
diff --git a/test cases/rust/20 rust and cpp/meson.build b/test cases/rust/20 rust and cpp/meson.build
new file mode 100644
index 000000000..c3010123a
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/meson.build
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+# Copyright © 2023 Intel Corporation
+
+project(
+ 'Rust and C++',
+ 'rust', 'cpp',
+ default_options : ['cpp_std=c++14'],
+ meson_version : '>= 1.2.0',
+)
+
+cpplib = static_library('cpp', 'lib.cpp')
+exe = executable('main', 'main.rs', link_with : cpplib)
+
+test('main', exe)
diff --git a/test cases/rust/20 rust and cpp/test.json b/test cases/rust/20 rust and cpp/test.json
new file mode 100644
index 000000000..c072a6c94
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/test.json
@@ -0,0 +1,15 @@
+{
+ "matrix": {
+ "options": {
+ "b_vscrt": [
+ { "val": "none" },
+ { "val": "mdd" },
+ { "val": "md" },
+ { "val": "mtd" },
+ { "val": "mt" },
+ { "val": "from_buildtype" },
+ { "val": "static_from_buildtype" }
+ ]
+ }
+ }
+}
diff --git a/test cases/rust/9 unit tests/helper.rs b/test cases/rust/9 unit tests/helper.rs
new file mode 100644
index 000000000..afe3233e4
--- /dev/null
+++ b/test cases/rust/9 unit tests/helper.rs
@@ -0,0 +1,3 @@
+pub fn subtract(a: i32, b: i32) -> i32 {
+ a - b
+}
diff --git a/test cases/rust/9 unit tests/meson.build b/test cases/rust/9 unit tests/meson.build
index b649abb85..94cc400d4 100644
--- a/test cases/rust/9 unit tests/meson.build
+++ b/test cases/rust/9 unit tests/meson.build
@@ -31,13 +31,17 @@ test(
suite : ['foo'],
)
-exe = executable('rust_exe', ['test2.rs', 'test.rs'])
+exe = executable('rust_exe', ['test2.rs', 'test.rs'], build_by_default : false)
rust = import('unstable-rust')
rust.test('rust_test_from_exe', exe, should_fail : true)
-lib = static_library('rust_static', ['test.rs'])
+lib = static_library('rust_static', ['test.rs'], build_by_default : false)
rust.test('rust_test_from_static', lib, args: ['--skip', 'test_add_intentional_fail'])
-lib = shared_library('rust_shared', ['test.rs'])
+lib = shared_library('rust_shared', ['test.rs'], build_by_default : false)
rust.test('rust_test_from_shared', lib, args: ['--skip', 'test_add_intentional_fail'])
+
+helper = static_library('helper', 'helper.rs')
+lib = static_library('rust_link_with', 'test3.rs', build_by_default : false)
+rust.test('rust_test_link_with', lib, link_with : helper, rust_args : ['--cfg', 'broken="false"'])
diff --git a/test cases/rust/9 unit tests/test3.rs b/test cases/rust/9 unit tests/test3.rs
new file mode 100644
index 000000000..6d538a059
--- /dev/null
+++ b/test cases/rust/9 unit tests/test3.rs
@@ -0,0 +1,23 @@
+pub fn add(a: i32, b: i32) -> i32 {
+ a + b
+}
+
+#[cfg(test)]
+mod tests {
+ extern crate helper;
+
+ use super::*;
+
+ // This is an intentinally broken test that should be turned off by extra rust arguments
+ #[cfg(not(broken = "false"))]
+ #[test]
+ fn test_broken() {
+ assert_eq!(0, 5);
+ }
+
+ #[test]
+ fn test_add_sub() {
+ let x = helper::subtract(6, 5);
+ assert_eq!(add(x, 5), 6);
+ }
+}