305 lines
10 KiB
Plaintext
305 lines
10 KiB
Plaintext
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Microsoft Research Singularity
|
||
|
//
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
//
|
||
|
// Creates startup boilerplate code from Resource descriptions.
|
||
|
|
||
|
using System;
|
||
|
|
||
|
using Microsoft.SingSharp;
|
||
|
using Microsoft.Contracts;
|
||
|
using Microsoft.Singularity;
|
||
|
using Microsoft.Singularity.Channels;
|
||
|
using Microsoft.Singularity.Extending;
|
||
|
using Microsoft.Singularity.Directory;
|
||
|
using Microsoft.Singularity.Configuration;
|
||
|
using Microsoft.Singularity.V1.Services;
|
||
|
|
||
|
namespace Microsoft.Singularity.UnitTest
|
||
|
{
|
||
|
|
||
|
transform TestTransform
|
||
|
where $Ex : Exception
|
||
|
where $EndpointType : unmanaged struct, Endpoint, ITracked
|
||
|
where $EpAttr : EndpointAttribute
|
||
|
{
|
||
|
#if false
|
||
|
[TestClass]
|
||
|
public class $$Fixture {
|
||
|
|
||
|
[TestMethod($fname)]
|
||
|
[ExceptionExpected(typeof($Ex))]
|
||
|
public void $$FailTests();
|
||
|
[TestMethod($name)]
|
||
|
public void $$Tests();
|
||
|
|
||
|
[ClassInitialize]
|
||
|
void $$ClassSetup();
|
||
|
|
||
|
[ClassCleanup]
|
||
|
void $$ClassTeardown();
|
||
|
}
|
||
|
|
||
|
generate class Module_Jig : ModuleJig
|
||
|
{
|
||
|
override public SuiteJig GetSuite(string! name, TestLog! log)
|
||
|
{
|
||
|
override public void Initialize() {
|
||
|
forall (; $f in $$Fixture;) {
|
||
|
if ($f.$name == tname) {
|
||
|
return $f();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
switch (name) {
|
||
|
case "FibTest":
|
||
|
return new FibTest_Jig(log);
|
||
|
default:
|
||
|
return base.GetSuite(name, log);
|
||
|
}
|
||
|
}
|
||
|
public static void RunTest()
|
||
|
{
|
||
|
forall (; $fix in $$Fixture;) {
|
||
|
$fix.DispatchTest();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
forall (; $suite in $$Fixture;) {
|
||
|
generate public class $suite_Jig : SuiteJig {
|
||
|
private $suite! m_test;
|
||
|
|
||
|
public $suite_Jig(TestLog! log) {
|
||
|
m_test = new $suite();
|
||
|
m_test.SetLog(log);
|
||
|
}
|
||
|
override public void Initialize() {
|
||
|
forall (; $s in $$Setup;) {
|
||
|
$s();
|
||
|
}
|
||
|
}
|
||
|
override public void Cleanup() {
|
||
|
forall (; $td in $$Teardown;) {
|
||
|
$td();
|
||
|
}
|
||
|
}
|
||
|
override public void DoTest(string! test) {
|
||
|
forall (; $test in $$Tests;) {
|
||
|
if ($test.$name == tname) {
|
||
|
$test();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
#if false
|
||
|
forall (; $ft in $$FailTests;) {
|
||
|
if ($ft.$fname == tname) {
|
||
|
try {
|
||
|
$ft();
|
||
|
throw new Exception("Failure expected: " + typeof($ft.$Ex).ToString());
|
||
|
}
|
||
|
catch ($ft.$Ex) {
|
||
|
// expected
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
Expect.Continue(false, "Unknown test");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#if false
|
||
|
generate static string[] TestNames = $BuildTestNames();
|
||
|
|
||
|
generate static string[] $BuildTestNames() {
|
||
|
Hashtable result = new Hashtable();
|
||
|
forall (; $cmd in $$Commands;) {
|
||
|
result [ $cmd.$name ] = new Command( $cmd );
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#if CASE_WORKS
|
||
|
generate void DispatchTest(string tname) {
|
||
|
switch (tname) {
|
||
|
case "SETUP":
|
||
|
forall (; $test in $$Setup;) {
|
||
|
$test();
|
||
|
}
|
||
|
break;
|
||
|
case "TEARDOWN":
|
||
|
forall (; $test in $$Setup;) {
|
||
|
$test();
|
||
|
}
|
||
|
break;
|
||
|
forall (; $test in $$Tests;) {
|
||
|
case $test.$name:
|
||
|
$test();
|
||
|
break;
|
||
|
}
|
||
|
forall (; $test in $$FailTests;) {
|
||
|
case $test.$name:
|
||
|
try {
|
||
|
$test();
|
||
|
throw new Exception("Failure expected: " + $test.$Ex);
|
||
|
}
|
||
|
catch ($test.$Ex ex) {
|
||
|
// expected
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
default:
|
||
|
throw new Exception("Unknown test.");
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
|
[ConsoleCategory(*, DefaultAction=true)]
|
||
|
internal class $DefaultCategory
|
||
|
{
|
||
|
// only match, don't implement
|
||
|
internal $DefaultCategory();
|
||
|
|
||
|
internal int AppMain();
|
||
|
|
||
|
// Single entry point
|
||
|
generate public static int Main(string[] args) {
|
||
|
#if SHOW_ARGS
|
||
|
if (args != null) {
|
||
|
foreach (string arg in args) {
|
||
|
DebugStub.WriteLine("startup argument '{0}'", __arglist(arg));
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
if (args == null || args.Length < 2) {
|
||
|
$DefaultCategory config = new $DefaultCategory();
|
||
|
return config.AppMain();
|
||
|
}
|
||
|
|
||
|
string action = args[1];
|
||
|
forall (; $Action in $$NamedCategories ;) {
|
||
|
if ($Action.$name == action) {
|
||
|
$Action config = new $Action();
|
||
|
return config.AppMain();
|
||
|
}
|
||
|
}
|
||
|
throw new Exception(String.Format("Unrecognized action {0}", action));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
[ConsoleCategory(*, Action=$name)]
|
||
|
internal class $$NamedCategories {
|
||
|
// only match, don't implement
|
||
|
internal $$NamedCategories();
|
||
|
|
||
|
internal int AppMain();
|
||
|
}
|
||
|
|
||
|
[ConsoleCategory(*)]
|
||
|
internal class $$Categories {
|
||
|
|
||
|
[$EpAttr(*)]
|
||
|
TRef<$EndpointType,$State> $$endpoints;
|
||
|
|
||
|
[StringParameter(*)]
|
||
|
string $$strings;
|
||
|
|
||
|
[StringArrayParameter(*)]
|
||
|
string[] $$stringArrays;
|
||
|
|
||
|
[LongParameter(*)]
|
||
|
long $$longs;
|
||
|
|
||
|
[BoolParameter(*)]
|
||
|
bool $$bools;
|
||
|
|
||
|
// [NotDelayed]
|
||
|
implement internal $$Categories() {
|
||
|
//DebugStub.WriteLine("ConsoleCategory action '{0}' applied", __arglist(this.GetType().ToString()));
|
||
|
|
||
|
int index;
|
||
|
ParameterCode code;
|
||
|
|
||
|
index = 0;
|
||
|
forall (; $s in $$strings ;) {
|
||
|
string stringParam;
|
||
|
code = Process.GetStartupStringArg(index, out stringParam);
|
||
|
if (code != ParameterCode.Success) {
|
||
|
throw new ArgumentException(String.Format("error acquiring startup string array {0}. code={1}", index, code));
|
||
|
}
|
||
|
this.$s = stringParam;
|
||
|
//DebugStub.WriteLine("got string {0}=({1})",__arglist(index, $s));
|
||
|
++index;
|
||
|
}
|
||
|
|
||
|
index = 0;
|
||
|
forall (; $sa in $$stringArrays ;) {
|
||
|
string[] stringArrayParam;
|
||
|
code = Process.GetStartupStringArrayArg(index, out stringArrayParam );
|
||
|
if (code != ParameterCode.Success) {
|
||
|
throw new ArgumentException(String.Format("error acquiring startup string {0}. code={1}", index, code));
|
||
|
}
|
||
|
this.$sa = stringArrayParam;
|
||
|
//DebugStub.WriteLine("got string {0}=({1})",__arglist(index, $s));
|
||
|
++index;
|
||
|
}
|
||
|
|
||
|
index = 0;
|
||
|
forall (; $l in $$longs ;) {
|
||
|
long longArg;
|
||
|
code = ProcessService.GetStartupLongArg(index, out longArg);
|
||
|
if (code != ParameterCode.Success) {
|
||
|
throw new ArgumentException(String.Format("error acquiring startup integer {0}. code={1}", index, code));
|
||
|
}
|
||
|
this.$l = longArg;
|
||
|
//DebugStub.WriteLine("got long {0}=({1})",__arglist(index, $l));
|
||
|
++index;
|
||
|
}
|
||
|
|
||
|
index = 0;
|
||
|
forall (; $b in $$bools ;) {
|
||
|
bool b;
|
||
|
code = ProcessService.GetStartupBoolArg(index, out b);
|
||
|
if (code != ParameterCode.Success) {
|
||
|
throw new ArgumentException(String.Format("error acquiring startup bool {0}. code={1}", index, code));
|
||
|
}
|
||
|
this.$b = b;
|
||
|
//DebugStub.WriteLine("got bool {0}=({1})",__arglist(index, b));
|
||
|
++index;
|
||
|
}
|
||
|
index = 0;
|
||
|
forall (; $e in $$endpoints;) {
|
||
|
if (index == 0 || index == 1) {
|
||
|
//DebugStub.WriteLine("transform skipping pipe at {0}",__arglist(index));
|
||
|
}
|
||
|
else {
|
||
|
$e.$EndpointType* in ExHeap opt($e.$State) ep = Process.GetStartupEndpoint(index)
|
||
|
as $e.$EndpointType* in ExHeap opt($e.$State);
|
||
|
if (ep == null) {
|
||
|
throw new ArgumentException(String.Format("missing startup endpoint {0}", index));
|
||
|
}
|
||
|
$e = new TRef<$e.$EndpointType, $e.$State> (ep);
|
||
|
//DebugStub.WriteLine("getting endpoint at {0}",__arglist(index));
|
||
|
}
|
||
|
++index;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Category specific entry point
|
||
|
internal int AppMain();
|
||
|
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
}
|