Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 71a699a

Browse files
committed
Test for calling seek on a chrdev
1 parent 8f35780 commit 71a699a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/chrdev/tests/tests.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fs;
2-
use std::io::Read;
2+
use std::io::{Read, Seek, SeekFrom};
33
use std::path::PathBuf;
44
use std::process::Command;
55

@@ -76,3 +76,35 @@ fn test_read() {
7676
assert_eq!(&data, b"123456789123")
7777
});
7878
}
79+
80+
#[test]
81+
fn test_lseek_unimplemented() {
82+
with_kernel_module(|| {
83+
let device_number = get_device_major_number();
84+
let p = temporary_file_path();
85+
let _u = mknod(&p, device_number, READ_FILE_MINOR);
86+
87+
let mut f = fs::File::open(&p).unwrap();
88+
assert_eq!(
89+
f.seek(SeekFrom::Start(12))
90+
.unwrap_err()
91+
.raw_os_error()
92+
.unwrap(),
93+
libc::ESPIPE
94+
);
95+
assert_eq!(
96+
f.seek(SeekFrom::End(-12))
97+
.unwrap_err()
98+
.raw_os_error()
99+
.unwrap(),
100+
libc::ESPIPE
101+
);
102+
assert_eq!(
103+
f.seek(SeekFrom::Current(12))
104+
.unwrap_err()
105+
.raw_os_error()
106+
.unwrap(),
107+
libc::ESPIPE
108+
);
109+
});
110+
}

0 commit comments

Comments
 (0)