1import os
2from autotest_lib.client.bin import test, utils
3
4
5# Dbt-2 is a fair-use implementation of the TPC-C benchmark.  The test is
6# currently hardcoded to use PostgreSQL but the kit also supports MySQL.
7
8class dbt2(test.test):
9    version = 2
10
11    def initialize(self):
12        self.job.require_gcc()
13
14
15    # http://osdn.dl.sourceforge.net/sourceforge/osdldbt/dbt2-0.39.tar.gz
16    def setup(self, tarball = 'dbt2-0.39.tar.bz2'):
17        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
18        utils.extract_tarball_to_dir(tarball, self.srcdir)
19        self.job.setup_dep(['pgsql', 'pgpool', 'mysql'])
20
21        #
22        # Extract one copy of the kit for MySQL.
23        #
24        utils.system('cp -pR ' + self.srcdir + ' ' + self.srcdir + '.mysql')
25        os.chdir(self.srcdir + '.mysql')
26        utils.configure('--with-mysql=%s/deps/mysql/mysql' % self.autodir)
27        utils.make()
28
29        #
30        # Extract one copy of the kit for PostgreSQL.
31        #
32        utils.system('cp -pR ' + self.srcdir + ' ' + self.srcdir + '.pgsql')
33        os.chdir(self.srcdir + '.pgsql')
34        utils.configure('--with-postgresql=%s/deps/pgsql/pgsql' % self.autodir)
35        utils.make()
36
37        # Create symlinks to autotest's results directory from dbt-2's
38        # preferred results directory to self.resultsdir
39        utils.system('ln -s %s %s' %
40                     (self.resultsdir, self.srcdir + '.mysql/scripts/output'))
41        utils.system('ln -s %s %s' %
42                     (self.resultsdir, self.srcdir + '.pgsql/scripts/output'))
43
44
45    def execute(self, db_type, args = ''):
46        logfile = self.resultsdir + '/dbt2.log'
47
48        if (db_type == "mysql"):
49            self.execute_mysql(args)
50        elif (db_type == "pgpool"):
51            self.execute_pgpool(args)
52        elif (db_type == "pgsql"):
53            self.execute_pgsql(args)
54
55
56    def execute_mysql(self, args = ''):
57        args = args
58        utils.system(self.srcdir + '.mysql/scripts/mysql/build_db.sh -g -w 1')
59        utils.system(self.srcdir + '.mysql/scripts/run_workload.sh ' + args)
60
61
62    def execute_pgpool(self, args = ''):
63        utils.system('%s/deps/pgpool/pgpool/bin/pgpool -f %s/../pgpool.conf' \
64                        % (self.autodir, self.srcdir))
65        self.execute_pgsql(args)
66        utils.system('%s/deps/pgpool/pgpool/bin/pgpool stop' % self.autodir)
67
68
69    def execute_pgsql(self, args = ''):
70        utils.system(self.srcdir + '.pgsql/scripts/pgsql/build_db.sh -g -w 1')
71        utils.system(self.srcdir + '.pgsql/scripts/run_workload.sh ' + args)
72        #
73        # Clean up by dropping the database after the test.
74        #
75        utils.system(self.srcdir + '.pgsql/scripts/pgsql/start_db.sh')
76        utils.system(self.srcdir + '.pgsql/scripts/pgsql/drop_db.sh')
77        utils.system(self.srcdir + '.pgsql/scripts/pgsql/stop_db.sh')
78