2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Note: Simple Singularity test program.
|
|
|
|
//
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using Microsoft.SingSharp;
|
|
|
|
using Microsoft.Singularity;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using Microsoft.Singularity.Stress.Contracts;
|
|
|
|
|
|
|
|
using Microsoft.Contracts;
|
|
|
|
using Microsoft.SingSharp.Reflection;
|
|
|
|
using Microsoft.Singularity.Applications;
|
|
|
|
using Microsoft.Singularity.Io;
|
|
|
|
using Microsoft.Singularity.Configuration;
|
|
|
|
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
namespace Microsoft.Singularity.Applications
|
|
|
|
{
|
2008-03-05 09:52:00 -05:00
|
|
|
[ConsoleCategory(DefaultAction=true)]
|
|
|
|
internal class Parameters {
|
|
|
|
[InputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
|
|
|
|
|
|
|
[OutputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
|
|
|
|
|
|
|
[BoolParameter( "kernel", Default=false, HelpMessage="Run kernel test.")]
|
|
|
|
internal bool doKernelTest;
|
|
|
|
|
|
|
|
reflective internal Parameters();
|
|
|
|
|
|
|
|
internal int AppMain() {
|
|
|
|
return GcStress.AppMain(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class GcStress : Microsoft.Singularity.Stress.GcStress
|
|
|
|
{
|
|
|
|
override protected void Print(string! s)
|
|
|
|
{
|
|
|
|
Console.Write(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
//[ShellCommand("gcstress", "Stress garbage collector")]
|
|
|
|
internal static int AppMain(Parameters! config)
|
|
|
|
{
|
|
|
|
const int ARGS_START = 1;
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (!config.doKernelTest) {
|
2008-03-05 09:52:00 -05:00
|
|
|
new GcStress().Run();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DirectoryServiceContract.Imp! epNS = DirectoryService.NewClientEndpoint();
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
try {
|
2008-03-05 09:52:00 -05:00
|
|
|
StressContract.Imp! imp;
|
|
|
|
StressContract.Exp! exp;
|
|
|
|
StressContract.NewChannel(out imp, out exp);
|
|
|
|
|
|
|
|
ErrorCode errorOut;
|
|
|
|
bool ok = SdsUtils.Bind(StressContract.ModuleName, epNS, exp, out errorOut);
|
|
|
|
if (!ok) {
|
|
|
|
Console.Write("failure on lookup of name " + StressContract.ModuleName
|
|
|
|
+ "reason: " + SdsUtils.ErrorCodeToString(errorOut));
|
|
|
|
delete imp;
|
2008-11-17 18:29:00 -05:00
|
|
|
if (errorOut == ErrorCode.ChannelClosed) {
|
2008-03-05 09:52:00 -05:00
|
|
|
throw new Exception("Encountered a ChannelClosed");
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
2008-11-17 18:29:00 -05:00
|
|
|
switch receive {
|
2008-03-05 09:52:00 -05:00
|
|
|
case imp.Ready() :
|
|
|
|
break;
|
|
|
|
case imp.ContractNotSupported() :
|
|
|
|
Console.Write("failure: contract not supported");
|
|
|
|
delete imp;
|
|
|
|
return 1;
|
|
|
|
case imp.ChannelClosed() :
|
|
|
|
Console.Write("failure: channel closed prematurely");
|
|
|
|
delete imp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
imp.SendGcStress();
|
2008-11-17 18:29:00 -05:00
|
|
|
while (true) {
|
|
|
|
switch receive {
|
2008-03-05 09:52:00 -05:00
|
|
|
case imp.Print(char[] in ExHeap s) :
|
|
|
|
Console.Write(Bitter.ToString(s));
|
|
|
|
imp.SendAckPrint();
|
|
|
|
delete s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case imp.GcStressDone() :
|
|
|
|
delete imp;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case imp.ChannelClosed() :
|
|
|
|
delete imp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
//
|
|
|
|
//// epNS.SendBind(Bitter.FromString2(StressContract.ModuleName), exp);
|
|
|
|
//
|
|
|
|
// switch receive {
|
|
|
|
// case epNS.NakBind(rejected, error) :
|
|
|
|
// // failure
|
|
|
|
// Console.Write("failure on lookup of name " + StressContract.ModuleName);
|
|
|
|
// delete imp;
|
|
|
|
// delete rejected;
|
|
|
|
// return 1;
|
|
|
|
//
|
|
|
|
// case epNS.AckBind() :
|
|
|
|
// // success
|
|
|
|
// switch receive {
|
|
|
|
// case imp.Ready() :
|
|
|
|
// break;
|
|
|
|
// case imp.ContractNotSupported() :
|
|
|
|
// Console.Write("failure: contract not supported");
|
|
|
|
// delete imp;
|
|
|
|
// return 1;
|
|
|
|
// case imp.ChannelClosed() :
|
|
|
|
// Console.Write("failure: channel closed prematurely");
|
|
|
|
// delete imp;
|
|
|
|
// return 1;
|
|
|
|
// }
|
|
|
|
// imp.SendGcStress();
|
|
|
|
// while (true) {
|
|
|
|
// switch receive {
|
|
|
|
// case imp.Print(char[] in ExHeap s) :
|
|
|
|
// Console.Write(Bitter.ToString(s));
|
|
|
|
// imp.SendAckPrint();
|
|
|
|
// delete s;
|
|
|
|
// break;
|
|
|
|
//
|
|
|
|
// case imp.GcStressDone() :
|
|
|
|
// delete imp;
|
|
|
|
// return 0;
|
|
|
|
//
|
|
|
|
// case imp.ChannelClosed() :
|
|
|
|
// delete imp;
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// case epNS.ChannelClosed() :
|
|
|
|
// throw new Exception("epNS channel closed");
|
|
|
|
// }
|
|
|
|
//
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
finally {
|
2008-03-05 09:52:00 -05:00
|
|
|
delete epNS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|