Ejemplo n.º 1
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 ms = new HighwaySettings(1024, 1, 1024);

            // Allocates 100 fragments and continuously resets one, while
            // new fragments are allocated.
            void allocAndManualReset(IMemoryHighway hw)
            {
                var F = new List <MemoryFragment>();

                for (int i = 0; i < 100; i++)
                {
                    F.Add(hw.AllocFragment(4));
                }
            }

            if (opt.Contains("mh"))
            {
                using (var hw = new HeapHighway(ms, 1024))
                    allocAndManualReset(hw);
            }

            if (opt.Contains("nh"))
            {
                using (var hw = new MarshalHighway(ms, 1024))
                    allocAndManualReset(hw);
            }

            if (opt.Contains("mmf"))
            {
                using (var hw = new MappedHighway(ms, 1024))
                    allocAndManualReset(hw);
            }

            if (!Passed.HasValue)
            {
                Passed = true;
            }
            IsComplete = true;
        }
Ejemplo n.º 2
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            await Task.Yield();

            using (var hw = new HeapHighway(ushort.MaxValue))
            {
                var d = new Dummy();

                var bs = d.Serialize(hw);
                var bd = bs.Deserialize <Dummy>();

                if (!Assert.SameValues(d, bd, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    Passed         = false;
                    FailureMessage = "Binary serialization mismatch.";
                    return;
                }

                Passed     = true;
                IsComplete = true;
            }
        }
Ejemplo n.º 3
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                  = 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;
        }
Ejemplo n.º 4
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            Beamer rayA = null;
            Beamer rayB = null;

            var       rdmSize     = new Random();
            const int TOTAL_SENDS = 100;
            const int MIN_SIZE    = 10_000;
            const int MAX_SIZE    = 10_000_000;
            var       rmask       = new bool[TOTAL_SENDS];
            var       smask       = new bool[TOTAL_SENDS];

            try
            {
                var targ = new TestArgs(args);
                var rst  = new CountdownEvent(TOTAL_SENDS);

                void receive(MemoryFragment f)
                {
                    int len = 0;

                    try
                    {
                        var s = f.Span();
                        f.Read(ref len, 0);

                        if (s.Length == len)
                        {
                            rmask[f[4]] = true;

                            for (int i = 4; i < len; i++)
                            {
                                if (f[i] != f[4])
                                {
                                    Passed = false;
                                    "Received incorrect data.".AsError();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Passed = false;
                            "rayB receive failed.".AsError();
                        }
                    }
                    catch (Exception ex)
                    {
                        Passed = false;
                        ex.Message.AsError();
                    }
                    finally
                    {
                        rst.Signal();
                        $"Signal {rst.CurrentCount}".AsInnerInfo();
                    }
                }

                rayA = new Beamer((f) => { },
                                  new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayA-ConcurrentBeams", targ.Log)
                    {
                        OnTrace = null
                    },
                });

                rayB = new Beamer((f) => receive(f), new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-ConcurrentBeams", targ.Log)
                    {
                        OnTrace = null
                    },
                });

                var ta = new Task(async() =>
                {
                    await rayA.LockOn(targ.AE, targ.BE, -1);

                    using (var hw = new HeapHighway())
                    {
                        Parallel.For(0, TOTAL_SENDS, (i) =>
                        {
                            try
                            {
                                if (rayA.IsStopped)
                                {
                                    return;
                                }
                                var len = rdmSize.Next(MIN_SIZE, MAX_SIZE);

                                using (var f = hw.Alloc(len))
                                {
                                    for (int j = 0; j < len; j++)
                                    {
                                        f[j] = (byte)i;
                                    }

                                    f.Write(len, 0);
                                    if (!rayA.Beam(f).Result)
                                    {
                                        "Failed to beam".AsError();
                                    }
                                }

                                smask[i] = true;
                                if (!hw.IsDisposed)
                                {
                                    $"Lanes :{hw.GetLanesCount()} i:{i}".AsInfo();
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.ToString().AsError();
                            }
                        });
                    }

                    $"Out of beaming loop".AsInnerInfo();
                });

                ta.Start();

                if (!rayB.LockOn(targ.BE, targ.AE))
                {
                    $"Failed to lock on rayA".AsError();
                }

                if (!rst.Wait(new TimeSpan(0, 4, 0)))
                {
                    Passed         = false;
                    FailureMessage = "Timeout.";
                }

                if (rmask.Contains(false))
                {
                    Passed         = false;
                    FailureMessage = "Non received data";
                }


                await Task.Yield();

                if (!Passed.HasValue)
                {
                    Passed = true;
                }
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                if (rayA != null)
                {
                    rayA.Dispose();
                }
                if (rayB != null)
                {
                    rayB.Dispose();
                }
            }
        }
Ejemplo n.º 5
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                  = 5,
                Size                   = 5000_000,
                InParallel             = 4,
                RandomizeAllocDelay    = true,
                RandomizeFragDisposal  = false,
                RandomizeLength        = false,
                AllocDelayMS           = 0,
                FragmentDisposeAfterMS = 4000                 // long enough
            };

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

            var defHwCap = HighwaySettings.DefaultLaneCapacity * 1.5;

            if (allocArgs.Count * allocArgs.Size < defHwCap)
            {
                Passed         = false;
                FailureMessage = "The default highway capacity can handle all fragments. Should test out of the capacity bounds.";
                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()";
                        return;
                    }
                    if (hw.GetLanesCount() < 3)
                    {
                        Passed         = false;
                        FailureMessage = "The HeapHighway has less than 3 lanes. ";
                        return;
                    }
                    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()";
                        return;
                    }
                    if (hw.GetLanesCount() < 3)
                    {
                        Passed         = false;
                        FailureMessage = "The HeapHighway has less than 3 lanes. ";
                        return;
                    }
                    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()";
                        return;
                    }
                    if (hw.GetLanesCount() < 3)
                    {
                        Passed         = false;
                        FailureMessage = "The HeapHighway has less than 3 lanes. ";
                        return;
                    }
                    Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                }
            }

            if (!Passed.HasValue)
            {
                Passed = true;
            }
            IsComplete = true;
        }
    }
Ejemplo n.º 6
0
        public Task Start(IDictionary <string, List <string> > args)
        {
            const int IN_PARALLEL = 30;
            var       T           = new Task[IN_PARALLEL];

            try
            {
                using (var hw = new HeapHighway(2000))
                {
                    // Alloc +1 ints, the last cell will be concurrently read/written by each task.
                    // When the task id is successfully stored, the task is allowed to update its on cell.
                    var frag = hw.Alloc((IN_PARALLEL + 1) * 4);

                    // Launch multiple tasks
                    for (int i = 0; i < IN_PARALLEL; i++)
                    {
                        T[i] = Task.Factory.StartNew((idx) =>
                        {
                            var intSpan = frag.ToSpan <int>();
                            int pos     = (int)idx;
                            var laps    = 0;

                            // Await with terrible cache flushing
                            while (Interlocked.CompareExchange(ref intSpan[IN_PARALLEL], pos, 0) != 0)
                            {
                                laps++;
                            }

                            var posAndLaps = laps + (pos * 10_000_000);

                            Volatile.Write(ref intSpan[pos], posAndLaps);

                            // Release
                            Interlocked.Exchange(ref intSpan[IN_PARALLEL], 0);
                        }, i);
                    }

                    Task.WaitAll(T);

                    // Check if all tasks have updated their corresponding cells
                    var theSpan = frag.ToSpan <int>();
                    for (int i = 0; i < theSpan.Length - 1; i++)
                    {
                        if (theSpan[i] < 0)
                        {
                            Passed         = false;
                            FailureMessage = $"The Task {i} hasn't touched its cell.";
                            break;
                        }
                        else
                        {
                            Print.AsInnerInfo($"{i}: {theSpan[i]} laps");
                        }
                    }

                    Passed = true;
                    Print.Trace(hw.FullTrace(), 2, true, ConsoleColor.Cyan, ConsoleColor.Black, null);
                }
            }
            catch (Exception ex)
            {
                Passed         = false;
                FailureMessage = ex.Message;
            }

            return(Task.Delay(0));
        }
Ejemplo n.º 7
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
#if !DEBUG && !ASSERT
            return;
#endif
            Beamer rayA = null;
            Beamer rayB = null;

            const int CAP           = 30_000_000;
            int       totalSend     = 0;
            int       totalReceived = 0;
            int       totalFragsOut = 0;
            int       totalFragsIn  = 0;
            var       rdmSize       = new Random();

            // If b is on a remote machine
            var OVER = 7654321;

            try
            {
                var targ = new TestArgs(args);
                var rst  = new ManualResetEvent(false);
                var aep  = targ.AE;
                var bep  = targ.BE;

                void receive(MemoryFragment f)
                {
                    int len = 0;

                    try
                    {
                        var s = f.Span();
                        f.Read(ref len, 0);
                        var fi = Interlocked.Increment(ref totalFragsIn);

                        if (s.Length == len)
                        {
                            for (int i = 4; i < len; i++)
                            {
                                if (f[i] != 43)
                                {
                                    Passed = false;
                                    "rayB received incorrect data.".AsError();
                                    break;
                                }
                            }

                            var ts = Interlocked.Add(ref totalReceived, len);
                            string.Format("R: {0, -10} TR: {1, -10} FI: {2, -3}", len, ts, fi).AsInnerInfo();
                        }
                        else
                        {
                            Passed = false;
                            "rayB receive failed.".AsError();
                        }
                    }
                    finally
                    {
                        if ((Passed.HasValue && !Passed.Value) || Volatile.Read(ref totalReceived) >= CAP)
                        {
                            if (!Passed.HasValue)
                            {
                                Passed = true;
                                "OK: Send/Receive with dropped random frames on both sides.".AsSuccess();
                            }

                            rst.Set();
                        }
                    }
                }

                if (targ.A)
                {
                    rayA = new Beamer(
                        (f) =>
                    {
                        // If using a remote, this is equivalent to rst.Set;

                        var over = 0;
                        f.Read(ref over, 0);

                        if (OVER == over)
                        {
                            rst.Set();
                        }
                        else
                        {
                            Passed         = false;
                            FailureMessage = $"rayA received unknown <over> signal.";
                        }
                    },
                        new BeamerCfg()
                    {
                        Log = new BeamerLogCfg("rayA-DroppingFrames30M", targ.Log)
                        {
                            OnTrace = null
                        },
#if DEBUG || ASSERT
                        dropFrames       = true,
                        deopFramePercent = 20
#endif
                    });
                }

                if (targ.B)
                {
                    rayB = new Beamer(receive, new BeamerCfg()
                    {
                        Log = new BeamerLogCfg("rayB-DroppingFrames30M", targ.Log)
                        {
                            OnTrace = null
                        },
#if DEBUG || ASSERT
                        dropFrames       = true,
                        deopFramePercent = 20
#endif
                    });
                }

                using (var hw = new HeapHighway())
                {
                    if (targ.A)
                    {
                        var ta = new Task(async() =>
                        {
                            await rayA.LockOn(aep, bep, -1);

                            while (!rayA.IsStopped)
                            {
                                var len = rdmSize.Next(10, 1_000_000);
                                var f   = hw.Alloc(len);

                                for (int i = 0; i < len; i++)
                                {
                                    f[i] = 43;
                                }

                                f.Write(len, 0);
                                rayA.Beam(f);

                                var fo = Interlocked.Increment(ref totalFragsOut);
                                var ts = Interlocked.Add(ref totalSend, len);

                                string.Format("S: {0, -10} TS: {1, -10} FO: {2, -3}", len, ts, fo).AsInnerInfo();

                                if (ts > CAP)
                                {
                                    break;
                                }
                            }

                            $"Out of beaming loop".AsInnerInfo();
                        });

                        ta.Start();
                    }

                    if (targ.B)
                    {
                        if (!rayB.LockOn(bep, aep))
                        {
                            $"Failed to lock on rayA".AsError();
                        }
                    }

                    if (!rst.WaitOne(new TimeSpan(0, 2, 0)))
                    {
                        Passed         = false;
                        FailureMessage = "Timeout.";
                    }
                }

                await Task.Yield();

                if (!Passed.HasValue)
                {
                    Passed = true;
                }
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                if (rayA != null)
                {
                    rayA.Dispose();
                }
                if (rayB != null)
                {
                    rayB.Dispose();
                }
            }
        }
Ejemplo n.º 8
0
        async Task Process(AllocType at, Socket client, Action <int> onmessage, bool stop = false)
        {
            Print.AsInfo(at.ToString() + Environment.NewLine);

            try
            {
                Print.AsInfo("New client" + Environment.NewLine);

                IMemoryHighway hw    = null;
                var            lanes = new int[] { 1025, 2048 };

                switch (at)
                {
                case AllocType.Heap:
                    hw = new HeapHighway(lanes);
                    break;

                case AllocType.MMF:
                    hw = new MappedHighway(lanes);
                    break;

                case AllocType.Marshal:
                    hw = new MarshalHighway(lanes);
                    break;

                default:
                    throw new ArgumentNullException();
                }

                using (hw)
                    using (var ns = new NetworkStream(client))
                    {
                        var header   = new byte[4];
                        var spoon    = new byte[16000];
                        var total    = 0;
                        var read     = 0;
                        var frameLen = 0;

                        while (!stop)
                        {
                            total = 0;
                            read  = await ns.ReadAsync(header, 0, 4).ConfigureAwait(false);

                            Print.AsInfo("Received header bytes: {0}.{1}.{2}.{3}", header[0], header[1], header[2], header[3]);

                            // The other side is gone.
                            // As long as the sender is not disposed/closed the ReadAsync will wait
                            if (read < 1)
                            {
                                Print.AsError("The client is gone.");
                                break;
                            }

                            frameLen = BitConverter.ToInt32(header, 0);

                            if (frameLen < 1)
                            {
                                Print.AsError("Bad header, thread {0}", Thread.CurrentThread.ManagedThreadId);
                                break;
                            }

                            using (var frag = hw.AllocFragment(frameLen))
                            {
                                Print.AsInfo("Frame length:{0}", frameLen);

                                // The sip length guards against jumping into the next frame
                                var sip = 0;
                                while (total < frameLen && !stop)
                                {
                                    sip = frameLen - total;
                                    if (sip > spoon.Length)
                                    {
                                        sip = spoon.Length;
                                    }

                                    // the read amount could be smaller than the sip
                                    read = await ns.ReadAsync(spoon, 0, sip).ConfigureAwait(false);

                                    frag.Write(spoon, total, read);
                                    total += read;

                                    Print.AsInnerInfo("read {0} on thread {1}", read, Thread.CurrentThread.ManagedThreadId);

                                    if (total >= frameLen)
                                    {
                                        onmessage?.Invoke(total);
                                        break;
                                    }
                                }
                            }
                        }
                    }
            }
            catch (MemoryLaneException mex)
            {
                Print.AsError(mex.Message);
                Print.AsError(mex.ErrorCode.ToString());
                Print.AsError(mex.StackTrace);
            }
            catch (Exception ex)
            {
                Print.AsError(ex.Message);
            }
        }
Ejemplo n.º 9
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
#if !DEBUG && !ASSERT
            return;
#endif
            Beamer rayA = null;
            Beamer rayB = null;

            const int MEG = 1_000_000;

            try
            {
                var targ = new TestArgs(args);
                var rst  = new ManualResetEvent(false);
                var aep  = targ.AE;
                var bep  = targ.BE;

                rayA = new Beamer(
                    (f) => { },
                    new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayA-DroppingFrames", targ.Log),
#if DEBUG || ASSERT
                    dropFrames       = true,
                    deopFramePercent = 30
#endif
                });
                rayB = new Beamer((f) =>
                {
                    try
                    {
                        var s = f.Span();

                        if (s.Length == MEG)
                        {
                            for (int i = 0; i < MEG; i++)
                            {
                                if (f[i] != 43)
                                {
                                    Passed = false;
                                    "rayB received incorrect data.".AsError();
                                    break;
                                }
                            }

                            Passed = true;
                            "OK: Send/Receive 1meg with dropped random frames on both sides.".AsSuccess();
                        }
                        else
                        {
                            Passed = false;
                            "rayB receive failed.".AsError();
                        }
                    }
                    finally
                    {
                        rst.Set();
                    }
                }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-DroppingFrames", targ.Log),
#if DEBUG || ASSERT
                    dropFrames       = true,
                    deopFramePercent = 30
#endif
                });

                using (var hw = new HeapHighway())
                {
                    if (rayB.LockOn(bep, aep) && rayA.LockOn(aep, bep) && await rayA.TargetIsActive())
                    {
                        var f = hw.Alloc(MEG);

                        for (int i = 0; i < MEG; i++)
                        {
                            f[i] = 43;
                        }

                        await rayA.Beam(f);


                        rst.WaitOne();
                    }
                }

                await Task.Yield();

                Passed     = true;
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Ejemplo n.º 10
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            Beamer rayA = null;
            Beamer rayB = null;

            try
            {
                var rst  = new ManualResetEvent(false);
                var targ = new TestArgs(args);
                var aep  = targ.AE;
                var bep  = targ.BE;

                rayA = new Beamer((f) => { Console.WriteLine("?"); },
                                  new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayA-OneByte", targ.Log)
                });
                rayB = new Beamer((f) =>
                {
                    if (f.Span()[0] == 77)
                    {
                        Passed = true;
                        "OK: rayB received 1 byte.".AsSuccess();
                    }
                    else
                    {
                        Passed = false;
                        "rayB receive failed.".AsError();
                    }

                    rst.Set();
                }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-OneByte", targ.Log)
                });

                using (var hw = new HeapHighway(50))
                {
                    var ta = new Task(async() =>
                    {
                        rayA.LockOn(aep, bep);

                        var f = hw.Alloc(1);

                        f.Write((byte)77, 0);
                        await rayA.Beam(f);
                    });

                    var tb = new Task(async() =>
                    {
                        rayB.LockOn(bep, aep);
                    });

                    ta.Start();
                    tb.Start();
                    rst.WaitOne();
                }

                await Task.Yield();

                Passed     = true;
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Ejemplo n.º 11
0
        async Task halfGigNoLogNoVerify(TestArgs targ)
        {
            "[In] halfGigNoLogNoVerify()".AsTestInfo();
            var started = DateTime.Now;

            Beamer rayA = null;
            Beamer rayB = null;

            const int CAP           = 500_000_000;
            int       totalSend     = 0;
            int       totalReceived = 0;
            int       totalFragsOut = 0;
            int       totalFragsIn  = 0;
            var       rdmSize       = new Random();

            try
            {
                var rst = new ManualResetEvent(false);

                var aep = targ.AE;
                var bep = targ.BE;

                void receive(MemoryFragment f)
                {
                    int  len = 0;
                    bool err = false;
                    int  rec = 0;

                    try
                    {
                        var s = f.Span();
                        f.Read(ref len, 0);
                        var fi = Interlocked.Increment(ref totalFragsIn);

                        if (s.Length == len)
                        {
                            rec = Interlocked.Add(ref totalReceived, len);
                        }
                        else
                        {
                            err = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString().AsError();
                    }
                    finally
                    {
                        f.Dispose();
                        var rem = CAP - rec;

                        if (rem < 0)
                        {
                            rem = 0;
                        }
                        $"Rem: {rem} ".AsInnerInfo();

                        if (err)
                        {
                            "rayB receive failed.".AsError();
                            rst.Set();
                        }
                        else if (rec >= CAP)
                        {
                            Passed     = true;
                            IsComplete = true;
                            var ts = DateTime.Now.Subtract(started);

                            $"OK: halfGigNoLogNoVerify() {ts.Seconds}s {ts.Milliseconds}ms".AsSuccess();
                            rst.Set();
                        }
                    }
                }

                var traceops = (LogFlags.ReqTiles | LogFlags.Tile | LogFlags.ProcTile);

                rayA = new Beamer((f) => { }, new BeamerCfg()
                {
                    TileSizeBytes = 60000
                });
                rayB = new Beamer(receive, new BeamerCfg()
                {
                    Log           = new BeamerLogCfg("rayB-HalfGig", targ.Log, traceops),
                    TileSizeBytes = 60000
                });

                using (var hw = new HeapHighway())
                {
                    var ta = new Task(async() =>
                    {
                        rayA.LockOn(aep, bep);

                        while (!rayA.IsStopped)
                        {
                            var len = rdmSize.Next(10, 10_000_000);
                            var f   = hw.Alloc(len);

                            f.Write(len, 0);
                            rayA.Beam(f).Wait();

                            Interlocked.Increment(ref totalFragsOut);
                            if (Interlocked.Add(ref totalSend, len) > CAP)
                            {
                                break;
                            }
                        }

                        $"Out of beaming loop".AsInnerInfo();
                    });

                    var tb = new Task(async() =>
                    {
                        rayB.LockOn(bep, aep);
                    });

                    ta.Start();
                    tb.Start();
                    if (!rst.WaitOne(new TimeSpan(0, 2, 0)))
                    {
                        Passed         = false;
                        FailureMessage = "Timeout.";
                        FailureMessage.AsError();
                    }
                }

                await Task.Yield();

                if (Passed.HasValue && !Passed.Value || !IsComplete)
                {
                    "halfGigNoLogNoVerify() failed".AsError();
                }
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Ejemplo n.º 12
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            Beamer rayA = null;
            Beamer rayB = null;

            const int MEG = 1_000_000;

            try
            {
                var rst  = new ManualResetEvent(false);
                var targ = new TestArgs(args);
                var aep  = targ.AE;
                var bep  = targ.BE;

                rayA = new Beamer(
                    (f) => { Console.WriteLine("?"); },
                    new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayA-OneMeg", targ.Log)
                });
                rayB = new Beamer((f) =>
                {
                    try
                    {
                        var s = f.Span();

                        if (s.Length == MEG)
                        {
                            for (int i = 0; i < MEG; i++)
                            {
                                if (f[i] != 43)
                                {
                                    Passed = false;
                                    "rayB received incorrect data.".AsError();
                                    break;
                                }
                            }

                            Passed = true;
                            "OK: Send/Receive 1meg.".AsSuccess();
                        }
                        else
                        {
                            Passed = false;
                            "rayB receive failed.".AsError();
                        }
                    }
                    finally
                    {
                        rst.Set();
                    }
                }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-OneMeg", targ.Log)
                });

                using (var hw = new HeapHighway())
                {
                    var ta = new Task(async() =>
                    {
                        rayA.LockOn(aep, bep);

                        var f = hw.Alloc(MEG);

                        for (int i = 0; i < MEG; i++)
                        {
                            f[i] = 43;
                        }

                        await rayA.Beam(f);
                    });

                    var tb = new Task(async() =>
                    {
                        rayB.LockOn(bep, aep);
                    });

                    ta.Start();
                    tb.Start();
                    rst.WaitOne();
                }

                await Task.Yield();

                Passed     = true;
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Ejemplo n.º 13
0
        async Task WithCheck(TestArgs targ)
        {
            const int PULSE_RETENTION = 0;

            $"WithCheck, PulseRetentionMS: {PULSE_RETENTION}".AsInfo();

            Beamer rayA = null;
            Beamer rayB = null;

            try
            {
                var done = new ResetEvent(false);
                var aep  = targ.AE;
                var bep  = targ.BE;

                const int BYTES_TO_TRANSFER = 10_000_000;
                const int MAX_RANDOM_SIZE   = 1000;
                int       totalSent         = 0;
                int       totalReceived     = 0;

                rayA = new Beamer(
                    (f) => { Console.WriteLine("?"); },
                    new BeamerCfg()
                {
                    EnablePulsing    = true,
                    PulseRetentionMS = 0,
                    Log = new BeamerLogCfg("rayA-PulseWithCheck", targ.Log)
                });

                rayB = new Beamer((f) =>
                {
                    try
                    {
                        if (f == null || f.IsDisposed || f.Length < 1)
                        {
                            throw new Exception("Frag");
                        }

                        var fs = f.Span();
                        var v  = fs[0];

                        for (int i = 1; i < fs.Length; i++)
                        {
                            if (v != fs[i] || fs[i] == 0)
                            {
                                FailureMessage = "Received wrong data";
                                Passed         = false;
                                done.Set(false);
                            }
                        }

                        var tr = Interlocked.Add(ref totalReceived, f.Length);

                        //$"TR: {tr}".AsInfo();

                        if (tr >= BYTES_TO_TRANSFER)
                        {
                            done.Set();
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString().AsError();
                    }
                    finally
                    {
                        if (f != null)
                        {
                            f.Dispose();
                        }
                    }
                }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-PulseWithCheck", targ.Log)
                });

                using (var hw = new HeapHighway())
                {
                    var ta = new Task(async() =>
                    {
                        await Task.Yield();

                        rayA.LockOn(aep, bep);
                        var rdm = new Random();

                        while (true)
                        {
                            try
                            {
                                if (done.Task.Status == TaskStatus.RanToCompletion)
                                {
                                    return;
                                }

                                using (var f = hw.Alloc(rdm.Next(1, MAX_RANDOM_SIZE)))
                                {
                                    var v = (byte)rdm.Next(1, 255);

                                    for (int j = 0; j < f.Length; j++)
                                    {
                                        f[j] = v;
                                    }

                                    rayA.Pulse(f);
                                    var ts = Interlocked.Add(ref totalSent, f.Length);
                                    if (ts >= BYTES_TO_TRANSFER)
                                    {
                                        break;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    });

                    var tb = new Task(() =>
                    {
                        rayB.LockOn(bep, aep);
                    });

                    ta.Start();
                    tb.Start();

                    if (await done.Wait() < 0)
                    {
                        Passed         = false;
                        FailureMessage = "Timeout";
                    }
                }

                if (!Passed.HasValue)
                {
                    "OK: WithCheck".AsSuccess();
                }
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Ejemplo n.º 14
0
        async Task NoCheck(TestArgs targ)
        {
            int PULSE_RETENTION = new BeamerCfg().PulseRetentionMS;

            $"WithoutCheck, PulseRetentionMS: {PULSE_RETENTION}".AsInfo();

            Beamer rayA = null;
            Beamer rayB = null;

            try
            {
                var done = new ResetEvent(false);
                var aep  = targ.AE;
                var bep  = targ.BE;

                const int BYTES_TO_TRANSFER = 100_000_000;
                const int MAX_RANDOM_SIZE   = 1000;
                int       totalSent         = 0;
                int       totalReceived     = 0;

                rayA = new Beamer((f) => { }, new BeamerCfg()
                {
                    EnablePulsing = true,
                    Log           = new BeamerLogCfg("rayA-PulseNoCheck", targ.Log)
                });

                rayB = new Beamer((f) =>
                {
                    try
                    {
                        if (f == null || f.IsDisposed || f.Length < 1)
                        {
                            throw new Exception("Frag");
                        }

                        var tr = Interlocked.Add(ref totalReceived, f.Length);
                        if (tr >= BYTES_TO_TRANSFER)
                        {
                            done.Set();
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString().AsError();
                    }
                    finally
                    {
                        if (f != null)
                        {
                            f.Dispose();
                        }
                    }
                }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-PulseNoCheck", targ.Log)
                });

                var hw = new HeapHighway();
                var ta = new Task(async() =>
                {
                    await Task.Yield();

                    rayA.LockOn(aep, bep);
                    var rdm = new Random();

                    while (true)
                    {
                        try
                        {
                            if (done.Task.Status == TaskStatus.RanToCompletion)
                            {
                                return;
                            }

                            using (var f = hw.Alloc(rdm.Next(1, MAX_RANDOM_SIZE)))
                            {
                                rayA.Pulse(f);
                                var ts = Interlocked.Add(ref totalSent, f.Length);
                                if (ts >= BYTES_TO_TRANSFER)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.Message.AsError();
                        }
                    }

                    rayA.trace("Out of pulsing", null);
                });

                var tb = new Task(async() =>
                {
                    rayB.LockOn(bep, aep);
                });

                ta.Start();
                tb.Start();

                if (await done.Wait() < 0)
                {
                    Passed         = false;
                    FailureMessage = "Timeout";
                }

                if (!Passed.HasValue)
                {
                    "OK: WithoutCheck".AsSuccess();
                }
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }