Skip to content

Commit 5d59bde

Browse files
committed
test cleanup
1 parent 5402be8 commit 5d59bde

File tree

2 files changed

+30
-55
lines changed

2 files changed

+30
-55
lines changed

src/tools/miri/tests/pass-dep/libc/libc-pipe.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,31 @@ fn main() {
1010

1111
fn test_pipe() {
1212
let mut fds = [-1, -1];
13-
let mut res = unsafe { libc::pipe(fds.as_mut_ptr()) };
13+
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
1414
assert_eq!(res, 0);
1515

1616
// Read size == data available in buffer.
1717
let data = "12345".as_bytes().as_ptr();
18-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5).try_into().unwrap() };
18+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
1919
assert_eq!(res, 5);
2020
let mut buf3: [u8; 5] = [0; 5];
21-
res = unsafe {
22-
libc::read(fds[0], buf3.as_mut_ptr().cast(), buf3.len() as libc::size_t).try_into().unwrap()
23-
};
21+
let res = unsafe { libc::read(fds[0], buf3.as_mut_ptr().cast(), buf3.len() as libc::size_t) };
2422
assert_eq!(res, 5);
2523
assert_eq!(buf3, "12345".as_bytes());
2624

2725
// Read size > data available in buffer.
2826
let data = "123".as_bytes().as_ptr();
29-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 3).try_into().unwrap() };
27+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 3) };
3028
assert_eq!(res, 3);
3129
let mut buf4: [u8; 5] = [0; 5];
32-
res = unsafe {
33-
libc::read(fds[0], buf4.as_mut_ptr().cast(), buf4.len() as libc::size_t).try_into().unwrap()
34-
};
30+
let res = unsafe { libc::read(fds[0], buf4.as_mut_ptr().cast(), buf4.len() as libc::size_t) };
3531
assert_eq!(res, 3);
3632
assert_eq!(&buf4[0..3], "123".as_bytes());
3733
}
3834

3935
fn test_pipe_threaded() {
4036
let mut fds = [-1, -1];
41-
let mut res = unsafe { libc::pipe(fds.as_mut_ptr()) };
37+
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
4238
assert_eq!(res, 0);
4339

4440
let thread1 = thread::spawn(move || {
@@ -54,7 +50,7 @@ fn test_pipe_threaded() {
5450
// FIXME: we should yield here once blocking is implemented.
5551
//thread::yield_now();
5652
let data = "abcde".as_bytes().as_ptr();
57-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5).try_into().unwrap() };
53+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
5854
assert_eq!(res, 5);
5955
thread1.join().unwrap();
6056

@@ -63,16 +59,13 @@ fn test_pipe_threaded() {
6359
// FIXME: we should yield here once blocking is implemented.
6460
//thread::yield_now();
6561
let data = "12345".as_bytes().as_ptr();
66-
let res: i64 =
67-
unsafe { libc::write(fds[1], data as *const libc::c_void, 5).try_into().unwrap() };
62+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
6863
assert_eq!(res, 5);
6964
});
7065
// FIXME: we should not yield here once blocking is implemented.
7166
thread::yield_now();
7267
let mut buf: [u8; 5] = [0; 5];
73-
res = unsafe {
74-
libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap()
75-
};
68+
let res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
7669
assert_eq!(res, 5);
7770
assert_eq!(buf, "12345".as_bytes());
7871
thread2.join().unwrap();
@@ -81,7 +74,7 @@ fn test_pipe_threaded() {
8174
fn test_race() {
8275
static mut VAL: u8 = 0;
8376
let mut fds = [-1, -1];
84-
let mut res = unsafe { libc::pipe(fds.as_mut_ptr()) };
77+
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
8578
assert_eq!(res, 0);
8679
let thread1 = thread::spawn(move || {
8780
let mut buf: [u8; 1] = [0; 1];
@@ -99,7 +92,7 @@ fn test_race() {
9992
});
10093
unsafe { VAL = 1 };
10194
let data = "a".as_bytes().as_ptr();
102-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 1).try_into().unwrap() };
95+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 1) };
10396
assert_eq!(res, 1);
10497
thread::yield_now();
10598
thread1.join().unwrap();

src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,66 @@ fn main() {
1010

1111
fn test_socketpair() {
1212
let mut fds = [-1, -1];
13-
let mut res =
14-
unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
13+
let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
1514
assert_eq!(res, 0);
1615

1716
// Read size == data available in buffer.
1817
let data = "abcde".as_bytes().as_ptr();
19-
res = unsafe { libc::write(fds[0], data as *const libc::c_void, 5).try_into().unwrap() };
18+
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 5) };
2019
assert_eq!(res, 5);
2120
let mut buf: [u8; 5] = [0; 5];
22-
res = unsafe {
23-
libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap()
24-
};
21+
let res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
2522
assert_eq!(res, 5);
2623
assert_eq!(buf, "abcde".as_bytes());
2724

2825
// Read size > data available in buffer.
2926
let data = "abc".as_bytes().as_ptr();
30-
res = unsafe { libc::write(fds[0], data as *const libc::c_void, 3).try_into().unwrap() };
27+
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 3) };
3128
assert_eq!(res, 3);
3229
let mut buf2: [u8; 5] = [0; 5];
33-
res = unsafe {
34-
libc::read(fds[1], buf2.as_mut_ptr().cast(), buf2.len() as libc::size_t).try_into().unwrap()
35-
};
30+
let res = unsafe { libc::read(fds[1], buf2.as_mut_ptr().cast(), buf2.len() as libc::size_t) };
3631
assert_eq!(res, 3);
3732
assert_eq!(&buf2[0..3], "abc".as_bytes());
3833

3934
// Test read and write from another direction.
4035
// Read size == data available in buffer.
4136
let data = "12345".as_bytes().as_ptr();
42-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5).try_into().unwrap() };
37+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
4338
assert_eq!(res, 5);
4439
let mut buf3: [u8; 5] = [0; 5];
45-
res = unsafe {
46-
libc::read(fds[0], buf3.as_mut_ptr().cast(), buf3.len() as libc::size_t).try_into().unwrap()
47-
};
40+
let res = unsafe { libc::read(fds[0], buf3.as_mut_ptr().cast(), buf3.len() as libc::size_t) };
4841
assert_eq!(res, 5);
4942
assert_eq!(buf3, "12345".as_bytes());
5043

5144
// Read size > data available in buffer.
5245
let data = "123".as_bytes().as_ptr();
53-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 3).try_into().unwrap() };
46+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 3) };
5447
assert_eq!(res, 3);
5548
let mut buf4: [u8; 5] = [0; 5];
56-
res = unsafe {
57-
libc::read(fds[0], buf4.as_mut_ptr().cast(), buf4.len() as libc::size_t).try_into().unwrap()
58-
};
49+
let res = unsafe { libc::read(fds[0], buf4.as_mut_ptr().cast(), buf4.len() as libc::size_t) };
5950
assert_eq!(res, 3);
6051
assert_eq!(&buf4[0..3], "123".as_bytes());
6152

6253
// Test when happens when we close one end, with some data in the buffer.
63-
res = unsafe { libc::write(fds[0], data as *const libc::c_void, 3).try_into().unwrap() };
54+
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 3) };
6455
assert_eq!(res, 3);
6556
unsafe { libc::close(fds[0]) };
6657
// Reading the other end should return that data, then EOF.
6758
let mut buf: [u8; 5] = [0; 5];
68-
res = unsafe {
69-
libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap()
70-
};
59+
let res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
7160
assert_eq!(res, 3);
7261
assert_eq!(&buf[0..3], "123".as_bytes());
73-
res = unsafe {
74-
libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap()
75-
};
62+
let res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
7663
assert_eq!(res, 0); // 0-sized read: EOF.
7764
// Writing the other end should emit EPIPE.
78-
res = unsafe { libc::write(fds[1], data as *const libc::c_void, 1).try_into().unwrap() };
65+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 1) };
7966
assert_eq!(res, -1);
8067
assert_eq!(std::io::Error::last_os_error().raw_os_error(), Some(libc::EPIPE));
8168
}
8269

8370
fn test_socketpair_threaded() {
8471
let mut fds = [-1, -1];
85-
let mut res =
86-
unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
72+
let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
8773
assert_eq!(res, 0);
8874

8975
let thread1 = thread::spawn(move || {
@@ -99,7 +85,7 @@ fn test_socketpair_threaded() {
9985
// FIXME: we should yield here once blocking is implemented.
10086
//thread::yield_now();
10187
let data = "abcde".as_bytes().as_ptr();
102-
res = unsafe { libc::write(fds[0], data as *const libc::c_void, 5).try_into().unwrap() };
88+
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 5) };
10389
assert_eq!(res, 5);
10490
thread1.join().unwrap();
10591

@@ -108,16 +94,13 @@ fn test_socketpair_threaded() {
10894
// FIXME: we should yield here once blocking is implemented.
10995
//thread::yield_now();
11096
let data = "12345".as_bytes().as_ptr();
111-
let res: i64 =
112-
unsafe { libc::write(fds[1], data as *const libc::c_void, 5).try_into().unwrap() };
97+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
11398
assert_eq!(res, 5);
11499
});
115100
// FIXME: we should not yield here once blocking is implemented.
116101
thread::yield_now();
117102
let mut buf: [u8; 5] = [0; 5];
118-
res = unsafe {
119-
libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap()
120-
};
103+
let res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
121104
assert_eq!(res, 5);
122105
assert_eq!(buf, "12345".as_bytes());
123106
thread2.join().unwrap();
@@ -126,8 +109,7 @@ fn test_socketpair_threaded() {
126109
fn test_race() {
127110
static mut VAL: u8 = 0;
128111
let mut fds = [-1, -1];
129-
let mut res =
130-
unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
112+
let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) };
131113
assert_eq!(res, 0);
132114
let thread1 = thread::spawn(move || {
133115
let mut buf: [u8; 1] = [0; 1];
@@ -145,7 +127,7 @@ fn test_race() {
145127
});
146128
unsafe { VAL = 1 };
147129
let data = "a".as_bytes().as_ptr();
148-
res = unsafe { libc::write(fds[0], data as *const libc::c_void, 1).try_into().unwrap() };
130+
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 1) };
149131
assert_eq!(res, 1);
150132
thread::yield_now();
151133
thread1.join().unwrap();

0 commit comments

Comments
 (0)