Skip to content

Commit

Permalink
Add validation for platform strings to exclude_parser.py (adoptium#5651)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jiekang authored Dec 2, 2024
1 parent a7f0676 commit de802c7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/disabled_tests/exclude_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
from common.models import Scheme, JdkInfo
from common.utils import to_shallow_dict, DEFAULT_TARGET

class ErrorTrackingHandler(logging.Handler):
def __init__(self):
super().__init__()
self.error_logged = False

def emit(self, record):
if record.levelno >= logging.ERROR:
self.error_logged = True

logging.basicConfig(
format="%(levelname)s - %(message)s"
)
LOG = logging.getLogger()
ERROR_TRACKER = ErrorTrackingHandler()
LOG.addHandler(ERROR_TRACKER)

OS_EXCEPTIONS = {
"macosx": "mac",
Expand All @@ -26,7 +37,6 @@
"x86": "x86-32",
}


class ExclusionFileProcessingException(Exception):
pass

Expand Down Expand Up @@ -112,7 +122,7 @@ class TestExclusionSplitLine(TestExclusionRawLine):

@classmethod
def from_raw_line(cls, test_excl: TestExclusionRawLine):
split_line = test_excl.raw_line.split(maxsplit=2)
split_line = test_excl.raw_line.split()
if len(split_line) != 3:
raise TestExclusionProcessingException(
f'Not exactly 3 elements when splitting {test_excl.raw_line}', test_excl)
Expand Down Expand Up @@ -185,7 +195,6 @@ def transform_platform(os_arch_platform: str) -> str:

return f"{arch_name}_{os_name}"


def resolve_platforms(split: TestExclusionSplitLine) -> List[str]:
revolved_platforms = []
list_of_unresolved_platform_names = [s.strip() for s in split.raw_platform.split(",") if s.strip()]
Expand Down Expand Up @@ -250,11 +259,10 @@ def main():
if args.verbose:
LOG.setLevel(logging.DEBUG)

# if the dir containing the exclude ProblemList*.txt is not passed, the attempt to use openjdk/excludes/ dir instead
if args.exclude_dir:
LOG.debug("Taking file list from directory")
exclude_files = [os.path.join(args.exclude_dir, file_name)
for file_name in os.listdir(args.exclude_dir)]
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))]
LOG.debug(exclude_files)
else:
LOG.debug("Taking file list from stdin")
exclude_files = [line.rstrip() for line in sys.stdin.readlines()] # remove the \n from each lines
Expand Down Expand Up @@ -283,7 +291,9 @@ def main():
fp=fp,
indent=2,
)

if ERROR_TRACKER.error_logged:
LOG.debug(f"Error found. Exiting with code 1")
sys.exit(1)

if __name__ == '__main__':
main()

0 comments on commit de802c7

Please sign in to comment.