The Assimilation Project  based on Assimilation version 1.1.7.1474836767
zexternal_test.py
Go to the documentation of this file.
1 # vim: smartindent tabstop=4 shiftwidth=4 expandtab colorcolumn=80
2 #
3 # This file is part of the Assimilation Project.
4 #
5 # Copyright (C) 2011, 2012 - Alan Robertson <alanr@unix.sh>
6 #
7 # The Assimilation software is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # The Assimilation software 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.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with the Assimilation Project software.
19 # If not, see http://www.gnu.org/licenses/
20 #
21 #
22 _suites = ['all', 'external']
23 import sys, os, subprocess, time, datetime, re
24 
25 
26 pingcount=30
27 
28 placestolook = ('.', '..', 'testcode', '../testcode', '../../testcode'
29 , '../bin/testcode', '../../bin/testcode', 'src/testcode', '../src/testcode'
30 , 'root_of_binary_tree/testcode', '../root_of_binary_tree/testcode'
31 , '../../root_of_binary_tree/testcode'
32 , 'cma', '../cma', '../../cma', 'src/cma','../src/cma', '../../src/cma')
33 
34 def findcmd(argv):
35  arg0 = argv[0]
36  if arg0.startswith('/'):
37  return argv
38  for prefix in placestolook:
39  fullpath = os.path.join(prefix, arg0)
40  if os.access(fullpath, os.X_OK):
41  argv[0] = fullpath
42  return argv
43  raise IOError('Cannot locate file %s' % arg0)
44 
45 
46 sudocmd = '/usr/bin/sudo'
47 gtestdir = None
48 class TestExternal(object):
49  '''
50  Run all the tests that don't run natively under testify
51  '''
52  gtestdir = None
53  gtestpattern = re.compile('gtest[0-9]+$') # pattern of names of our gtests
54 
55  def setup_class(self):
56  '''This function is designed to Fail right away and make sure the other
57  tests don't bother running if we can't find an example test.
58  Turns out to be handy to know where that command is anyway...
59  '''
60  cmd=['gtest01',]
61  findcmd(cmd)
62  TestExternal.gtestdir = os.path.dirname(cmd[0])
63 
64 
65 
66  def runacommand(self, argv, sudo=False):
67  print '\n******RUNNING TEST COMMAND %s' % str(argv)
68  findcmd(argv)
69  if sudo and os.geteuid() != 0:
70  argv.insert(0, sudocmd)
71  print 'ARGV: %s' % str(argv)
72  start = datetime.datetime.now()
73  subprocess.check_call(argv) # Will raise exception if non-zero exit
74  end = datetime.datetime.now()
75  diff = end - start
76  print '\nSUCCESS: %s exited with return code 0 in %s' % (str(argv), diff)
77  pass
78 
79  def test_valgrind(self):
80  self.runacommand(['grind.sh',], sudo=True)
81 
82  def test_gtest_cases(self):
83  files = os.listdir(TestExternal.gtestdir)
84  files.sort()
85  for f in files:
86  if TestExternal.gtestpattern.match(f):
87  self.runacommand([f,], sudo=True)
88 
89  def test_pinger(self):
90  self.runacommand(['grindping.sh',],sudo=False)
91 
93  self.runacommand(['test_discovery.sh',],sudo=False)
94 
96  MODULES = ('bestpractices.py', 'cmaconfig.py', 'cmainit.py',
97  'cmadb.py', 'graphnodes.py', 'graphnodeexpression.py',
98  'monitoring.py', 'query.py',
99  'store.py', 'transaction.py',
100  'systemtests/logwatcher.py')
101  for mod in MODULES:
102  modpath = findcmd([mod,])
103  self.runacommand(['/usr/bin/env', 'python', modpath[0]], False)
104 
105 
106 if __name__ == "__main__":
107  run()
def runacommand(self, argv, sudo=False)