App.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http:#www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. class for handling Test Apps. Currently it provides the following features:
  16. 1. get SDK path
  17. 2. get SDK tools
  18. 3. parse application info from its path. for example:
  19. * provide download info
  20. * provide partition table info
  21. Test Apps should inherent from BaseApp class and overwrite the methods.
  22. """
  23. import os
  24. import sys
  25. import time
  26. # timestamp used for calculate log folder name
  27. LOG_FOLDER_TIMESTAMP = time.time()
  28. class BaseApp(object):
  29. """
  30. Base Class for App.
  31. Defines the mandatory methods that App need to implement.
  32. Also implements some common methods.
  33. :param app_path: the path for app.
  34. :param config_name: app configuration to be tested
  35. :param target: build target
  36. """
  37. def __init__(self, app_path, config_name=None, target=None):
  38. pass
  39. @classmethod
  40. def get_sdk_path(cls):
  41. """
  42. get sdk path.
  43. subclass must overwrite this method.
  44. :return: abs sdk path
  45. """
  46. pass
  47. @classmethod
  48. def get_tools(cls):
  49. """
  50. get SDK related tools for applications
  51. subclass must overwrite this method.
  52. :return: tuple, abs path of each tool
  53. """
  54. pass
  55. @classmethod
  56. def get_log_folder(cls, test_suite_name):
  57. """
  58. By default log folder is ``${SDK_PATH}/TEST_LOGS/${test_suite_name}_${timestamp}``.
  59. The log folder name is consist once start running, ensure all logs of will be put into the same folder.
  60. :param test_suite_name: the test suite name, by default it's the base file name for main module
  61. :return: the log folder path
  62. """
  63. if not test_suite_name:
  64. test_suite_name = os.path.splitext(os.path.basename(sys.modules['__main__'].__file__))[0]
  65. sdk_path = cls.get_sdk_path()
  66. log_folder = os.path.join(sdk_path, 'TEST_LOGS',
  67. test_suite_name +
  68. time.strftime('_%m%d_%H_%M_%S', time.localtime(LOG_FOLDER_TIMESTAMP)))
  69. if not os.path.exists(log_folder):
  70. os.makedirs(log_folder)
  71. return log_folder
  72. def process_app_info(self):
  73. """
  74. parse built app info for DUTTool
  75. subclass must overwrite this method.
  76. :return: required info for specific DUTTool
  77. """
  78. pass