1# Copyright (C) 2018 The Android Open Source Project 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# Status dict updated from HC. 17DEVICE_STATUS_DICT = { 18 # default state, currently not in use. 19 "unknown": 0, 20 # for devices detected via "fastboot devices" shell command. 21 "fastboot": 1, 22 # for devices detected via "adb devices" shell command. 23 "online": 2, 24 # currently not in use. 25 "ready": 3, 26 # currently not in use. 27 "use": 4, 28 # for devices in error state. 29 "error": 5, 30 # for devices which timed out (not detected either via fastboot or adb). 31 "no-response": 6 32} 33 34# Scheduling status dict based on the status of each jobs in job queue. 35DEVICE_SCHEDULING_STATUS_DICT = { 36 # for devices detected but not scheduled. 37 "free": 0, 38 # for devices scheduled but not running. 39 "reserved": 1, 40 # for devices scheduled for currently leased job(s). 41 "use": 2 42} 43 44# Job status dict 45JOB_STATUS_DICT = { 46 # scheduled but not leased yet 47 "ready": 0, 48 # scheduled and in running 49 "leased": 1, 50 # completed job 51 "complete": 2, 52 # unexpected error during running 53 "infra-err": 3, 54 # never leased within schedule period 55 "expired": 4, 56 # device boot error after flashing the given img sets 57 "bootup-err": 5 58} 59 60JOB_PRIORITY_DICT = { 61 "top": 3, 62 "high": 6, 63 "medium": 9, 64 "low": 12, 65 "other": 15 66} 67 68 69STORAGE_TYPE_DICT = { 70 "unknown": 0, 71 "PAB": 1, 72 "GCS": 2 73} 74 75 76TEST_TYPE_UNKNOWN = "unknown" 77TEST_TYPE_TOT = "ToT" 78TEST_TYPE_OTA = "OTA" 79TEST_TYPE_SIGNED = "signed" 80TEST_TYPE_PRESUBMIT = "presubmit" 81TEST_TYPE_MANUAL = "manual" 82 83# a dict, where keys indicate test type and values have bitwise values. 84# bit 0-1 : version related test type 85# 00 - Unknown 86# 01 - ToT 87# 10 - OTA 88# bit 2 : device signed build 89# bit 3-4 : reserved for gerrit related test type 90# 01 - pre-submit 91# bit 5 : manually created test job 92TEST_TYPE_DICT = { 93 TEST_TYPE_UNKNOWN: 0, 94 TEST_TYPE_TOT: 1, 95 TEST_TYPE_OTA: 1 << 1, 96 TEST_TYPE_SIGNED: 1 << 2, 97 TEST_TYPE_PRESUBMIT: 1 << 3, 98 TEST_TYPE_MANUAL: 1 << 5 99} 100 101# # of errors in a row to suspend a schedule 102NUM_ERRORS_FOR_SUSPENSION = 3 103 104# filter methods 105FILTER_EqualTo = "EqualTo" 106FILTER_LessThan = "LessThan" 107FILTER_GreaterThan = "GreaterThan" 108FILTER_LessThanOrEqualTo = "LessThanOrEqualTo" 109FILTER_GreaterThanOrEqualTo = "GreaterThanOrEqualTo" 110FILTER_NotEqualTo = "NotEqualTo" 111FILTER_Has = "Has" 112 113FILTER_METHOD = { 114 FILTER_EqualTo: 1, 115 FILTER_LessThan: 2, 116 FILTER_GreaterThan: 3, 117 FILTER_LessThanOrEqualTo: 4, 118 FILTER_GreaterThanOrEqualTo: 5, 119 FILTER_NotEqualTo: 6, 120 FILTER_Has: 7, 121} 122 123 124def GetPriorityValue(priority): 125 """Helper function to sort jobs based on priority. 126 127 Args: 128 priority: string, the job priority. 129 130 Returns: 131 int, priority order (the lower, the higher) 132 """ 133 if priority: 134 priority = priority.lower() 135 if priority in JOB_PRIORITY_DICT: 136 return JOB_PRIORITY_DICT[priority] 137 return JOB_PRIORITY_DICT["other"] 138