64 lines
1.8 KiB
Plaintext
64 lines
1.8 KiB
Plaintext
package PackUnpack_Test;
|
|
|
|
import StmtFSM::*;
|
|
import Assert::*;
|
|
import GetPut::*;
|
|
import ClientServer::*;
|
|
|
|
import PackUnpack::*;
|
|
import Testing::*;
|
|
|
|
module mkTB();
|
|
let testflags <- mkTestFlags();
|
|
|
|
Server#(UInt#(17), Bit#(8)) dut_pack <- mkPacker();
|
|
Server#(Bit#(8), UInt#(17)) dut_unpack <- mkUnpacker();
|
|
|
|
function Action put_pack(UInt#(17) v);
|
|
return action
|
|
dut_pack.request.put(v);
|
|
if (testflags.verbose)
|
|
$display("pack.put(%0d), binary %017b", v, v);
|
|
endaction;
|
|
endfunction
|
|
|
|
function Action check_pack(Bit#(8) want);
|
|
return action
|
|
let got <- dut_pack.response.get();
|
|
if (testflags.verbose)
|
|
$display("pack.get = %0d (%08b), want %0d (%08b)", got, got, want, want);
|
|
dynamicAssert(got == want, "got incorrect packed byte");
|
|
|
|
dut_unpack.request.put(got);
|
|
if (testflags.verbose)
|
|
$display("unpack.put(%0d), binary %08b", got, got);
|
|
endaction;
|
|
endfunction
|
|
|
|
function Action check_unpack(UInt#(17) want);
|
|
return action
|
|
let got <- dut_unpack.response.get();
|
|
if (testflags.verbose)
|
|
$display("unpack.get = %0d (%08b), want %0d (%08b)", got, got, want, want);
|
|
dynamicAssert(got == want, "got incorrect unpacked value");
|
|
endaction;
|
|
endfunction
|
|
|
|
runTest(100,
|
|
mkTest("PackUnpack", seq
|
|
put_pack(115738);
|
|
check_pack(8'b00000001);
|
|
check_pack(8'b11000100);
|
|
check_pack(8'b00011010);
|
|
check_unpack(115738);
|
|
|
|
put_pack(0);
|
|
check_pack(0);
|
|
check_pack(0);
|
|
check_pack(0);
|
|
check_unpack(0);
|
|
endseq));
|
|
endmodule
|
|
|
|
endpackage
|