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

Enhance rand to support macos #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

jiangliu
Copy link
Member

@jiangliu jiangliu commented Mar 18, 2022

Summary of the PR

Enhance rand to support macos, also fixes some failure in unit tests on macos

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • Any newly added unsafe code is properly documented.

The rand::timestamp_cycles() may return duplicated value on non-x86
architectures, so fixes it by retry.

Signed-off-by: Liu Jiang <[email protected]>
Some assumptions in unit test cases are not suitable for Darwin/macos,
so relax those test cases.

Signed-off-by: Liu Jiang <[email protected]>
Copy link
Member

@andreeaflorescu andreeaflorescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see support for macos being added to rust-vmm. Thanks Gerry 👍

@@ -144,6 +144,7 @@ mod tests {
let path = t.as_path();
assert!(path.exists());
assert!(path.is_dir());
#[cfg(not(target_os = "macos"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead check that the path is in the equivalent temp_dir for mac os? Otherwise this test is not very useful.

@@ -185,12 +186,14 @@ mod tests {
let path = t.as_path();
assert!(path.exists());
assert!(path.is_dir());
#[cfg(not(target_os = "macos"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an equivalent check here instead?

Copy link

@mjt0k mjt0k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, not all platforms have 64bit atomic types. There's configuration to check: cfg(target_has_atomic = "64"). I just submitted an issue to omit compilation of src/metrics.rs if target does not have 64bit atomics. Examples of such platforms are armel, mipsel and (surprize!) x32 (tho I think this last one is due to lack of proper rust support there, since i386 does have 64bit atomics).

@@ -24,17 +24,28 @@ pub fn timestamp_cycles() -> u64 {

#[cfg(not(target_arch = "x86_64"))]
{
use std::sync::atomic::{AtomicU64, Ordering};
static TIMESTAMP: AtomicU64 = AtomicU64::new(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be static?

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

Successfully merging this pull request may close these issues.

4 participants