]>
git.proxmox.com Git - rustc.git/blob - vendor/jobserver/tests/server.rs
1 extern crate jobserver
;
6 use std
::io
::prelude
::*;
7 use std
::process
::Command
;
8 use std
::sync
::atomic
::{AtomicBool, Ordering}
;
13 use jobserver
::Client
;
20 Err(e
) => panic
!("{} failed with {}", stringify
!($e
), e
),
27 let c
= t
!(Client
::new(1));
28 drop(c
.acquire().unwrap());
29 drop(c
.acquire().unwrap());
33 fn server_multiple() {
34 let c
= t
!(Client
::new(2));
35 let a
= c
.acquire().unwrap();
36 let b
= c
.acquire().unwrap();
42 let c
= t
!(Client
::new(1));
43 let a
= c
.acquire().unwrap();
44 let hit
= Arc
::new(AtomicBool
::new(false));
45 let hit2
= hit
.clone();
46 let (tx
, rx
) = mpsc
::channel();
47 let t
= thread
::spawn(move || {
49 let _b
= c
.acquire().unwrap();
50 hit2
.store(true, Ordering
::SeqCst
);
53 assert
!(!hit
.load(Ordering
::SeqCst
));
56 assert
!(hit
.load(Ordering
::SeqCst
));
60 fn make_as_a_single_thread_client() {
61 let c
= t
!(Client
::new(1));
62 let td
= TempDir
::new("foo").unwrap();
64 let prog
= env
::var("MAKE").unwrap_or("make".to_string());
65 let mut cmd
= Command
::new(prog
);
66 cmd
.current_dir(td
.path());
68 t
!(t
!(File
::create(td
.path().join("Makefile"))).write_all(
78 // The jobserver protocol means that the `make` process itself "runs with a
79 // token", so we acquire our one token to drain the jobserver, and this
80 // should mean that `make` itself never has a second token available to it.
82 c
.configure(&mut cmd
);
83 let output
= t
!(cmd
.output());
85 "\n\t=== stderr\n\t\t{}",
86 String
::from_utf8_lossy(&output
.stderr
).replace("\n", "\n\t\t")
89 "\t=== stdout\n\t\t{}",
90 String
::from_utf8_lossy(&output
.stdout
).replace("\n", "\n\t\t")
93 assert
!(output
.status
.success());
94 assert
!(output
.stderr
.is_empty());
96 let stdout
= String
::from_utf8_lossy(&output
.stdout
).replace("\r\n", "\n");
110 assert
!(stdout
== a
|| stdout
== b
);
114 fn make_as_a_multi_thread_client() {
115 let c
= t
!(Client
::new(1));
116 let td
= TempDir
::new("foo").unwrap();
118 let prog
= env
::var("MAKE").unwrap_or("make".to_string());
119 let mut cmd
= Command
::new(prog
);
120 cmd
.current_dir(td
.path());
122 t
!(t
!(File
::create(td
.path().join("Makefile"))).write_all(
132 // We're leaking one extra token to `make` sort of violating the makefile
133 // jobserver protocol. It has the desired effect though.
134 c
.configure(&mut cmd
);
135 let output
= t
!(cmd
.output());
137 "\n\t=== stderr\n\t\t{}",
138 String
::from_utf8_lossy(&output
.stderr
).replace("\n", "\n\t\t")
141 "\t=== stdout\n\t\t{}",
142 String
::from_utf8_lossy(&output
.stdout
).replace("\n", "\n\t\t")
145 assert
!(output
.status
.success());
150 let client
= t
!(Client
::new(0));
151 let (tx
, rx
) = mpsc
::channel();
153 .into_helper_thread(move |a
| drop(tx
.send(a
)))
155 helper
.request_token();
156 helper
.request_token();
159 assert
!(rx
.try_recv().is_err());