What's Recommended - `ifdef or Class Extension

We need to implement a UVM TB for an IP that will be shipped out in two sets of features: F1 and F2.

F2 has all that F1 has and some additional features.

The test bench needs to adapt the stimulus largely, and to a limited extent the structure according to F1 or F2. What is a better way to approach this:

  1. Maintain common code files for both F1 and F2 with a lots of `ifdefs that change which code is included/excluded for F1/F2, or,

  2. Write base classes for F1, extend specific classes for F2 which require additional/different code. The extended classes will contain method and data property overrides wherever required.

Request your inputs on the pros and cons of both approaches, or your recommendation with reasons.

Thanks,

In reply to verificator:

This is a very hard question to answer without more specific details about what the feature difference mean for the testbench. Can the classes easily be extended from the base class, or will you wind up overriding methods and copying/pasting code from the base clsss methods into the overriden class methods?

If there’s ever a case when there are two instances of the IP needing the different sets of features in the same testbench, then class extension is the only way to go. Macros cannot target specific instances.

In reply to dave_59:

Hi Dave,

Was hoping this question would catch your attention. You are correct. While I am for the class extension based approach, the counter argument that I am getting is as follows:

class B extends A;

Over time, class A adds a new function F1 that must be overridden in class B because class B needs a different behaviour for F1. In this case, we must rewrite (copy-paste) F1 in class B thereby loosing the advantage that class extension gave us over ifdef. They are saying it would be better to keep just one class and include/exclude the different behaviours of F1 based on ifdef. I can’t convince people about the particular advantage that the class extension approach brings, because F1 could be a few thousand lines of code! Rewriting F1 in the extended class is going to be tedious and error prone. What do we do?

However, I think your point about the two class instances being present simultaneously in the testbench could seal the deal for me.

Many thanks Dave. (Any more thoughts on the topic are welcome.)