2011-10-21 21:07:00 +00:00
|
|
|
#!/usr/bin/env python
|
2011-10-21 21:09:41 +00:00
|
|
|
#
|
|
|
|
# Copyright(C) 2011 Simon Howard
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
# 02111-1307, USA.
|
|
|
|
#
|
2011-10-21 21:07:00 +00:00
|
|
|
|
2011-10-22 00:48:13 +00:00
|
|
|
# statchecker regression testing script.
|
|
|
|
#
|
|
|
|
# This script examines the zip files in the Compet-N tree, extracts
|
|
|
|
# the demos and plays them back using the configured source port.
|
|
|
|
# Statistics information is logged to a file using the -statdump
|
|
|
|
# parameter and the output is compared with the reference version
|
|
|
|
# for Vanilla Doom. A summary is outputted of the demos that pass
|
|
|
|
# or fail this test.
|
|
|
|
|
2019-05-16 02:09:58 +00:00
|
|
|
from __future__ import division, absolute_import
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2011-10-21 21:07:00 +00:00
|
|
|
import os
|
2015-06-13 03:12:28 +00:00
|
|
|
import re
|
2011-10-21 21:07:00 +00:00
|
|
|
import sys
|
2019-05-16 01:47:22 +00:00
|
|
|
import tempfile
|
|
|
|
|
2011-10-21 21:07:00 +00:00
|
|
|
from common import *
|
|
|
|
from config import *
|
|
|
|
|
2015-06-13 03:12:28 +00:00
|
|
|
EXCEPTIONS_PARSE_RE = re.compile(r'(\S+)\s+(\S+)')
|
|
|
|
|
2011-10-21 21:07:00 +00:00
|
|
|
GREEN = '\033[92m'
|
|
|
|
RED = '\033[91m'
|
|
|
|
COLOR_END = '\033[0m'
|
|
|
|
|
2015-06-13 03:12:28 +00:00
|
|
|
def read_exceptions(filename):
|
|
|
|
"""Read exceptions config file."""
|
|
|
|
with open(filename) as f:
|
|
|
|
result = {}
|
|
|
|
for line in f:
|
|
|
|
if line.strip().startswith("#"):
|
|
|
|
continue
|
|
|
|
match = EXCEPTIONS_PARSE_RE.match(line)
|
|
|
|
if match:
|
|
|
|
result[match.group(1)] = match.group(2)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2011-10-21 21:07:00 +00:00
|
|
|
def read_file(filename):
|
|
|
|
result = []
|
|
|
|
|
|
|
|
stream = open(filename)
|
|
|
|
lines = stream.readlines()
|
|
|
|
stream.close()
|
|
|
|
|
|
|
|
lines = map(lambda x: x.strip(), lines)
|
|
|
|
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
def check_output(output_filename, zipfile_path, lmpname):
|
2011-10-21 21:07:00 +00:00
|
|
|
expected_file = os.path.join("output", zipfile_path,
|
|
|
|
lmpname.lower().replace(".lmp", ".txt"))
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
output = read_file(output_filename)
|
2011-10-21 21:07:00 +00:00
|
|
|
expected = read_file(expected_file)
|
|
|
|
|
|
|
|
if output != expected:
|
2015-06-13 16:35:22 +00:00
|
|
|
os.system("diff --strip-trailing-cr -u %s %s" % (
|
|
|
|
expected_file, output_filename))
|
2011-10-21 21:07:00 +00:00
|
|
|
|
|
|
|
return output == expected
|
|
|
|
|
|
|
|
def print_result(zipfile_path, lmpname, success):
|
|
|
|
|
|
|
|
if success:
|
|
|
|
success_string = GREEN + " OK " + COLOR_END
|
|
|
|
else:
|
|
|
|
success_string = RED + "FAIL" + COLOR_END
|
|
|
|
|
2019-05-16 02:09:58 +00:00
|
|
|
print("%-50s%-15s%s" % (zipfile_path, lmpname, success_string))
|
2011-10-21 22:56:12 +00:00
|
|
|
sys.stdout.flush()
|
2011-10-21 21:07:00 +00:00
|
|
|
|
|
|
|
# Run the specified demo and check the output is correct.
|
|
|
|
|
2011-10-29 15:20:03 +00:00
|
|
|
def process_lmp(gametype, zipfile_path, zf, lmpname, pwad):
|
2011-10-25 20:46:53 +00:00
|
|
|
|
|
|
|
global output_counter
|
2011-10-21 21:07:00 +00:00
|
|
|
|
|
|
|
gamepath, exe = GAME_PATHS[gametype]
|
|
|
|
iwad = os.path.join(gamepath, "%s.wad" % gametype)
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
# Extract .lmp file. To avoid conflicts between concurrent
|
|
|
|
# tests, rename to a generated name.
|
2019-05-16 01:47:22 +00:00
|
|
|
lmpname2 = os.path.join(tempdir, "tst%i.lmp" % output_counter)
|
|
|
|
zf.extract(lmpname, path=tempdir)
|
|
|
|
os.rename(os.path.join(tempdir, lmpname), lmpname2)
|
2011-10-25 20:46:53 +00:00
|
|
|
|
2019-05-16 01:47:22 +00:00
|
|
|
output_filename = (
|
|
|
|
os.path.join(tempdir, "output-%i.txt" % output_counter))
|
2011-10-25 20:46:53 +00:00
|
|
|
output_counter += 1
|
2011-10-21 21:07:00 +00:00
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
cmd = "%s %s" % (PORT_EXE, PORT_OPTIONS)
|
|
|
|
cmd += " -iwad %s" % iwad
|
|
|
|
cmd += " -timedemo %s" % lmpname2
|
|
|
|
cmd += " -statdump %s" % output_filename
|
2011-10-21 21:07:00 +00:00
|
|
|
|
2011-10-29 18:17:35 +00:00
|
|
|
if pwad is not None:
|
|
|
|
cmd += " -file %s" % os.path.join(gamepath, pwad)
|
|
|
|
|
2015-06-13 03:12:28 +00:00
|
|
|
zipfile_relpath = os.path.relpath(zipfile_path, COMPETN_PATH)
|
|
|
|
if zipfile_relpath in exceptions:
|
|
|
|
cmd += " -gameversion %s" % exceptions[zipfile_relpath]
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
def process_complete(exit_code, stdout, stderr):
|
|
|
|
global passed, failed
|
2011-10-21 21:07:00 +00:00
|
|
|
|
|
|
|
relpath = os.path.relpath(zipfile_path, COMPETN_PATH)
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
success = check_output(output_filename, relpath, lmpname)
|
2011-10-21 21:07:00 +00:00
|
|
|
|
|
|
|
print_result(relpath, lmpname, success)
|
2011-10-21 21:16:54 +00:00
|
|
|
|
|
|
|
if success:
|
|
|
|
passed += 1
|
|
|
|
else:
|
|
|
|
failed += 1
|
2011-10-21 21:07:00 +00:00
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
os.remove(lmpname2)
|
|
|
|
os.remove(output_filename)
|
|
|
|
|
|
|
|
pipeline.call(cmd, process_complete)
|
|
|
|
|
2011-10-29 16:07:08 +00:00
|
|
|
# Use SDL's dummy video driver that does not open a window:
|
|
|
|
os.putenv("SDL_VIDEODRIVER", "dummy")
|
|
|
|
|
2019-05-16 01:47:22 +00:00
|
|
|
tempdir = tempfile.mkdtemp()
|
2011-10-25 20:46:53 +00:00
|
|
|
output_counter = 0
|
2011-10-21 21:16:54 +00:00
|
|
|
passed, failed = 0, 0
|
2015-06-13 03:12:28 +00:00
|
|
|
exceptions = read_exceptions("exceptions.cfg")
|
2011-10-25 20:46:53 +00:00
|
|
|
pipeline = CommandPipeline(CONCURRENT_PROCESSES)
|
2011-10-21 21:16:54 +00:00
|
|
|
|
2011-10-21 21:07:00 +00:00
|
|
|
process_all_zips(COMPETN_PATH, process_lmp)
|
|
|
|
|
2011-10-25 20:46:53 +00:00
|
|
|
pipeline.finish()
|
|
|
|
|
2019-05-16 02:09:58 +00:00
|
|
|
print("%i demo(s) passed, %i demo(s) failed." % (passed, failed))
|
2011-10-21 21:16:54 +00:00
|
|
|
|