Exemple #1
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
#if !DEBUG && !ASSERT
            return;
#endif
            Beamer rayA = null;
            Beamer rayB = null;

            const int CFGA = 11;
            const int CFGB = 12;

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

                rayA = new Beamer((f) => { }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayA-ConfigExchange", targ.Log),
                    MaxBeamedTilesAtOnce = CFGA
#if DEBUG
                    , dropFrames     = true,
                    deopFramePercent = 50
#endif
                });

                rayB = new Beamer((f) => { }, new BeamerCfg()
                {
                    Log = new BeamerLogCfg("rayB-ConfigExchange", targ.Log),
                    MaxBeamedTilesAtOnce = CFGB
#if DEBUG
                    , dropFrames     = true,
                    deopFramePercent = 50
#endif
                });

                var ta = new Task(async() =>
                {
                    if (rayA.LockOn(aep, bep) && await rayA.ConfigRequest())
                    {
                        // The remote config must be available here
                        var tc = rayA.GetTargetConfig();
                        if (tc == null || tc.MaxBeamedTilesAtOnce != CFGB)
                        {
                            Passed         = false;
                            FailureMessage = "The remote config B is not correct or is missing.";
                        }
                    }
                });

                var tb = new Task(async() =>
                {
                    if (rayB.LockOn(bep, aep) && await rayB.ConfigRequest())
                    {
                        var tc = rayB.GetTargetConfig();
                        if (tc == null || tc.MaxBeamedTilesAtOnce != CFGA)
                        {
                            Passed         = false;
                            FailureMessage = "The remote config A is not correct or is missing.";
                        }
                    }
                });

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

                if (!Task.WaitAll(new Task[] { ta, tb }, new TimeSpan(0, 2, 0)))
                {
                    Passed         = false;
                    FailureMessage = "Timeout.";
                    FailureMessage.AsError();
                }

                await Task.Yield();

                if (Passed.HasValue && !Passed.Value)
                {
                    "configExchange() failed".AsError();
                }
                else
                {
                    "OK: configExchange()".AsSuccess();
                    Passed = true;
                }
                IsComplete = true;
            }
            catch (Exception ex)
            {
                FailureMessage = ex.Message;
                Passed         = false;
            }
            finally
            {
                rayA.Dispose();
                rayB.Dispose();
            }
        }
Exemple #2
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();
                }
            }
        }
Exemple #3
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();
            }
        }
Exemple #4
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();
            }
        }
Exemple #5
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();
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
0
        public async Task Start(IDictionary <string, List <string> > args)
        {
            Beamer a = null;
            Beamer b = null;

            try
            {
                var targ = new TestArgs(args);
                var s    = targ.AE;
                var t    = targ.BE;

                a = new Beamer((_) => { }, new BeamerCfg()
                {
                    EnableProbes = true,
                    ProbeFreqMS  = 400
                });

                b = new Beamer((_) => { }, new BeamerCfg()
                {
                    EnableProbes = true,
                    ProbeFreqMS  = 100
                });

                a.LockOn(s, t);
                b.LockOn(t, s);

                await Task.Delay(2000);

                var ap = DateTime.Now.Subtract(b.LastProbe).TotalMilliseconds;
                var bp = DateTime.Now.Subtract(a.LastProbe).TotalMilliseconds;

                if (ap > 500)
                {
                    FailureMessage = $"Expected at least one probe in the {a.Config.ProbeFreqMS} interval";
                    Passed         = false;
                    return;
                }

                if (bp > 150)
                {
                    FailureMessage = $"Expected at least one probe in the {b.Config.ProbeFreqMS} interval";
                    Passed         = false;
                    return;
                }

                "OK: Probing loop.".AsSuccess();

                // Stop the probing
                Volatile.Write(ref a.Config.EnableProbes, false);
                Volatile.Write(ref b.Config.EnableProbes, false);

                await Task.Delay(2000);

                ap = DateTime.Now.Subtract(b.LastProbe).TotalMilliseconds;
                bp = DateTime.Now.Subtract(a.LastProbe).TotalMilliseconds;

                if (ap < 1000 || bp < 1000)
                {
                    FailureMessage = $"The probing should have stopped";
                    Passed         = false;
                    return;
                }

                "OK: Stopping the probing loop.".AsSuccess();

                var apr = a.Probe();

                if (!apr)
                {
                    FailureMessage = $"Probe request failed";
                    Passed         = false;
                    return;
                }


                "OK: Probe request.".AsSuccess();

                b.Dispose();

                apr = a.Probe(300);

                if (apr)
                {
                    FailureMessage = $"A probe request succeeded after the remote Beamer was disposed.";
                    Passed         = false;
                    return;
                }

                Task.Delay(1500).ContinueWith((_) =>
                {
                    b = new Beamer((f) => { }, new BeamerCfg());
                    b.LockOn(t, s);
                });

                Task.Run(() =>
                {
                    if (!a.TargetIsActive(8000).Result)
                    {
                        Passed         = false;
                        FailureMessage = "Second TargetIsActive() await failed";
                    }
                    else
                    {
                        "OK: Second TargetIsActive() await.".AsSuccess();
                    }
                });

                apr = await a.TargetIsActive(8000);

                if (!apr)
                {
                    FailureMessage = "Awaiting for target to become active with a probe failed!";
                    Passed         = false;
                    return;
                }

                "OK: Awaiting for target to become active with a probe.".AsSuccess();

                await Task.Delay(300);

                Passed     = true;
                IsComplete = true;
            }
            catch (Exception ex)
            {
                Passed         = false;
                FailureMessage = ex.Message;
            }
            finally
            {
                a.Dispose();
                b.Dispose();
            }
        }
Exemple #8
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();
            }
        }
Exemple #9
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();
            }
        }