Commit d74c3457 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Added iOS build/tests from command line.

parent e91405fa
PROJECT=LuaInterface.iOS.sln
MDTOOL=/Applications/MonoDevelop.app/Contents/MacOS/mdtool
MTOUCH=/Developer/MonoTouch/usr/bin/mtouch
TOUCH_SERVER=./Touch.Server/bin/Debug/Touch.Server.exe
all: build-simulator build-device
run run-test: run-simulator run-device
$(TOUCH_SERVER):
cd Touch.Server && xbuild
build-simulator:
$(MDTOOL) -v build -t:Build "-c:Release|iPhoneSimulator" $(PROJECT)
run-simulator: build-simulator Touch.Server
rm -f sim-results.log
mono --debug $(TOUCH_SERVER) --launchsim ios/LuaInterfaceTestsiOS/bin/iPhoneSimulator/Release/LuaInterfaceTest.app -autoexit -logfile=sim-results.log
cat sim-results.log
build-device:
$(MDTOOL) -v build -t:Build "-c:Release|iPhone" $(PROJECT)
run-device: build-device
$(MTOUCH) --installdev ios/LuaInterfaceTestsiOS/bin/iPhone/Release/LuaInterfaceTest.app
# kill an existing instance (based on the bundle id)
$(MTOUCH) --killdev com.xamarin.touch-unit
rm -f dev-results.log
mono --debug $(TOUCH_SERVER) --launchdev com.codefoco.luainterfacetest -autoexit -logfile=dev-results.log
cat dev-results.log
// Main.cs: Touch.Unit Simple Server
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2011-2012 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Diagnostics;
using System.Threading;
using Mono.Options;
// a simple, blocking (i.e. one device/app at the time), listener
class SimpleListener {
static byte[] buffer = new byte [16 * 1024];
TcpListener server;
IPAddress Address { get; set; }
int Port { get; set; }
string LogPath { get; set; }
string LogFile { get; set; }
bool AutoExit { get; set; }
public void Cancel ()
{
try {
server.Stop ();
} catch {
// We might have stopped already, so just swallow any exceptions.
}
}
public int Start ()
{
bool processed;
Console.WriteLine ("Touch.Unit Simple Server listening on: {0}:{1}", Address, Port);
server = new TcpListener (Address, Port);
try {
server.Start ();
do {
using (TcpClient client = server.AcceptTcpClient ()) {
processed = Processing (client);
}
} while (!AutoExit || !processed);
}
catch (Exception e) {
Console.WriteLine ("[{0}] : {1}", DateTime.Now, e);
return 1;
}
finally {
server.Stop ();
}
return 0;
}
public bool Processing (TcpClient client)
{
string logfile = Path.Combine (LogPath, LogFile ?? DateTime.UtcNow.Ticks.ToString () + ".log");
string remote = client.Client.RemoteEndPoint.ToString ();
Console.WriteLine ("Connection from {0} saving logs to {1}", remote, logfile);
using (FileStream fs = File.OpenWrite (logfile)) {
// a few extra bits of data only available from this side
string header = String.Format ("[Local Date/Time:\t{1}]{0}[Remote Address:\t{2}]{0}",
Environment.NewLine, DateTime.Now, remote);
byte[] array = Encoding.UTF8.GetBytes (header);
fs.Write (array, 0, array.Length);
fs.Flush ();
// now simply copy what we receive
int i;
int total = 0;
NetworkStream stream = client.GetStream ();
while ((i = stream.Read (buffer, 0, buffer.Length)) != 0) {
fs.Write (buffer, 0, i);
fs.Flush ();
total += i;
}
if (total < 16) {
// This wasn't a test run, but a connection from the app (on device) to find
// the ip address we're reachable on.
return false;
}
}
return true;
}
static void ShowHelp (OptionSet os)
{
Console.WriteLine ("Usage: mono Touch.Server.exe [options]");
os.WriteOptionDescriptions (Console.Out);
}
public static int Main (string[] args)
{
Console.WriteLine ("Touch.Unit Simple Server");
Console.WriteLine ("Copyright 2011, Xamarin Inc. All rights reserved.");
bool help = false;
string address = null;
string port = null;
string log_path = ".";
string log_file = null;
string launchdev = null;
string launchsim = null;
bool autoexit = false;
var os = new OptionSet () {
{ "h|?|help", "Display help", v => help = true },
{ "ip", "IP address to listen (default: Any)", v => address = v },
{ "port", "TCP port to listen (default: 16384)", v => port = v },
{ "logpath", "Path to save the log files (default: .)", v => log_path = v },
{ "logfile=", "Filename to save the log to (default: automatically generated)", v => log_file = v },
{ "launchdev=", "Run the specified app on a device (specify using bundle identifier)", v => launchdev = v },
{ "launchsim=", "Run the specified app on the simulator (specify using path to *.app directory)", v => launchsim = v },
{ "autoexit", "Exit the server once a test run has completed (default: false)", v => autoexit = true },
};
try {
os.Parse (args);
if (help)
ShowHelp (os);
var listener = new SimpleListener ();
IPAddress ip;
if (String.IsNullOrEmpty (address) || !IPAddress.TryParse (address, out ip))
listener.Address = IPAddress.Any;
ushort p;
if (UInt16.TryParse (port, out p))
listener.Port = p;
else
listener.Port = 16384;
listener.LogPath = log_path ?? ".";
listener.LogFile = log_file;
listener.AutoExit = autoexit;
if (launchdev != null) {
ThreadPool.QueueUserWorkItem ((v) => {
using (Process proc = new Process ()) {
StringBuilder procArgs = new StringBuilder ();
string sdk_root = Environment.GetEnvironmentVariable ("XCODE_DEVELOPER_ROOT");
if (!String.IsNullOrEmpty (sdk_root))
procArgs.Append ("--sdkroot ").Append (sdk_root);
procArgs.Append (" --launchdev ");
procArgs.Append (launchdev);
procArgs.Append (" -argument=-connection-mode -argument=none");
procArgs.Append (" -argument=-app-arg:-autostart");
procArgs.Append (" -argument=-app-arg:-autoexit");
procArgs.Append (" -argument=-app-arg:-enablenetwork");
procArgs.AppendFormat (" -argument=-app-arg:-hostport:{0}", listener.Port);
procArgs.Append (" -argument=-app-arg:-hostname:");
var ipAddresses = System.Net.Dns.GetHostEntry (System.Net.Dns.GetHostName ()).AddressList;
for (int i = 0; i < ipAddresses.Length; i++) {
if (i > 0)
procArgs.Append (',');
procArgs.Append (ipAddresses [i].ToString ());
}
proc.StartInfo.FileName = "/Developer/MonoTouch/usr/bin/mtouch";
proc.StartInfo.Arguments = procArgs.ToString ();
proc.Start ();
proc.WaitForExit ();
if (proc.ExitCode != 0)
listener.Cancel ();
}
});
}
if (launchsim != null) {
ThreadPool.QueueUserWorkItem ((v) => {
using (Process proc = new Process ()) {
StringBuilder output = new StringBuilder ();
StringBuilder procArgs = new StringBuilder ();
string sdk_root = Environment.GetEnvironmentVariable ("XCODE_DEVELOPER_ROOT");
if (!String.IsNullOrEmpty (sdk_root))
procArgs.Append ("--sdkroot ").Append (sdk_root);
procArgs.Append (" --launchsim ");
procArgs.Append (launchsim);
procArgs.Append (" -argument=-connection-mode -argument=none");
procArgs.Append (" -argument=-app-arg:-autostart");
procArgs.Append (" -argument=-app-arg:-autoexit");
procArgs.Append (" -argument=-app-arg:-enablenetwork");
procArgs.Append (" -argument=-app-arg:-hostname:127.0.0.1");
procArgs.AppendFormat (" -argument=-app-arg:-hostport:{0}", listener.Port);
proc.StartInfo.FileName = "/Developer/MonoTouch/usr/bin/mtouch";
proc.StartInfo.Arguments = procArgs.ToString ();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
lock (output)
output.AppendLine (e.Data);
};
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
lock (output)
output.AppendLine (e.Data);
};
proc.Start ();
proc.BeginErrorReadLine ();
proc.BeginOutputReadLine ();
proc.WaitForExit ();
if (proc.ExitCode != 0) {
listener.Cancel ();
Console.WriteLine (output.ToString ());
}
}
});
}
return listener.Start ();
} catch (OptionException oe) {
Console.WriteLine ("{0} for options '{1}'", oe.Message, oe.OptionName);
return 1;
} catch (Exception ex) {
Console.WriteLine (ex);
return 1;
}
}
}
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhone</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A1303AE1-2693-4DF7-A17B-20C2ABA1E2ED}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Touch.Server</RootNamespace>
<AssemblyName>Touch.Server</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;LINQ</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<DefineConstants>LINQ</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Options.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>LuaInterfaceTest</string> <string>LuaInterfaceTest</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>com.codefoco.luainterfacetest</string> <string>org.nlua.nluatest</string>
<key>MinimumOSVersion</key> <key>MinimumOSVersion</key>
<string>3.2</string> <string>3.2</string>
<key>UIDeviceFamily</key> <key>UIDeviceFamily</key>
...@@ -26,5 +26,7 @@ ...@@ -26,5 +26,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict> </dict>
</plist> </plist>
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<MtouchArch>ARMv7</MtouchArch> <MtouchArch>ARMv7</MtouchArch>
<MtouchLink>None</MtouchLink> <MtouchLink>None</MtouchLink>
<MtouchUseLlvm>true</MtouchUseLlvm> <MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchUseThumb>true</MtouchUseThumb> <BuildIpa>true</BuildIpa>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
...@@ -78,6 +78,9 @@ ...@@ -78,6 +78,9 @@
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
<CodesignProvision>Automatic:AdHoc</CodesignProvision> <CodesignProvision>Automatic:AdHoc</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey> <CodesignKey>iPhone Distribution</CodesignKey>
<IpaPackageName />
<MtouchI18n />
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
......
...@@ -30,7 +30,8 @@ namespace LuaInterfaceTestsiOS ...@@ -30,7 +30,8 @@ namespace LuaInterfaceTestsiOS
// create a new window instance based on the screen size // create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds); window = new UIWindow (UIScreen.MainScreen.Bounds);
runner = new TouchRunner (window); runner = new TouchRunner (window);
runner.AutoStart = true;
runner.TerminateAfterExecution = true;
// register every tests included in the main application/assembly // register every tests included in the main application/assembly
runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); runner.Add (System.Reflection.Assembly.GetExecutingAssembly ());
......
#!/bin/sh
cd Core/KeraLua
make -f Makefile.iOS
xbuild KeraLua.sln /p:Configuration=Release
cd ../../
make -f Makefile.iOS run
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment