Ejemplo n.º 1
0
        public void FullAdderModuleTest()
        {
            var values = new[]
            {
                new { A = 0, B = 0, CIn = 0, O = 0, COut = 0 },
                new { A = 1, B = 0, CIn = 0, O = 1, COut = 0 },
                new { A = 0, B = 1, CIn = 0, O = 1, COut = 0 },
                new { A = 1, B = 1, CIn = 0, O = 0, COut = 1 },
                new { A = 0, B = 0, CIn = 1, O = 1, COut = 0 },
                new { A = 1, B = 0, CIn = 1, O = 0, COut = 1 },
                new { A = 0, B = 1, CIn = 1, O = 0, COut = 1 },
                new { A = 1, B = 1, CIn = 1, O = 1, COut = 1 },
            };

            Func <int, bool> toBool = (v) => v == 0 ? false : true;

            foreach (var set in values)
            {
                var sim = new RTLSimulator <FullAdderModule>();
                sim.IsRunning = (cb) => cb.Clock == 0;
                sim.TopLevel.Schedule(() => new FullAdderInputs()
                {
                    A = toBool(set.A), B = toBool(set.B), CIn = toBool(set.CIn)
                });
                sim.Run();
                Assert.AreEqual(toBool(set.O), sim.TopLevel.O);
                Assert.AreEqual(toBool(set.COut), sim.TopLevel.COut);
            }
        }
Ejemplo n.º 2
0
        public void CompositionModuleTest()
        {
            var bytesToProcess = 256;
            var receivedData   = new List <byte>();

            var sim = new RTLSimulator <CompositionModule>();

            //sim.TraceToVCD(PathTools.VCDOutputPath());

            sim.IsRunning = (simulatorCallback) => receivedData.Count < bytesToProcess;

            sim.OnPostStage = (topLevel) =>
            {
                if (topLevel.HasData)
                {
                    receivedData.Add(topLevel.Data);
                }
            };

            sim.Run();

            Assert.AreEqual(bytesToProcess, receivedData.Count);
            var missing = Enumerable
                          .Range(0, bytesToProcess)
                          .Zip(receivedData, (e, a) => new { e, a })
                          .Where(p => p.e != p.a)
                          .Select(p => $"E: {p.e}, A: {p.a}")
                          .ToList();

            Assert.AreEqual(0, missing.Count, missing.ToCSV());
        }
Ejemplo n.º 3
0
        public void NotGateFeedbackModuleTest()
        {
            var sim = new RTLSimulator <NotGateFeedbackModule>();

            sim.TraceToVCD(VCDOutputPath());

            Assert.ThrowsException <MaxStageIterationReachedException>(() =>
            {
                sim.Run();
            });
        }
Ejemplo n.º 4
0
        public void NotGateModuleTest()
        {
            var sim = new RTLSimulator <NotGateModule>();

            sim.IsRunning = (cb) => cb.Clock == 0;
            sim.TraceToVCD(VCDOutputPath());
            sim.TopLevel.Schedule(() => new NotGateInputs()
            {
                Input = true
            });;

            Assert.AreEqual(true, sim.TopLevel.Output);
            sim.Run();
            Assert.AreEqual(false, sim.TopLevel.Output);
        }
Ejemplo n.º 5
0
        public void CounterModuleTest()
        {
            var sim = new RTLSimulator <CounterModule>();

            sim.IsRunning = (cb) => cb.Clock < 100;
            sim.TraceToVCD(VCDOutputPath());
            sim.TopLevel.Schedule(() => new CounterInputs()
            {
                Enabled = true
            });

            Assert.AreEqual(0, sim.TopLevel.Value);
            sim.Run();
            Assert.AreEqual(100, sim.TopLevel.Value);
        }