Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. `timescale 1ns / 1ps
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // Company:
  5. // Engineer:
  6. //
  7. // Create Date: 16:19:23 03/09/2009
  8. // Design Name: DataMemory
  9. // Module Name: E:/350/Lab9/DataMemory/DataMemoryTest.v
  10. // Project Name: DataMemory
  11. // Target Device:
  12. // Tool versions:
  13. // Description:
  14. //
  15. // Verilog Test Fixture created by ISE for module: DataMemory
  16. //
  17. // Dependencies:
  18. //
  19. // Revision:
  20. // Revision 0.01 - File Created
  21. // Additional Comments:
  22. //
  23. ////////////////////////////////////////////////////////////////////////////////
  24.  
  25. `define STRLEN 32
  26. module DataMemoryTest_v;
  27.  
  28.  
  29. task passTest;
  30. input [31:0] actualOut, expectedOut;
  31. input [`STRLEN*8:0] testType;
  32. inout [7:0] passed;
  33.  
  34. if(actualOut == expectedOut) begin $display ("%s passed", testType); passed = passed + 1; end
  35. else $display ("%s failed: %d should be %d", testType, actualOut, expectedOut);
  36. endtask
  37.  
  38. task allPassed;
  39. input [7:0] passed;
  40. input [7:0] numTests;
  41.  
  42. if(passed == numTests) $display ("All tests passed");
  43. else $display("Some tests failed");
  44. endtask
  45.  
  46.  
  47. // Inputs
  48. reg [31:0] Address;
  49. reg [31:0] WriteData;
  50. reg MemoryRead;
  51. reg MemoryWrite;
  52. reg Clock;
  53. reg [7:0] passed;
  54.  
  55. // Outputs
  56. wire [31:0] ReadData;
  57.  
  58. // Instantiate the Unit Under Test (UUT)
  59. DataMemory uut (
  60. .ReadData(ReadData),
  61. .Address(Address),
  62. .WriteData(WriteData),
  63. .MemoryRead(MemoryRead),
  64. .MemoryWrite(MemoryWrite),
  65. .Clock(Clock)
  66. );
  67.  
  68. initial begin
  69. // Initialize Inputs
  70. Address = 0;
  71. WriteData = 0;
  72. MemoryRead = 0;
  73. MemoryWrite = 0;
  74. Clock = 0;
  75. passed = 0;
  76.  
  77. // Add stimulus here
  78. $display("Init Memory with some useful data");
  79. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h0, 32'h4, 2'h2};#50 Clock = 0;
  80. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h4, 32'h3, 2'h2};#50 Clock = 0;
  81. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h8, 32'd50, 2'h2};#50 Clock = 0;
  82. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'hc, 32'd40, 2'h2};#50 Clock = 0;
  83. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h10, 32'd30, 2'h2};#50 Clock = 0;
  84. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h14, 32'h0, 2'h2};#50 Clock = 0;
  85. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h20, 32'h0, 2'h2};#50 Clock = 0;
  86. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h78, 32'h132, 2'h2};#50 Clock = 0;
  87. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'h80, 32'd16435934, 2'h2};#50 Clock = 0;
  88. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'hc8, 32'haaaaffff, 2'h2};#50 Clock = 0;
  89. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'hcc, 32'd1431699200, 2'h2};#50 Clock = 0;
  90. #50 Clock = 1;{Address, WriteData, MemoryWrite, MemoryRead} = {32'hf0, 32'hffff0000, 2'h2};#50 Clock = 0;
  91.  
  92. #50 Clock = 1;
  93.  
  94. {Address, WriteData, MemoryWrite, MemoryRead} = {32'h14, 32'hffff0000, 2'h1};
  95. #50 Clock = 0;
  96. #50 Clock = 1;
  97. passTest(ReadData, 32'h0, "Read address 0x14", passed);
  98.  
  99. {Address, WriteData, MemoryWrite, MemoryRead} = {32'hf0, 32'hffff0000, 2'h1};
  100. #50 Clock = 0;
  101. #50 Clock = 1;
  102. passTest(ReadData, 32'hffff0000, "Read address 0xf0", passed);
  103.  
  104. {Address, WriteData, MemoryWrite, MemoryRead} = {32'hcc, 32'hffff0000, 2'h1};
  105. #50 Clock = 0;
  106. #50 Clock = 1;
  107. passTest(ReadData, 32'd1431699200, "Read address 0xcc", passed);
  108.  
  109. {Address, WriteData, MemoryWrite, MemoryRead} = {32'hc8, 32'hffff0000, 2'h1};
  110. #50 Clock = 0;
  111. #50 Clock = 1;
  112. passTest(ReadData, 32'haaaaffff, "Read address 0xc8", passed);
  113.  
  114. {Address, WriteData, MemoryWrite, MemoryRead} = {32'hc, 32'hffff0000, 2'h1};
  115. #50 Clock = 0;
  116. #50 Clock = 1;
  117. passTest(ReadData, 32'd40, "Read address 0xc", passed);
  118.  
  119. allPassed(passed, 5);
  120.  
  121. end
  122.  
  123. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement