18c2ecf20Sopenharmony_citdc - Adding plugins for tdc
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciAuthor: Brenda J. Butler - bjb@mojatatu.com
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciADDING PLUGINS
68c2ecf20Sopenharmony_ci--------------
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciA new plugin should be written in python as a class that inherits from TdcPlugin.
98c2ecf20Sopenharmony_ciThere are some examples in plugin-lib.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciThe plugin can be used to add functionality to the test framework,
128c2ecf20Sopenharmony_cisuch as:
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci- adding commands to be run before and/or after the test suite
158c2ecf20Sopenharmony_ci- adding commands to be run before and/or after the test cases
168c2ecf20Sopenharmony_ci- adding commands to be run before and/or after the execute phase of the test cases
178c2ecf20Sopenharmony_ci- ability to alter the command to be run in any phase:
188c2ecf20Sopenharmony_ci    pre        (the pre-suite stage)
198c2ecf20Sopenharmony_ci    prepare
208c2ecf20Sopenharmony_ci    execute
218c2ecf20Sopenharmony_ci    verify
228c2ecf20Sopenharmony_ci    teardown
238c2ecf20Sopenharmony_ci    post       (the post-suite stage)
248c2ecf20Sopenharmony_ci- ability to add to the command line args, and use them at run time
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciThe functions in the class should follow the following interfaces:
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci    def __init__(self)
308c2ecf20Sopenharmony_ci    def pre_suite(self, testcount, testidlist)     # see "PRE_SUITE" below
318c2ecf20Sopenharmony_ci    def post_suite(self, ordinal)                  # see "SKIPPING" below
328c2ecf20Sopenharmony_ci    def pre_case(self, test_ordinal, testid)       # see "PRE_CASE" below
338c2ecf20Sopenharmony_ci    def post_case(self)
348c2ecf20Sopenharmony_ci    def pre_execute(self)
358c2ecf20Sopenharmony_ci    def post_execute(self)
368c2ecf20Sopenharmony_ci    def adjust_command(self, stage, command)       # see "ADJUST" below
378c2ecf20Sopenharmony_ci    def add_args(self, parser)                     # see "ADD_ARGS" below
388c2ecf20Sopenharmony_ci    def check_args(self, args, remaining)          # see "CHECK_ARGS" below
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciPRE_SUITE
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThis method takes a testcount (number of tests to be run) and
448c2ecf20Sopenharmony_citestidlist (array of test ids for tests that will be run).  This is
458c2ecf20Sopenharmony_ciuseful for various things, including when an exception occurs and the
468c2ecf20Sopenharmony_cirest of the tests must be skipped.  The info is stored in the object,
478c2ecf20Sopenharmony_ciand the post_suite method can refer to it when dumping the "skipped"
488c2ecf20Sopenharmony_ciTAP output.  The tdc.py script will do that for the test suite as
498c2ecf20Sopenharmony_cidefined in the test case, but if the plugin is being used to run extra
508c2ecf20Sopenharmony_citests on each test (eg, check for memory leaks on associated
518c2ecf20Sopenharmony_cico-processes) then that other tap output can be generated in the
528c2ecf20Sopenharmony_cipost-suite method using this info passed in to the pre_suite method.
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciSKIPPING
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciThe post_suite method will receive the ordinal number of the last
588c2ecf20Sopenharmony_citest to be attempted.  It can use this info when outputting
598c2ecf20Sopenharmony_cithe TAP output for the extra test cases.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciPRE_CASE
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciThe pre_case method will receive the ordinal number of the test
658c2ecf20Sopenharmony_ciand the test id.  Useful for outputing the extra test results.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciADJUST
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciThe adjust_command method receives a string representing
718c2ecf20Sopenharmony_cithe execution stage and a string which is the actual command to be
728c2ecf20Sopenharmony_ciexecuted.  The plugin can adjust the command, based on the stage of
738c2ecf20Sopenharmony_ciexecution.
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciThe stages are represented by the following strings:
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci    'pre'
788c2ecf20Sopenharmony_ci    'setup'
798c2ecf20Sopenharmony_ci    'command'
808c2ecf20Sopenharmony_ci    'verify'
818c2ecf20Sopenharmony_ci    'teardown'
828c2ecf20Sopenharmony_ci    'post'
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciThe adjust_command method must return the adjusted command so tdc
858c2ecf20Sopenharmony_cican use it.
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciADD_ARGS
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciThe add_args method receives the argparser object and can add
918c2ecf20Sopenharmony_ciarguments to it.  Care should be taken that the new arguments do not
928c2ecf20Sopenharmony_ciconflict with any from tdc.py or from other plugins that will be used
938c2ecf20Sopenharmony_ciconcurrently.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciThe add_args method should return the argparser object.
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ciCHECK_ARGS
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ciThe check_args method is so that the plugin can do validation on
1018c2ecf20Sopenharmony_cithe args, if needed.  If there is a problem, and Exception should
1028c2ecf20Sopenharmony_cibe raised, with a string that explains the problem.
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cieg:  raise Exception('plugin xxx, arg -y is wrong, fix it')
105