Skip to content

Add launch test log file support for the xpu test utils #1879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/xpu/xpu_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import unittest
import logging

import torch
from torch import bfloat16, cuda
Expand All @@ -27,6 +28,7 @@
UnaryUfuncInfo,
)

_loggers = {}
_xpu_computation_op_list = [
"empty",
"eye",
Expand Down Expand Up @@ -441,6 +443,28 @@
}


def create_file_logger(name, log_path=None, level=logging.DEBUG):
global _loggers
if name in _loggers:
return _loggers[name]

logger = logging.getLogger(name)
logger.setLevel(level)
if not log_path:
if 'WORKSPACE' in os.environ:
parent = os.environ['WORKSPACE']
else:
parent = os.path.dirname(os.path.abspath(__file__))
log_path = os.path.join(parent, f"{name}.log")

log_path = os.path.normpath(log_path)
file_handle = logging.FileHandler(log_path, mode='a', errors='ignore')
file_handle.setFormatter(logging.Formatter("%(levelname)s %(asctime)s %(message)s", "%Y%m%d-%H:%M:%S"))
logger.addHandler(file_handle)
_loggers[name] = logger
return logger


def get_wrapped_fn(fn):
if hasattr(fn, "__wrapped__"):
wrapped = fn.__wrapped__
Expand Down Expand Up @@ -1161,6 +1185,7 @@ def copy_tests(


def launch_test(test_case, skip_list=None, exe_list=None):
logger = create_file_logger('launch_test')
os.environ["PYTORCH_ENABLE_XPU_FALLBACK"] = "1"
os.environ["PYTORCH_TEST_WITH_SLOW"] = "1"
if skip_list is not None:
Expand Down Expand Up @@ -1190,4 +1215,5 @@ def launch_test(test_case, skip_list=None, exe_list=None):
f"pytest --timeout 600 -v --junit-xml=./op_ut_with_skip_{test_case}.xml "
+ test_case
)
logger.info(test_command)
return os.system(test_command)
Loading