3
using System.Collections;
4
using System.Runtime.Remoting;
5
using System.Runtime.Remoting.Channels;
6
using System.Runtime.Remoting.Channels.Tcp;
7
using System.Runtime.Serialization.Formatters;
8
using System.Reflection;
9
using System.Threading;
14
using PNUnit.Framework;
18
namespace PNUnit.Agent
23
static void Main(string[] args)
27
AgentConfig config = new AgentConfig();
30
bool bDaemonMode = ReadFlag(args, "--daemon");
32
bool bDomainPool = ReadFlag(args, "--domainpool");
34
bool bNoTimeout = ReadFlag(args, "--notimeout");
36
string configfile = ReadArg(args);
40
string pathtoassemblies = ReadArg(args);
42
if (pathtoassemblies != null)
44
port = int.Parse(configfile);
48
// Load the test configuration file
49
if (pathtoassemblies == null && configfile == null)
51
Console.WriteLine("Usage: agent [configfile | port path_to_assemblies] [--daemon] [--domainpool] [--noTimeout]");
55
if (configfile != null)
57
config = AgentConfigLoader.LoadFromFile(configfile);
61
Console.WriteLine("No agent.conf file found");
67
config.PathToAssemblies = pathtoassemblies;
70
// only override if set
73
config.UseDomainPool = true;
78
config.NoTimeout = true;
81
// initialize NUnit services
82
// Add Standard Services to ServiceManager
83
ServiceManager.Services.AddService(new SettingsService());
84
ServiceManager.Services.AddService(new DomainManager());
85
ServiceManager.Services.AddService(new ProjectService());
87
// initialize NUnit services
88
// Add Standard Services to ServiceManager
89
ServiceManager.Services.AddService(new SettingsService());
90
ServiceManager.Services.AddService(new DomainManager());
91
ServiceManager.Services.AddService(new ProjectService());
93
// Initialize Services
94
ServiceManager.Services.InitializeServices();
97
PNUnitAgent agent = new PNUnitAgent();
98
agent.Run(config, bDaemonMode);
101
private static bool ReadFlag(string[] args, string flag)
103
for (int i = args.Length - 1; i >= 0; --i)
113
private static string ReadArg(string[] args)
115
for (int i = 0; i < args.Length; ++i)
118
string result = args[i];
125
private static void ConfigureLogging()
127
string log4netpath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "agent.log.conf");
128
XmlConfigurator.Configure(new FileInfo(log4netpath));
132
public class PNUnitAgent : MarshalByRefObject, IPNUnitAgent
134
private AgentConfig mConfig;
135
private static readonly ILog log = LogManager.GetLogger(typeof(PNUnitAgent));
139
public void RunTest(PNUnitTestInfo info)
141
log.InfoFormat("RunTest called for Test {0}, AssemblyName {1}, TestToRun {2}",
142
info.TestName, info.AssemblyName, info.TestToRun);
144
new PNUnitTestRunner(info, mConfig).Run();
149
#region MarshallByRefObject
151
public override object InitializeLifetimeService()
158
private void ConfigureRemoting(int port)
160
if( File.Exists("agent.remoting.conf") )
162
log.Info("Using agent.remoting.conf");
163
#if CLR_2_0 || CLR_4_0
164
RemotingConfiguration.Configure("agent.remoting.conf", false);
166
RemotingConfiguration.Configure("agent.remoting.conf");
172
BinaryClientFormatterSinkProvider clientProvider =
173
new BinaryClientFormatterSinkProvider();
174
BinaryServerFormatterSinkProvider serverProvider =
175
new BinaryServerFormatterSinkProvider();
176
serverProvider.TypeFilterLevel =
177
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
179
IDictionary props = new Hashtable();
180
props["port"] = port;
181
string s = System.Guid.NewGuid().ToString();
183
props["typeFilterLevel"] = TypeFilterLevel.Full;
186
TcpChannel chan = new TcpChannel(
187
props, clientProvider, serverProvider);
189
log.InfoFormat("Registering channel on port {0}", port);
190
#if CLR_2_0 || CLR_4_0
191
ChannelServices.RegisterChannel(chan, false);
193
ChannelServices.RegisterChannel(chan);
198
log.InfoFormat("Can't register channel.\n{0}", e.Message);
203
public void Run(AgentConfig config, bool bDaemonMode)
205
if( config.UseDomainPool )
206
log.Info("Agent using a domain pool to launch tests");
209
ConfigureRemoting(mConfig.Port);
212
RemotingServices.Marshal(this, PNUnit.Framework.Names.PNUnitAgentServiceName);
214
// otherwise in .NET 2.0 memory grows continuosly
228
while( (line = Console.ReadLine()) != "" )
233
Console.WriteLine("Cleaning up memory {0} Mb",
234
GC.GetTotalMemory(true)/1024/1024);
237
Console.WriteLine("Collecting memory {0} Mb",
238
GC.GetTotalMemory(false)/1024/1024);
240
Console.WriteLine("Memory collected {0} Mb",
241
GC.GetTotalMemory(false)/1024/1024);
247
//RemotingServices.Disconnect(this);
250
private void FreeMemory()
252
GC.GetTotalMemory(true);
3
using System.Collections;
4
using System.Runtime.Remoting;
5
using System.Runtime.Remoting.Channels;
6
using System.Runtime.Remoting.Channels.Tcp;
7
using System.Runtime.Serialization.Formatters;
8
using System.Reflection;
9
using System.Threading;
14
using PNUnit.Framework;
18
namespace PNUnit.Agent
23
static void Main(string[] args)
27
AgentConfig config = new AgentConfig();
30
bool bDaemonMode = ReadFlag(args, "--daemon");
32
bool bDomainPool = ReadFlag(args, "--domainpool");
34
bool bNoTimeout = ReadFlag(args, "--notimeout");
36
string configfile = ReadArg(args);
40
string pathtoassemblies = ReadArg(args);
42
if (pathtoassemblies != null)
44
port = int.Parse(configfile);
48
// Load the test configuration file
49
if (pathtoassemblies == null && configfile == null)
51
Console.WriteLine("Usage: agent [configfile | port path_to_assemblies] [--daemon] [--domainpool] [--noTimeout]");
55
if (configfile != null)
57
config = AgentConfigLoader.LoadFromFile(configfile);
61
Console.WriteLine("No agent.conf file found");
67
config.PathToAssemblies = pathtoassemblies;
70
// only override if set
73
config.UseDomainPool = true;
78
config.NoTimeout = true;
81
// initialize NUnit services
82
// Add Standard Services to ServiceManager
83
ServiceManager.Services.AddService(new SettingsService());
84
ServiceManager.Services.AddService(new DomainManager());
85
ServiceManager.Services.AddService(new ProjectService());
87
// initialize NUnit services
88
// Add Standard Services to ServiceManager
89
ServiceManager.Services.AddService(new SettingsService());
90
ServiceManager.Services.AddService(new DomainManager());
91
ServiceManager.Services.AddService(new ProjectService());
93
// Initialize Services
94
ServiceManager.Services.InitializeServices();
97
PNUnitAgent agent = new PNUnitAgent();
98
agent.Run(config, bDaemonMode);
101
private static bool ReadFlag(string[] args, string flag)
103
for (int i = args.Length - 1; i >= 0; --i)
113
private static string ReadArg(string[] args)
115
for (int i = 0; i < args.Length; ++i)
118
string result = args[i];
125
private static void ConfigureLogging()
127
string log4netpath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "agent.log.conf");
128
XmlConfigurator.Configure(new FileInfo(log4netpath));
132
public class PNUnitAgent : MarshalByRefObject, IPNUnitAgent
134
private AgentConfig mConfig;
135
private static readonly ILog log = LogManager.GetLogger(typeof(PNUnitAgent));
139
public void RunTest(PNUnitTestInfo info)
141
log.InfoFormat("RunTest called for Test {0}, AssemblyName {1}, TestToRun {2}",
142
info.TestName, info.AssemblyName, info.TestToRun);
144
new PNUnitTestRunner(info, mConfig).Run();
149
#region MarshallByRefObject
151
public override object InitializeLifetimeService()
158
private void ConfigureRemoting(int port)
160
if( File.Exists("agent.remoting.conf") )
162
log.Info("Using agent.remoting.conf");
163
#if CLR_2_0 || CLR_4_0
164
RemotingConfiguration.Configure("agent.remoting.conf", false);
166
RemotingConfiguration.Configure("agent.remoting.conf");
172
BinaryClientFormatterSinkProvider clientProvider =
173
new BinaryClientFormatterSinkProvider();
174
BinaryServerFormatterSinkProvider serverProvider =
175
new BinaryServerFormatterSinkProvider();
176
serverProvider.TypeFilterLevel =
177
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
179
IDictionary props = new Hashtable();
180
props["port"] = port;
181
string s = System.Guid.NewGuid().ToString();
183
props["typeFilterLevel"] = TypeFilterLevel.Full;
186
TcpChannel chan = new TcpChannel(
187
props, clientProvider, serverProvider);
189
log.InfoFormat("Registering channel on port {0}", port);
190
#if CLR_2_0 || CLR_4_0
191
ChannelServices.RegisterChannel(chan, false);
193
ChannelServices.RegisterChannel(chan);
198
log.InfoFormat("Can't register channel.\n{0}", e.Message);
203
public void Run(AgentConfig config, bool bDaemonMode)
205
if( config.UseDomainPool )
206
log.Info("Agent using a domain pool to launch tests");
209
ConfigureRemoting(mConfig.Port);
212
RemotingServices.Marshal(this, PNUnit.Framework.Names.PNUnitAgentServiceName);
214
// otherwise in .NET 2.0 memory grows continuosly
228
while( (line = Console.ReadLine()) != "" )
233
Console.WriteLine("Cleaning up memory {0} Mb",
234
GC.GetTotalMemory(true)/1024/1024);
237
Console.WriteLine("Collecting memory {0} Mb",
238
GC.GetTotalMemory(false)/1024/1024);
240
Console.WriteLine("Memory collected {0} Mb",
241
GC.GetTotalMemory(false)/1024/1024);
247
//RemotingServices.Disconnect(this);
250
private void FreeMemory()
252
GC.GetTotalMemory(true);