Home | History | Annotate | Download | only in tracing_build
      1 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import json
      6 import os
      7 
      8 import tracing_project
      9 
     10 
     11 import webapp2
     12 from webapp2 import Route
     13 
     14 
     15 def _RelPathToUnixPath(p):
     16   return p.replace(os.sep, '/')
     17 
     18 
     19 class TestListHandler(webapp2.RequestHandler):
     20 
     21   def get(self, *args, **kwargs):  # pylint: disable=unused-argument
     22     project = tracing_project.TracingProject()
     23     test_relpaths = ['/' + _RelPathToUnixPath(x)
     24                      for x in project.FindAllTestModuleRelPaths()]
     25 
     26     tests = {'test_relpaths': test_relpaths}
     27     tests_as_json = json.dumps(tests)
     28     self.response.content_type = 'application/json'
     29     return self.response.write(tests_as_json)
     30 
     31 
     32 class TracingDevServerConfig(object):
     33 
     34   def __init__(self):
     35     self.project = tracing_project.TracingProject()
     36 
     37   def GetName(self):
     38     return 'tracing'
     39 
     40   def GetRunUnitTestsUrl(self):
     41     return '/tracing/tests.html'
     42 
     43   def AddOptionstToArgParseGroup(self, g):
     44     g.add_argument('-d', '--data-dir', default=self.project.test_data_path)
     45     g.add_argument('-s', '--skp-data-dir', default=self.project.skp_data_path)
     46 
     47   def GetRoutes(self, args):  # pylint: disable=unused-argument
     48     return [Route('/tracing/tests', TestListHandler)]
     49 
     50   def GetSourcePaths(self, args):  # pylint: disable=unused-argument
     51     return list(self.project.source_paths)
     52 
     53   def GetTestDataPaths(self, args):  # pylint: disable=unused-argument
     54     return [
     55         ('/tracing/test_data/', os.path.expanduser(args.data_dir)),
     56         ('/tracing/skp_data/', os.path.expanduser(args.skp_data_dir)),
     57     ]
     58