qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC v3 19/32] tests: check Rust and C CABI diffs


From: marcandre . lureau
Subject: [RFC v3 19/32] tests: check Rust and C CABI diffs
Date: Tue, 7 Sep 2021 16:19:30 +0400

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 meson.build              |  3 +++
 Cargo.lock               |  7 +++++++
 Cargo.toml               |  1 +
 scripts/diff_commands.py | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/Cargo.toml         | 13 +++++++++++++
 tests/meson.build        | 29 +++++++++++++++++++++++++----
 tests/qapi-cabi.rs       |  5 +++++
 tests/qapi_ffi.rs        |  8 ++++++++
 8 files changed, 102 insertions(+), 4 deletions(-)
 create mode 100644 scripts/diff_commands.py
 create mode 100644 tests/Cargo.toml
 create mode 100644 tests/qapi-cabi.rs
 create mode 100644 tests/qapi_ffi.rs

diff --git a/meson.build b/meson.build
index b45f409eb4..74e90059c2 100644
--- a/meson.build
+++ b/meson.build
@@ -118,6 +118,7 @@ cargo_wrapper = [
   find_program('scripts/cargo_wrapper.py'),
   '--configh', meson.current_build_dir() / 'config-host.h'
 ]
+diff_commands = find_program('scripts/diff_commands.py')
 
 if with_rust
   rust_target_triple = get_option('with_rust_target')
@@ -212,7 +213,9 @@ iokit = []
 emulator_link_args = []
 nvmm =not_found
 hvf = not_found
+exe_suffix = ''
 if targetos == 'windows'
+  exe_suffix = '.exe'
   socket = cc.find_library('ws2_32')
   winmm = cc.find_library('winmm')
 
diff --git a/Cargo.lock b/Cargo.lock
index 8dc2dd9da7..f2cd0ee96e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -61,3 +61,10 @@ dependencies = [
  "libc",
  "memoffset",
 ]
+
+[[package]]
+name = "qemu-tests"
+version = "0.0.1"
+dependencies = [
+ "common",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 14131eed3c..f4a078e62d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,4 +1,5 @@
 [workspace]
 members = [
   "rust/common",
+  "tests",
 ]
diff --git a/scripts/diff_commands.py b/scripts/diff_commands.py
new file mode 100644
index 0000000000..eecc03dd76
--- /dev/null
+++ b/scripts/diff_commands.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020 Red Hat, Inc.
+#
+# Author:
+#  Marc-André Lureau <marcandre.lureau@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+
+import argparse
+import difflib
+import subprocess
+import sys
+
+
+def main() -> None:
+    parser = argparse.ArgumentParser()
+    parser.add_argument("EXE1")
+    parser.add_argument("EXE2")
+    args = parser.parse_args()
+
+    exe1_out = subprocess.check_output(args.EXE1, universal_newlines=True)
+    exe2_out = subprocess.check_output(args.EXE2, universal_newlines=True)
+    out_diff = difflib.unified_diff(
+        exe1_out.splitlines(True),
+        exe2_out.splitlines(True),
+        fromfile=args.EXE1,
+        tofile=args.EXE2,
+    )
+    has_diff = False
+    for line in out_diff:
+        has_diff = True
+        sys.stdout.write(line)
+
+    if has_diff:
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
new file mode 100644
index 0000000000..7a4f6060b1
--- /dev/null
+++ b/tests/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "qemu-tests"
+version = "0.0.1"
+edition = "2018"
+publish = false
+
+[dependencies]
+common = { path = "../rust/common" }
+
+[[bin]]
+name = "qapi-cabi-rs"
+path = "qapi-cabi.rs"
+doc = false
diff --git a/tests/meson.build b/tests/meson.build
index 7292fe20df..f9af42caba 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -52,6 +52,19 @@ if with_rust
                                command: [ qapi_gen, '-o', 
meson.current_build_dir(),
                                           '-r', '-b', '-p', 'test-', 
'@INPUT0@' ],
                                depend_files: qapi_gen_depends)
+  qapi_cabi_rs = custom_target('qapi-cabi-rs',
+                               output: ['qapi-cabi-rs' + exe_suffix],
+                               build_always_stale: true,
+                               depends: [test_qapi_rs],
+                               command: [cargo_wrapper,
+                                         meson.current_build_dir(),
+                                         meson.current_source_dir(),
+                                         meson.build_root(),
+                                         rs_build_type,
+                                         rust_target_triple,
+                                         'build-bin',
+                                         'qapi-cabi-rs',
+                                         '--', '--cfg', 'QAPI_CABI'])
 endif
 
 # meson doesn't like generated output in other directories
@@ -75,10 +88,18 @@ testqapi = declare_dependency(link_with: libtestqapi,
                               dependencies: [qemuutil],
                               sources: [genh, test_qapi_headers])
 
-executable('qapi-cabi',
-           files('qapi-cabi.c'),
-           dependencies: testqapi,
-           c_args: ['-DQAPI_CABI'])
+qapi_cabi = executable('qapi-cabi',
+                       files('qapi-cabi.c'),
+                       dependencies: testqapi,
+                       c_args: ['-DQAPI_CABI'])
+
+if with_rust
+  test('Test QAPI CABI diff',
+       diff_commands,
+       args: [qapi_cabi.full_path(), qapi_cabi_rs.full_path()],
+       depends: [qapi_cabi, qapi_cabi_rs],
+       suite: ['qapi'])
+endif
 
 test_deps = {
   'test-qht-par': qht_bench,
diff --git a/tests/qapi-cabi.rs b/tests/qapi-cabi.rs
new file mode 100644
index 0000000000..0b4b99cc78
--- /dev/null
+++ b/tests/qapi-cabi.rs
@@ -0,0 +1,5 @@
+mod qapi_ffi;
+
+fn main() {
+    qapi_ffi::cabi()
+}
diff --git a/tests/qapi_ffi.rs b/tests/qapi_ffi.rs
new file mode 100644
index 0000000000..d50a02efbe
--- /dev/null
+++ b/tests/qapi_ffi.rs
@@ -0,0 +1,8 @@
+#![allow(dead_code)]
+
+use common::libc;
+
+include!(concat!(
+    env!("MESON_BUILD_ROOT"),
+    "/tests/test-qapi-ffi-types.rs"
+));
-- 
2.33.0.113.g6c40894d24




reply via email to

[Prev in Thread] Current Thread [Next in Thread]