@@ -94,6 +94,27 @@ def get_json_repr(self):
9494 def save (self , infolder ):
9595 text = json .dumps (self .get_json_repr (), indent = 2 )
9696 f = open (join (infolder , self .get_display_name ()) + ".json" , 'w' ).write (text )
97+ def load (self ,testnb = 0 ):
98+ jsonfile = os .path .join (os .path .dirname (self .localfile ),self .get_display_name ()+ '.json' )
99+ f = open (jsonfile , "r" , encoding = "utf-8" )
100+ obj = json .load (f )
101+ # # Populate test
102+ self .displayname = obj ['displayname' ]
103+ self .sourcefile = obj ['sourcefile' ]
104+ self .localfile = obj ['localfile' ]
105+ self .instrname = obj ['instrname' ]
106+ self .testnb = obj ['testnb' ]
107+ self .parvals = obj ['parvals' ]
108+ self .detector = obj ['detector' ]
109+ self .targetval = obj ['targetval' ]
110+ self .testval = obj ['testval' ]
111+ self .linted = obj ['linted' ]
112+ self .compiled = obj ['compiled' ]
113+ self .compiletime = obj ['compiletime' ]
114+ self .didrun = obj ['didrun' ]
115+ self .runtime = obj ['runtime' ]
116+ self .errmsg = obj ['errmsg' ]
117+
97118 def get_display_name (self ):
98119 if self .testnb > 1 :
99120 return self .instrname + "_%d" % self .testnb
@@ -172,6 +193,7 @@ def extract_testvals(datafolder, monitorname):
172193
173194def mccode_test (branchdir , testdir , limitinstrs = None , instrfilter = None , compfilter = None , version = None ):
174195 ''' this main test function tests the given mccode branch/version '''
196+ skipped = False
175197 global runLocal
176198 # copy instr files and record info
177199 if not runLocal :
@@ -202,17 +224,14 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, compfilt
202224 # copy the test folder for this instrument
203225 instrname = splitext (basename (f ))[0 ]
204226 instrdir = join (testdir , instrname )
205-
227+
228+ # Read instr file content to look for tests
229+ text = open (f , encoding = 'utf-8' ).read ()
230+ f_new = join (instrdir ,os .path .basename (f ))
231+ # create a test object for every test defined in the instrument header
232+ instrtests = create_instr_test_objs (sourcefile = f , localfile = f_new , header = text )
206233 try :
207234 shutil .copytree (os .path .dirname (f ),instrdir )
208-
209- f_new = join (instrdir ,os .path .basename (f ))
210-
211- # Read instr file content to look for tests
212- text = open (f , encoding = 'utf-8' ).read ()
213-
214- # create a test object for every test defined in the instrument header
215- instrtests = create_instr_test_objs (sourcefile = f , localfile = f_new , header = text )
216235 tests = tests + instrtests
217236
218237 # extract and record %Example info from text
@@ -228,6 +247,13 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, compfilt
228247 logging .debug (formatstr % instrname )
229248 except :
230249 print ("\n WARNING: Skipped " + instrname + " test - did " + instrdir + " exist already??\n " )
250+ skipped = True
251+ populated = []
252+ for t in instrtests :
253+ if t .testnb >= 0 :
254+ t .load (t .testnb )
255+ populated .append (t )
256+ tests = tests + populated
231257 pass
232258
233259
@@ -297,8 +323,10 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, compfilt
297323 f .close ()
298324 else :
299325 logging .info ("Skipping compile of " + test .instrname )
326+ skipped = True
300327 # save (incomplete) test results to disk
301- test .save (infolder = join (testdir , test .instrname ))
328+ if not skipped :
329+ test .save (infolder = join (testdir , test .instrname ))
302330
303331 # run, record time
304332 logging .info ("" )
@@ -324,27 +352,36 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, compfilt
324352 # run the test, record time and runtime success/fail
325353 t1 = time .time ()
326354 cmd = mccode_config .configuration ["MCRUN" ]
327- if nexus :
328- cmd = cmd + " --format=NeXus "
329- if mpi is not None :
330- if openacc is True :
331- if version :
332- cmd = cmd + " --override-config=" + join (os .path .dirname (__file__ ), mccode_config .configuration ["MCCODE" ] + "-test" ,version )
333- cmd = cmd + " -s 1000 %s %s -n%s --openacc --mpi=%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , mpi , test .testnb , test .testnb )
355+
356+ suffix = ""
357+ # Did test run already?
358+ if not os .path .exists (join (testdir , test .instrname , str (test .testnb ))):
359+ if nexus :
360+ cmd = cmd + " --format=NeXus "
361+ if mpi is not None :
362+ if openacc is True :
363+ if version :
364+ cmd = cmd + " --override-config=" + join (os .path .dirname (__file__ ), mccode_config .configuration ["MCCODE" ] + "-test" ,version )
365+ cmd = cmd + " -s 1000 %s %s -n%s --openacc --mpi=%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , mpi , test .testnb , test .testnb )
366+ else :
367+ if version :
368+ cmd = cmd + " --override-config=" + join (os .path .dirname (__file__ ), mccode_config .configuration ["MCCODE" ] + "-test" ,version )
369+ cmd = cmd + " -s 1000 %s %s -n%s --mpi=%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , mpi , test .testnb , test .testnb )
334370 else :
335371 if version :
336372 cmd = cmd + " --override-config=" + join (os .path .dirname (__file__ ), mccode_config .configuration ["MCCODE" ] + "-test" ,version )
337- cmd = cmd + " -s 1000 %s %s -n%s --mpi=%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , mpi , test .testnb , test .testnb )
373+ cmd = cmd + " -s 1000 %s %s -n%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , test .testnb , test .testnb )
374+
375+ retcode = utils .run_subtool_noread (cmd , cwd = join (testdir , test .instrname ),timeout = runmax )
376+ t2 = time .time ()
377+ didwrite = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.sim" ))
378+ didwrite_nexus = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.h5" ))
379+ test .didrun = retcode != 0 or didwrite or didwrite_nexus
380+ test .runtime = t2 - t1
338381 else :
339- if version :
340- cmd = cmd + " --override-config=" + join (os .path .dirname (__file__ ), mccode_config .configuration ["MCCODE" ] + "-test" ,version )
341- cmd = cmd + " -s 1000 %s %s -n%s -d%d > run_stdout_%d.txt 2>&1" % (test .instrname , test .parvals , ncount , test .testnb , test .testnb )
342- retcode = utils .run_subtool_noread (cmd , cwd = join (testdir , test .instrname ),timeout = runmax )
343- t2 = time .time ()
344- didwrite = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.sim" ))
345- didwrite_nexus = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.h5" ))
346- test .didrun = retcode != 0 or didwrite or didwrite_nexus
347- test .runtime = t2 - t1
382+ suffix = " (cached)"
383+ didwrite = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.sim" ))
384+ didwrite_nexus = os .path .exists (join (testdir , test .instrname , str (test .testnb ), "mccode.h5" ))
348385
349386 # log to terminal
350387 if not test .didrun :
@@ -377,13 +414,14 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, compfilt
377414 formatstr = "%-" + "%ds: " % (maxnamelen + 1 ) + \
378415 "{:3d}." .format (math .floor (test .runtime )) + str (test .runtime - int (test .runtime )).split ('.' )[1 ][:2 ]
379416 if test .targetval != 0 : # Normal situation, non-zero target value
380- logging .info (formatstr % test .get_display_name () + " [val: " + str (test .testval ) + " / " + str (test .targetval ) + " = " + str (round (100.0 * test .testval / test .targetval )) + " %]" )
417+ logging .info (formatstr % test .get_display_name () + " [val: " + str (test .testval ) + " / " + str (test .targetval ) + " = " + str (round (100.0 * test .testval / test .targetval )) + " %]" + suffix )
381418 else : # Special case, expected test target value is 0
382- logging .info (formatstr % test .get_display_name () + " [val: " + str (test .testval ) + " vs " + str (test .targetval ) + " (absolute vs 0) ]" )
419+ logging .info (formatstr % test .get_display_name () + " [val: " + str (test .testval ) + " vs " + str (test .targetval ) + " (absolute vs 0) ]" + suffix )
383420
384421 # save test result to disk
385422 test .testcomplete = True
386- test .save (infolder = join (testdir , test .instrname ))
423+ if not skipped :
424+ test .save (infolder = join (testdir , test .instrname ))
387425
388426 # cpu type: cat /proc/cpuinfo |grep name |uniq | cut -f2- -d:
389427 # gpu type: nvidia-smi -L | head -1 |cut -f2- -d: |cut -f1 -d\(
0 commit comments