]> granicus.if.org Git - esp-idf/blob - tools/tiny-test-fw/App.py
Merge branch 'bugfix/rom_export_functions' into 'master'
[esp-idf] / tools / tiny-test-fw / App.py
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 """
16 class for handling Test Apps. Currently it provides the following features:
17
18 1. get SDK path
19 2. get SDK tools
20 3. parse application info from its path. for example:
21     * provide download info
22     * provide partition table info
23
24 Test Apps should inherent from BaseApp class and overwrite the methods.
25 """
26 import os
27 import sys
28 import time
29
30 # timestamp used for calculate log folder name
31 LOG_FOLDER_TIMESTAMP = time.time()
32
33
34 class BaseApp(object):
35     """
36     Base Class for App.
37     Defines the mandatory methods that App need to implement.
38     Also implements some common methods.
39
40     :param app_path: the path for app.
41     """
42
43     def __init__(self, app_path):
44         pass
45
46     @classmethod
47     def get_sdk_path(cls):
48         """
49         get sdk path.
50
51         subclass must overwrite this method.
52
53         :return: abs sdk path
54         """
55         pass
56
57     @classmethod
58     def get_tools(cls):
59         """
60         get SDK related tools for applications
61
62         subclass must overwrite this method.
63
64         :return: tuple, abs path of each tool
65         """
66         pass
67
68     @classmethod
69     def get_log_folder(cls, test_suite_name):
70         """
71         By default log folder is ``${SDK_PATH}/TEST_LOGS/${test_suite_name}_${timestamp}``.
72
73         The log folder name is consist once start running, ensure all logs of will be put into the same folder.
74
75         :param test_suite_name: the test suite name, by default it's the base file name for main module
76         :return: the log folder path
77         """
78         if not test_suite_name:
79             test_suite_name = os.path.splitext(os.path.basename(sys.modules['__main__'].__file__))[0]
80         sdk_path = cls.get_sdk_path()
81         log_folder = os.path.join(sdk_path, "TEST_LOGS",
82                                   test_suite_name +
83                                   time.strftime("_%m%d_%H_%M_%S", time.localtime(LOG_FOLDER_TIMESTAMP)))
84         if not os.path.exists(log_folder):
85             os.makedirs(log_folder)
86         return log_folder
87
88     def process_app_info(self):
89         """
90         parse built app info for DUTTool
91
92         subclass must overwrite this method.
93
94         :return: required info for specific DUTTool
95         """
96         pass