Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_db.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2014 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. Author: Przemyslaw Wirkus <[email protected]>
  14. """
  15. import re
  16. import json
  17. class BaseDBAccess():
  18. """ Class used to connect with test database and store test results
  19. """
  20. def __init__(self):
  21. self.db_object = None
  22. self.db_type = None
  23. # Connection credentials
  24. self.host = None
  25. self.user = None
  26. self.passwd = None
  27. self.db = None
  28. # Test Suite DB scheme (table names)
  29. self.TABLE_BUILD_ID = 'mtest_build_id'
  30. self.TABLE_BUILD_ID_STATUS = 'mtest_build_id_status'
  31. self.TABLE_BUILD_ID_TYPE = 'mtest_build_id_type'
  32. self.TABLE_TARGET = 'mtest_target'
  33. self.TABLE_TEST_ENTRY = 'mtest_test_entry'
  34. self.TABLE_TEST_ID = 'mtest_test_id'
  35. self.TABLE_TEST_RESULT = 'mtest_test_result'
  36. self.TABLE_TEST_TYPE = 'mtest_test_type'
  37. self.TABLE_TOOLCHAIN = 'mtest_toolchain'
  38. # Build ID status PKs
  39. self.BUILD_ID_STATUS_STARTED = 1 # Started
  40. self.BUILD_ID_STATUS_IN_PROGRESS = 2 # In Progress
  41. self.BUILD_ID_STATUS_COMPLETED = 3 #Completed
  42. self.BUILD_ID_STATUS_FAILED = 4 # Failed
  43. # Build ID type PKs
  44. self.BUILD_ID_TYPE_TEST = 1 # Test
  45. self.BUILD_ID_TYPE_BUILD_ONLY = 2 # Build Only
  46. def get_hostname(self):
  47. """ Useful when creating build_id in database
  48. Function returns (hostname, uname) which can be used as (build_id_name, build_id_desc)
  49. """
  50. # Get hostname from socket
  51. import socket
  52. hostname = socket.gethostbyaddr(socket.gethostname())[0]
  53. # Get uname from platform resources
  54. import platform
  55. uname = json.dumps(platform.uname())
  56. return (hostname, uname)
  57. def get_db_type(self):
  58. """ Returns database type. E.g. 'mysql', 'sqlLite' etc.
  59. """
  60. return self.db_type
  61. def detect_database(self, verbose=False):
  62. """ detect database and return VERION data structure or string (verbose=True)
  63. """
  64. return None
  65. def parse_db_connection_string(self, str):
  66. """ Parsing SQL DB connection string. String should contain:
  67. - DB Name, user name, password, URL (DB host), name
  68. Function should return tuple with parsed (db_type, username, password, host, db_name) or None if error
  69. (db_type, username, password, host, db_name) = self.parse_db_connection_string(db_url)
  70. E.g. connection string: 'mysql://username:[email protected]/db_name'
  71. """
  72. result = None
  73. if type(str) == type(''):
  74. PATTERN = '^([\w]+)://([\w]+):([\w]*)@(.*)/([\w]+)'
  75. result = re.match(PATTERN, str)
  76. if result is not None:
  77. result = result.groups() # Tuple (db_name, host, user, passwd, db)
  78. return result # (db_type, username, password, host, db_name)
  79. def is_connected(self):
  80. """ Returns True if we are connected to database
  81. """
  82. pass
  83. def connect(self, host, user, passwd, db):
  84. """ Connects to DB and returns DB object
  85. """
  86. pass
  87. def connect_url(self, db_url):
  88. """ Connects to database using db_url (database url parsing),
  89. store host, username, password, db_name
  90. """
  91. pass
  92. def reconnect(self):
  93. """ Reconnects to DB and returns DB object using stored host name,
  94. database name and credentials (user name and password)
  95. """
  96. pass
  97. def disconnect(self):
  98. """ Close DB connection
  99. """
  100. pass
  101. def escape_string(self, str):
  102. """ Escapes string so it can be put in SQL query between quotes
  103. """
  104. pass
  105. def select_all(self, query):
  106. """ Execute SELECT query and get all results
  107. """
  108. pass
  109. def insert(self, query, commit=True):
  110. """ Execute INSERT query, define if you want to commit
  111. """
  112. pass
  113. def get_next_build_id(self, name, desc='', location='', type=None, status=None):
  114. """ Insert new build_id (DB unique build like ID number to send all test results)
  115. """
  116. pass
  117. def get_table_entry_pk(self, table, column, value, update_db=True):
  118. """ Checks for entries in tables with two columns (<TABLE_NAME>_pk, <column>)
  119. If update_db is True updates table entry if value in specified column doesn't exist
  120. """
  121. pass
  122. def update_table_entry(self, table, column, value):
  123. """ Updates table entry if value in specified column doesn't exist
  124. Locks table to perform atomic read + update
  125. """
  126. pass
  127. def update_build_id_info(self, build_id, **kw):
  128. """ Update additional data inside build_id table
  129. Examples:
  130. db.update_build_is(build_id, _status_fk=self.BUILD_ID_STATUS_COMPLETED, _shuffle_seed=0.0123456789):
  131. """
  132. pass
  133. def insert_test_entry(self, build_id, target, toolchain, test_type, test_id, test_result, test_time, test_timeout, test_loop, test_extra=''):
  134. """ Inserts test result entry to database. All checks regarding existing
  135. toolchain names in DB are performed.
  136. If some data is missing DB will be updated
  137. """
  138. pass