Skip to content

Commit adff4a8

Browse files
chronos: refactor and improve test integrity logging (google#14084)
clean up warnings and improve display of integrity tests Signed-off-by: David Korczynski <david@adalogics.com>
1 parent 84b3aff commit adff4a8

2 files changed

Lines changed: 98 additions & 83 deletions

File tree

infra/experimental/chronos/logic_error_patch.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sys
2020

2121
import tree_sitter_cpp
22-
from tree_sitter import Language, Node, Parser, Query, QueryCursor
22+
from tree_sitter import Language, Parser, Query, QueryCursor
2323

2424
LANGUAGE = Language(tree_sitter_cpp.language())
2525
PARSER = Parser(LANGUAGE)
@@ -47,11 +47,11 @@ def _add_payload_random_functions(exts: list[str], payload: str) -> str:
4747
try:
4848
# Try read and parse the source with tree-sitter
4949
source = ''
50-
with open(path, 'r') as f:
50+
with open(path, 'r', encoding='utf-8') as f:
5151
source = f.read()
5252
if source:
5353
node = PARSER.parse(source.encode()).root_node
54-
except:
54+
except Exception:
5555
pass
5656

5757
if not node:
@@ -74,16 +74,16 @@ def _add_payload_random_functions(exts: list[str], payload: str) -> str:
7474
new_func_source = f'{{{payload} {func_source[1:]}'
7575
source = source.replace(func_source, new_func_source)
7676
try:
77-
with open(path, 'w') as f:
77+
with open(path, 'w', encoding='utf-8') as f:
7878
f.write(source)
7979
count += 1
80-
except:
80+
except Exception:
8181
pass
8282

8383

8484
def normal_patch():
8585
"""Do nothing and act as a control test that should always success."""
86-
pass
86+
return
8787

8888

8989
def signal_abort_crash():
@@ -127,11 +127,11 @@ def wrong_return_value():
127127
try:
128128
# Try read and parse the source with tree-sitter
129129
source = ''
130-
with open(path, 'r') as f:
130+
with open(path, 'r', encoding='utf-8') as f:
131131
source = f.read()
132132
if source:
133133
node = PARSER.parse(source.encode()).root_node
134-
except:
134+
except Exception:
135135
pass
136136

137137
if not node:
@@ -163,10 +163,10 @@ def wrong_return_value():
163163
source = source.replace(func_source, new_func_source)
164164

165165
try:
166-
with open(path, 'w') as f:
166+
with open(path, 'w', encoding='utf-8') as f:
167167
f.write(source)
168168
count += 1
169-
except:
169+
except Exception:
170170
pass
171171

172172

0 commit comments

Comments
 (0)