|
| 1 | +use libc::*; |
| 2 | + |
| 3 | +#[cfg(all(target_os = "linux", target_env = "gnu"))] |
| 4 | +#[test] |
| 5 | +fn baud() { |
| 6 | + let controller_fd = unsafe { posix_openpt(O_RDWR | O_NOCTTY) }; |
| 7 | + assert!(controller_fd >= 0); |
| 8 | + unsafe { |
| 9 | + grantpt(controller_fd); |
| 10 | + unlockpt(controller_fd); |
| 11 | + } |
| 12 | + let mut buffer = [0; 256]; |
| 13 | + let ret = unsafe { ptsname_r(controller_fd, buffer.as_mut_ptr(), 256) }; |
| 14 | + assert!(ret >= 0); |
| 15 | + let terminal_fd = unsafe { libc::open(buffer.as_ptr(), O_RDWR | O_NOCTTY) }; |
| 16 | + assert!(terminal_fd >= 0); |
| 17 | + let mut tio: libc::termios = unsafe { std::mem::zeroed() }; |
| 18 | + let ret = unsafe { tcgetattr(terminal_fd, &raw mut tio) }; |
| 19 | + assert!(ret >= 0); |
| 20 | + assert_eq!(unsafe { cfgetispeed(&raw const tio) }, B38400); |
| 21 | + assert_eq!(unsafe { cfgetospeed(&raw const tio) }, B38400); |
| 22 | + let ret = unsafe { cfsetspeed(&raw mut tio, B4000000) }; |
| 23 | + assert!(ret >= 0); |
| 24 | + assert_eq!(unsafe { cfgetispeed(&raw const tio) }, B4000000); |
| 25 | + assert_eq!(unsafe { cfgetospeed(&raw const tio) }, B4000000); |
| 26 | + let ret = unsafe { cfsetispeed(&raw mut tio, B9600) }; |
| 27 | + assert!(ret >= 0); |
| 28 | + assert_eq!(unsafe { cfgetispeed(&raw const tio) }, B9600); |
| 29 | + assert_eq!(unsafe { cfgetospeed(&raw const tio) }, B4000000); |
| 30 | + let ret = unsafe { cfsetospeed(&raw mut tio, B19200) }; |
| 31 | + assert!(ret >= 0); |
| 32 | + assert_eq!(unsafe { cfgetispeed(&raw const tio) }, B9600); |
| 33 | + assert_eq!(unsafe { cfgetospeed(&raw const tio) }, B19200); |
| 34 | + unsafe extern "C" { |
| 35 | + unsafe fn cfsetspeed_b38400(termios: *mut crate::termios) -> c_int; |
| 36 | + } |
| 37 | + let ret = unsafe { cfsetspeed_b38400(&raw mut tio) }; |
| 38 | + assert!(ret >= 0); |
| 39 | + assert_eq!(unsafe { cfgetispeed(&raw const tio) }, B38400); |
| 40 | + assert_eq!(unsafe { cfgetospeed(&raw const tio) }, B38400); |
| 41 | +} |
0 commit comments