/* ---------------------------------------------------------------------------- * * tut9.tv * * This carries out the same test as tut8.tv, but effectively carries it out * manually, rather than using vectors. The output is tested with an assertion * statement. A is driven manually, but the B and C inputs are still driven * with drive statements (test vectors). * * Note: * * 1 - A test vector is just a statement, like any other (it is not an * "expression statement", though; it has no value). However, it has lots * of side effects: it automatically drives inputs, tests outputs, and * maintains the internal '_passCount' and '_failCount' variables * * 2 - The user can also read and write _passCount and _failCount * * 3 - Declared ports and signals are simply external variables; they can * be driven and read like any other variable * * 4 - '_timeNow' is a read-only internal variable which gives the current * simulation time. It is a real number, in the units specified by the * timescale. * * 5 - __FILE__ and __NAME__ are standard preprocessor (cpp) macros; they give * the current location in the source code * * 6 - The drive declaration "[B,C]" sets a default time step of 5 * (since there are no timing declarations). When a test vector is * encountered in the source, the (untimed) inputs are driven at relative * time 0, and the step ends at time 5 * * 7 - The 'wait' statement can be used to explicitly advance time. Note that * the 'Ok' message is displayed at 17.5ns, rather than 5ns. * * 8 - '_StrictChecking' is set to 0, to allow us to drive and test 1-bit * ports directly with unsized constant values. It is always possible to * carry out a comparison in a *vector* against a simple decimal constant, * but we're not using vectors here; we are directly reading and writing * the ports. * ------------------------------------------------------------------------- */ #pragma _StrictChecking 0 DUT { module comb3(input A, B, C, output D); [B, C]; timescale ns; } main() { wait 12.5; // drive an input and test the output manually. this code is essentially // equivalent to "[0,0,0] -> [1]", with some extra reporting output. A = 0; // drive the A input [0, 0]; // drive the B and C inputs if(D == 1) { // test the D output _passCount++; report "(%s, line %d: %3.1f ns) Ok\n", __FILE__, __LINE__, _timeNow; } else { _failCount++; report "(%s, line %d: %3.1f ns) **FAIL**\n", __FILE__, __LINE__, _timeNow; } // A = 0; [0, 0]; assert D == 1; // we've already done this test A = 0; [0, 1]; assert D == 0; A = 0; [1, 0]; assert D == 0; A = 0; [1, 1]; assert D == 1; A = 1; [0, 0]; assert(D == 1); // brackets are optional A = 1; [0, 1]; assert(D == 1); A = 1; [1, 0]; assert(D == 1); A = 1; [1, 1]; assert(D == 0); } // ----------------------------------- EOF ------------------------------------