;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2023 Bruno Victal ;;; Copyright © 2023 Felix Lechner ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests pam) #:use-module (gnu tests) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu system) #:use-module (gnu system pam) #:use-module (gnu system vm) #:use-module (guix gexp) #:use-module (ice-9 format) #:export (%test-pam-limits)) ;;; ;;; pam-limits-se
aboutsummaryrefslogtreecommitdiff
`default_nettype none

`include "messages.vh"

`ifndef SIMULATION
 `error_SIMULATION_not_defined
; /* Cause syntax error */
`endif

module div_test();
   reg clock;
   reg start;
   reg [15:0] dividend;
   reg [15:0] divisor;

   wire [15:0] quotient;
   wire [15:0] remainder;
   wire        done;

   div
  #(
    .WIDTH(16)
    ) div
    (
     .clock(clock),
     .start(start),
     .dividend(dividend),
     .divisor(divisor),
     .quotient(quotient),
     .remainder(remainder),
     .done(done)
     );

   integer     seed;
   integer     progress;
   reg [15:0]  new_divisor;
   reg [16:0]  max_divisor;

   initial begin
      seed <= 0;
      progress <= 0;
      clock <= 0;
   end

   // initial
   //   $monitor("[%t] clock is %b", $time, clock);

   always #1
     clock <= ~clock;

   always @ (posedge clock) begin
      if (progress == 0) begin
	 start <= 1;
	 dividend <= 15;
	 divisor <= 3;
	 progress <= progress + 1;
      end else begin
	 if (done) begin
	    if (dividend / divisor === quotient && dividend % divisor === remainder) begin
	       `DBG(("%0d/%0d computed as %0d r %0d", dividend, divisor, quotient, remainder));
	    end else begin
	       `MSG(("error: %0d/%0d computed as %0d r %0d",
		     dividend, divisor, quotient, remainder));
	    end
	    start <= 1;
	    case (progress)
	      1 : begin
		 dividend <= 3;
		 divisor <= 4;
	      end
	      2 : begin
		 dividend <= 65535;
		 divisor <= 65534;
	      end
	      3 : begin
		 dividend <= 1024;
		 divisor <= 4;
	      end
	      4 : begin
		 dividend <= 319;
		 divisor <= 17;
	      end
	      default : begin
		 if (progress == 500)
		   $finish;
		 else if (progress > 400)
		   max_divisor = 2**16;
		 else if (progress > 200)
		   max_divisor = 2**10;
		 else
 		   max_divisor = 2**5;

		 for (new_divisor = $urandom(seed) % max_divisor;
		      new_divisor == 0;
		      new_divisor = $urandom(seed) % max_divisor)
		   ;

		 dividend <= $urandom(seed);
		 divisor <= new_divisor;
	      end
	    endcase // case (progress)
	    progress <= progress + 1;
	 end else begin // if (done)
	    start <= 0;
	 end // else: !if(done)
      end // else: !if(progress == 0)
   end // always @ (posedge clock)
endmodule // div_test