Skip to content

Commit a8c19e1

Browse files
authored
Rollup merge of #79375 - vext01:kernel-copy-temps, r=bjorn3
Make the kernel_copy tests more robust/concurrent. These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.: ``` ---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10 ---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs💯10 ``` Use `std::sys_common::io__test::tmpdir()` to solve this. CC ``@the8472.``
2 parents 1b4ffe4 + 87c1fdb commit a8c19e1

File tree

1 file changed

+11
-8
lines changed
  • library/std/src/sys/unix/kernel_copy

1 file changed

+11
-8
lines changed

library/std/src/sys/unix/kernel_copy/tests.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use crate::env::temp_dir;
21
use crate::fs::OpenOptions;
32
use crate::io;
43
use crate::io::Result;
54
use crate::io::SeekFrom;
65
use crate::io::{BufRead, Read, Seek, Write};
76
use crate::os::unix::io::AsRawFd;
7+
use crate::sys_common::io::test::tmpdir;
88

99
#[test]
1010
fn copy_specialization() -> Result<()> {
1111
use crate::io::{BufReader, BufWriter};
1212

13-
let path = crate::env::temp_dir();
14-
let source_path = path.join("copy-spec.source");
15-
let sink_path = path.join("copy-spec.sink");
13+
let tmp_path = tmpdir();
14+
let source_path = tmp_path.join("copy-spec.source");
15+
let sink_path = tmp_path.join("copy-spec.sink");
1616

1717
let result: Result<()> = try {
1818
let mut source = crate::fs::OpenOptions::new()
@@ -68,7 +68,8 @@ fn copy_specialization() -> Result<()> {
6868
#[bench]
6969
fn bench_file_to_file_copy(b: &mut test::Bencher) {
7070
const BYTES: usize = 128 * 1024;
71-
let src_path = temp_dir().join("file-copy-bench-src");
71+
let temp_path = tmpdir();
72+
let src_path = temp_path.join("file-copy-bench-src");
7273
let mut src = crate::fs::OpenOptions::new()
7374
.create(true)
7475
.truncate(true)
@@ -78,7 +79,7 @@ fn bench_file_to_file_copy(b: &mut test::Bencher) {
7879
.unwrap();
7980
src.write(&vec![0u8; BYTES]).unwrap();
8081

81-
let sink_path = temp_dir().join("file-copy-bench-sink");
82+
let sink_path = temp_path.join("file-copy-bench-sink");
8283
let mut sink = crate::fs::OpenOptions::new()
8384
.create(true)
8485
.truncate(true)
@@ -97,7 +98,8 @@ fn bench_file_to_file_copy(b: &mut test::Bencher) {
9798
#[bench]
9899
fn bench_file_to_socket_copy(b: &mut test::Bencher) {
99100
const BYTES: usize = 128 * 1024;
100-
let src_path = temp_dir().join("pipe-copy-bench-src");
101+
let temp_path = tmpdir();
102+
let src_path = temp_path.join("pipe-copy-bench-src");
101103
let mut src = OpenOptions::new()
102104
.create(true)
103105
.truncate(true)
@@ -128,7 +130,8 @@ fn bench_file_to_socket_copy(b: &mut test::Bencher) {
128130
#[bench]
129131
fn bench_file_to_uds_copy(b: &mut test::Bencher) {
130132
const BYTES: usize = 128 * 1024;
131-
let src_path = temp_dir().join("uds-copy-bench-src");
133+
let temp_path = tmpdir();
134+
let src_path = temp_path.join("uds-copy-bench-src");
132135
let mut src = OpenOptions::new()
133136
.create(true)
134137
.truncate(true)

0 commit comments

Comments
 (0)