Remove libc from more tests

This commit is contained in:
Ben Kimock 2024-04-15 23:46:27 -04:00
parent 1dea922ea6
commit 1567d4d850
5 changed files with 30 additions and 45 deletions

View File

@ -1,31 +1,29 @@
//@ run-pass //@ run-pass
#![allow(unused_imports)]
//@ ignore-wasm32 can't run commands //@ ignore-wasm32 can't run commands
//@ ignore-sgx no processes //@ ignore-sgx no processes
//@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590) //@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc;
use std::env; use std::env;
use std::ffi::c_char;
use std::process::{Command, ExitStatus}; use std::process::{Command, ExitStatus};
#[link(name = "rust_test_helpers", kind = "static")] #[link(name = "rust_test_helpers", kind = "static")]
extern "C" { extern "C" {
fn rust_get_null_ptr() -> *mut ::libc::c_char; fn rust_get_null_ptr() -> *mut c_char;
} }
#[cfg(unix)] #[cfg(unix)]
fn check_status(status: std::process::ExitStatus) { fn check_status(status: ExitStatus) {
use libc; extern crate libc;
use std::os::unix::process::ExitStatusExt; use std::os::unix::process::ExitStatusExt;
assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS)); assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS));
} }
#[cfg(not(unix))] #[cfg(not(unix))]
fn check_status(status: std::process::ExitStatus) { fn check_status(status: ExitStatus) {
assert!(!status.success()); assert!(!status.success());
} }

View File

@ -11,10 +11,8 @@
// processes with and without the attribute. Search for // processes with and without the attribute. Search for
// `unix_sigpipe_attr_specified()` in the code base to learn more. // `unix_sigpipe_attr_specified()` in the code base to learn more.
#![feature(rustc_private)]
#![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))] #![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))]
extern crate libc;
extern crate sigpipe_utils; extern crate sigpipe_utils;
use sigpipe_utils::*; use sigpipe_utils::*;

View File

@ -1,13 +1,6 @@
#![feature(lang_items)] #![feature(lang_items)]
#![no_std] #![no_std]
// Since `rustc` generally passes `-nodefaultlibs` to the linker,
// Rust programs link necessary system libraries via `#[link()]`
// attributes in the `libc` crate. `libc` is a dependency of `std`,
// but as we are `#![no_std]`, we need to include it manually.
#![feature(rustc_private)]
extern crate libc;
#[panic_handler] #[panic_handler]
pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! { pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! {
loop {} loop {}

View File

@ -1,31 +1,28 @@
// Test that println! to a closed stdout does not panic.
// On Windows, close via SetStdHandle to 0.
//@ run-pass //@ run-pass
#![allow(dead_code)]
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; #[cfg(windows)]
fn close_stdout() {
type DWORD = u32; type DWORD = u32;
type HANDLE = *mut u8; type HANDLE = *mut u8;
type BOOL = i32; type BOOL = i32;
#[cfg(windows)]
extern "system" { extern "system" {
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL; fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
} }
#[cfg(windows)]
fn close_stdout() {
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); } unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); }
} }
#[cfg(windows)] #[cfg(not(windows))]
fn close_stdout() {}
fn main() { fn main() {
close_stdout(); close_stdout();
println!("hello"); println!("hello");
println!("world"); println!("world");
} }
#[cfg(not(windows))]
fn main() {}

View File

@ -1,28 +1,27 @@
// Test that println! to a closed stdout does not panic.
// On Windows, close via CloseHandle.
//@ run-pass //@ run-pass
#![allow(dead_code)]
//@ ignore-sgx no libc //@ ignore-sgx no libc
#![feature(rustc_private)] #![feature(rustc_private)]
extern crate libc; #[cfg(windows)]
fn close_stdout() {
type DWORD = u32; type DWORD = u32;
type HANDLE = *mut u8; type HANDLE = *mut u8;
#[cfg(windows)]
extern "system" { extern "system" {
fn GetStdHandle(which: DWORD) -> HANDLE; fn GetStdHandle(which: DWORD) -> HANDLE;
fn CloseHandle(handle: HANDLE) -> i32; fn CloseHandle(handle: HANDLE) -> i32;
} }
#[cfg(windows)]
fn close_stdout() {
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); } unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); }
} }
#[cfg(not(windows))] #[cfg(not(windows))]
fn close_stdout() { fn close_stdout() {
extern crate libc;
unsafe { libc::close(1); } unsafe { libc::close(1); }
} }