예제 #1
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();
                }
            }
        }
예제 #2
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();
            }
        }
예제 #3
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();
            }
        }
예제 #4
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();
            }
        }
예제 #5
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();
            }
        }