Skip to content
Snippets Groups Projects
Select Git revision
  • c1ede1b615c326148cb927dd58d24cf81ea5fed4
  • main default protected
  • feat_dma230_dataio
  • feat_qspi_rom
  • feat_extio
  • feat_dmax4
  • feat_dma350
  • feat_nanosoc_regions
  • feat_accel_decouple
  • dev
  • feat_accel_hash_stream
  • nanosoc-2023
12 results

test_adp.py

Blame
  • AdderTest.scala 922 B
    // SPDX-FileCopyrightText: 2021 Minyong Li <ml10g20@soton.ac.uk>
    // SPDX-License-Identifier: GPL-3.0-or-later
    
    package uk.ac.soton.ecs.can.core
    
    import org.scalatest._
    import chiseltest._
    import chisel3._
    import scala.util.Random
    import scala.math.abs
    
    class AdderTest extends FlatSpec with ChiselScalatestTester {
      private val maxUInt = (Int.MaxValue.toLong << 1) | 1
    
      behavior of "The Adder"
    
      it should "sum the 16 32b unsigned integers" in {
        test(new Adder) { c =>
          val randomLhs = c.lhs.map(_ => abs(Random.nextInt))
          val randomRhs = c.rhs.map(_ => abs(Random.nextInt))
          val randomRes = randomLhs.zip(randomRhs).map { case (l, r) =>
            (l.toLong + r.toLong) % maxUInt
          }
    
          c.lhs.zip(randomLhs).foreach { case (p, r) => p.poke(r.U) }
          c.rhs.zip(randomRhs).foreach { case (p, r) => p.poke(r.U) }
          c.out.zip(randomRes).foreach { case (p, r) => p.expect(r.U) }
        }
      }
    }