Skip to content

Commit 32c9802

Browse files
committed
Hooks in test-system for linting (e.g. via cppcheck)
1 parent d54f415 commit 32c9802

2 files changed

Lines changed: 57 additions & 21 deletions

File tree

tools/Python/mctest/mctest.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ def __init__(self, sourcefile, localfile, parvals=None, detector=None, targetval
6464
self.targetval = targetval
6565
self.testval = None
6666

67+
self.linted = None
6768
self.compiled = None
6869
self.compiletime = None
6970
self.didrun = None
7071
self.runtime = None
7172
self.errmsg = None
73+
7274
def get_json_repr(self):
7375
return {
7476
"displayname" : self.get_display_name(),
@@ -82,6 +84,7 @@ def get_json_repr(self):
8284
"targetval" : self.targetval,
8385
"testval" : self.testval,
8486

87+
"linted" : self.linted,
8588
"compiled" : self.compiled,
8689
"compiletime" : self.compiletime,
8790
"didrun" : self.didrun,
@@ -219,34 +222,45 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, version=
219222

220223

221224
# compile, record time
222-
global ncount, mpi, openacc, suffix, nexus
225+
global ncount, mpi, openacc, suffix, nexus, lint
223226
logging.info("")
224-
logging.info("Compiling instruments [seconds]...")
227+
if not lint:
228+
logging.info("Compiling instruments [seconds]...")
229+
else:
230+
logging.info("c-lint'ing instruments [seconds]...")
231+
225232
for test in tests:
226233
# if binary exists, set compile time = 0 and continue
227234
binfile = os.path.splitext(test.localfile)[0] + "." + mccode_config.platform["EXESUFFIX"].lower()
228235
failed=os.path.splitext(test.localfile)[0] + ".failed"
236+
# if we linted, continue
237+
linted=os.path.splitext(test.localfile)[0] + ".linted"
229238
if os.path.exists(failed):
230239
test.compiled = False
231240
test.compiletime = -1
232241
elif os.path.exists(binfile):
233242
test.compiled = True
234243
test.compiletime = 0
244+
elif os.path.exists(linted):
245+
test.linted = True
235246
else:
236247
if test.testnb > 0 or (not args.skipnontest):
237248
log = LineLogger()
238249
t1 = time.time()
239250
cmd = mccode_config.configuration["MCRUN"]
240-
if nexus:
241-
cmd = cmd + " --format=NeXus "
242-
if version:
243-
cmd = cmd + " --override-config=" + join(os.path.dirname(__file__), mccode_config.configuration["MCCODE"] + "-test",version)
244-
if openacc:
245-
cmd = cmd + " --openacc "
246-
if mpi:
247-
cmd = cmd + " --mpi=1 "
251+
if lint:
252+
cmd = cmd + " --verbose -C %s > compile_stdout.txt 2>&1" % test.instrname
253+
else:
254+
if nexus:
255+
cmd = cmd + " --format=NeXus "
256+
if version:
257+
cmd = cmd + " --override-config=" + join(os.path.dirname(__file__), mccode_config.configuration["MCCODE"] + "-test",version)
258+
if openacc:
259+
cmd = cmd + " --openacc "
260+
if mpi:
261+
cmd = cmd + " --mpi=1 "
262+
cmd = cmd + " --verbose -c -n0 %s > compile_stdout.txt 2>&1" % test.instrname
248263

249-
cmd = cmd + " --verbose -c -n0 %s > compile_stdout.txt 2>&1" % test.instrname
250264
utils.run_subtool_noread(cmd, cwd=join(testdir, test.instrname))
251265
t2 = time.time()
252266
test.compiled = os.path.exists(binfile)
@@ -258,21 +272,33 @@ def mccode_test(branchdir, testdir, limitinstrs=None, instrfilter=None, version=
258272
"{:3d}.".format(math.floor(test.compiletime)) + str(test.compiletime-int(test.compiletime)).split('.')[1][:2]
259273
logging.info(formatstr % test.get_display_name())
260274
else:
261-
formatstr = "%-" + "%ds: COMPILE ERROR using:\n" % maxnamelen
262-
logging.info(formatstr % test.instrname + cmd)
263-
f = open(failed, "a")
264-
f.write(formatstr % test.instrname + cmd)
265-
f.close()
275+
if lint:
276+
formatstr = "%-" + "%ds: Linted using using:\n" % maxnamelen
277+
logging.info(formatstr % test.instrname + cmd)
278+
f = open(linted, "a")
279+
f.write(formatstr % test.instrname + cmd)
280+
f.close()
281+
test.linted = True
282+
else:
283+
formatstr = "%-" + "%ds: COMPILE ERROR using:\n" % maxnamelen
284+
logging.info(formatstr % test.instrname + cmd)
285+
f = open(failed, "a")
286+
f.write(formatstr % test.instrname + cmd)
287+
f.close()
266288
else:
267289
logging.info("Skipping compile of " + test.instrname)
268290
# save (incomplete) test results to disk
269291
test.save(infolder=join(testdir, test.instrname))
270292

271293
# run, record time
272294
logging.info("")
273-
logging.info("Running tests...")
295+
logging.info("Running tests / getting status...")
274296
for test in tests:
275-
if not test.compiled:
297+
if test.linted:
298+
formatstr = "%-" + "%ds: Linter only" % (maxnamelen+1)
299+
logging.info(formatstr % test.instrname)
300+
continue
301+
elif not test.compiled:
276302
formatstr = "%-" + "%ds: NO COMPILE" % (maxnamelen+1)
277303
logging.info(formatstr % test.instrname)
278304
continue
@@ -597,6 +623,7 @@ def print_to_console(str):
597623
openacc = None
598624
suffix = None
599625
nexus = None
626+
lint = None
600627

601628
def main(args):
602629
# mutually excusive main branches
@@ -659,7 +686,7 @@ def main(args):
659686
quit(1)
660687
logging.debug("")
661688

662-
global ncount, mpi, skipnontest, openacc, nexus
689+
global ncount, mpi, skipnontest, openacc, nexus, lint
663690
if args.ncount:
664691
ncount = args.ncount[0]
665692
elif args.n:
@@ -687,6 +714,10 @@ def main(args):
687714
nexus = True
688715
suffix = '_NeXus' + suffix
689716
logging.info("NeXus compilation / output format is enabled")
717+
if args.lint:
718+
lint = True
719+
suffix = '_lint' + suffix
720+
logging.info("c-linting enabled")
690721
# decide and run main branch
691722
if version and configs or version and vinfo or configs and vinfo:
692723
print("WARNING: version, --configs and --versions are mutually exclusive, exiting")
@@ -720,6 +751,7 @@ def main(args):
720751
parser.add_argument('--skipnontest', action='store_true', help='Skip compilation of instruments without a test')
721752
parser.add_argument('--suffix', nargs=1, help='Add suffix to test directory name, e.g. 3.x-dev_suffix')
722753
parser.add_argument('--nexus', action='store_true', help='Compile for / use NeXus output format everywhere')
754+
parser.add_argument('--lint', action='store_true', help='Just run the c-linter')
723755
args = parser.parse_args()
724756

725757
try:

tools/Python/mctest/mcviewtest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def get_cell_tuple(cellobj, refval=None):
7272
curl = label + "/" + cellobj["instrname"] + "/compile_stdout.txt"
7373

7474
if not cellobj["compiled"]:
75-
state = 4
76-
return (state, "<strong><font color=\"red\">! Compile error !</font></strong>", "", "", "", curl)
75+
if cellobj["linted"]:
76+
state = 4
77+
return (state, "<strong><font color=\"red\">Linted only</font></strong>", "", "", "", curl)
78+
else:
79+
state = 4
80+
return (state, "<strong><font color=\"red\">! Compile error !</font></strong>", "", "", "", curl)
7781
elif not cellobj["didrun"]:
7882
state = 3
7983
compiletime = "%.2f s" % cellobj["compiletime"]

0 commit comments

Comments
 (0)