1*93707cbaSBrenda J. Butlertdc - Adding plugins for tdc
2*93707cbaSBrenda J. Butler
3*93707cbaSBrenda J. ButlerAuthor: Brenda J. Butler - [email protected]
4*93707cbaSBrenda J. Butler
5*93707cbaSBrenda J. ButlerADDING PLUGINS
6*93707cbaSBrenda J. Butler--------------
7*93707cbaSBrenda J. Butler
8*93707cbaSBrenda J. ButlerA new plugin should be written in python as a class that inherits from TdcPlugin.
9*93707cbaSBrenda J. ButlerThere are some examples in plugin-lib.
10*93707cbaSBrenda J. Butler
11*93707cbaSBrenda J. ButlerThe plugin can be used to add functionality to the test framework,
12*93707cbaSBrenda J. Butlersuch as:
13*93707cbaSBrenda J. Butler
14*93707cbaSBrenda J. Butler- adding commands to be run before and/or after the test suite
15*93707cbaSBrenda J. Butler- adding commands to be run before and/or after the test cases
16*93707cbaSBrenda J. Butler- adding commands to be run before and/or after the execute phase of the test cases
17*93707cbaSBrenda J. Butler- ability to alter the command to be run in any phase:
18*93707cbaSBrenda J. Butler    pre        (the pre-suite stage)
19*93707cbaSBrenda J. Butler    prepare
20*93707cbaSBrenda J. Butler    execute
21*93707cbaSBrenda J. Butler    verify
22*93707cbaSBrenda J. Butler    teardown
23*93707cbaSBrenda J. Butler    post       (the post-suite stage)
24*93707cbaSBrenda J. Butler- ability to add to the command line args, and use them at run time
25*93707cbaSBrenda J. Butler
26*93707cbaSBrenda J. Butler
27*93707cbaSBrenda J. ButlerThe functions in the class should follow the following interfaces:
28*93707cbaSBrenda J. Butler
29*93707cbaSBrenda J. Butler    def __init__(self)
30*93707cbaSBrenda J. Butler    def pre_suite(self, testcount, testidlist)     # see "PRE_SUITE" below
31*93707cbaSBrenda J. Butler    def post_suite(self, ordinal)                  # see "SKIPPING" below
32*93707cbaSBrenda J. Butler    def pre_case(self, test_ordinal, testid)       # see "PRE_CASE" below
33*93707cbaSBrenda J. Butler    def post_case(self)
34*93707cbaSBrenda J. Butler    def pre_execute(self)
35*93707cbaSBrenda J. Butler    def post_execute(self)
36*93707cbaSBrenda J. Butler    def adjust_command(self, stage, command)       # see "ADJUST" below
37*93707cbaSBrenda J. Butler    def add_args(self, parser)                     # see "ADD_ARGS" below
38*93707cbaSBrenda J. Butler    def check_args(self, args, remaining)          # see "CHECK_ARGS" below
39*93707cbaSBrenda J. Butler
40*93707cbaSBrenda J. Butler
41*93707cbaSBrenda J. ButlerPRE_SUITE
42*93707cbaSBrenda J. Butler
43*93707cbaSBrenda J. ButlerThis method takes a testcount (number of tests to be run) and
44*93707cbaSBrenda J. Butlertestidlist (array of test ids for tests that will be run).  This is
45*93707cbaSBrenda J. Butleruseful for various things, including when an exception occurs and the
46*93707cbaSBrenda J. Butlerrest of the tests must be skipped.  The info is stored in the object,
47*93707cbaSBrenda J. Butlerand the post_suite method can refer to it when dumping the "skipped"
48*93707cbaSBrenda J. ButlerTAP output.  The tdc.py script will do that for the test suite as
49*93707cbaSBrenda J. Butlerdefined in the test case, but if the plugin is being used to run extra
50*93707cbaSBrenda J. Butlertests on each test (eg, check for memory leaks on associated
51*93707cbaSBrenda J. Butlerco-processes) then that other tap output can be generated in the
52*93707cbaSBrenda J. Butlerpost-suite method using this info passed in to the pre_suite method.
53*93707cbaSBrenda J. Butler
54*93707cbaSBrenda J. Butler
55*93707cbaSBrenda J. ButlerSKIPPING
56*93707cbaSBrenda J. Butler
57*93707cbaSBrenda J. ButlerThe post_suite method will receive the ordinal number of the last
58*93707cbaSBrenda J. Butlertest to be attempted.  It can use this info when outputting
59*93707cbaSBrenda J. Butlerthe TAP output for the extra test cases.
60*93707cbaSBrenda J. Butler
61*93707cbaSBrenda J. Butler
62*93707cbaSBrenda J. ButlerPRE_CASE
63*93707cbaSBrenda J. Butler
64*93707cbaSBrenda J. ButlerThe pre_case method will receive the ordinal number of the test
65*93707cbaSBrenda J. Butlerand the test id.  Useful for outputing the extra test results.
66*93707cbaSBrenda J. Butler
67*93707cbaSBrenda J. Butler
68*93707cbaSBrenda J. ButlerADJUST
69*93707cbaSBrenda J. Butler
70*93707cbaSBrenda J. ButlerThe adjust_command method receives a string representing
71*93707cbaSBrenda J. Butlerthe execution stage and a string which is the actual command to be
72*93707cbaSBrenda J. Butlerexecuted.  The plugin can adjust the command, based on the stage of
73*93707cbaSBrenda J. Butlerexecution.
74*93707cbaSBrenda J. Butler
75*93707cbaSBrenda J. ButlerThe stages are represented by the following strings:
76*93707cbaSBrenda J. Butler
77*93707cbaSBrenda J. Butler    'pre'
78*93707cbaSBrenda J. Butler    'setup'
79*93707cbaSBrenda J. Butler    'command'
80*93707cbaSBrenda J. Butler    'verify'
81*93707cbaSBrenda J. Butler    'teardown'
82*93707cbaSBrenda J. Butler    'post'
83*93707cbaSBrenda J. Butler
84*93707cbaSBrenda J. ButlerThe adjust_command method must return the adjusted command so tdc
85*93707cbaSBrenda J. Butlercan use it.
86*93707cbaSBrenda J. Butler
87*93707cbaSBrenda J. Butler
88*93707cbaSBrenda J. ButlerADD_ARGS
89*93707cbaSBrenda J. Butler
90*93707cbaSBrenda J. ButlerThe add_args method receives the argparser object and can add
91*93707cbaSBrenda J. Butlerarguments to it.  Care should be taken that the new arguments do not
92*93707cbaSBrenda J. Butlerconflict with any from tdc.py or from other plugins that will be used
93*93707cbaSBrenda J. Butlerconcurrently.
94*93707cbaSBrenda J. Butler
95*93707cbaSBrenda J. ButlerThe add_args method should return the argparser object.
96*93707cbaSBrenda J. Butler
97*93707cbaSBrenda J. Butler
98*93707cbaSBrenda J. ButlerCHECK_ARGS
99*93707cbaSBrenda J. Butler
100*93707cbaSBrenda J. ButlerThe check_args method is so that the plugin can do validation on
101*93707cbaSBrenda J. Butlerthe args, if needed.  If there is a problem, and Exception should
102*93707cbaSBrenda J. Butlerbe raised, with a string that explains the problem.
103*93707cbaSBrenda J. Butler
104*93707cbaSBrenda J. Butlereg:  raise Exception('plugin xxx, arg -y is wrong, fix it')
105