@@ -18,6 +18,7 @@ use std::thread;
18
18
use std:: time:: Duration ;
19
19
20
20
const REMOTE_ADDR_ENV : & str = "TEST_DEVICE_ADDR" ;
21
+ const DEFAULT_ADDR : & str = "127.0.0.1:12345" ;
21
22
22
23
macro_rules! t {
23
24
( $e: expr) => {
@@ -30,8 +31,12 @@ macro_rules! t {
30
31
31
32
fn main ( ) {
32
33
let mut args = env:: args ( ) . skip ( 1 ) ;
34
+ let next = args. next ( ) ;
35
+ if next. is_none ( ) {
36
+ return help ( ) ;
37
+ }
33
38
34
- match & args . next ( ) . unwrap ( ) [ ..] {
39
+ match & next. unwrap ( ) [ ..] {
35
40
"spawn-emulator" => spawn_emulator (
36
41
& args. next ( ) . unwrap ( ) ,
37
42
Path :: new ( & args. next ( ) . unwrap ( ) ) ,
@@ -40,12 +45,16 @@ fn main() {
40
45
) ,
41
46
"push" => push ( Path :: new ( & args. next ( ) . unwrap ( ) ) ) ,
42
47
"run" => run ( args. next ( ) . unwrap ( ) , args. collect ( ) ) ,
43
- cmd => panic ! ( "unknown command: {}" , cmd) ,
48
+ "help" | "-h" | "--help" => help ( ) ,
49
+ cmd => {
50
+ println ! ( "unknown command: {}" , cmd) ;
51
+ help ( ) ;
52
+ }
44
53
}
45
54
}
46
55
47
56
fn spawn_emulator ( target : & str , server : & Path , tmpdir : & Path , rootfs : Option < PathBuf > ) {
48
- let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( "127.0.0.1:12345" . to_string ( ) ) ;
57
+ let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( DEFAULT_ADDR . to_string ( ) ) ;
49
58
50
59
if env:: var ( REMOTE_ADDR_ENV ) . is_ok ( ) {
51
60
println ! ( "Connecting to remote device {} ..." , device_address) ;
@@ -172,7 +181,7 @@ fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path
172
181
}
173
182
174
183
fn push ( path : & Path ) {
175
- let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( "127.0.0.1:12345" . to_string ( ) ) ;
184
+ let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( DEFAULT_ADDR . to_string ( ) ) ;
176
185
let client = t ! ( TcpStream :: connect( device_address) ) ;
177
186
let mut client = BufWriter :: new ( client) ;
178
187
t ! ( client. write_all( b"push" ) ) ;
@@ -189,7 +198,7 @@ fn push(path: &Path) {
189
198
}
190
199
191
200
fn run ( files : String , args : Vec < String > ) {
192
- let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( "127.0.0.1:12345" . to_string ( ) ) ;
201
+ let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( DEFAULT_ADDR . to_string ( ) ) ;
193
202
let client = t ! ( TcpStream :: connect( device_address) ) ;
194
203
let mut client = BufWriter :: new ( client) ;
195
204
t ! ( client. write_all( b"run " ) ) ;
@@ -284,3 +293,40 @@ fn send(path: &Path, dst: &mut dyn Write) {
284
293
t ! ( dst. write_all( & [ ( amt >> 24 ) as u8 , ( amt >> 16 ) as u8 , ( amt >> 8 ) as u8 , ( amt >> 0 ) as u8 , ] ) ) ;
285
294
t ! ( io:: copy( & mut file, dst) ) ;
286
295
}
296
+
297
+ fn help ( ) {
298
+ println ! (
299
+ "
300
+ Usage: {0} <command> [<args>]
301
+
302
+ Sub-commands:
303
+ spawn-emulator <target> <server> <tmpdir> [rootfs] See below
304
+ push <path> Copy <path> to emulator
305
+ run <files> [args...] Run program on emulator
306
+ help Display help message
307
+
308
+ Spawning an emulator:
309
+
310
+ For Android <target>s, adb will push the <server>, set up TCP forwarding and run
311
+ the <server>. Otherwise qemu emulates the target using a rootfs image created in
312
+ <tmpdir> and generated from <rootfs> plus the <server> executable.
313
+ If {1} is set in the environment, this step is skipped.
314
+
315
+ Pushing a path to a running emulator:
316
+
317
+ A running emulator or adb device is connected to at the IP address and port in
318
+ the {1} environment variable or {2} if this isn't
319
+ specified. The file at <path> is sent to this target.
320
+
321
+ Executing commands on a running emulator:
322
+
323
+ First the target emulator/adb session is connected to as for pushing files. Next
324
+ the colon separated list of <files> is pushed to the target. Finally, the first
325
+ file in <files> is executed in the emulator, preserving the current environment.
326
+ That command's status code is returned.
327
+ " ,
328
+ env:: args( ) . next( ) . unwrap( ) ,
329
+ REMOTE_ADDR_ENV ,
330
+ DEFAULT_ADDR
331
+ ) ;
332
+ }
0 commit comments