Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / distribution / sanitytest / src / main / java / org / opendaylight / controller / distribution / Sanity.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.distribution;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.OutputStream;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 public class Sanity {
18
19     static void copy(InputStream in, OutputStream out) throws IOException {
20       while (true) {
21         int c = in.read();
22         if (c == -1) break;
23         out.write((char)c);
24       }
25     }
26
27     public static void main(String[] args) throws IOException, InterruptedException {
28         String cwd = System.getProperty("user.dir");
29
30         System.out.println("Current working directory = " + cwd);
31
32         String os = System.getProperty("os.name").toLowerCase();
33         List<String> script = new ArrayList<String>();
34
35         if(os.contains("windows")){
36             script.add("cmd.exe");
37             script.add("/c");
38             script.add("runsanity.bat");
39         } else {
40             script.add("./runsanity.sh");
41         }
42
43         ProcessBuilder processBuilder = new ProcessBuilder();
44         processBuilder.inheritIO().command(script);
45         Process p = processBuilder.start();
46
47         copy(p.getInputStream(), System.out);
48
49         p.waitFor();
50
51         System.out.println("Test exited with exitValue = " + p.exitValue());
52
53         System.exit(p.exitValue());
54     }
55 }