📄 tests.py
字号:
mpdtest = MPDTest() if not os.access("%s/test/mpi/spawn/spawnintra" % (MPI_srcdir),os.R_OK): os.system("cd %s/test/util ; make" % (MPI_srcdir) ) os.system("cd %s/test/mpi/spawn ; make spawnintra" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) os.system('cp %s/test/mpi/spawn/spawnintra .' % (MPI_srcdir)) expout = ['No Errors'] rv = mpdtest.run(cmd="mpiexec%s -n 1 ./spawnintra" % (PYEXT), # -n 2 grepOut=1, expOut=expout ) os.system('rm -f spawnintra') os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) if testsToRun[2006]: print "TEST namepub" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/test/mpi/spawn/namepub" % (MPI_srcdir),os.R_OK): os.system("cd %s/test/util ; make" % (MPI_srcdir) ) os.system("cd %s/test/mpi/spawn ; make namepub" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) expout = ['No Errors'] os.system('cp %s/test/mpi/spawn/namepub .' % (MPI_srcdir)) rv = mpdtest.run(cmd="mpiexec%s -n 1 ./namepub" % (PYEXT), # -n 2 grepOut=1, expOut=expout ) os.system('rm -f namepub') os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) if testsToRun[2007]: print "TEST concurrent_spawns" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/test/mpi/spawn/concurrent_spawns" % (MPI_srcdir),os.R_OK): os.system("cd %s/test/util ; make" % (MPI_srcdir) ) os.system("cd %s/test/mpi/spawn ; make concurrent_spawns" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) expout = ['No Errors'] os.system('cp %s/test/mpi/spawn/concurrent_spawns .' % (MPI_srcdir)) rv = mpdtest.run(cmd="mpiexec%s -n 1 ./concurrent_spawns" % (PYEXT), # -n 2 grepOut=1, expOut=expout ) os.system('rm -f concurrent_spawns') os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) )if testsToRun[2008]: print "TEST singleton init (cpi)" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/examples/cpi" % (MPI_srcdir),os.R_OK): os.system("cd %s/examples ; make cpi" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) expout = ['Process 0 of 1','pi is approximately 3'] rv = mpdtest.run(cmd="%s/examples/cpi" % (MPI_srcdir), grepOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) )if testsToRun[2009]: print "TEST bnr (mpich1-compat using cpi)" if not MPI_1_dir: print " skipping; no mpich1 dir specified" else: NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/examples/cpi" % (MPI_srcdir),os.R_OK): os.system("cd %s/examples ; make cpi" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) expout = ['Process 0 on','Process 1 on','Process 2 on','pi is approximately 3'] rv = mpdtest.run(cmd="mpiexec%s -bnr -n 3 %s/examples/cpi" % (PYEXT,MPI_1_dir), grepOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) )if 1 in testsToRun[3000:4000]: print "console pgm tests---------------------------------------------------"if testsToRun[3000]: print "TEST mpdtrace" NMPDS = 3 if NMPDS > len(clusterHosts)+1: print " skipping; too few hosts" else: mpdtest = MPDTest() os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) temph = open(HFILE,'w') for host in clusterHosts: print >>temph, host temph.close() os.system("mpdboot%s -f %s -n %d" % (PYEXT,HFILE,NMPDS) ) expout = ['%s' % (socket.gethostname()), '%s' % (clusterHosts[0]), '%s' % (clusterHosts[1])] rv = mpdtest.run(cmd="mpdtrace%s -l" % (PYEXT), grepOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.unlink(HFILE)if testsToRun[3001]: print "TEST mpdringtest" NMPDS = 3 if NMPDS > len(clusterHosts)+1: print " skipping; too few hosts" else: mpdtest = MPDTest() os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) temph = open(HFILE,'w') for host in clusterHosts: print >>temph, host temph.close() os.system("mpdboot%s -f %s -n %d" % (PYEXT,HFILE,NMPDS) ) nLoops = 100 expout = ['time for %d loops' % (nLoops) ] rv = mpdtest.run(cmd="mpdringtest%s %d" % (PYEXT,nLoops), grepOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.unlink(HFILE)if testsToRun[3002]: print "TEST mpdexit" NMPDS = 3 if NMPDS > len(clusterHosts)+1: print " skipping; too few hosts" else: mpdtest = MPDTest() os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) temph = open(HFILE,'w') for host in clusterHosts: print >>temph, host temph.close() os.system("mpdboot%s -f %s -n %d" % (PYEXT,HFILE,NMPDS) ) linesAsStr = commands.getoutput("mpdtrace%s -l" % (PYEXT) ) for line in linesAsStr.split('\n'): if line.find(clusterHosts[0]) >= 0: mpdid = line.split(' ')[0] # strip off the (ifhn) stuff break else: mpdid = '' if mpdid: rv = mpdtest.run(cmd="mpdexit%s %s" % (PYEXT,mpdid), chkOut=1 ) else: print 'failed to find %s in mpdtrace for mpdexit' % (clusterHosts[0]) sys.exit(-1) expout = ['%s' % (socket.gethostname()), '%s' % (clusterHosts[1])] rv = mpdtest.run(cmd="mpdtrace%s -l" % (PYEXT), grepOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.unlink(HFILE)if testsToRun[3003]: print "TEST mpdlistjobs and mpdkilljob" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/src/pm/mpd/infloop" % (MPI_srcdir),os.R_OK): os.system("cd %s/src/pm/mpd ; cc -o infloop infloop.c" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) if not os.access("./infloop",os.R_OK): os.system('cp %s/src/pm/mpd/infloop .' % (MPI_srcdir)) os.system("mpiexec%s -s all -a ralph -n 2 ./infloop -p &" % (PYEXT)) # -p => don't print import time ## give the mpiexec time.sleep(2) ## time to get going expout = ['ralph'] rv = mpdtest.run(cmd="mpdlistjobs%s" % (PYEXT), grepOut=1, expOut=expout ) rv = mpdtest.run(cmd="mpdkilljob%s -a ralph" % (PYEXT), chkOut=0 ) expout = '' rv = mpdtest.run(cmd="mpdlistjobs%s" % (PYEXT), chkOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("killall -q infloop") ## just to be safe os.system('rm -f infloop') if testsToRun[3004]: print "TEST mpdsigjob" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/src/pm/mpd/infloop" % (MPI_srcdir),os.R_OK): os.system("cd %s/src/pm/mpd ; cc -o infloop infloop.c" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) if not os.access("./infloop",os.R_OK): os.system('cp %s/src/pm/mpd/infloop .' % (MPI_srcdir)) os.system("mpiexec%s -s all -a ralph -n 2 ./infloop -p &" % (PYEXT)) # -p => don't print import time ## give the mpiexec time.sleep(2) ## time to get going expout = ['ralph'] rv = mpdtest.run(cmd="mpdlistjobs%s" % (PYEXT), grepOut=1, expOut=expout ) rv = mpdtest.run(cmd="mpdsigjob%s INT -a ralph -g" % (PYEXT), chkOut=0 ) expout = '' rv = mpdtest.run(cmd="mpdlistjobs%s" % (PYEXT), chkOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system('rm -f infloop') if 1 in testsToRun[8000:9000]: print "misc tests---------------------------------------------------"if testsToRun[8000]: print "TEST ^C to mpiexec" NMPDS = 1 mpdtest = MPDTest() if not os.access("%s/src/pm/mpd/infloop" % (MPI_srcdir),os.R_OK): os.system("cd %s/src/pm/mpd ; cc -o infloop infloop.c" % (MPI_srcdir) ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("mpdboot%s -n %d" % (PYEXT,NMPDS) ) if not os.access("./infloop",os.R_OK): os.system('cp %s/src/pm/mpd/infloop .' % (MPI_srcdir)) import popen2 runner = popen2.Popen4("mpiexec%s -n 2 ./infloop -p" % (PYEXT)) # -p => don't print import time ## give the mpiexec time.sleep(2) ## time to get going os.system("kill -INT %d" % (runner.pid) ) # simulate user ^C expout = '' rv = mpdtest.run(cmd="mpdlistjobs%s" % (PYEXT), chkOut=1, expOut=expout ) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) os.system("killall -q infloop") ## just to be safe os.system('rm -f infloop')if testsToRun[8001]: print "TEST re-knit a ring" NMPDS = 3 if NMPDS > len(clusterHosts)+1: print " skipping; too few hosts" else: mpdtest = MPDTest() os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) ) import popen2, time mpd1 = popen2.Popen4("mpd%s -l 12345" % (PYEXT)) time.sleep(2) mpd2 = popen2.Popen4("mpd%s -n -h %s -p 12345" % (PYEXT,socket.gethostname()) ) mpd3 = popen2.Popen4("mpd%s -n -h %s -p 12345" % (PYEXT,socket.gethostname()) ) time.sleep(2) rv = mpdtest.run(cmd="mpdtrace%s" % (PYEXT), chkOut=0 ) if len(rv['OUT']) != NMPDS: print "a: unexpected number of lines of output from mpdtrace", rv['OUT'] sys.exit(-1) hostname = socket.gethostname() for line in rv['OUT']: if line.find(hostname) < 0: print "a: bad lines in output of mpdtrace", rv['OUT'] sys.exit(-1) os.system("kill -9 %d" % (mpd3.pid) ) time.sleep(1) rv = mpdtest.run(cmd="mpdtrace%s" % (PYEXT), chkOut=0 ) if len(rv['OUT']) != NMPDS-1: print "b: unexpected number of lines of output from mpdtrace", rv['OUT'] sys.exit(-1) hostname = socket.gethostname() for line in rv['OUT']: if line.find(hostname) < 0: print "b: bad lines in output of mpdtrace", rv['OUT'] sys.exit(-1) os.system("mpdallexit%s 1> /dev/null 2> /dev/null" % (PYEXT) )if testsToRun[8002]: print "TEST installing mpd as user" if not os.access("%s/src/pm/mpd/mpdroot" % (MPI_srcdir),os.X_OK): os.system("cd %s/src/pm/mpd ; ./configure ; make") os.system("cd %s/src/pm/mpd ; make prefix=%s install" % (MPI_srcdir,USER_INSTALL_DIR) ) print "TEST the mpd installed as user ; run mpdtrace as user" NMPDS = 1 mpdtest = MPDTest() os.system("%s/bin/mpdallexit%s 1> /dev/null 2> /dev/null" % (USER_INSTALL_DIR,PYEXT) ) os.system("%s/bin/mpdboot%s -n %d" % (USER_INSTALL_DIR,PYEXT,NMPDS) ) expout = ['%s' % (socket.gethostname())] rv = mpdtest.run(cmd="%s/bin/mpdtrace%s -l" % (USER_INSTALL_DIR,PYEXT), grepOut=1, expOut=expout ) os.system("%s/bin/mpdallexit%s 1> /dev/null 2> /dev/null" % (USER_INSTALL_DIR,PYEXT) )if 1 in testsToRun[9000:10000]: print "root tests---------------------------------------------------" import popen2 runner = popen2.Popen4("sudo echo hello") sout_serr = runner.fromchild line = sout_serr.readline() if line.find('hello') < 0: print " ** you do not have sudo capability; terminating\n" sys.exit(-1)if testsToRun[9000]: os.environ['MPD_CON_EXT'] = "" # get rid of this for root testing print "TEST installing mpd as root" if not os.access("%s/src/pm/mpd/mpdroot" % (MPI_srcdir),os.X_OK): os.system("cd %s/src/pm/mpd ; ./configure ; make") os.system("cd %s/src/pm/mpd ; sudo make prefix=%s install" % (MPI_srcdir,ROOT_INSTALL_DIR) ) print "TEST mpd as root ; mpdtrace as user" NMPDS = 1 mpdtest = MPDTest() os.system("sudo %s/bin/mpdallexit%s 1> /dev/null 2> /dev/null" % (ROOT_INSTALL_DIR,PYEXT) ) os.system("sudo %s/bin/mpd%s -d" % (ROOT_INSTALL_DIR,PYEXT) ) # not using boot here import time time.sleep(2) os.environ['MPD_USE_ROOT_MPD'] = '1' # os.system("%s/bin/mpdtrace%s -l" % (ROOT_INSTALL_DIR,PYEXT)) expout = ['%s' % (socket.gethostname())] rv = mpdtest.run(cmd="%s/bin/mpdtrace%s -l" % (ROOT_INSTALL_DIR,PYEXT), grepOut=1, expOut=expout ) print "TEST that user cannot remove files owned by root" os.system("sudo touch /tmp/testroot") expout = ['cannot remove'] rv = mpdtest.run(cmd="%s/bin/mpiexec%s -n 1 /bin/rm -f /tmp/testroot" % (ROOT_INSTALL_DIR,PYEXT), grepOut=1, expOut=expout ) os.system("sudo rm -f /tmp/testroot") os.system("sudo %s/bin/mpdallexit%s 1> /dev/null 2> /dev/null" % (ROOT_INSTALL_DIR,PYEXT) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -