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