Skip to content

Commit de802c7

Browse files
authored
Add validation for platform strings to exclude_parser.py (#5651)
* Add validation for platform strings to exclude_parser.py * Exit with code 1 on logging of error. Only parse files in exclude_path * Remove comment that does not apply to current code * Simplify validation of exclusion format
1 parent a7f0676 commit de802c7

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

scripts/disabled_tests/exclude_parser.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@
1010
from common.models import Scheme, JdkInfo
1111
from common.utils import to_shallow_dict, DEFAULT_TARGET
1212

13+
class ErrorTrackingHandler(logging.Handler):
14+
def __init__(self):
15+
super().__init__()
16+
self.error_logged = False
17+
18+
def emit(self, record):
19+
if record.levelno >= logging.ERROR:
20+
self.error_logged = True
21+
1322
logging.basicConfig(
1423
format="%(levelname)s - %(message)s"
1524
)
1625
LOG = logging.getLogger()
26+
ERROR_TRACKER = ErrorTrackingHandler()
27+
LOG.addHandler(ERROR_TRACKER)
1728

1829
OS_EXCEPTIONS = {
1930
"macosx": "mac",
@@ -26,7 +37,6 @@
2637
"x86": "x86-32",
2738
}
2839

29-
3040
class ExclusionFileProcessingException(Exception):
3141
pass
3242

@@ -112,7 +122,7 @@ class TestExclusionSplitLine(TestExclusionRawLine):
112122

113123
@classmethod
114124
def from_raw_line(cls, test_excl: TestExclusionRawLine):
115-
split_line = test_excl.raw_line.split(maxsplit=2)
125+
split_line = test_excl.raw_line.split()
116126
if len(split_line) != 3:
117127
raise TestExclusionProcessingException(
118128
f'Not exactly 3 elements when splitting {test_excl.raw_line}', test_excl)
@@ -185,7 +195,6 @@ def transform_platform(os_arch_platform: str) -> str:
185195

186196
return f"{arch_name}_{os_name}"
187197

188-
189198
def resolve_platforms(split: TestExclusionSplitLine) -> List[str]:
190199
revolved_platforms = []
191200
list_of_unresolved_platform_names = [s.strip() for s in split.raw_platform.split(",") if s.strip()]
@@ -250,11 +259,10 @@ def main():
250259
if args.verbose:
251260
LOG.setLevel(logging.DEBUG)
252261

253-
# if the dir containing the exclude ProblemList*.txt is not passed, the attempt to use openjdk/excludes/ dir instead
254262
if args.exclude_dir:
255263
LOG.debug("Taking file list from directory")
256-
exclude_files = [os.path.join(args.exclude_dir, file_name)
257-
for file_name in os.listdir(args.exclude_dir)]
264+
exclude_files = [os.path.join(args.exclude_dir, f) for f in os.listdir(args.exclude_dir) if os.path.isfile(os.path.join(args.exclude_dir, f))]
265+
LOG.debug(exclude_files)
258266
else:
259267
LOG.debug("Taking file list from stdin")
260268
exclude_files = [line.rstrip() for line in sys.stdin.readlines()] # remove the \n from each lines
@@ -283,7 +291,9 @@ def main():
283291
fp=fp,
284292
indent=2,
285293
)
286-
294+
if ERROR_TRACKER.error_logged:
295+
LOG.debug(f"Error found. Exiting with code 1")
296+
sys.exit(1)
287297

288298
if __name__ == '__main__':
289299
main()

0 commit comments

Comments
 (0)