proxygen
gtest_shuffle_test Namespace Reference

Classes

class  GTestShuffleUnitTest
 

Functions

def AlsoRunDisabledTestsFlag ()
 
def FilterFlag (test_filter)
 
def RepeatFlag (n)
 
def ShuffleFlag ()
 
def RandomSeedFlag (n)
 
def RunAndReturnOutput (extra_env, args)
 
def GetTestsForAllIterations (extra_env, args)
 
def GetTestCases (tests)
 
def CalculateTestLists ()
 

Variables

string __author__ = 'wan@google.com (Zhanyong Wan)'
 
 COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_shuffle_test_')
 
string TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
 
string SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
 
string TEST_FILTER = 'A*.A:A*.B:C*'
 
list ALL_TESTS = []
 
list ACTIVE_TESTS = []
 
list FILTERED_TESTS = []
 
list SHARDED_TESTS = []
 
list SHUFFLED_ALL_TESTS = []
 
list SHUFFLED_ACTIVE_TESTS = []
 
list SHUFFLED_FILTERED_TESTS = []
 
list SHUFFLED_SHARDED_TESTS = []
 

Function Documentation

def gtest_shuffle_test.AlsoRunDisabledTestsFlag ( )

Definition at line 58 of file gtest_shuffle_test.py.

Referenced by CalculateTestLists().

59  return '--gtest_also_run_disabled_tests'
60 
61 
def gtest_shuffle_test.CalculateTestLists ( )
Calculates the list of tests run under different flags.

Definition at line 130 of file gtest_shuffle_test.py.

References AlsoRunDisabledTestsFlag(), FilterFlag(), GetTestsForAllIterations(), RandomSeedFlag(), and ShuffleFlag().

Referenced by gtest_shuffle_test.GTestShuffleUnitTest.setUp().

131  """Calculates the list of tests run under different flags."""
132 
133  if not ALL_TESTS:
134  ALL_TESTS.extend(
136 
137  if not ACTIVE_TESTS:
138  ACTIVE_TESTS.extend(GetTestsForAllIterations({}, [])[0])
139 
140  if not FILTERED_TESTS:
141  FILTERED_TESTS.extend(
142  GetTestsForAllIterations({}, [FilterFlag(TEST_FILTER)])[0])
143 
144  if not SHARDED_TESTS:
145  SHARDED_TESTS.extend(
146  GetTestsForAllIterations({TOTAL_SHARDS_ENV_VAR: '3',
147  SHARD_INDEX_ENV_VAR: '1'},
148  [])[0])
149 
150  if not SHUFFLED_ALL_TESTS:
151  SHUFFLED_ALL_TESTS.extend(GetTestsForAllIterations(
153 
154  if not SHUFFLED_ACTIVE_TESTS:
155  SHUFFLED_ACTIVE_TESTS.extend(GetTestsForAllIterations(
156  {}, [ShuffleFlag(), RandomSeedFlag(1)])[0])
157 
158  if not SHUFFLED_FILTERED_TESTS:
159  SHUFFLED_FILTERED_TESTS.extend(GetTestsForAllIterations(
160  {}, [ShuffleFlag(), RandomSeedFlag(1), FilterFlag(TEST_FILTER)])[0])
161 
162  if not SHUFFLED_SHARDED_TESTS:
163  SHUFFLED_SHARDED_TESTS.extend(
164  GetTestsForAllIterations({TOTAL_SHARDS_ENV_VAR: '3',
165  SHARD_INDEX_ENV_VAR: '1'},
166  [ShuffleFlag(), RandomSeedFlag(1)])[0])
167 
168 
def GetTestsForAllIterations(extra_env, args)
def FilterFlag(test_filter)
def gtest_shuffle_test.FilterFlag (   test_filter)

Definition at line 62 of file gtest_shuffle_test.py.

Referenced by CalculateTestLists().

62 def FilterFlag(test_filter):
63  return '--gtest_filter=%s' % (test_filter,)
64 
65 
def FilterFlag(test_filter)
def gtest_shuffle_test.GetTestCases (   tests)
Returns a list of test cases in the given full test names.

Args:
  tests: a list of full test names

Returns:
  A list of test cases from 'tests', in their original order.
  Consecutive duplicates are removed.

Definition at line 110 of file gtest_shuffle_test.py.

Referenced by gtest_shuffle_test.GTestShuffleUnitTest.testShuffleChangesTestCaseOrder().

110 def GetTestCases(tests):
111  """Returns a list of test cases in the given full test names.
112 
113  Args:
114  tests: a list of full test names
115 
116  Returns:
117  A list of test cases from 'tests', in their original order.
118  Consecutive duplicates are removed.
119  """
120 
121  test_cases = []
122  for test in tests:
123  test_case = test.split('.')[0]
124  if not test_case in test_cases:
125  test_cases.append(test_case)
126 
127  return test_cases
128 
129 
def gtest_shuffle_test.GetTestsForAllIterations (   extra_env,
  args 
)
Runs the test program and returns a list of test lists.

Args:
  extra_env: a map from environment variables to their values
  args: command line flags to pass to gtest_shuffle_test_

Returns:
  A list where the i-th element is the list of tests run in the i-th
  test iteration.

Definition at line 87 of file gtest_shuffle_test.py.

References RunAndReturnOutput(), and folly::gen.split().

Referenced by CalculateTestLists(), gtest_shuffle_test.GTestShuffleUnitTest.testShuffleGeneratesNewOrderInEachIteration(), gtest_shuffle_test.GTestShuffleUnitTest.testShuffleRestoresOrderAfterEachIteration(), and gtest_shuffle_test.GTestShuffleUnitTest.testShuffleShardedTestsPreservesPartition().

87 def GetTestsForAllIterations(extra_env, args):
88  """Runs the test program and returns a list of test lists.
89 
90  Args:
91  extra_env: a map from environment variables to their values
92  args: command line flags to pass to gtest_shuffle_test_
93 
94  Returns:
95  A list where the i-th element is the list of tests run in the i-th
96  test iteration.
97  """
98 
99  test_iterations = []
100  for line in RunAndReturnOutput(extra_env, args).split('\n'):
101  if line.startswith('----'):
102  tests = []
103  test_iterations.append(tests)
104  elif line.strip():
105  tests.append(line.strip()) # 'TestCaseName.TestName'
106 
107  return test_iterations
108 
109 
def GetTestsForAllIterations(extra_env, args)
S split(const StringPiece source, char delimiter)
Definition: String.h:61
def RunAndReturnOutput(extra_env, args)
def gtest_shuffle_test.RepeatFlag (   n)
def gtest_shuffle_test.RunAndReturnOutput (   extra_env,
  args 
)
Runs the test program and returns its output.

Definition at line 78 of file gtest_shuffle_test.py.

Referenced by GetTestsForAllIterations().

78 def RunAndReturnOutput(extra_env, args):
79  """Runs the test program and returns its output."""
80 
81  environ_copy = os.environ.copy()
82  environ_copy.update(extra_env)
83 
84  return gtest_test_utils.Subprocess([COMMAND] + args, env=environ_copy).output
85 
86 
def RunAndReturnOutput(extra_env, args)

Variable Documentation

string gtest_shuffle_test.__author__ = 'wan@google.com (Zhanyong Wan)'
private

Definition at line 33 of file gtest_shuffle_test.py.

list gtest_shuffle_test.ACTIVE_TESTS = []

Definition at line 48 of file gtest_shuffle_test.py.

list gtest_shuffle_test.ALL_TESTS = []

Definition at line 47 of file gtest_shuffle_test.py.

gtest_shuffle_test.COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_shuffle_test_')

Definition at line 39 of file gtest_shuffle_test.py.

list gtest_shuffle_test.FILTERED_TESTS = []

Definition at line 49 of file gtest_shuffle_test.py.

string gtest_shuffle_test.SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'

Definition at line 43 of file gtest_shuffle_test.py.

list gtest_shuffle_test.SHARDED_TESTS = []

Definition at line 50 of file gtest_shuffle_test.py.

list gtest_shuffle_test.SHUFFLED_ACTIVE_TESTS = []

Definition at line 53 of file gtest_shuffle_test.py.

list gtest_shuffle_test.SHUFFLED_ALL_TESTS = []

Definition at line 52 of file gtest_shuffle_test.py.

list gtest_shuffle_test.SHUFFLED_FILTERED_TESTS = []

Definition at line 54 of file gtest_shuffle_test.py.

list gtest_shuffle_test.SHUFFLED_SHARDED_TESTS = []

Definition at line 55 of file gtest_shuffle_test.py.

string gtest_shuffle_test.TEST_FILTER = 'A*.A:A*.B:C*'

Definition at line 45 of file gtest_shuffle_test.py.

string gtest_shuffle_test.TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'

Definition at line 42 of file gtest_shuffle_test.py.