App.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. """
  4. class for handling Test Apps. Currently it provides the following features:
  5. 1. get SDK path
  6. 2. get SDK tools
  7. 3. parse application info from its path. for example:
  8. * provide download info
  9. * provide partition table info
  10. Test Apps should inherent from BaseApp class and overwrite the methods.
  11. """
  12. import os
  13. import sys
  14. import time
  15. # timestamp used for calculate log folder name
  16. LOG_FOLDER_TIMESTAMP = time.time()
  17. class BaseApp(object):
  18. """
  19. Base Class for App.
  20. Defines the mandatory methods that App need to implement.
  21. Also implements some common methods.
  22. :param app_path: the path for app.
  23. :param config_name: app configuration to be tested
  24. :param target: build target
  25. """
  26. def __init__(self, app_path, config_name=None, target=None):
  27. pass
  28. @classmethod
  29. def get_sdk_path(cls):
  30. """
  31. get sdk path.
  32. subclass must overwrite this method.
  33. :return: abs sdk path
  34. """
  35. pass
  36. @classmethod
  37. def get_tools(cls):
  38. """
  39. get SDK related tools for applications
  40. subclass must overwrite this method.
  41. :return: tuple, abs path of each tool
  42. """
  43. pass
  44. @classmethod
  45. def get_log_folder(cls, test_suite_name):
  46. """
  47. By default log folder is ``${SDK_PATH}/TEST_LOGS/${test_suite_name}_${timestamp}``.
  48. The log folder name is consist once start running, ensure all logs of will be put into the same folder.
  49. :param test_suite_name: the test suite name, by default it's the base file name for main module
  50. :return: the log folder path
  51. """
  52. if not test_suite_name:
  53. test_suite_name = os.path.splitext(os.path.basename(sys.modules['__main__'].__file__))[0]
  54. sdk_path = cls.get_sdk_path()
  55. log_folder = os.path.join(sdk_path, 'TEST_LOGS',
  56. test_suite_name +
  57. time.strftime('_%m%d_%H_%M_%S', time.localtime(LOG_FOLDER_TIMESTAMP)))
  58. if not os.path.exists(log_folder):
  59. os.makedirs(log_folder)
  60. return log_folder
  61. def process_app_info(self):
  62. """
  63. parse built app info for DUTTool
  64. subclass must overwrite this method.
  65. :return: required info for specific DUTTool
  66. """
  67. pass