1*4882a593Smuzhiyuntdc - Adding plugins for tdc 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunAuthor: Brenda J. Butler - bjb@mojatatu.com 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunADDING PLUGINS 6*4882a593Smuzhiyun-------------- 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunA new plugin should be written in python as a class that inherits from TdcPlugin. 9*4882a593SmuzhiyunThere are some examples in plugin-lib. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunThe plugin can be used to add functionality to the test framework, 12*4882a593Smuzhiyunsuch as: 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun- adding commands to be run before and/or after the test suite 15*4882a593Smuzhiyun- adding commands to be run before and/or after the test cases 16*4882a593Smuzhiyun- adding commands to be run before and/or after the execute phase of the test cases 17*4882a593Smuzhiyun- ability to alter the command to be run in any phase: 18*4882a593Smuzhiyun pre (the pre-suite stage) 19*4882a593Smuzhiyun prepare 20*4882a593Smuzhiyun execute 21*4882a593Smuzhiyun verify 22*4882a593Smuzhiyun teardown 23*4882a593Smuzhiyun post (the post-suite stage) 24*4882a593Smuzhiyun- ability to add to the command line args, and use them at run time 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThe functions in the class should follow the following interfaces: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun def __init__(self) 30*4882a593Smuzhiyun def pre_suite(self, testcount, testidlist) # see "PRE_SUITE" below 31*4882a593Smuzhiyun def post_suite(self, ordinal) # see "SKIPPING" below 32*4882a593Smuzhiyun def pre_case(self, test_ordinal, testid) # see "PRE_CASE" below 33*4882a593Smuzhiyun def post_case(self) 34*4882a593Smuzhiyun def pre_execute(self) 35*4882a593Smuzhiyun def post_execute(self) 36*4882a593Smuzhiyun def adjust_command(self, stage, command) # see "ADJUST" below 37*4882a593Smuzhiyun def add_args(self, parser) # see "ADD_ARGS" below 38*4882a593Smuzhiyun def check_args(self, args, remaining) # see "CHECK_ARGS" below 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunPRE_SUITE 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunThis method takes a testcount (number of tests to be run) and 44*4882a593Smuzhiyuntestidlist (array of test ids for tests that will be run). This is 45*4882a593Smuzhiyunuseful for various things, including when an exception occurs and the 46*4882a593Smuzhiyunrest of the tests must be skipped. The info is stored in the object, 47*4882a593Smuzhiyunand the post_suite method can refer to it when dumping the "skipped" 48*4882a593SmuzhiyunTAP output. The tdc.py script will do that for the test suite as 49*4882a593Smuzhiyundefined in the test case, but if the plugin is being used to run extra 50*4882a593Smuzhiyuntests on each test (eg, check for memory leaks on associated 51*4882a593Smuzhiyunco-processes) then that other tap output can be generated in the 52*4882a593Smuzhiyunpost-suite method using this info passed in to the pre_suite method. 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunSKIPPING 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunThe post_suite method will receive the ordinal number of the last 58*4882a593Smuzhiyuntest to be attempted. It can use this info when outputting 59*4882a593Smuzhiyunthe TAP output for the extra test cases. 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunPRE_CASE 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunThe pre_case method will receive the ordinal number of the test 65*4882a593Smuzhiyunand the test id. Useful for outputing the extra test results. 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunADJUST 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunThe adjust_command method receives a string representing 71*4882a593Smuzhiyunthe execution stage and a string which is the actual command to be 72*4882a593Smuzhiyunexecuted. The plugin can adjust the command, based on the stage of 73*4882a593Smuzhiyunexecution. 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunThe stages are represented by the following strings: 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun 'pre' 78*4882a593Smuzhiyun 'setup' 79*4882a593Smuzhiyun 'command' 80*4882a593Smuzhiyun 'verify' 81*4882a593Smuzhiyun 'teardown' 82*4882a593Smuzhiyun 'post' 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunThe adjust_command method must return the adjusted command so tdc 85*4882a593Smuzhiyuncan use it. 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunADD_ARGS 89*4882a593Smuzhiyun 90*4882a593SmuzhiyunThe add_args method receives the argparser object and can add 91*4882a593Smuzhiyunarguments to it. Care should be taken that the new arguments do not 92*4882a593Smuzhiyunconflict with any from tdc.py or from other plugins that will be used 93*4882a593Smuzhiyunconcurrently. 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunThe add_args method should return the argparser object. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunCHECK_ARGS 99*4882a593Smuzhiyun 100*4882a593SmuzhiyunThe check_args method is so that the plugin can do validation on 101*4882a593Smuzhiyunthe args, if needed. If there is a problem, and Exception should 102*4882a593Smuzhiyunbe raised, with a string that explains the problem. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyuneg: raise Exception('plugin xxx, arg -y is wrong, fix it') 105