Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sound] test execution reports warning on pipewire and alsa backends code #785

Closed
sandrobonazzola opened this issue Dec 2, 2024 · 3 comments

Comments

@sandrobonazzola
Copy link
Contributor

During RPM building of rust-vhost-device-sound in Fedora I noticed a couple of warnings reported during the test phase.
Reporting them:

warning: fields `dbus` and `tempdir` are never read
  --> src/audio_backends/pipewire/test_utils.rs:56:9
   |
55 | pub struct PipewireTestHarness {
   |            ------------------- fields in this struct
56 |     pub dbus: DbusSession,
   |         ^^^^
57 |     pub pipewire_child: Child,
58 |     pub tempdir: TempDir,
   |         ^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: creating a shared reference to mutable static is discouraged
  --> src/audio_backends/alsa/test_utils.rs:30:18
   |
30 |         unsafe { TEST_HARNESS.as_ref().unwrap() },
   |                  ^^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
   |
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
   = note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
   = note: `#[warn(static_mut_refs)]` on by default

warning: `vhost-device-sound` (lib test) generated 2 warnings
@stefano-garzarella
Copy link
Member

@sandrobonazzola thanks for reporting!
The first warning is already fixed by ef98372 ("chore: fix clippy warnings"), indeed I can't reproduce in current main.

@epilys can you take a look at the second warning? (I can reproduce running cargo test with rustc 1.83.0 (90b35a623 2024-11-26)

@epilys
Copy link
Member

epilys commented Dec 2, 2024

@stefano-garzarella fix in PR #788

@stefano-garzarella
Copy link
Member

@epilys great, thanks!

epilys added a commit to epilys/vhost-device that referenced this issue Dec 2, 2024
Instead of using unsafe {} and undefined behavior (mutable shared static
references) use LazyLock which initializes the harness on first
dereference and provides immutable access only (the harness type has
interior mutability).

Fixes: rust-vmm#785

Signed-off-by: Manos Pitsidianakis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants