git » libjio » next » tree

[next] / tests / util / quick-test-run

#!/usr/bin/env python

# This is a convenience script for running some of the other tests without
# manual intervention, as a means of a fast and easy correctness test.
#
# If you are making an intrusive or risky change, please take the time to run
# the other tests by hand with more intensive parameters, and check the
# coverage and use the other tools mentioned in the README.

import sys
import os
import subprocess
import random


# Go to our directory, which we will use to find the other tools
os.chdir(os.path.dirname(sys.argv[0]))

if len(sys.argv) != 2 or sys.argv[1] not in ("normal", "fiu"):
	sys.stderr.write("Usage: %s [normal|fiu]" %
				os.path.basename(sys.argv[0]))
	sys.exit(1)

def run_behaviour_tests(test_type):
	ret = subprocess.call(["./wrap-python", "2", "../behaviour/runtests",
				test_type])
	if ret != 0:
		sys.exit(ret)

def run_stress_tests(nops = 0, nprocs = 0, fi = False, fsize = 20):
	# Create a temporary path. We can't use os.tempnam() because it emits
	# a warning about a security risk, although it is safe for us because
	# of how jiostress opens the file.
	tmp_path = "%s/libjio-tests-%d-%d" % ( \
			os.environ.get("TMPDIR", "/tmp"),
			os.getpid(),
			random.randint(0, 1000000000))

	args = ["./wrap-python", "3", "../stress/jiostress",
			tmp_path, str(fsize)]
	if nops:
		args += ["-n", str(nops)]
	if nprocs:
		args += ["-p", str(nprocs)]
	if fi:
		args += ["--fi"]

	ret = subprocess.call(args)
	if ret != 0:
		sys.exit(ret)

if sys.argv[1] == "normal":
	print "behaviour tests (normal)"
	run_behaviour_tests("normal")
	print
	print "stress tests (normal)"
	run_stress_tests(nops = 50, nprocs = 3)
else:
	print "behaviour tests (all)"
	run_behaviour_tests("all")
	print
	print "stress tests (normal)"
	run_stress_tests(nops = 50, nprocs = 3)
	print
	print "stress tests (fiu)"
	run_stress_tests(nops = 400, fi = True)

print
print
print "Tests completed successfuly"
print