CTS Android Automation via CI Tool - cts

I am trying to execute android CTS via this command:
./cts-tradefed run cts --shards ${no_of_devices}
When I execute a plain shell command from terminal it detects all the connected devices and executes test suite in parallel using all connected devices to execute tests.
While when I try to call this shell command from Java code(locally) or CI server; it detects all devices but executes tests on (no_of_devices -1).
The device that gets ignored is always the first device in the list. Confirmed that device itself is not a problem because if same device is not the first one in the list of devices, that device will be used for executing the tests.
My shell script looks like:
!#/bin/bash
./cts-tradefed run cts --shards 2 #say if I have two devices connected
The java code I use to execute the shell script is this:
public class Main {
public static void main(String[] args) {
ProcessBuilder pb = new ProcessBuilder("temp/run-cts-with-sharding.sh");
try {
Process p = pb.start();
Thread.sleep(2000);
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch(Exception e) {
System.out.println("Exception on pb.start(): " + e);
}
}
}

Related

Windows 10 Universal Voice Commands Command Prefix

Hello I have a question regarding using Voice Commands in a Windows 10 UA. I have added a Voice Command Definition file into a Unity3D created Universal app and added the necessary code to install it at first run. However, when having started the first time, it never responds to voice commands. I added a Command Prefix, which should allow someone to start the app by uttering that prefix, but when I do that it just opens Cortana search.
I am at a loss as to why that happens.
Below are the important pieces of the code:
Xml:
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-gb">
<CommandPrefix>Unity Battle</CommandPrefix>
<Example>Speak to the game</Example>
<Command Name="startWithText">
<Example>Say the message you want to appear in the game</Example>
<ListenFor> {naturalLanguage} </ListenFor>
<Feedback> Starting Game... </Feedback>
<Navigate/>
</Command>
<PhraseTopic Label="naturalLanguage" Scenario="Natural Language"/>
</CommandSet>
</VoiceCommands>
install code:
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
try
{
Windows.Storage.StorageFile vcdStorageFile =
await Package.Current.InstalledLocation.GetFileAsync(#"VoiceCommandDefinition.xml");
await
Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager
.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Installing Voice Commands Failed: " + ex.ToString());
}
}
On Activated:
protected override void OnActivated(IActivatedEventArgs args)
{
string appArgs = "";
switch (args.Kind)
{
case ActivationKind.Protocol:
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
splashScreen = eventArgs.SplashScreen;
appArgs += string.Format("Uri={0}", eventArgs.Uri.AbsoluteUri);
break;
case ActivationKind.VoiceCommand:
SpeechHelper.HandleSpeechCommand(args);
break;
}
InitializeUnity(appArgs);
}
I have already ran through the code with the debugger attached but it never hits the OnActivated(..) method.

Powershell Invoke method neither throwing exception nor returning result

I am trying to build an ASP.Net, c# application to expose few IIS management related activities through web interface for a distributed Admin group.
I am making use of System.Management.Automation V3.0 library to wrap power shell commands. As a first step I wanted to list all Web Applications that are currently up and running on local IIS by invoking Get-WebApplication command.
This is where I am facing the issue. Method call is neither throwing any exception nor its returning the result. Does anyone know the root cause of this issue? Please share your experience of building such interface using System.Management.Automation.dll.
var shell = PowerShell.Create();
shell.Commands.AddScript("Get-WebApplication | Out-String");
try
{
var results = shell.Invoke();
if (results.Count > 0)
{
var builder = new StringBuilder();
foreach (var psObject in results)
{
builder.Append(psObject.BaseObject.ToString() + "\r\n");
}
}
}
catch(Exception ex)
{
throw;
}
PS: Get-Service in place of Get-WebApplication works absolutely fine by returning list of services available on the machine.
PowerShell.Create() does not create new PowerShell process. If you does not specify Runspace for it, then it will create new in-process Runspace. Since it run in your process, it will match your process bitness and you can not change that. To create Runspace with different bitness you need to create out of process Runspace. Here is a sample console application, which demonstrate how you can do that:
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
public static class TestApplication {
public static void Main() {
Console.WriteLine(Environment.Is64BitProcess);
using(PowerShellProcessInstance pspi = new PowerShellProcessInstance()) {
string psfn = pspi.Process.StartInfo.FileName;
psfn=psfn.ToLowerInvariant().Replace("\\syswow64\\", "\\sysnative\\");
pspi.Process.StartInfo.FileName=psfn;
using(Runspace r = RunspaceFactory.CreateOutOfProcessRunspace(null, pspi)) {
r.Open();
using(PowerShell ps = PowerShell.Create()) {
ps.Runspace=r;
ps.AddScript("[Environment]::Is64BitProcess");
foreach(PSObject pso in ps.Invoke()) {
Console.WriteLine(pso);
}
}
}
}
}
}
If you compile this application as x32, it still will use x64 out of process Runspace on x64 operation system.

Command to re-calibrate magnetic sensor

Is there any command through which I can reset the magnetic sensor in an Android device?
I tried echo 1 > /sys/class/sensors/proximity_sensor/prox_cal as suggested here but it's not working.
Are these commands handset dependent?
I am trying this code:
Process process ;
try {
process = Runtime.getRuntime().exec("echo 1 > /sys/class/sensors/proximity_sensor/prox_cal");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
System.out.println("Executing ADB Command");
}
catch(IOException e)
{
System.out.println("Some error while executing ADB Command");
}
It's always going in the catch block. Can anyone help me on this?

Problems when using robocode with JESS

I'm attempting to use JESS in order to utilise a rule-based system for making a robot. I've got both robocode and the JESS .jar imported into Eclipse. Here's my code -
public class myRobot extends Robot {
Rete r = new Rete();
public void run() {
try {
String reset = "(reset)";
r.executeCommand(reset);
String enemyInfo = "(deftemplate enemyInfo (slot present) (slot energy) (slot name))";
r.executeCommand(enemyInfo);
while (true) {
String command = "(assert (enemyInfo (present no) (energy -1) (name none)))";
r.executeCommand(command);
}
} catch (JessException ex) {
System.err.println(ex);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
try {
String command = "(assert (enemyInfo (present yes) (energy " + e.getEnergy() + ") (name " + e.getName() + ")))";
r.executeCommand(command);
} catch (JessException ex) {
System.err.println(ex);
}
}
}
I haven't added in any rules yet because I just wanted to check that robocode and JESS run properly together. When I fire this up, the robocode application opens up. But when I try adding this robot in a battle and starting it, the application just freezes up completely.
I can't access the robot's console to see what's wrong since it hangs just immediately after I try and start a battle. Since all my System.out.println() debugging statements are printed to the robot's console as opposed to the main one, I can't even figure out what's wrong. Any suggestions to get this to work?
The problem is, that the robocode application does not know the JESS library. You will need to include it in the jar of your exported robot.
How to include librarys to jars

Running Selenium via NUnit and Cruise Control .NET

I'm having an issue running Selenium tests in NUnit from Cruise Control .NET. I have a simple test that runs fine when I run from the NUnit GUI on our continuous integration server. However when the NUnit test is run from Cruise Control .NET on the same server, the test always fails. Tests that don't use Selenium run fine from both the NUnit GUI and from Cruise Control.
[SetUp]
public void SetupTest()
{
Driver = new InternetExplorerDriver();
}
[TearDown]
public void TeardownTest()
{
Driver.Quit();
}
/// <summary>
/// Test basic Selenium functionality.
/// </summary>
[Test]
public void SeleniumTest()
{
Driver.Navigate().GoToUrl(TestConfig.TestURL);
IWebElement testEle = WaitForElement(Driver, By.Id, "body", TestConfig.TestWaitMS);
Assert.IsTrue(true);
}
private static IWebElement WaitForElement(IWebDriver driver, ByFunc byFunc, string elementId, int waitMs,
string waitOutput = null, int pause = 50)
{
bool elementFound = false;
int i = 0;
IWebElement webElement = null;
while (!elementFound && (i * pause) < waitMs)
{
try
{
webElement = driver.FindElement(byFunc(elementId));
elementFound = true;
}
catch (NoSuchElementException)
{
i++;
Thread.Sleep(pause);
if (waitOutput != null)
Console.Write(waitOutput);
}
}
if (elementFound)
return webElement;
else
throw new NoSuchElementException(string.Format("Could not find element {0} after waiting {1}ms.", elementId, waitMs));
}
WaitForElement is just a helper function that allows me to assign specific waits for certain elements rather than have a blanket waiting time for the entire test run.
The test fails when the NoSuchElementException is raised from the WaitForElement function.
I've found some links on Google saying that you need to run SeleniumRC as a service to get it to run from Cruise Control. I don't think that applies here as I'm using the WebDriver version. Please correct me if I'm wrong.
IE version 8
Cruise Control .NET 1.8.3.0
NUnit 2.6
Selenium 2.0.0
Thanks for the pointers #Arran. Switching to a Firefox driver fixed the issue. I guess the fault must lie somewhere in the Internet Explorer driver.
[SetUp]
public void SetupTest()
{
Driver = new FirefoxDriver();
}