Add a global mechanism to the job object to allow users to change
the behaviour of profile_only, so that all tests default to

Signed-off-by: John Admanski <jadmanski@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3818 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/test.py b/client/common_lib/test.py
index 589ad30..e948e1c 100644
--- a/client/common_lib/test.py
+++ b/client/common_lib/test.py
@@ -261,7 +261,7 @@
         self.analyze_perf_constraints(constraints)
 
 
-    def execute(self, iterations=None, test_length=None, profile_only=False,
+    def execute(self, iterations=None, test_length=None, profile_only=None,
                 _get_time=time.time, postprocess_profiled_run=None,
                 constraints=(), *args, **dargs):
         """
@@ -279,8 +279,8 @@
             be silently ignored if you specify both.
 
         @param profile_only: If true run X iterations with profilers enabled.
-            Otherwise run X iterations and one with profiling if profiles are
-            enabled.
+            If false run X iterations and one with profiling if profiles are
+            enabled. If None, default to the value of job.default_profile_only.
 
         @param _get_time: [time.time] Used for unit test time injection.
 
@@ -295,6 +295,8 @@
         profilers = self.job.profilers
         if profilers.active():
             profilers.stop(self)
+        if profile_only is None:
+            profile_only = self.job.default_profile_only
         # If the user called this test in an odd way (specified both iterations
         # and test_length), let's warn them.
         if iterations and test_length:
diff --git a/client/common_lib/test_unittest.py b/client/common_lib/test_unittest.py
index 481bc72..9710fd0 100755
--- a/client/common_lib/test_unittest.py
+++ b/client/common_lib/test_unittest.py
@@ -22,6 +22,7 @@
                 def present(self):
                     return True
             self.job = MockJob()
+            self.job.default_profile_only = False
             self.job.profilers = MockProfilerManager()
             self._new_keyval = False
             self.iteration = 0
@@ -132,6 +133,19 @@
         self.god.check_playback()
 
 
+    def test_execute_default_profile_only(self):
+        # test that profile_only=True works.
+        self.god.stub_function(self.test, 'drop_caches_between_iterations')
+        for _ in xrange(3):
+            self.test.drop_caches_between_iterations.expect_call()
+            self.test.run_once_profiling.expect_call(None)
+        self.test.postprocess.expect_call()
+        self.test.process_failed_constraints.expect_call()
+        self.test.job.default_profile_only = True
+        self.test.execute(iterations=3)
+        self.god.check_playback()
+
+
     def test_execute_postprocess_profiled_false(self):
         # test that postprocess_profiled_run=False works
         self.god.stub_function(self.test, '_call_run_once')