Skip to content

Commit

Permalink
Test fixes and rebase conflicts
Browse files Browse the repository at this point in the history
* vec::raw::to_ptr is gone
* Pausible => Pausable
* Removing @
* Calling the main task "<main>"
* Removing unused imports
* Removing unused mut
* Bringing some libextra tests up to date
* Allowing compiletest to work at stage0
* Fixing the bootstrap-from-c rmake tests
* assert => rtassert in a few cases
* printing to stderr instead of stdout in fail!()
  • Loading branch information
alexcrichton committed Dec 26, 2013
1 parent b47ff23 commit 6cad8f4
Show file tree
Hide file tree
Showing 41 changed files with 274 additions and 191 deletions.
1 change: 1 addition & 0 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#[allow(non_camel_case_types)];
#[deny(warnings)];

#[cfg(stage0)] extern mod green;
extern mod extra;

use std::os;
Expand Down
11 changes: 4 additions & 7 deletions src/libextra/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub fn rendezvous<T: Send>() -> (SyncPort<T>, SyncChan<T>) {
#[cfg(test)]
mod test {
use comm::{DuplexStream, rendezvous};
use std::rt::test::run_in_uv_task;


#[test]
Expand Down Expand Up @@ -124,13 +123,11 @@ mod test {
#[test]
fn recv_a_lot() {
// Rendezvous streams should be able to handle any number of messages being sent
do run_in_uv_task {
let (port, chan) = rendezvous();
do spawn {
1000000.times(|| { chan.send(()) })
}
1000000.times(|| { port.recv() })
let (port, chan) = rendezvous();
do spawn {
1000000.times(|| { chan.send(()) })
}
1000000.times(|| { port.recv() })
}

#[test]
Expand Down
32 changes: 15 additions & 17 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,23 +761,21 @@ mod tests {
fn test_sem_runtime_friendly_blocking() {
// Force the runtime to schedule two threads on the same sched_loop.
// When one blocks, it should schedule the other one.
do task::spawn_sched(task::SingleThreaded) {
let s = Semaphore::new(1);
let s2 = s.clone();
let (p, c) = Chan::new();
let mut child_data = Some((s2, c));
s.access(|| {
let (s2, c) = child_data.take_unwrap();
do task::spawn {
c.send(());
s2.access(|| { });
c.send(());
}
let _ = p.recv(); // wait for child to come alive
5.times(|| { task::deschedule(); }); // let the child contend
});
let _ = p.recv(); // wait for child to be done
}
let s = Semaphore::new(1);
let s2 = s.clone();
let (p, c) = Chan::new();
let mut child_data = Some((s2, c));
s.access(|| {
let (s2, c) = child_data.take_unwrap();
do task::spawn {
c.send(());
s2.access(|| { });
c.send(());
}
let _ = p.recv(); // wait for child to come alive
5.times(|| { task::deschedule(); }); // let the child contend
});
let _ = p.recv(); // wait for child to be done
}
/************************************************************************
* Mutex tests
Expand Down
2 changes: 0 additions & 2 deletions src/libextra/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use std::task;
use std::vec;

#[cfg(test)] use std::task::SingleThreaded;

enum Msg<T> {
Execute(proc(&T)),
Quit
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! loop if no other one is provided (and M:N scheduling is desired).
use std::cast;
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausibleIdleCallback,
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausableIdleCallback,
Callback};
use std::unstable::sync::Exclusive;
use std::util;
Expand Down
29 changes: 13 additions & 16 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
//! functionality inside of 1:1 programs.
#[pkgid = "green#0.9-pre"];
#[link(name = "green",
package_id = "green",
vers = "0.9-pre",
uuid = "20c38f8c-bfea-83ed-a068-9dc05277be26",
url = "https://github.com/mozilla/rust/tree/master/src/libgreen")];

#[crate_id = "green#0.9-pre"];
#[license = "MIT/ASL2"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
Expand Down Expand Up @@ -61,16 +56,13 @@ pub mod stack;
pub mod task;

#[lang = "start"]
#[cfg(not(test))]
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
use std::cast;
let mut ret = None;
simple::task().run(|| {
ret = Some(do start(argc, argv) {
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
main();
})
});
ret.unwrap()
do start(argc, argv) {
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
main();
}
}

/// Set up a default runtime configuration, given compiler-supplied arguments.
Expand All @@ -93,10 +85,14 @@ pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
/// error.
pub fn start(argc: int, argv: **u8, main: proc()) -> int {
rt::init(argc, argv);
let exit_code = run(main);
let mut main = Some(main);
let mut ret = None;
simple::task().run(|| {
ret = Some(run(main.take_unwrap()));
});
// unsafe is ok b/c we're sure that the runtime is gone
unsafe { rt::cleanup() }
exit_code
ret.unwrap()
}

/// Execute the main function in a pool of M:N schedulers.
Expand All @@ -114,6 +110,7 @@ pub fn run(main: proc()) -> int {
let (port, chan) = Chan::new();
let mut opts = TaskOpts::new();
opts.notify_chan = Some(chan);
opts.name = Some(SendStrStatic("<main>"));
pool.spawn(opts, main);

// Wait for the main task to return, and set the process error code
Expand Down
3 changes: 1 addition & 2 deletions src/libgreen/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ macro_rules! rtabort (
pub fn dumb_println(args: &fmt::Arguments) {
use std::io;
use std::libc;
use std::vec;

struct Stderr;
impl io::Writer for Stderr {
fn write(&mut self, data: &[u8]) {
unsafe {
libc::write(libc::STDERR_FILENO,
vec::raw::to_ptr(data) as *libc::c_void,
data.as_ptr() as *libc::c_void,
data.len() as libc::size_t);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::cast;
use std::rand::{XorShiftRng, Rng, Rand};
use std::rt::local::Local;
use std::rt::rtio::{RemoteCallback, PausibleIdleCallback, Callback, EventLoop};
use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
use std::rt::task::BlockedTask;
use std::rt::task::Task;
use std::sync::deque;
Expand Down Expand Up @@ -779,6 +779,9 @@ impl Scheduler {
/// randomness is a result of performing a round of work stealing (which
/// may end up stealing from the current scheduler).
pub fn yield_now(mut ~self, cur: ~GreenTask) {
// Async handles trigger the scheduler by calling yield_now on the local
// task, which eventually gets us to here. See comments in SchedRunner
// for more info on this.
if cur.is_sched() {
assert!(self.sched_task.is_none());
self.run_sched_once(cur);
Expand Down Expand Up @@ -1345,7 +1348,7 @@ mod test {

impl Drop for S {
fn drop(&mut self) {
let _foo = @0;
let _foo = ~0;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::cast;
use std::io;
use std::libc::{pid_t, c_void, c_int};
use std::libc;
Expand All @@ -17,6 +16,8 @@ use std::ptr;
use std::rt::rtio;
use p = std::io::process;

#[cfg(windows)] use std::cast;

use super::file;

/**
Expand Down
13 changes: 5 additions & 8 deletions src/libnative/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
//! version of I/O.
#[pkgid = "native#0.9-pre"];
#[link(name = "native",
package_id = "native",
vers = "0.9-pre",
uuid = "535344a7-890f-5a23-e1f3-e0d118805141",
url = "https://github.com/mozilla/rust/tree/master/src/native")];

#[crate_id = "native#0.9-pre"];
#[license = "MIT/ASL2"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
Expand All @@ -46,7 +41,7 @@ pub mod task;
#[lang = "start"]
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
use std::cast;
use std::task::try;
use std::task;

do start(argc, argv) {
// Instead of invoking main directly on this thread, invoke it on
Expand All @@ -55,7 +50,9 @@ pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
// of the main thread's stack, so for stack overflow detection to work
// we must spawn the task in a subtask which we know the stack size of.
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
match do try { main() } {
let mut task = task::task();
task.name("<main>");
match do task.try { main() } {
Ok(()) => { os::set_exit_status(0); }
Err(..) => { os::set_exit_status(rt::DEFAULT_ERROR_CODE); }
}
Expand Down
12 changes: 11 additions & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ pub mod write {
}

unsafe fn configure_llvm(sess: Session) {
use std::unstable::mutex::{MUTEX_INIT, Mutex};
static mut LOCK: Mutex = MUTEX_INIT;
static mut CONFIGURED: bool = false;

// Copy what clan does by turning on loop vectorization at O2 and
// slp vectorization at O3
let vectorize_loop = !sess.no_vectorize_loops() &&
Expand Down Expand Up @@ -360,7 +364,13 @@ pub mod write {
add(*arg);
}

llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr());
LOCK.lock();
if !CONFIGURED {
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
llvm_args.as_ptr());
CONFIGURED = true;
}
LOCK.unlock();
}

unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef,
Expand Down
9 changes: 5 additions & 4 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,9 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path {
}

fn output_file_name(workspace: &Path, short_name: ~str) -> Path {
target_build_dir(workspace).join(short_name.as_slice()).join(format!("{}{}", short_name,
os::EXE_SUFFIX))
target_build_dir(workspace).join(short_name.as_slice())
.join(format!("{}{}", short_name,
os::consts::EXE_SUFFIX))
}

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -1353,7 +1354,7 @@ fn test_import_rustpkg() {
command_line_test([~"build", ~"foo"], workspace);
debug!("workspace = {}", workspace.display());
assert!(target_build_dir(workspace).join("foo").join(format!("pkg{}",
os::EXE_SUFFIX)).exists());
os::consts::EXE_SUFFIX)).exists());
}

#[test]
Expand All @@ -1366,7 +1367,7 @@ fn test_macro_pkg_script() {
command_line_test([~"build", ~"foo"], workspace);
debug!("workspace = {}", workspace.display());
assert!(target_build_dir(workspace).join("foo").join(format!("pkg{}",
os::EXE_SUFFIX)).exists());
os::consts::EXE_SUFFIX)).exists());
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion src/librustuv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::rt::task::BlockedTask;
use std::io::{FileStat, IoError};
use std::io;
use std::rt::rtio;
use std::vec;

use homing::{HomingIO, HomeHandle};
use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after, wakeup};
Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod test {
use std::cast;
use std::cell::RefCell;
use std::rc::Rc;
use std::rt::rtio::{Callback, PausibleIdleCallback};
use std::rt::rtio::{Callback, PausableIdleCallback};
use std::rt::task::{BlockedTask, Task};
use std::rt::local::Local;
use super::IdleWatcher;
Expand Down
3 changes: 1 addition & 2 deletions src/librustuv/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ macro_rules! uvdebug (
pub fn dumb_println(args: &fmt::Arguments) {
use std::io;
use std::libc;
use std::vec;

struct Stderr;
impl io::Writer for Stderr {
fn write(&mut self, data: &[u8]) {
unsafe {
libc::write(libc::STDERR_FILENO,
vec::raw::to_ptr(data) as *libc::c_void,
data.as_ptr() as *libc::c_void,
data.len() as libc::size_t);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl RtioSignal for SignalWatcher {}
impl Drop for SignalWatcher {
fn drop(&mut self) {
let _m = self.fire_homing_missile();
self.close_async_();
self.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Drop for TimerWatcher {
let _action = {
let _m = self.fire_homing_missile();
self.stop();
self.close_async_();
self.close();
self.action.take()
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustuv/uvio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ impl rtio::EventLoop for UvEventLoop {
IdleWatcher::onetime(&mut self.uvio.loop_, f);
}

fn pausible_idle_callback(&mut self, cb: ~rtio::Callback)
-> ~rtio::PausibleIdleCallback
fn pausable_idle_callback(&mut self, cb: ~rtio::Callback)
-> ~rtio::PausableIdleCallback
{
IdleWatcher::new(&mut self.uvio.loop_, cb) as ~rtio::PausibleIdleCallback
IdleWatcher::new(&mut self.uvio.loop_, cb) as ~rtio::PausableIdleCallback
}

fn remote_callback(&mut self, f: ~rtio::Callback) -> ~rtio::RemoteCallback {
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/io/net/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ mod tests {
fn connect_error() {
let mut called = false;
io_error::cond.trap(|e| {
assert_eq!(e.kind, OtherIoError);
assert_eq!(e.kind,
if cfg!(windows) {OtherIoError} else {FileNotFound});
called = true;
}).inside(|| {
let stream = UnixStream::connect(&("path/to/nowhere"));
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use libc;
use option::{Option, Some, None};
use result::{Ok, Err};
use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY};
use vec;

// And so begins the tale of acquiring a uv handle to a stdio stream on all
// platforms in all situations. Our story begins by splitting the world into two
Expand Down Expand Up @@ -137,7 +136,7 @@ fn with_task_stdout(f: |&mut Writer|) {
fn write(&mut self, data: &[u8]) {
unsafe {
libc::write(libc::STDOUT_FILENO,
vec::raw::to_ptr(data) as *libc::c_void,
data.as_ptr() as *libc::c_void,
data.len() as libc::size_t);
}
}
Expand Down
Loading

5 comments on commit 6cad8f4

@bors
Copy link
Contributor

@bors bors commented on 6cad8f4 Dec 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@6cad8f4

@bors
Copy link
Contributor

@bors bors commented on 6cad8f4 Dec 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libgreen = 6cad8f4 into auto

@bors
Copy link
Contributor

@bors bors commented on 6cad8f4 Dec 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libgreen = 6cad8f4 merged ok, testing candidate = 9477c49

@bors
Copy link
Contributor

@bors bors commented on 6cad8f4 Dec 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6cad8f4 Dec 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9477c49

Please sign in to comment.