##// END OF EJS Templates
Test --time, --profile and --lsprof
Patrick Mezard -
r5099:105d4cf7 default
parent child Browse files
Show More
@@ -0,0 +1,12 b''
1 #!/bin/sh
2
3 echo % test --time
4 hg --time help 2>&1 | grep -q Time || echo --time failed
5
6 echo % test --profile
7 hg --profile help 2>&1 | grep -q ncalls || echo --profile failed
8
9 echo % test --lsprof
10 if "$TESTDIR/hghave" -q lsprof; then
11 hg --lsprof help 2>&1 | grep -q CallCount || echo --lsprof failed
12 fi No newline at end of file
@@ -0,0 +1,3 b''
1 % test --time
2 % test --profile
3 % test --lsprof
@@ -1,90 +1,98 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """Test the running system for features availability. Exit with zero
2 """Test the running system for features availability. Exit with zero
3 if all features are there, non-zero otherwise. If a feature name is
3 if all features are there, non-zero otherwise. If a feature name is
4 prefixed with "no-", the absence of feature is tested.
4 prefixed with "no-", the absence of feature is tested.
5 """
5 """
6 import optparse
6 import optparse
7 import os
7 import os
8 import sys
8 import sys
9 import tempfile
9 import tempfile
10
10
11 tempprefix = 'hg-hghave-'
11 tempprefix = 'hg-hghave-'
12
12
13 def has_symlink():
13 def has_symlink():
14 return hasattr(os, "symlink")
14 return hasattr(os, "symlink")
15
15
16 def has_fifo():
16 def has_fifo():
17 return hasattr(os, "mkfifo")
17 return hasattr(os, "mkfifo")
18
18
19 def has_executablebit():
19 def has_executablebit():
20 fd, path = tempfile.mkstemp(prefix=tempprefix)
20 fd, path = tempfile.mkstemp(prefix=tempprefix)
21 os.close(fd)
21 os.close(fd)
22 try:
22 try:
23 s = os.lstat(path).st_mode
23 s = os.lstat(path).st_mode
24 os.chmod(path, s | 0100)
24 os.chmod(path, s | 0100)
25 return (os.lstat(path).st_mode & 0100 != 0)
25 return (os.lstat(path).st_mode & 0100 != 0)
26 finally:
26 finally:
27 os.remove(path)
27 os.remove(path)
28
28
29 def has_eol_in_paths():
29 def has_eol_in_paths():
30 try:
30 try:
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
32 os.close(fd)
32 os.close(fd)
33 os.remove(path)
33 os.remove(path)
34 return True
34 return True
35 except:
35 except:
36 return False
36 return False
37
37
38 def has_lsprof():
39 try:
40 import _lsprof
41 return True
42 except ImportError:
43 return False
44
38 checks = {
45 checks = {
39 "symlink": (has_symlink, "symbolic links"),
46 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
47 "execbit": (has_executablebit, "executable bit"),
40 "fifo": (has_fifo, "named pipes"),
48 "fifo": (has_fifo, "named pipes"),
41 "execbit": (has_executablebit, "executable bit"),
49 "lsprof": (has_lsprof, "python lsprof module"),
42 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
50 "symlink": (has_symlink, "symbolic links"),
43 }
51 }
44
52
45 def list_features():
53 def list_features():
46 for name, feature in checks.iteritems():
54 for name, feature in checks.iteritems():
47 desc = feature[1]
55 desc = feature[1]
48 print name + ':', desc
56 print name + ':', desc
49
57
50 parser = optparse.OptionParser("%prog [options] [features]")
58 parser = optparse.OptionParser("%prog [options] [features]")
51 parser.add_option("--list-features", action="store_true",
59 parser.add_option("--list-features", action="store_true",
52 help="list available features")
60 help="list available features")
53 parser.add_option("-q", "--quiet", action="store_true",
61 parser.add_option("-q", "--quiet", action="store_true",
54 help="check features silently")
62 help="check features silently")
55
63
56 if __name__ == '__main__':
64 if __name__ == '__main__':
57 options, args = parser.parse_args()
65 options, args = parser.parse_args()
58 if options.list_features:
66 if options.list_features:
59 list_features()
67 list_features()
60 sys.exit(0)
68 sys.exit(0)
61
69
62 quiet = options.quiet
70 quiet = options.quiet
63
71
64 failures = 0
72 failures = 0
65
73
66 def error(msg):
74 def error(msg):
67 global failures
75 global failures
68 if not quiet:
76 if not quiet:
69 sys.stderr.write(msg + '\n')
77 sys.stderr.write(msg + '\n')
70 failures += 1
78 failures += 1
71
79
72 for feature in args:
80 for feature in args:
73 negate = feature.startswith('no-')
81 negate = feature.startswith('no-')
74 if negate:
82 if negate:
75 feature = feature[3:]
83 feature = feature[3:]
76
84
77 if feature not in checks:
85 if feature not in checks:
78 error('hghave: unknown feature: ' + feature)
86 error('hghave: unknown feature: ' + feature)
79 continue
87 continue
80
88
81 check, desc = checks[feature]
89 check, desc = checks[feature]
82 if not negate and not check():
90 if not negate and not check():
83 error('hghave: missing feature: ' + desc)
91 error('hghave: missing feature: ' + desc)
84 elif negate and check():
92 elif negate and check():
85 error('hghave: system supports %s' % desc)
93 error('hghave: system supports %s' % desc)
86
94
87 if failures != 0:
95 if failures != 0:
88 sys.exit(1)
96 sys.exit(1)
89
97
90
98
General Comments 0
You need to be logged in to leave comments. Login now