1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 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 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.android.chre.test.chqts; 17 18 import org.junit.Assert; 19 20 /** 21 * These values come from nanoapps/general_test/test_names.h and 22 * nanoapps/shared/send_message.h. 23 * 24 * TODO: This is very fragile. We should try to automate keeping this 25 * in sync. That's made mildly more challenging by different 26 * language constructs and naming conventions. 27 */ 28 public class ContextHubTestConstants { 29 /** 30 * Names of the tests we support. 31 */ 32 public enum TestNames { 33 /** 34 * Value which should never be used. 35 */ 36 INVALID_TEST(0x0400), 37 38 /** 39 * Test: ContextHubSimpleGeneralNanoAppTests[HelloWorld] 40 */ 41 HELLO_WORLD(0x0401), 42 43 /** 44 * Test: ContextHubSimpleHeapAllocNanoAppTest 45 */ 46 SIMPLE_HEAP_ALLOC(0x0402), 47 48 /** 49 * Test: ContextHubSimpleGeneralNanoAppTests[HeapAllocStress] 50 */ 51 HEAP_ALLOC_STRESS(0x0403), 52 53 /** 54 * Test: ContextHubGetTimeNanoAppTest 55 */ 56 GET_TIME(0x0404), 57 58 /** 59 * Test: ContextHubEventBetweenAppsNanoAppTest 60 */ 61 EVENT_BETWEEN_APPS0(0x0405), 62 63 /** 64 * Test: ContextHubEventBetweenAppsNanoAppTest 65 */ 66 EVENT_BETWEEN_APPS1(0x0406), 67 68 /** 69 * Test: ContextHubSimpleGeneralNanoAppTests[SendEvent] 70 */ 71 SEND_EVENT(0x0407), 72 73 /** 74 * Test: ContextHubSimpleGeneralNanoAppTests[BasicAccelerometer] 75 */ 76 BASIC_ACCELEROMETER(0x0408), 77 78 /** 79 * Test: ContextHubSimpleGeneralNanoAppTests[BasicInstantMotionDetect] 80 */ 81 BASIC_INSTANT_MOTION_DETECT(0x0409), 82 83 /** 84 * Test: ContextHubSimpleGeneralNanoAppTests[BasicStationaryDetect] 85 */ 86 BASIC_STATIONARY_DETECT(0x040A), 87 88 /** 89 * Test: ContextHubSimpleGeneralNanoAppTests[BasicGyroscope] 90 */ 91 BASIC_GYROSCOPE(0x040B), 92 93 /** 94 * Test: ContextHubSimpleGeneralNanoAppTests[BasicMagnetometer] 95 */ 96 BASIC_MAGNETOMETER(0x040C), 97 98 /** 99 * Test: ContextHubSimpleGeneralNanoAppTests[BasicBarometer] 100 */ 101 BASIC_BAROMETER(0x040D), 102 103 /** 104 * Test: ContextHubSimpleGeneralNanoAppTests[BasicLightSensor] 105 */ 106 BASIC_LIGHT_SENSOR(0x040E), 107 108 /** 109 * Test: ContextHubSimpleGeneralNanoAppTests[BasicProximity] 110 */ 111 BASIC_PROXIMITY(0x040F), 112 113 /** 114 * Test: ContextHubSimpleGeneralNanoAppTests[VersionConsistency] 115 */ 116 VERSION_CONSISTENCY(0x0410), 117 118 /** 119 * Test: ContextHubSimpleGeneralNanoAppTests[LoggingConsistency] 120 */ 121 LOGGING_CONSISTENCY(0x0411), 122 123 /** 124 * Test: ContextHubSendMessageToHostNanoAppTest 125 */ 126 SEND_MESSAGE_TO_HOST(0x0412), 127 128 /** 129 * Test: ContextHubSimpleGeneralNanoAppTests[TimerSet] 130 */ 131 TIMER_SET(0x0413), 132 133 /** 134 * Test: ContextHubSimpleGeneralNanoAppTests[TimerCancel] 135 */ 136 TIMER_CANCEL(0x0414), 137 138 /** 139 * Test: ContextHubSimpleGeneralNanoAppTests[TimerStress] 140 */ 141 TIMER_STRESS(0x0415), 142 143 /** 144 * Test: ContextHubSimpleGeneralNanoAppTests[SendEventStress] 145 */ 146 SEND_EVENT_STRESS(0x0416), 147 148 /** 149 * Test: ContextHubSimpleGeneralNanoAppTests[HeapExhaustionStability] 150 */ 151 HEAP_EXHAUSTION_STABILITY(0x0417), 152 153 /** 154 * Test: ContextHubSimpleGeneralNanoAppTests[GnssCapabilities] 155 */ 156 GNSS_CAPABILITIES(0x0418), 157 158 /** 159 * Test: ContextHubSimpleGeneralNanoAppTests[WifiCapabilities] 160 */ 161 WIFI_CAPABILITIES(0x0419), 162 163 /** 164 * Test: ContextHubSimpleGeneralNanoAppTests[WwanCapabilities] 165 */ 166 WWAN_CAPABILITIES(0x041A), 167 168 /** 169 * Test: ContextHubSimpleGeneralNanoAppTests[SensorInfoTest] 170 */ 171 SENSOR_INFO(0x041B), 172 173 /** 174 * Test: ContextHubSimpleGeneralNanoAppTests[WwanCellInfo] 175 */ 176 WWAN_CELL_INFO(0x041C), 177 178 /** 179 * Test: ContextHubEstimatedHostTimeTest 180 */ 181 ESTIMATED_HOST_TIME(0x041D), 182 183 /** 184 * Test: ContextHubNanoAppInfoByIdTests[NanoappInfoByAppId] 185 */ 186 NANOAPP_INFO_BY_APP_ID(0x041E), 187 188 /** 189 * Test: ContextHubNanoAppInfoByIdTests[NanoappInfoByInstanceId] 190 */ 191 NANOAPP_INFO_BY_INSTANCE_ID(0x041F), 192 193 /** 194 * Test: ContextHubNanoAppInfoEventsTest (Performer) 195 */ 196 NANO_APP_INFO_EVENTS_PERFORMER(0x0420), 197 198 /** 199 * Test: ContextHubNanoAppInfoEventsTest (Observer) 200 */ 201 NANO_APP_INFO_EVENTS_OBSERVER(0x0421), 202 203 /** 204 * Test: ContextHubSimpleGeneralNanoAppTests[BasicAudioTest] 205 */ 206 BASIC_AUDIO_TEST(0x0422), 207 208 /** 209 * Test: ContextHubSimpleGeneralNanoAppTests[HostAwakeSuspend] 210 */ 211 HOST_AWAKE_SUSPEND(0x0423), 212 213 /** 214 * Test: ContextHubSimpleGeneralNanoAppTests[BasicGnssTest] 215 */ 216 BASIC_GNSS_TEST(0x0424), 217 218 /** 219 * Test: ContextHubSimpleGeneralNanoAppTests[BasicWifiTest] 220 */ 221 BASIC_WIFI_TEST(0x0425), 222 223 /** 224 * Test: ContextHubSimpleGeneralNanoAppTests[BasicSensorFlushAsyncTest] 225 */ 226 BASIC_SENSOR_FLUSH_ASYNC_TEST(0x0426), 227 228 /** 229 * Test: ContextHubSimpleGeneralNanoAppTests[BasicBleTest] 230 */ 231 BASIC_BLE_TEST(0x0427); 232 233 private final int mValue; TestNames(int value)234 TestNames(int value) { 235 this.mValue = value; 236 } 237 238 /** 239 * Get the integer value for this TestNames. 240 * 241 * This is very efficient, O(1). 242 * 243 * @return integer value 244 */ asInt()245 public int asInt() { 246 return mValue; 247 } 248 } 249 250 /** 251 * Messages types which are sent between Nanoapps and the Java Host testing 252 * code. 253 */ 254 public enum MessageType { 255 /** 256 * Value which should never be used. 257 * 258 * This type should never be sent by Host or Nanoapp code. 259 */ 260 INVALID_MESSAGE_TYPE(0x0400), 261 262 /** 263 * Test has completed in success. 264 * 265 * Upon receiving this message type, the infrastructure considers 266 * the test a success and concludes testing. 267 * 268 * This type should only be sent by the Nanoapp code. 269 */ 270 SUCCESS(0x0401), 271 272 /** 273 * Test has failed. 274 * 275 * Upon receiving this message type, the infrastructure considers 276 * the test to be a failure, and concludes testing. The presumption 277 * is that the failure is due to an issue in the CHRE implementation 278 * and/or Context Hub HAL implementation. 279 * 280 * This type should only be sent by the Nanoapp code. 281 */ 282 FAILURE(0x0402), 283 284 /** 285 * Test has failed due to an issue within the testing framework. 286 * 287 * Upon receiving this message type, the infrastructure considers 288 * the test to be a failure, and concludes testing. The presumption 289 * is that the failure is due to an issue in the test itself, or 290 * the testing framework code, and that the CHRE and/or Context Hub HAL 291 * implementations may not have any issues. 292 * 293 * This type should only be sent by the Nanoapp code. 294 */ 295 INTERNAL_FAILURE(0x0403), 296 297 /** 298 * Test is being skipped because it is not relevant. 299 * 300 * Upon receiving this message type, the infrastructure considers 301 * the test to be "skipped". That is, this test is not considered 302 * relevant, and shouldn't considered a failure, but it never 303 * executed. 304 * 305 * This type should only be send by the Nanoapp code. 306 */ 307 SKIPPED(0x0404), 308 309 /** 310 * A generic message indicating that the test should continue. 311 * 312 * The meaning of this generic message depends on the specific test. 313 * In general, it means something along the lines of "The test is 314 * successful thus far, please proceed to the next stage." 315 * 316 * This type can be sent by the Host or Nanoapp code. 317 */ 318 CONTINUE(0x0405), 319 320 /** 321 * A message type to be used to test sending messages through the ContextHubClient. 322 * 323 * This message type should be used only for tests under the ContextHubServiceTestBase 324 * framework. 325 */ 326 SERVICE_MESSAGE(0x0406); 327 328 private final int mValue; MessageType(int value)329 MessageType(int value) { 330 this.mValue = value; 331 } 332 333 /** 334 * Get the integer value for this message type. 335 * 336 * This is very efficient, O(1). 337 * 338 * @return integer value 339 */ asInt()340 public int asInt() { 341 return mValue; 342 } 343 344 /** 345 * Get the MessageType for a given integer value. 346 * 347 * This method will abort the running test if the given value does 348 * not correspond to any MessageType. 349 * 350 * This is inefficient: O(N). 351 * 352 * @param value The value we're finding the MessageType for. 353 * @param errorMessage In the case 'value' does not match any 354 * MessageType, our test failure message will include this. 355 * @return The matching MessageType. 356 */ fromInt(int value, String errorMessage)357 public static MessageType fromInt(int value, String errorMessage) { 358 for (MessageType type : MessageType.values()) { 359 if (value == type.asInt()) { 360 return type; 361 } 362 } 363 364 Assert.fail("Unknown MessageType (" + value + ") from " 365 + errorMessage); 366 // Will never get here. 367 return MessageType.INVALID_MESSAGE_TYPE; 368 } 369 } 370 } 371