2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2010 Patrick Crews
7
## This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
""" randgen_test_management:
22
code related to the gathering / analysis / management of
24
ie - collecting the list of tests in each suite, then
25
gathering additional, relevant information for randgen
26
mode. (stocastic model-based testing)
34
from ConfigParser import RawConfigParser
36
import lib.test_mgmt.test_management as test_management
41
"""Holds info on a single randgen test
44
def __init__( self, system_manager, name=None
45
, fullname = None, server_requirements=[[]]
46
, comment=None, test_command=None, debug=False ):
47
self.system_manager = system_manager
48
self.logging = self.system_manager.logging
49
self.skip_keys = ['system_manager','logging']
51
self.fullname = fullname
52
self.suitename = 'randgen_tests'
54
self.comment = comment
55
self.server_requirements = server_requirements
56
self.test_command = test_command
59
self.system_manager.logging.debug_class(self)
62
if self.skip_flag or self.disable:
71
class testManager(test_management.testManager):
72
"""Deals with scanning test directories, gathering test cases, and
73
collecting per-test information (opt files, etc) for use by the
78
def __init__(self, verbose, debug, default_engine, dotest, skiptest
79
, reorder, suitelist, suitepaths, system_manager
81
super(testManager, self).__init__( verbose, debug, default_engine
82
, dotest, skiptest, reorder
83
, suitelist, suitepaths
84
, system_manager, test_cases, mode)
85
self.suitepaths = [os.path.join(self.testdir,'randgen_tests')]
87
self.suitelist = ['main']
89
self.suitelist = suitelist
91
def process_suite(self,suite_dir):
92
"""Process a test suite.
93
Look for randgen tests, which are nice clean conf files
97
# We know this based on how we organize randgen test conf files
98
suite_name = os.path.basename(suite_dir)
100
self.system_manager.logging.verbose("Processing suite: %s" %(suite_name))
101
testlist = [os.path.join(suite_dir,test_file) for test_file in sorted(os.listdir(suite_dir)) if test_file.endswith('.cnf')]
103
# Search for specific test names
104
if self.desired_tests: # We have specific, named tests we want from the suite(s)
106
for test in self.desired_tests:
107
if test.endswith('.cnf'):
111
test = os.path.join(suite_dir,test)
113
tests_to_use.append(test)
114
testlist = tests_to_use
115
for test_case in testlist:
116
self.add_test(self.process_test_file(suite_name, test_case))
119
def process_test_file(self, suite_name, testfile):
120
""" We convert the info in a testfile into a testCase object """
122
config_reader = RawConfigParser()
123
config_reader.read(testfile)
124
# test_name = filename - .cnf...simpler
125
test_name = os.path.basename(testfile).replace('.cnf','')
126
test_comment = config_reader.get('test_info','comment')
127
server_requirements = self.process_server_reqs(config_reader.get('test_servers','servers'))
128
test_command = config_reader.get('test_command','command')
129
return testCase( self.system_manager
131
, fullname = "%s.%s" %(suite_name, test_name)
132
, server_requirements = server_requirements
133
, test_command = test_command
134
, debug = self.debug )
138
def process_server_reqs(self,data_string):
139
""" We read in the list of lists as a string, so we need to
140
handle this / break it down into proper chunks
144
# We expect to see a list of lists and throw away the
146
option_sets = data_string[1:-1].strip().split(',')
147
for option_set in option_sets:
148
server_reqs.append([option_set[1:-1].strip()])