public async Task Start(IDictionary <string, List <string> > args)
        {
            await Task.Delay(0);

            if (args.ContainsKey("+all"))
            {
                args.Add("-store", new List <string>()
                {
                    "mh", "mmf", "nh"
                });
            }

            args.AssertAll("-store");
            var opt = args["-store"];

            opt.AssertNothingOutsideThese("mh", "mmf", "nh");

            var allocArgs = new AllocTestArgs()
            {
                Count                  = 20,
                Size                   = 180000,
                InParallel             = 10,
                RandomizeAllocDelay    = true,
                RandomizeFragDisposal  = true,
                RandomizeLength        = true,
                AllocDelayMS           = 0,
                AllocTries             = 1,
                FragmentDisposeAfterMS = 60
            };

            if (args.ContainsKey("-count"))
            {
                allocArgs.Count = int.Parse(args["-count"][0]);
            }
            if (args.ContainsKey("-size"))
            {
                allocArgs.Size = int.Parse(args["-size"][0]);
            }

            if (allocArgs.Count * allocArgs.Size > 12_000_000)
            {
                Passed         = false;
                FailureMessage = "The default highway capacity is not enough if all fragments live forever.";
                return;
            }

            Print.Trace(allocArgs.FullTrace(), ConsoleColor.Cyan, ConsoleColor.Black, null);

            if (opt.Contains("mh"))
            {
                using (var hw = new HeapHighway())
                {
                    hw.AllocAndWait(allocArgs);
                    if (hw.GetTotalActiveFragments() > 0)
                    {
                        Passed         = false;
                        FailureMessage = "The HeapHighway has active fragments after the AllocAndWait()";
                    }
                    Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                }
            }

            if (opt.Contains("nh"))
            {
                using (var hw = new MarshalHighway())
                {
                    hw.AllocAndWait(allocArgs);
                    if (hw.GetTotalActiveFragments() > 0)
                    {
                        Passed         = false;
                        FailureMessage = "The MarshalHighway has active fragments after the AllocAndWait()";
                    }
                    Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                }
            }

            if (opt.Contains("mmf"))
            {
                using (var hw = new MappedHighway())
                {
                    hw.AllocAndWait(allocArgs);
                    if (hw.GetTotalActiveFragments() > 0)
                    {
                        Passed         = false;
                        FailureMessage = "The MappedHighway has active fragments after the AllocAndWait()";
                    }
                    Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                }
            }

            if (!Passed.HasValue)
            {
                Passed = true;
            }
            IsComplete = true;
        }
Beispiel #2
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            await Task.Delay(0);

            if (args.ContainsKey("+all"))
            {
                args.Add("-store", new List <string>()
                {
                    "mh", "mmf", "nh"
                });
            }

            args.AssertAll("-store");
            var opt = args["-store"];

            opt.AssertNothingOutsideThese("mh", "mmf", "nh");

            var allocArgs = new AllocTestArgs()
            {
                Count                  = 6000,
                Size                   = 1200,
                InParallel             = 12,
                RandomizeAllocDelay    = false,
                RandomizeFragDisposal  = true,
                RandomizeLength        = false,
                AllocDelayMS           = 10,
                AllocTries             = 20,
                AwaitFragmentDisposal  = false,
                FragmentDisposeAfterMS = 100,
                Trace                  = 0
            };

            var H     = new Dictionary <string, IMemoryHighway>();
            var ms    = new HighwaySettings(300_000, 300, 700_000_000);
            var lanes = new int[10];

            Array.Fill(lanes, 300_000);

            H.Add("mh", new HeapHighway(ms, lanes));
            H.Add("nh", new MarshalHighway(ms, lanes));
            H.Add("mmf", new MappedHighway(ms, lanes));

            Print.Trace(allocArgs.FullTrace(), ConsoleColor.Cyan, ConsoleColor.Black, null);

            foreach (var kp in H)
            {
                if (opt.Contains(kp.Key))
                {
                    var hw     = kp.Value;
                    var hwName = hw.GetType().Name;

                    using (hw)
                    {
                        hw.AllocAndWait(allocArgs);
                        var fragsCount = hw.GetTotalActiveFragments();

                        if (fragsCount < args.Count)
                        {
                            Passed         = false;
                            FailureMessage = string.Format(
                                "{0}: Failed to allocate all {1} fragments, got {2}.",
                                hwName, allocArgs.Count, fragsCount);

                            return;
                        }

                        Print.AsInnerInfo(
                            "{0}: Total lanes count: {1} Total active fragments: {2}",
                            hwName, hw.GetLanesCount(), hw.GetTotalActiveFragments());

                        Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                    }
                }
            }

            if (!Passed.HasValue)
            {
                Passed = true;
            }
            IsComplete = true;
        }