Skip to content

Commit

Permalink
Add run-make test for libnative file I/O and O_NONBLOCK
Browse files Browse the repository at this point in the history
This tests rust-lang#13336.
  • Loading branch information
lilyball committed Apr 7, 2014
1 parent 31e8f24 commit e14a2b6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/run-make/libnative-nonblock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-include ../tools.mk

all:
$(RUSTC) write.rs
$(CC) -o $(TMPDIR)/mknblock mknblock.c
mkfifo $(TMPDIR)/fifo
/bin/sh -c "(sleep 1; cat) < $(TMPDIR)/fifo > /dev/null" &
/bin/sh -c "($(TMPDIR)/mknblock; $(TMPDIR)/write) > $(TMPDIR)/fifo"
20 changes: 20 additions & 0 deletions src/test/run-make/libnative-nonblock/mknblock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#include <fcntl.h>
#include <stdio.h>

int main() {
if (fcntl(1, F_SETFL, O_NONBLOCK) == -1) {
perror("fcntl");
return 1;
}
return 0;
}
33 changes: 33 additions & 0 deletions src/test/run-make/libnative-nonblock/write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io;
use std::io::IoResult;
use std::os;

fn run() -> IoResult<()> {
let mut out = io::stdio::stdout_raw();
for _ in range(0u, 1024) {
let mut buf = ['x' as u8, ..1024];
buf[1023] = '\n' as u8;
try!(out.write(buf));
}
Ok(())
}

fn main() {
match run() {
Err(e) => {
(writeln!(&mut io::stderr(), "Error: {}", e)).unwrap();
os::set_exit_status(1);
}
Ok(()) => ()
}
}

0 comments on commit e14a2b6

Please sign in to comment.