PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/base/Applications/Tests/Scheduler/RMAPI/RMAPI.cs

#
C# | 123 lines | 92 code | 22 blank | 9 comment | 10 complexity | a06cc3e579d505922f835c8809106253 MD5 | raw file
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Research Singularity
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. using System;
  8. using System.Threading;
  9. using Microsoft.Contracts;
  10. using Microsoft.SingSharp.Reflection;
  11. using Microsoft.Singularity.UnitTest;
  12. using Microsoft.Singularity.V1.Services;
  13. using Microsoft.Singularity.Channels;
  14. using Microsoft.Singularity.Directory;
  15. using Microsoft.Singularity.Applications;
  16. using Microsoft.Singularity.Io;
  17. using Microsoft.Singularity.Configuration;
  18. [assembly: Transform(typeof(ApplicationResourceTransform))]
  19. namespace Microsoft.Singularity.Applications
  20. {
  21. [ConsoleCategory(HelpMessage="Utility to test Resource Management APIs. Run selected tests.",
  22. DefaultAction=true)]
  23. internal class Parameters {
  24. [InputEndpoint("data")]
  25. public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
  26. [OutputEndpoint("data")]
  27. public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
  28. [Endpoint]
  29. public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
  30. [BoolParameter("ProcessWithOutput", Default = false,
  31. HelpMessage="Run process creation test with children output to console.")]
  32. public bool runProcessWithOutput;
  33. [BoolParameter("ProcessNoOutputLoop", Default = false,
  34. HelpMessage="Run process creation test where children don't output to console. Run in infinit loop")]
  35. public bool runProcessWithOutputLoop;
  36. [BoolParameter("ProcessNoOutput", Default = false,
  37. HelpMessage="Run process creation test where children don't output to console.")]
  38. public bool runProcessNoOutput;
  39. reflective internal Parameters();
  40. internal int AppMain() {
  41. TestsToRun testsToRun = TestsToRun.None;
  42. if (runProcessWithOutput) {
  43. testsToRun |= TestsToRun.ProcessWithOutput;
  44. }
  45. if (runProcessNoOutput) {
  46. testsToRun |= TestsToRun.ProcessNoOutput;
  47. }
  48. if (runProcessWithOutputLoop) {
  49. testsToRun |= TestsToRun.ProcessNoOutputLoop;
  50. }
  51. return RMAPI.AppMain(testsToRun);
  52. }
  53. }
  54. [ConsoleCategory(HelpMessage="Utility to test Resource Management APIs. Run all tests.",
  55. Action="all")]
  56. internal class AllTestsParameters {
  57. [InputEndpoint("data")]
  58. public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
  59. [OutputEndpoint("data")]
  60. public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
  61. [Endpoint]
  62. public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
  63. reflective internal AllTestsParameters();
  64. internal int AppMain() {
  65. return RMAPI.AppMain(TestsToRun.All);
  66. }
  67. }
  68. [Flags]
  69. internal enum TestsToRun
  70. {
  71. None = 0x0,
  72. ProcessWithOutput = 0x1,
  73. ProcessNoOutput = 0x2,
  74. ProcessNoOutputLoop = 0x4,
  75. All = 0xF,
  76. }
  77. internal sealed class RMAPI
  78. {
  79. internal static int AppMain(TestsToRun testsToRun)
  80. {
  81. // Run test cases where the child processes don't output to the console
  82. if ((testsToRun & TestsToRun.ProcessNoOutput) != 0) {
  83. TestProcessCreation.RunWithNoChildOutput();
  84. }
  85. // Run test cases where the child processes output to the console
  86. if ((testsToRun & TestsToRun.ProcessWithOutput) != 0) {
  87. TestProcessCreation.RunWithChildOutput();
  88. }
  89. // Run test cases where the child processes don't output to the console
  90. if ((testsToRun & TestsToRun.ProcessNoOutputLoop) != 0) {
  91. for (int i = 0; ; i++) {
  92. Console.Write(i);
  93. Console.Write('.');
  94. TestProcessCreation.RunWithNoChildOutput();
  95. Thread.Sleep(1000);
  96. }
  97. }
  98. return 0;
  99. }
  100. }
  101. }