tests/util: Rewrite the scripts in Python
[libjio.git] / tests / util / quick-test-run
blob87061d51fbdc8dde7cf75848dc4b887d117bbf56
1 #!/usr/bin/env python
3 # This is a convenience script for running some of the other tests without
4 # manual intervention, as a means of a fast and easy correctness test.
6 # If you are making an intrusive or risky change, please take the time to run
7 # the other tests by hand with more intensive parameters, and check the
8 # coverage and use the other tools mentioned in the README.
10 import sys
11 import os
12 import subprocess
13 import random
16 # Go to our directory, which we will use to find the other tools
17 os.chdir(os.path.dirname(sys.argv[0]))
19 if len(sys.argv) != 2 or sys.argv[1] not in ("normal", "fiu"):
20 sys.stderr.write("Usage: %s [normal|fiu]" %
21 os.path.basename(sys.argv[0]))
22 sys.exit(1)
24 def run_behaviour_tests(test_type):
25 ret = subprocess.call(["./wrap-python", "2", "../behaviour/runtests",
26 test_type])
27 if ret != 0:
28 sys.exit(ret)
30 def run_stress_tests(nops = 0, nprocs = 0, fi = False, fsize = 20):
31 # Create a temporary path. We can't use os.tempnam() because it emits
32 # a warning about a security risk, although it is safe for us because
33 # of how jiostress opens the file.
34 tmp_path = "%s/libjio-tests-%d-%d" % ( \
35 os.environ.get("TMPDIR", "/tmp"),
36 os.getpid(),
37 random.randint(0, 1000000000))
39 args = ["./wrap-python", "3", "../stress/jiostress",
40 tmp_path, str(fsize)]
41 if nops:
42 args += ["-n", str(nops)]
43 if nprocs:
44 args += ["-p", str(nprocs)]
45 if fi:
46 args += ["--fi"]
48 ret = subprocess.call(args)
49 if ret != 0:
50 sys.exit(ret)
52 if sys.argv[1] == "normal":
53 print "behaviour tests (normal)"
54 run_behaviour_tests("normal")
55 print
56 print "stress tests (normal)"
57 run_stress_tests(nops = 50, nprocs = 3)
58 else:
59 print "behaviour tests (all)"
60 run_behaviour_tests("all")
61 print
62 print "stress tests (normal)"
63 run_stress_tests(nops = 50, nprocs = 3)
64 print
65 print "stress tests (fiu)"
66 run_stress_tests(nops = 400, fi = True)
68 print
69 print
70 print "Tests completed successfuly"
71 print