1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Bug 315055 - [testing] RSEShellSubsystemTestSuite fails 3x on Windows

This commit is contained in:
Martin Oberhuber 2010-05-31 16:23:18 +00:00
parent 2992afa61f
commit eb411f1dd2
2 changed files with 34 additions and 12 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Anna Dushistova (MontaVista) - adapted from FileServiceTest * Anna Dushistova (MontaVista) - adapted from FileServiceTest
* Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests * Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests
* Martin Oberhuber (Wind River) - [315055] ShellServiceTest fails on Windows
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.tests.subsystems.shells; package org.eclipse.rse.tests.subsystems.shells;
@ -15,6 +16,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -131,26 +133,34 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase {
} }
public void testLaunchShell() throws Exception { public void testLaunchShell() throws Exception {
Object[] allOutput = launchShell("", "echo test", new String[] {}); //Bug 315055: Windows needs a PATH which includes cmd.exe
//On Linux, the "echo test" also works without any PATH
//Object[] allOutput = launchShell("", "echo test", new String[] {});
Object[] allOutput = launchShell("", "echo test", shellService.getHostEnvironment());
boolean matchFound = false; boolean matchFound = false;
for (int i = 0; i < allOutput.length; i++) { for (int i = 0; i < allOutput.length; i++) {
matchFound = ((IHostOutput) allOutput[i]).getString() matchFound = ((IHostOutput) allOutput[i]).getString()
.equals("test"); .equals("test");
System.out.println(((IHostOutput) allOutput[i]).getString()); //System.out.println(((IHostOutput) allOutput[i]).getString());
if (matchFound) if (matchFound)
break; break;
} }
assertTrue(matchFound); assertTrue("Missing output of \"echo test\": "+Arrays.asList(allOutput), matchFound);
// now set working directory -- Linux only // now set working directory -- Linux only
allOutput = launchShell("/", "echo test", new String[] {}); //Bug 315055: Windows needs a PATH which includes cmd.exe
//On Linux, the "echo test" also works without any PATH
//allOutput = launchShell("/", "echo test", new String[] {});
allOutput = launchShell("/", "echo test", shellService.getHostEnvironment());
matchFound = false; matchFound = false;
for (int i = 0; i < allOutput.length; i++) { for (int i = 0; i < allOutput.length; i++) {
matchFound = ((IHostOutput) allOutput[i]).getString() matchFound = ((IHostOutput) allOutput[i]).getString()
.equals("test"); .equals("test");
System.out.println(((IHostOutput) allOutput[i]).getString()); //System.out.println(((IHostOutput) allOutput[i]).getString());
if (matchFound) if (matchFound)
break; break;
} }
assertTrue("Missing output of \"echo test\": "+Arrays.asList(allOutput), matchFound);
} }
public Object[] launchShell(String workingDirectory, String cmd, public Object[] launchShell(String workingDirectory, String cmd,

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,10 +8,12 @@
* Contributors: * Contributors:
* Anna Dushistova (MontaVista) - adapted from FileServiceTest * Anna Dushistova (MontaVista) - adapted from FileServiceTest
* Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests * Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests
* Martin Oberhuber (Wind River) - [315055] ShellServiceTest fails on Windows
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.tests.subsystems.shells; package org.eclipse.rse.tests.subsystems.shells;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -139,8 +141,11 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase {
public void testRunCommand() throws Exception { public void testRunCommand() throws Exception {
if (shellSubSystem.canRunCommand()) { if (shellSubSystem.canRunCommand()) {
Object[] results = shellSubSystem //Bug 315055: Windows cmd invocation does not split commands on \r\n
.runCommand("echo test\r\nexit", null, mon); //String cmd = "echo test\r\nexit"; //$NON-NLS-1$
String commandSeparator = shellSubSystem.getParentRemoteCmdSubSystemConfiguration().getCommandSeparator();
String cmd = "echo test"+commandSeparator+"exit"; //$NON-NLS-1$
Object[] results = shellSubSystem.runCommand(cmd, null, mon);
boolean matchFound = false; boolean matchFound = false;
Object cmdObject = results[0]; Object cmdObject = results[0];
@ -159,7 +164,7 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase {
break; break;
} }
assertTrue(matchFound); assertTrue("Missing output of \"echo test\": "+Arrays.asList(result), matchFound);
} }
} }
@ -167,8 +172,15 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase {
if (shellSubSystem.canRunShell()) { if (shellSubSystem.canRunShell()) {
IRemoteCommandShell cmd = shellSubSystem.runShell(null, mon); IRemoteCommandShell cmd = shellSubSystem.runShell(null, mon);
shellSubSystem.cancelShell(cmd, mon); shellSubSystem.cancelShell(cmd, mon);
assertFalse(cmd.isActive()); //Bug 315055 - Race condition on Windows:
//cancelShell() is not synchronous, so we need to wait a little (max 2 sec)
int tries = 0;
while(tries <20 && cmd.isActive()) {
Thread.sleep(100);
tries++;
}
assertFalse("Shell not canceled", cmd.isActive());
System.out.println("Shell canceled after "+tries*100+" msec.");
} }
} }
} }