-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-645] Add flakiness checker #11572
Changes from 6 commits
ca5553b
68ea32e
14df126
e03e964
16bf6b7
8a06042
e25b3ff
137c44e
6df65db
41f5d33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
""" Checks a given test for flakiness | ||
Takes the file name and function name of a test, as well as, optionally, | ||
the number of trials to run and the random seed to use | ||
""" | ||
|
||
import subprocess | ||
import sys | ||
import os | ||
import random | ||
import argparse | ||
import re | ||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
DEFAULT_NUM_TRIALS = 10000 | ||
DEFAULT_VERBOSITY = 2 | ||
|
||
def run_test_trials(args): | ||
test_path = args.test_path + ":" + args.test_name | ||
logging.info("Testing: %s", test_path) | ||
|
||
new_env = os.environ.copy() | ||
new_env["MXNET_TEST_COUNT"] = str(args.num_trials) | ||
|
||
if args.seed is None: | ||
logging.info("No test seed provided, using random seed") | ||
else: | ||
new_env["MXNET_TEST_SEED"] = str(args.seed) | ||
|
||
verbosity = "--verbosity=" + str(args.verbosity) | ||
|
||
code = subprocess.call(["nosetests", verbosity, test_path], | ||
env = new_env) | ||
|
||
logging.info("Nosetests terminated with exit code %d", code) | ||
|
||
def find_test_path(test_file): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some documentation? From the name alone it was not clear to me what this exactly does. Also, how is it going to handle duplicates and the fact that we import tests into other testfiles, e.g. test_operator_gpu? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you take a closer look at the code, you'll see that the file name and test name are both provided by the user. So if you would like to run the gpu version of test_sigmoid then you'll do <path-to-test_operator_gpu.py>:test_sigmoid or test_operator_gpu.test_sigmoid. The problem you're asking is probably "if we modified some tests in test_operator.py, how do we detect that we also need to run the gpu version of it?", which is designed to be handled by other components in the project (this is stated in the design doc too). |
||
"""Searches for the test file and returns the path if found | ||
As a default, the currend working directory is the top of the search. | ||
If a directory was provided as part of the argument, the directory will be | ||
joined with cwd unless it was an absolute path, in which case, the | ||
absolute path will be used instead. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if the behaviour described in this doc is actually resembled by the code. I'm a bit concerned about the absolute path because you always join with cwd. Also you should only append the .py if it isn't present yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Path.join will only use the last absolute path provided, so if the user provides an absolute path it will override cwd, I've tested this and it does work this way. Currently, I'm using re.split to process the command line argument with test file and test name, and I'm removing .py from the case when it's present. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! Very nice catch and approach! |
||
test_file += ".py" | ||
test_path = os.path.split(test_file) | ||
top = os.path.join(os.getcwd(), test_path[0]) | ||
|
||
for (path, dirs, files) in os.walk(top): | ||
if test_path[1] in files: | ||
return os.path.join(path, test_path[1]) | ||
raise FileNotFoundError("Could not find " + test_path[1] + | ||
"in directory: " + top) | ||
|
||
class NameAction(argparse.Action): | ||
"""Parses command line argument to get test file and test name""" | ||
def __call__(self, parser, namespace, values, option_string=None): | ||
name = re.split("\.py:|\.", values) | ||
if len(name) != 2: | ||
raise ValueError("Invalid argument format for test. Format: " | ||
"<file-name>.<test-name> or" | ||
" <directory>/<file>:<test-name>") | ||
setattr(namespace, "test_path", find_test_path(name[0])) | ||
setattr(namespace, "test_name", name[1]) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description="Check test for flakiness") | ||
|
||
parser.add_argument("test", action=NameAction, | ||
help="file name and and function name of test, " | ||
"provided in the format: <file-name>:<test-name> " | ||
"or <directory>/<file>:<test-name>") | ||
|
||
parser.add_argument("-n", "--num-trials", metavar="N", | ||
default=DEFAULT_NUM_TRIALS, type=int, | ||
help="number of test trials, passed as " | ||
"MXNET_TEST_COUNT, defaults to 500") | ||
|
||
parser.add_argument("-s", "--seed", type=int, | ||
help="test seed, passed as MXNET_TEST_SEED, " | ||
"defaults to random seed") | ||
|
||
parser.add_argument("-v", "--verbosity", | ||
default=DEFAULT_VERBOSITY, type=int, | ||
help="logging level, passed to nosetests") | ||
|
||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
|
||
run_test_trials(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use logging instead of print. This allows you to make log messages without having to concatenate strings