Sanity test to verify that the bundles that are included as plugins in the controller...
[controller.git] / opendaylight / distribution / sanitytest / src / main / java / org / opendaylight / controller / distribution / Sanity.java
1 package org.opendaylight.controller.distribution;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
7
8 public class Sanity {
9
10     static void copy(InputStream in, OutputStream out) throws IOException {
11       while (true) {
12         int c = in.read();
13         if (c == -1) break;
14         out.write((char)c);
15       }
16     }
17
18     public static void main(String[] args) throws IOException, InterruptedException {
19         String cwd = System.getProperty("user.dir");
20
21         System.out.println("Current working directory = " + cwd);
22
23         // We assume that the program is being run from the sanitytest directory
24         // We need to specify the opendaylight directory as the working directory for the shell/batch scripts
25         File processWorkingDir = new File(cwd, "../opendaylight");
26
27         String os = System.getProperty("os.name").toLowerCase();
28         String script = "./run.sh";
29
30         if(os.contains("windows")){
31             script = "run.bat";
32         }
33
34         ProcessBuilder processBuilder = new ProcessBuilder();
35         processBuilder.directory(processWorkingDir.getCanonicalFile());
36         processBuilder.command(script);
37         Process p = processBuilder.start();
38
39         copy(p.getInputStream(), System.out);
40
41         p.waitFor();
42
43         System.out.println("Test exited with exitValue = " + p.exitValue());
44
45         System.exit(p.exitValue());
46     }
47 }