Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
432b4c14
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
432b4c14
编写于
5月 21, 2020
作者:
E
Eric Huss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use cfg_if in libtest.
Simplifies some of the expressions, and provides a default.
上级
8c6c1dd3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
131 deletion
+98
-131
Cargo.lock
Cargo.lock
+1
-0
src/libtest/Cargo.toml
src/libtest/Cargo.toml
+1
-0
src/libtest/helpers/concurrency.rs
src/libtest/helpers/concurrency.rs
+69
-102
src/libtest/helpers/isatty.rs
src/libtest/helpers/isatty.rs
+27
-29
未找到文件。
Cargo.lock
浏览文件 @
432b4c14
...
...
@@ -4552,6 +4552,7 @@ dependencies = [
name = "test"
version = "0.0.0"
dependencies = [
"cfg-if",
"core",
"getopts",
"libc",
...
...
src/libtest/Cargo.toml
浏览文件 @
432b4c14
...
...
@@ -10,6 +10,7 @@ path = "lib.rs"
crate-type
=
[
"dylib"
,
"rlib"
]
[dependencies]
cfg-if
=
{
version
=
"0.1.8"
,
features
=
['rustc-dep-of-std']
}
getopts
=
{
version
=
"0.2.21"
,
features
=
['rustc-dep-of-std']
}
term
=
{
path
=
"../libterm"
}
std
=
{
path
=
"../libstd"
}
...
...
src/libtest/helpers/concurrency.rs
浏览文件 @
432b4c14
...
...
@@ -14,61 +14,36 @@ pub fn get_concurrency() -> usize {
}
Err
(
..
)
=>
num_cpus
(),
};
}
#[cfg(windows)]
#[allow(nonstandard_style)]
fn
num_cpus
()
->
usize
{
#[repr(C)]
struct
SYSTEM_INFO
{
wProcessorArchitecture
:
u16
,
wReserved
:
u16
,
dwPageSize
:
u32
,
lpMinimumApplicationAddress
:
*
mut
u8
,
lpMaximumApplicationAddress
:
*
mut
u8
,
dwActiveProcessorMask
:
*
mut
u8
,
dwNumberOfProcessors
:
u32
,
dwProcessorType
:
u32
,
dwAllocationGranularity
:
u32
,
wProcessorLevel
:
u16
,
wProcessorRevision
:
u16
,
}
extern
"system"
{
fn
GetSystemInfo
(
info
:
*
mut
SYSTEM_INFO
)
->
i32
;
}
unsafe
{
let
mut
sysinfo
=
std
::
mem
::
zeroed
();
GetSystemInfo
(
&
mut
sysinfo
);
sysinfo
.dwNumberOfProcessors
as
usize
cfg_if
::
cfg_if!
{
if
#[cfg(windows)]
{
#[allow(nonstandard_style)]
fn
num_cpus
()
->
usize
{
#[repr(C)]
struct
SYSTEM_INFO
{
wProcessorArchitecture
:
u16
,
wReserved
:
u16
,
dwPageSize
:
u32
,
lpMinimumApplicationAddress
:
*
mut
u8
,
lpMaximumApplicationAddress
:
*
mut
u8
,
dwActiveProcessorMask
:
*
mut
u8
,
dwNumberOfProcessors
:
u32
,
dwProcessorType
:
u32
,
dwAllocationGranularity
:
u32
,
wProcessorLevel
:
u16
,
wProcessorRevision
:
u16
,
}
extern
"system"
{
fn
GetSystemInfo
(
info
:
*
mut
SYSTEM_INFO
)
->
i32
;
}
unsafe
{
let
mut
sysinfo
=
std
::
mem
::
zeroed
();
GetSystemInfo
(
&
mut
sysinfo
);
sysinfo
.dwNumberOfProcessors
as
usize
}
}
}
#[cfg(target_os
=
"vxworks"
)]
fn
num_cpus
()
->
usize
{
// FIXME: Implement num_cpus on vxWorks
1
}
#[cfg(target_os
=
"redox"
)]
fn
num_cpus
()
->
usize
{
// FIXME: Implement num_cpus on Redox
1
}
#[cfg(target_os
=
"hermit"
)]
fn
num_cpus
()
->
usize
{
// FIXME: Implement num_cpus on HermitCore
1
}
#[cfg(any(
all(target_arch
=
"wasm32"
,
not(target_os
=
"emscripten"
)),
all(target_vendor
=
"fortanix"
,
target_env
=
"sgx"
)
))]
fn
num_cpus
()
->
usize
{
1
}
#[cfg(any(
}
else
if
#[cfg(any(
target_os
=
"android"
,
target_os
=
"cloudabi"
,
target_os
=
"emscripten"
,
...
...
@@ -78,23 +53,46 @@ fn num_cpus() -> usize {
target_os
=
"macos"
,
target_os
=
"solaris"
,
target_os
=
"illumos"
,
))]
fn
num_cpus
()
->
usize
{
unsafe
{
libc
::
sysconf
(
libc
::
_
SC_NPROCESSORS_ONLN
)
as
usize
}
}
#[cfg(any(target_os
=
"freebsd"
,
target_os
=
"dragonfly"
,
target_os
=
"netbsd"
))]
fn
num_cpus
()
->
usize
{
use
std
::
ptr
;
))]
{
fn
num_cpus
()
->
usize
{
unsafe
{
libc
::
sysconf
(
libc
::
_
SC_NPROCESSORS_ONLN
)
as
usize
}
}
}
else
if
#[cfg(any(target_os
=
"freebsd"
,
target_os
=
"dragonfly"
,
target_os
=
"netbsd"
))]
{
fn
num_cpus
()
->
usize
{
use
std
::
ptr
;
let
mut
cpus
:
libc
::
c_uint
=
0
;
let
mut
cpus_size
=
std
::
mem
::
size_of_val
(
&
cpus
);
let
mut
cpus
:
libc
::
c_uint
=
0
;
let
mut
cpus_size
=
std
::
mem
::
size_of_val
(
&
cpus
);
unsafe
{
cpus
=
libc
::
sysconf
(
libc
::
_
SC_NPROCESSORS_ONLN
)
as
libc
::
c_uint
;
unsafe
{
cpus
=
libc
::
sysconf
(
libc
::
_
SC_NPROCESSORS_ONLN
)
as
libc
::
c_uint
;
}
if
cpus
<
1
{
let
mut
mib
=
[
libc
::
CTL_HW
,
libc
::
HW_NCPU
,
0
,
0
];
unsafe
{
libc
::
sysctl
(
mib
.as_mut_ptr
(),
2
,
&
mut
cpus
as
*
mut
_
as
*
mut
_
,
&
mut
cpus_size
as
*
mut
_
as
*
mut
_
,
ptr
::
null_mut
(),
0
,
);
}
if
cpus
<
1
{
cpus
=
1
;
}
}
cpus
as
usize
}
if
cpus
<
1
{
}
else
if
#[cfg(target_os
=
"openbsd"
)]
{
fn
num_cpus
()
->
usize
{
use
std
::
ptr
;
let
mut
cpus
:
libc
::
c_uint
=
0
;
let
mut
cpus_size
=
std
::
mem
::
size_of_val
(
&
cpus
);
let
mut
mib
=
[
libc
::
CTL_HW
,
libc
::
HW_NCPU
,
0
,
0
];
unsafe
{
libc
::
sysctl
(
mib
.as_mut_ptr
(),
...
...
@@ -108,43 +106,12 @@ fn num_cpus() -> usize {
if
cpus
<
1
{
cpus
=
1
;
}
cpus
as
usize
}
cpus
as
usize
}
#[cfg(target_os
=
"openbsd"
)]
fn
num_cpus
()
->
usize
{
use
std
::
ptr
;
let
mut
cpus
:
libc
::
c_uint
=
0
;
let
mut
cpus_size
=
std
::
mem
::
size_of_val
(
&
cpus
);
let
mut
mib
=
[
libc
::
CTL_HW
,
libc
::
HW_NCPU
,
0
,
0
];
unsafe
{
libc
::
sysctl
(
mib
.as_mut_ptr
(),
2
,
&
mut
cpus
as
*
mut
_
as
*
mut
_
,
&
mut
cpus_size
as
*
mut
_
as
*
mut
_
,
ptr
::
null_mut
(),
0
,
);
}
if
cpus
<
1
{
cpus
=
1
;
}
else
{
// FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re
fn
num_cpus
()
->
usize
{
1
}
cpus
as
usize
}
#[cfg(target_os
=
"haiku"
)]
fn
num_cpus
()
->
usize
{
// FIXME: implement
1
}
#[cfg(target_os
=
"l4re"
)]
fn
num_cpus
()
->
usize
{
// FIXME: implement
1
}
}
src/libtest/helpers/isatty.rs
浏览文件 @
432b4c14
//! Helper module which provides a function to test
//! if stdout is a tty.
#[cfg(any(
target_os
=
"cloudabi"
,
target_os
=
"hermit"
,
all(target_arch
=
"wasm32"
,
not(target_os
=
"emscripten"
)),
all(target_vendor
=
"fortanix"
,
target_env
=
"sgx"
)
))]
pub
fn
stdout_isatty
()
->
bool
{
// FIXME: Implement isatty on SGX
false
}
#[cfg(unix)]
pub
fn
stdout_isatty
()
->
bool
{
unsafe
{
libc
::
isatty
(
libc
::
STDOUT_FILENO
)
!=
0
}
}
#[cfg(windows)]
pub
fn
stdout_isatty
()
->
bool
{
type
DWORD
=
u32
;
type
BOOL
=
i32
;
type
HANDLE
=
*
mut
u8
;
type
LPDWORD
=
*
mut
u32
;
const
STD_OUTPUT_HANDLE
:
DWORD
=
-
11i32
as
DWORD
;
extern
"system"
{
fn
GetStdHandle
(
which
:
DWORD
)
->
HANDLE
;
fn
GetConsoleMode
(
hConsoleHandle
:
HANDLE
,
lpMode
:
LPDWORD
)
->
BOOL
;
}
unsafe
{
let
handle
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
let
mut
out
=
0
;
GetConsoleMode
(
handle
,
&
mut
out
)
!=
0
cfg_if
::
cfg_if!
{
if
#[cfg(unix)]
{
pub
fn
stdout_isatty
()
->
bool
{
unsafe
{
libc
::
isatty
(
libc
::
STDOUT_FILENO
)
!=
0
}
}
}
else
if
#[cfg(windows)]
{
pub
fn
stdout_isatty
()
->
bool
{
type
DWORD
=
u32
;
type
BOOL
=
i32
;
type
HANDLE
=
*
mut
u8
;
type
LPDWORD
=
*
mut
u32
;
const
STD_OUTPUT_HANDLE
:
DWORD
=
-
11i32
as
DWORD
;
extern
"system"
{
fn
GetStdHandle
(
which
:
DWORD
)
->
HANDLE
;
fn
GetConsoleMode
(
hConsoleHandle
:
HANDLE
,
lpMode
:
LPDWORD
)
->
BOOL
;
}
unsafe
{
let
handle
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
let
mut
out
=
0
;
GetConsoleMode
(
handle
,
&
mut
out
)
!=
0
}
}
}
else
{
// FIXME: Implement isatty on SGX
pub
fn
stdout_isatty
()
->
bool
{
false
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录