• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         private final int mValue;
TestNames(int value)229         TestNames(int value) {
230             this.mValue = value;
231         }
232 
233         /**
234          * Get the integer value for this TestNames.
235          *
236          * This is very efficient, O(1).
237          *
238          * @return integer value
239          */
asInt()240         public int asInt() {
241             return mValue;
242         }
243     }
244 
245     /**
246      * Messages types which are sent between Nanoapps and the Java Host testing
247      * code.
248      */
249     public enum MessageType {
250         /**
251          * Value which should never be used.
252          *
253          * This type should never be sent by Host or Nanoapp code.
254          */
255         INVALID_MESSAGE_TYPE(0x0400),
256 
257         /**
258          * Test has completed in success.
259          *
260          * Upon receiving this message type, the infrastructure considers
261          * the test a success and concludes testing.
262          *
263          * This type should only be sent by the Nanoapp code.
264          */
265         SUCCESS(0x0401),
266 
267         /**
268          * Test has failed.
269          *
270          * Upon receiving this message type, the infrastructure considers
271          * the test to be a failure, and concludes testing.  The presumption
272          * is that the failure is due to an issue in the CHRE implementation
273          * and/or Context Hub HAL implementation.
274          *
275          * This type should only be sent by the Nanoapp code.
276          */
277         FAILURE(0x0402),
278 
279         /**
280          * Test has failed due to an issue within the testing framework.
281          *
282          * Upon receiving this message type, the infrastructure considers
283          * the test to be a failure, and concludes testing.  The presumption
284          * is that the failure is due to an issue in the test itself, or
285          * the testing framework code, and that the CHRE and/or Context Hub HAL
286          * implementations may not have any issues.
287          *
288          * This type should only be sent by the Nanoapp code.
289          */
290         INTERNAL_FAILURE(0x0403),
291 
292         /**
293          * Test is being skipped because it is not relevant.
294          *
295          * Upon receiving this message type, the infrastructure considers
296          * the test to be "skipped".  That is, this test is not considered
297          * relevant, and shouldn't considered a failure, but it never
298          * executed.
299          *
300          * This type should only be send by the Nanoapp code.
301          */
302         SKIPPED(0x0404),
303 
304         /**
305          * A generic message indicating that the test should continue.
306          *
307          * The meaning of this generic message depends on the specific test.
308          * In general, it means something along the lines of "The test is
309          * successful thus far, please proceed to the next stage."
310          *
311          * This type can be sent by the Host or Nanoapp code.
312          */
313         CONTINUE(0x0405),
314 
315         /**
316          * A message type to be used to test sending messages through the ContextHubClient.
317          *
318          * This message type should be used only for tests under the ContextHubServiceTestBase
319          * framework.
320          */
321         SERVICE_MESSAGE(0x0406);
322 
323         private final int mValue;
MessageType(int value)324         MessageType(int value) {
325             this.mValue = value;
326         }
327 
328         /**
329          * Get the integer value for this message type.
330          *
331          * This is very efficient, O(1).
332          *
333          * @return integer value
334          */
asInt()335         public int asInt() {
336             return mValue;
337         }
338 
339         /**
340          * Get the MessageType for a given integer value.
341          *
342          * This method will abort the running test if the given value does
343          * not correspond to any MessageType.
344          *
345          * This is inefficient: O(N).
346          *
347          * @param value  The value we're finding the MessageType for.
348          * @param errorMessage  In the case 'value' does not match any
349          *     MessageType, our test failure message will include this.
350          * @return The matching MessageType.
351          */
fromInt(int value, String errorMessage)352         public static MessageType fromInt(int value, String errorMessage) {
353             for (MessageType type : MessageType.values()) {
354                 if (value == type.asInt()) {
355                     return type;
356                 }
357             }
358 
359             Assert.fail("Unknown MessageType (" + value + ") from "
360                         + errorMessage);
361             // Will never get here.
362             return MessageType.INVALID_MESSAGE_TYPE;
363         }
364     }
365 }
366