forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_cache_stress_test.py
More file actions
executable file
·101 lines (86 loc) · 3.29 KB
/
parser_cache_stress_test.py
File metadata and controls
executable file
·101 lines (86 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mmap
import os
import re
import string
import subprocess
import sys
def parseArgs():
import argparse
description = """This script performs the following steps:
[1] buck kill && buck targets --json - to make sure we preheat graph cache
[2] change revision to N commits up - only HG supported
[3] buck targets --json - cache will be kept/dropped
[4] buck kill && buck targets --json - without cache
[5] compares the output of steps [3] and [4], they expected to match"""
parser = argparse.ArgumentParser(
description=description, formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument("buck_path", help="Path to Buck")
parser.add_argument("repo_root", help="Path to HG repo")
parser.add_argument(
"target_to_test", help="Buck targets to test, i.e. //apps/myapp:"
)
parser.add_argument("iteration_count", help="Number of iterations to run")
parser.add_argument("stepping", help="Number of commits to jump in each iteration")
return parser.parse_args()
def invoke(repo_path, command_as_list):
print("Invoking: " + str(command_as_list))
pipe = subprocess.PIPE
process = subprocess.Popen(command_as_list, stdout=pipe, stderr=pipe, cwd=repo_path)
out, err = process.communicate()
exit_code = process.wait()
if exit_code != 0:
sys.exit(
"Failed to invoke command: "
+ str(command_as_list)
+ "\nstderr:\n"
+ str(err)
)
return out
def change_revision(repo_path, stepping):
invoke(repo_path, ["hg", "up", "-C", ".~" + str(stepping)])
def run_iteration(repo_root, buck, targets, stepping):
revision = invoke(repo_root, ["hg", "id", "-i"])
print("Current revision: " + revision.strip())
# [1]
invoke(repo_root, [buck, "kill"])
invoke(repo_root, [buck, "targets", targets, "--json"])
# [2]
change_revision(repo_root, stepping)
# [3]
out3 = invoke(repo_root, [buck, "targets", targets, "--json"])
# [4]
invoke(repo_root, [buck, "kill"])
out4 = invoke(repo_root, [buck, "targets", targets, "--json"])
# [5]
if out3 == out4:
print("OUTPUTS MATCH! SUCCESS!")
print("Output:\n" + str(out3) + "\n\n\n")
else:
print("Outputs are different.")
print("Step [3] output:\n" + str(out3) + "\n\n")
print("Step [4] output:\n" + str(out4) + "\n\n")
sys.exit("Terminating.")
def main():
args = parseArgs()
for i in range(0, int(args.iteration_count)):
print("Iteration " + str(i))
run_iteration(
args.repo_root, args.buck_path, args.target_to_test, int(args.stepping)
)
if __name__ == "__main__":
main()