Jump to content

Phasing tests in a testbench: An elegant way of doing this?


Recommended Posts

Hello,

I have a system-under-test that can connect to one or more producers, as well as one or more consumers. I am currently writing a testbench for this system. I have a sequence of N test scenarios I would like to submit my SUT to, so I'd like phase through each in my testbench. I could instantiate N separate testbenches, but I am looking for a more elegant solution that only requires me to instantiate one testbench, and phase through the tests within it. I am looking for suggestions on how to do this. The primary concerns for me are that it should not be too difficult to understand the testing mechanism, and it should be as easy as possible to add new tests, or modify existing ones. To give this some substance, this is the solution I have design so far:

class Producer : public sc_module
{
public:
	sc_event first_test_e;
	sc_event second_test_e;
	sc_mutex busy_lock;

	// ... 

	void first_test()
	{
		wait(first_test_e);
		busy_lock.lock();

		// ...

		busy_lock.unlock();
	}

	void second_test()
	{
		wait(second_test_e);
		busy_lock.lock();

		// ...

		busy_lock.unlock();
	}
};

class Consumer : public sc_module
{
public:
	sc_event first_test_e;
	sc_event second_test_e;
	sc_mutex busy_lock;

	// ...

	void first_test()
	{
		wait(first_test_e);
		busy_lock.lock();

		// ...

		busy_lock.unlock();
	}

	void second_test()
	{
		wait(second_test_e);
		busy_lock.lock();

		// ...

		busy_lock.unlock();
	}
};

class tb_top : public sc_module
{
public:
	Producer prod_i;
	Consumer cons_i;

	// ...

	void top_test()
	{
		// First test starts...
		prod_i.first_test_e.notify(SC_ZERO_TIME);
		cons_i.first_test_e.notify(SC_ZERO_TIME);
		wait(SC_ZERO_TIME);
		wait(SC_ZERO_TIME);
		prod_i.busy_lock.lock();
		cons_i.busy_lock.lock();
		// First test done.
		prod_i.busy_lock.unlock();
		cons_i.busy_lock.unlock();

		// Go on to second test...
		// ...
		
	}
};

Here, I use events owned by the producers/consumers to begin tests. I use locks to communicate to the top test thread when all producers/consumers are done. I created a rudimentary prototype for this with success. Do you have any feedback?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...