Exemplo n.º 1
0
    def testMockedResults(self):
        task_execution_time_metric = task_execution_time.TaskExecutionTime()
        ps = self.CreateEmptyPageSet()
        page = TestTaskExecutionTimePage(ps, ps.base_dir)
        ps.AddUserStory(page)

        # Get the name of a thread used by task_execution_time metric and set up
        # some dummy execution data pretending to be from that thread & process.
        first_thread_name = task_execution_time_metric._RENDERER_THREADS[0]
        data = TaskExecutionTestData(first_thread_name)
        task_execution_time_metric._renderer_process = data._renderer_process

        # Pretend we're about to run the tests to silence lower level asserts.
        data.results.WillRunPage(page)
        data.AddSlice('fast', 0, 1)
        data.AddSlice('medium', 0, 500)
        data.AddSlice('slow', 0, 1000)

        # Run the code we are testing.
        task_execution_time_metric.ValidateAndMeasurePage(
            None, None, data.results)

        # Confirm we get back 3 results that are correctly sorted and named.
        self.assertEqual(len(data.results.all_page_specific_values), 3)
        self.assertEqual(data.results.all_page_specific_values[0].name,
                         'process 1:' + first_thread_name + ':slow')
        self.assertEqual(data.results.all_page_specific_values[1].name,
                         'process 1:' + first_thread_name + ':medium')
        self.assertEqual(data.results.all_page_specific_values[2].name,
                         'process 1:' + first_thread_name + ':fast')
        self.assertEqual(data.results.all_page_specific_values[0].value, 1000)
        self.assertEqual(data.results.all_page_specific_values[1].value, 500)
        self.assertEqual(data.results.all_page_specific_values[2].value, 1)
Exemplo n.º 2
0
    def testSlicesConformToRequiredNamingConventionsUsingDummyPage(self):
        """This test ensures the presence of required keywords.

       Some arbitrary keywords are required to generate the names of the top 10
       tasks. The code has a weak dependancy on 'src_func', 'class' and 'line'
       existing; if they exist in a slice's args they are used to generate a
       name, if they don't exists the code falls back to using the name of the
       slice, which is less clear.

       If the code has been refactored and these keywords no longer exist
       the code that relies on them in task_execution_time.py should be
       updated to use the appropriate technique for assertaining this data
       (and this test changed in the same way).
    """
        ps = self.CreateEmptyPageSet()
        ps.AddUserStory(TestTaskExecutionTimePage(ps, ps.base_dir))
        measurement = task_execution_time.TaskExecutionTime()

        self.RunMeasurement(measurement, ps, options=self._options)

        required_keywords = {'src_func': 0, 'class': 0, 'line': 0}

        # Check all slices and count the uses of the required keywords.
        for thread in measurement._renderer_process.threads.values():
            for slice_info in thread.IterAllSlices():
                _CheckSliceForKeywords(slice_info, required_keywords)

        # Confirm that all required keywords have at least one instance.
        for use_counts in required_keywords.values():
            self.assertGreater(use_counts, 0)
Exemplo n.º 3
0
    def testSomeResultsReturnedFromDummyPage(self):
        ps = self.CreateEmptyPageSet()
        ps.AddUserStory(TestTaskExecutionTimePage(ps, ps.base_dir))
        measurement = task_execution_time.TaskExecutionTime()

        results = self.RunMeasurement(measurement, ps, options=self._options)

        self.assertGreater(len(results.all_page_specific_values), 0)
Exemplo n.º 4
0
  def _GenerateDataForEmptyPageSet(self):
    self._measurement = task_execution_time.TaskExecutionTime()
    self._page_set = self.CreateEmptyPageSet()
    page = TestTaskExecutionTimePage(self._page_set, self._page_set.base_dir)
    self._page_set.AddStory(page)

    # Get the name of a thread used by task_execution_time metric and set up
    # some dummy execution data pretending to be from that thread & process.
    data = TaskExecutionTestData(self._first_thread_name)
    self._measurement._renderer_process = data._renderer_process

    # Pretend we are about to run the tests to silence lower level asserts.
    data.results.WillRunPage(page)

    return data
Exemplo n.º 5
0
    def testIdleTasksAreReported(self):
        task_execution_time_metric = task_execution_time.TaskExecutionTime()
        ps = self.CreateEmptyPageSet()
        page = TestTaskExecutionTimePage(ps, ps.base_dir)
        ps.AddUserStory(page)

        # Get the name of a thread used by task_execution_time metric and set up
        # some dummy execution data pretending to be from that thread & process.
        first_thread_name = task_execution_time_metric._RENDERER_THREADS[0]
        data = TaskExecutionTestData(first_thread_name)
        task_execution_time_metric._renderer_process = data._renderer_process

        # Pretend we're about to run the tests to silence lower level asserts.
        data.results.WillRunPage(page)

        # Make a slice that looks like an idle task parent.
        slice_start_time = 0
        slice_duration = 1000
        parent_slice = data.AddSlice(
            task_execution_time_metric.IDLE_SECTION_TRIGGER, slice_start_time,
            slice_duration)
        # Add a sub-slice, this should be reported back as occuring in idle time.
        sub_slice = slice_data.Slice(None, 'category', 'slow_sub_slice',
                                     slice_start_time, slice_duration)
        parent_slice.sub_slices.append(sub_slice)

        # Add a non-idle task.
        data.AddSlice('not_idle', slice_start_time, slice_duration)

        # Run the code we are testing.
        task_execution_time_metric.ValidateAndMeasurePage(
            None, None, data.results)

        # The 'slow_sub_slice' should be inside the Idle section and therefore
        # removed from the results.
        for result in data.results.all_page_specific_values:
            if 'slow_sub_slice' in result.name:
                self.fail('Tasks within idle section should not be reported')

        # The 'not_idle' slice should not have the IDLE_SECTION added to its name
        # and should exist.
        for result in data.results.all_page_specific_values:
            if 'not_idle' in result.name:
                self.assertTrue(
                    task_execution_time_metric.IDLE_SECTION not in result.name)
                break
        else:
            self.fail('Task was incorrectly marked as Idle')