This is an automated email from the ASF dual-hosted git repository.
tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 1a2f9423 [TEST] Fix the main test failures after #869 and #861 (#871)
1a2f9423 is described below
commit 1a2f94238f3259e729bdd18f1b0e6144b6988323
Author: Linzhang Li <[email protected]>
AuthorDate: Fri Oct 23 20:47:36 2026 -0400
[TEST] Fix the main test failures after #869 and #861 (#871)
## Summary
Fix the two test failures of `main` after #869 and #861 merged.
- **`test_rs_class`** segfaults now and then
([39880320266](https://github.com/apache/tvm-ffi/actions/runs/39880320266/job/120252443676)).
Same race as #862: `#[rs_class]` types register on first use, so a test
registering one grows `type_table_` while another test reads it through
`TVMFFIGetTypeInfo`. As in #862, `register_types()` now registers every
type
of the file once, behind a `std::sync::Once`, before each test.
- **`test_cli_check_ignores_how_a_binding_is_spelled`** fails on every
run
([39880346684](https://github.com/apache/tvm-ffi/actions/runs/39880346684/job/120252471634)).
#869 made the generated `<Leaf>Obj::new` of a non-final type `pub`, but
#861, written before it, still looks for `pub(crate) fn new(`. The test
now
looks for `pub fn new(`.
---
rust/tvm-ffi/tests/test_rs_class.rs | 22 ++++++++++++++++++++++
tests/python/test_stubgen_rust.py | 4 ++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/rust/tvm-ffi/tests/test_rs_class.rs
b/rust/tvm-ffi/tests/test_rs_class.rs
index 5cb5583c..8a3f889b 100644
--- a/rust/tvm-ffi/tests/test_rs_class.rs
+++ b/rust/tvm-ffi/tests/test_rs_class.rs
@@ -190,8 +190,24 @@ fn deep_copy<T: AnyCompatible + Clone + TryFrom<Any, Error
= Error>>(value: &T)
T::try_from(call("ffi.DeepCopy", &[AnyView::from(&any)])).unwrap()
}
+// A type registers on first use, and the runtime does not guard its type table
+// against readers on other threads, so each test registers every type here
+// before it reads the table.
+fn register_types() {
+ static REGISTERED: std::sync::Once = std::sync::Once::new();
+ REGISTERED.call_once(|| {
+ RsPointObj::type_index();
+ RsPoint3Obj::type_index();
+ RsMarkerObj::type_index();
+ RsScalarsObj::type_index();
+ RsCxxChildObj::type_index();
+ reexported::ReexportedObj::type_index();
+ });
+}
+
#[test]
fn test_fields_are_registered_with_their_flags() {
+ register_types();
assert_eq!(field_names::<RsPointObj>(), ["x", "label"]);
let [x, label] = fields(type_info::<RsPointObj>()) else {
unreachable!()
@@ -229,6 +245,7 @@ fn test_fields_are_registered_with_their_flags() {
#[test]
fn test_constructors_deref_and_upcast() {
+ register_types();
let p3 = point3(1, 3);
// Through `RsPoint3Obj` to `RsPointObj`.
assert_eq!((p3.x, p3.label.as_str()), (1, "p3"));
@@ -256,6 +273,7 @@ fn test_constructors_deref_and_upcast() {
#[test]
fn test_new_takes_literals_of_the_field_types() {
+ register_types();
let scalars = RsScalars::from(RsScalarsObj::new(Object::new(),
5_000_000_000, 1, 2, 0.5));
assert_eq!(
(scalars.big, scalars.count, scalars.port, scalars.ratio),
@@ -269,6 +287,7 @@ fn test_new_takes_literals_of_the_field_types() {
#[test]
fn test_cpp_structural_equality_and_deep_copy_see_the_fields() {
+ register_types();
// `label` is ignored.
assert!(structural_equal(&point(1, "a"), &point(1, "b")));
assert!(!structural_equal(&point(1, "a"), &point(2, "a")));
@@ -291,6 +310,7 @@ fn
test_cpp_structural_equality_and_deep_copy_see_the_fields() {
#[test]
fn test_shallow_copy_and_finality_are_type_attributes() {
+ register_types();
let attr = |type_index, name| get_type_attr(type_index, name).unwrap();
let is_final = |type_index| bool::try_from(attr(type_index,
"__ffi_type_final__")).unwrap();
assert!(!is_final(RsPointObj::type_index()));
@@ -310,6 +330,7 @@ fn test_shallow_copy_and_finality_are_type_attributes() {
#[test]
fn test_subtype_of_a_cpp_type() {
+ register_types();
let child = cxx_child(7, 8, "c");
assert_eq!((child.v_i64, child.v_i32, child.name.as_str()), (7, 8, "c"));
// The C++ fields are reflected under the subtype.
@@ -331,6 +352,7 @@ fn test_subtype_of_a_cpp_type() {
#[test]
fn test_crate_path_names_a_reexported_tvm_ffi() {
+ register_types();
let value =
reexported::Reexported::from(reexported::ReexportedObj::new(Object::new(), 5));
assert_eq!(value.v, 5);
assert!(ObjectRef::from(&value).same_as(&value));
diff --git a/tests/python/test_stubgen_rust.py
b/tests/python/test_stubgen_rust.py
index 01375e77..0ed51f2a 100644
--- a/tests/python/test_stubgen_rust.py
+++ b/tests/python/test_stubgen_rust.py
@@ -1500,14 +1500,14 @@ def test_cli_check_ignores_how_a_binding_is_spelled(
(" base: Object,\n", " base: tvm_ffi::Object,\n"),
("/// Complete: ", "/// Mirrored: "),
(
- " pub(crate) fn new(\n"
+ " pub fn new(\n"
" p_required: i64,\n"
" p_default: i64,\n"
" k_required: i64,\n"
" k_default: i64,\n"
" hidden: i64,\n"
" ) -> Self {\n",
- " pub(crate) fn new(p_required: i64, p_default: i64,
k_required: i64, "
+ " pub fn new(p_required: i64, p_default: i64, k_required: i64, "
"k_default: i64, hidden: i64) -> Self {\n",
),
]: