diff options
-rw-r--r-- | test/suite/run.py | 2 | ||||
-rw-r--r-- | test/suite/test_base03.py | 28 | ||||
-rw-r--r-- | test/suite/wtscenario.py | 96 |
3 files changed, 117 insertions, 9 deletions
diff --git a/test/suite/run.py b/test/suite/run.py index a8a2927d6b4..4ccdbfe5d17 100644 --- a/test/suite/run.py +++ b/test/suite/run.py @@ -69,7 +69,7 @@ if len(sys.argv) < 2: # Use the backport of Python 2.7+ unittest discover module. # (Under a BSD license, so we include a copy in our tree for simplicity.) from discover import defaultTestLoader as loader - tests.addTests(loader.discover(suitedir)) + tests.addTests(generate_scenarios(loader.discover(suitedir))) # Otherwise, turn numbers and ranges into test module names preserve = False diff --git a/test/suite/test_base03.py b/test/suite/test_base03.py index 3b2c755fcb8..f2902bdede2 100644 --- a/test/suite/test_base03.py +++ b/test/suite/test_base03.py @@ -12,6 +12,7 @@ import unittest import wiredtiger import wttest +import wtscenario class test_base03(wttest.WiredTigerTestCase): """ @@ -23,16 +24,24 @@ class test_base03(wttest.WiredTigerTestCase): table_name4 = 'test_base03d' nentries = 10 - def create_table(self, tablename): - extra_params = ',intl_node_min=512,intl_node_max=16384,leaf_node_min=131072,leaf_node_max=131072' - self.pr('create_table') - self.session.create(tablename, 'key_format=S,value_format=S' + extra_params) + scenarios = wtscenario.wtscenario.session_create_scenario() + + def session_create(self, name, args): + """ + session.create, but report errors more completely + """ + try: + self.session.create(name, args) + except: + print('**** ERROR in session.create("' + name + '","' + args + '") ***** ') + raise def test_table_ss(self): """ Create entries, and read back in a cursor: key=string, value=string """ - self.session.create("table:" + self.table_name1, 'key_format=S,value_format=S') + create_args = 'key_format=S,value_format=S' + self.session_create_scenario.configString() + self.session_create("table:" + self.table_name1, create_args) self.pr('creating cursor') cursor = self.session.open_cursor('table:' + self.table_name1, None, None) for i in range(0, self.nentries): @@ -53,7 +62,8 @@ class test_base03(wttest.WiredTigerTestCase): """ Create entries, and read back in a cursor: key=string, value=int """ - self.session.create("table:" + self.table_name2, 'key_format=S,value_format=i') + create_args = 'key_format=S,value_format=i' + self.session_create_scenario.configString() + self.session_create("table:" + self.table_name2, create_args) self.pr('creating cursor') cursor = self.session.open_cursor('table:' + self.table_name2, None, None) for i in range(0, self.nentries): @@ -77,7 +87,8 @@ class test_base03(wttest.WiredTigerTestCase): """ Create entries, and read back in a cursor: key=int, value=string """ - self.session.create("table:" + self.table_name3, 'key_format=i,value_format=S') + create_args = 'key_format=i,value_format=S' + self.session_create_scenario.configString() + self.session_create("table:" + self.table_name3, create_args) self.pr('creating cursor') cursor = self.session.open_cursor('table:' + self.table_name3, None, None) for i in range(0, self.nentries): @@ -99,7 +110,8 @@ class test_base03(wttest.WiredTigerTestCase): """ Create entries, and read back in a cursor: key=int, value=int """ - self.session.create("table:" + self.table_name4, 'key_format=i,value_format=i') + create_args = 'key_format=i,value_format=i' + self.session_create_scenario.configString() + self.session_create("table:" + self.table_name4, create_args) self.pr('creating cursor') cursor = self.session.open_cursor('table:' + self.table_name4, None, None) self.pr('stepping') diff --git a/test/suite/wtscenario.py b/test/suite/wtscenario.py new file mode 100644 index 00000000000..0240d766c32 --- /dev/null +++ b/test/suite/wtscenario.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +# +# See the file LICENSE for redistribution information. +# +# Copyright (c) 2011 WiredTiger, Inc. +# All rights reserved. +# +# wtscenarios.py +# Support scenarios based testing +# + +import testscenarios + +def powerrange(start, stop, mult): + """ + Like xrange, generates a range from start to stop. + Unlike xrange, the range is inclusive of stop, + each step is multiplicative, and as a special case, + the stop value is returned as the last item. + """ + val = start + while val <= stop: + yield val + newval = val * mult + if val < stop and newval > stop: + val = stop + else: + val = newval + +def log2chr(val): + """ + For the log-base 2 of val, return the numeral or letter + corresponding to val (which is < 36). Hence, 1 return '0', + 2 return '1', 2*15 returns 'f', 2*16 returns 'g', etc. + """ + p = 0 + while val >= 2: + p += 1 + val /= 2 + if p < 10: + return chr(ord('0') + p) + else: + return chr(ord('a') + p - 10) + +megabyte = 1024 * 1024 + +class wtscenario: + """ + A set of generators for different test scenarios + """ + + @staticmethod + def session_create_scenario(): + """ + Return a set of scenarios with the name of this method + 'session_create_scenario' as the name of instance + variable containing a wtscenario object. The wtscenario + object can be queried to get a config string. + Each scenario is named according to the shortName() method. + """ + s = [ + ('default', dict(session_create_scenario=wtscenario())) ] + for imin in powerrange(512, 512*megabyte, 1024): + for imax in powerrange(imin, 512*megabyte, 1024): + for lmin in powerrange(512, 512*megabyte, 1024): + for lmax in powerrange(lmin, 512*megabyte, 1024): + scen = wtscenario() + scen.imin = imin + scen.imax = imax + scen.lmin = lmin + scen.lmax = lmax + s.append((scen.shortName(), dict(session_create_scenario=scen))) + return s + + def shortName(self): + """ + Return a name of a scenario, based on the 'log2chr-ed numerals' + representing the four values for {internal,leaf} {minimum, maximum} + page size. + """ + return 'scen_' + log2chr(self.imin) + log2chr(self.imax) + log2chr(self.lmin) + log2chr(self.lmax) + + def configString(self): + """ + Return the associated configuration string + """ + res = '' + if hasattr(self, 'imin'): + res += ',internal_node_min=' + str(self.imin) + if hasattr(self, 'imax'): + res += ',internal_node_max=' + str(self.imax) + if hasattr(self, 'lmin'): + res += ',leaf_node_min=' + str(self.lmin) + if hasattr(self, 'lmax'): + res += ',leaf_node_max=' + str(self.lmax) + return res |