• 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 
17 #include <general_test/version_sanity_test.h>
18 
19 #include <cstddef>
20 
21 #include <shared/send_message.h>
22 
23 #include <chre.h>
24 
25 using nanoapp_testing::sendFatalFailureToHost;
26 using nanoapp_testing::sendSuccessToHost;
27 
28 namespace general_test {
29 
VersionSanityTest()30 VersionSanityTest::VersionSanityTest() : Test(CHRE_API_VERSION_1_0) {}
31 
setUp(uint32_t messageSize,const void *)32 void VersionSanityTest::setUp(uint32_t messageSize,
33                               const void * /* message */) {
34   if (messageSize != 0) {
35     sendFatalFailureToHost(
36         "VersionSanity message expects 0 additional bytes, got ", &messageSize);
37   }
38 
39   if (mApiVersion < CHRE_API_VERSION_1_0) {
40     sendFatalFailureToHost("API version less than 1.0", &mApiVersion);
41   }
42   if ((mApiVersion & UINT32_C(0xFFFF)) != 0) {
43     sendFatalFailureToHost("API version has two LSB set", &mApiVersion);
44   }
45   uint32_t platformVersion = chreGetVersion();
46   constexpr uint32_t kMajorMinorMask = UINT32_C(0xFFFF0000);
47   // Both mApiVersion and platformVersion refer to what the CHRE was
48   // built against, so they must agree in major and minor version.
49   if ((platformVersion & kMajorMinorMask) != (mApiVersion & kMajorMinorMask)) {
50     sendFatalFailureToHost("API and platform version mismatch",
51                            &platformVersion);
52   }
53 
54   // Confirm that our app (CHRE_API_VERSION) and CHRE (mApiVersion) were
55   // both compiled against the same major version.  They're allowed to
56   // differ in minor version.
57   constexpr uint32_t kMajorMask = UINT32_C(0xFF000000);
58   if ((mApiVersion & kMajorMask) != (CHRE_API_VERSION & kMajorMask)) {
59     uint32_t appVersion = CHRE_API_VERSION;
60     sendFatalFailureToHost("App built against different major version",
61                            &appVersion);
62   }
63 
64   uint64_t platformId = chreGetPlatformId();
65   if ((platformId == UINT64_C(0)) || (platformId == UINT64_C(-1))) {
66     sendFatalFailureToHost("Bogus platform ID");
67   }
68   // TODO(b/30077401): We should send the Platform ID back to the Host, and
69   //     have the Host confirm this is the Platform ID we used for loading
70   //     the nanoapp.
71 
72   sendSuccessToHost();
73 }
74 
handleEvent(uint32_t senderInstanceId,uint16_t eventType,const void * eventData)75 void VersionSanityTest::handleEvent(uint32_t senderInstanceId,
76                                     uint16_t eventType, const void *eventData) {
77   unexpectedEvent(eventType);
78 }
79 
80 }  // namespace general_test
81