1*5c44d1b3SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5c44d1b3SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5c44d1b3SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5c44d1b3SAndrew Rist * distributed with this work for additional information 6*5c44d1b3SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5c44d1b3SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5c44d1b3SAndrew Rist * "License"); you may not use this file except in compliance 9*5c44d1b3SAndrew Rist * with the License. You may obtain a copy of the License at 10*5c44d1b3SAndrew Rist * 11*5c44d1b3SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*5c44d1b3SAndrew Rist * 13*5c44d1b3SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5c44d1b3SAndrew Rist * software distributed under the License is distributed on an 15*5c44d1b3SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5c44d1b3SAndrew Rist * KIND, either express or implied. See the License for the 17*5c44d1b3SAndrew Rist * specific language governing permissions and limitations 18*5c44d1b3SAndrew Rist * under the License. 19*5c44d1b3SAndrew Rist * 20*5c44d1b3SAndrew Rist *************************************************************/ 21*5c44d1b3SAndrew Rist 22*5c44d1b3SAndrew Rist 23cdf0e10cSrcweir package clitest; 24cdf0e10cSrcweir 25cdf0e10cSrcweir 26cdf0e10cSrcweir import complexlib.ComplexTestCase; 27cdf0e10cSrcweir import java.io.*; 28cdf0e10cSrcweir 29cdf0e10cSrcweir public class CLITest extends ComplexTestCase 30cdf0e10cSrcweir { getTestMethodNames()31cdf0e10cSrcweir public String[] getTestMethodNames() 32cdf0e10cSrcweir { 33cdf0e10cSrcweir // TODO think about trigger of sub-tests from outside 34cdf0e10cSrcweir return new String[] 35cdf0e10cSrcweir { 36cdf0e10cSrcweir "runCLITests" 37cdf0e10cSrcweir }; 38cdf0e10cSrcweir } 39cdf0e10cSrcweir runCLITests()40cdf0e10cSrcweir public void runCLITests() 41cdf0e10cSrcweir { 42cdf0e10cSrcweir try 43cdf0e10cSrcweir { 44cdf0e10cSrcweir String testProgram = System.getProperty("cli_test", ""); 45cdf0e10cSrcweir if (testProgram.length() == 0) 46cdf0e10cSrcweir failed("Check the make file. Java must be called with -Dcli_test=pathtoexe"); 47cdf0e10cSrcweir 48cdf0e10cSrcweir String arg1 = System.getProperty("cli_test_arg", ""); 49cdf0e10cSrcweir if (arg1.length() == 0) 50cdf0e10cSrcweir failed("Check the make file. Java must be called with " + 51cdf0e10cSrcweir "-Dcli_test_arg=path_to_bootstrap_ini"); 52cdf0e10cSrcweir String[] cmdarray = new String[] {testProgram, arg1}; 53cdf0e10cSrcweir 54cdf0e10cSrcweir Process proc = null; 55cdf0e10cSrcweir Reader outReader; 56cdf0e10cSrcweir Reader errReader; 57cdf0e10cSrcweir try{ 58cdf0e10cSrcweir 59cdf0e10cSrcweir proc = Runtime.getRuntime().exec(cmdarray); 60cdf0e10cSrcweir outReader = new Reader(proc.getInputStream()); 61cdf0e10cSrcweir errReader = new Reader(proc.getErrorStream()); 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir } 65cdf0e10cSrcweir catch(Exception e) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir System.out.println("\n ###" + e.getMessage() + "\n"); 68cdf0e10cSrcweir 69cdf0e10cSrcweir } 70cdf0e10cSrcweir // System.out.println("### waiting for " + testProgram); 71cdf0e10cSrcweir proc.waitFor(); 72cdf0e10cSrcweir // System.out.println("### " + testProgram + " finished"); 73cdf0e10cSrcweir int retVal = proc.exitValue(); 74cdf0e10cSrcweir if (retVal != 0) 75cdf0e10cSrcweir failed("CLI test failed."); 76cdf0e10cSrcweir } catch( java.lang.Exception e) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir failed("Unexpected exception."); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir /* This reads reads from an InputStream and discards the data. 86cdf0e10cSrcweir */ 87cdf0e10cSrcweir class Reader extends Thread 88cdf0e10cSrcweir { 89cdf0e10cSrcweir InputStream is; Reader(InputStream stream)90cdf0e10cSrcweir public Reader(InputStream stream) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir is = stream; 93cdf0e10cSrcweir start(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir run()96cdf0e10cSrcweir public void run() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir try 99cdf0e10cSrcweir { 100cdf0e10cSrcweir byte[] buf = new byte[1024]; 101cdf0e10cSrcweir while (-1 != is.read(buf)); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir catch (java.io.IOException exc) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108