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 #ifndef _GTS_NANOAPPS_GENERAL_TEST_TEST_H_ 18 #define _GTS_NANOAPPS_GENERAL_TEST_TEST_H_ 19 20 #include <shared/send_message.h> 21 22 #include <chre.h> 23 24 namespace general_test { 25 26 /** 27 * Abstract base for all test cases. 28 */ 29 class Test { 30 public: 31 Test(uint32_t minSupportedVersion); ~Test()32 virtual ~Test() {} 33 34 void testHandleEvent(uint32_t senderInstanceId, uint16_t eventType, 35 const void *eventData); 36 37 void testSetUp(uint32_t messageSize, const void *message); 38 39 protected: 40 /** 41 * Report a test-ending error due to an unexpectedEvent. 42 * 43 * @param eventType The event type 44 * @returns Never. This method aborts execution. 45 */ 46 static void unexpectedEvent(uint16_t eventType); 47 48 /** 49 * Get the message data sent from the host, after performing sanity checks. 50 * 51 * The method centralizes a number of common sanity checks that tests 52 * will perform in taking the given CHRE event data and extracting out 53 * the raw data payload sent by the host. This method is still useful 54 * when no message data is expected from the host, as we'll still 55 * perform the sanity checks. 56 * 57 * This method will end the test in failure if any of the following happen: 58 * o 'senderInstanceId' != CHRE_INSTANCE_ID 59 * o 'eventType' != CHRE_EVENT_MESSAGE_FROM_HOST 60 * o 'eventData'->reservedMessageType != expectedMessageType 61 * o 'eventData'->messageSize != expectedMessageSize 62 * 63 * @param senderInstanceId From handleEvent() 64 * @param eventType From handleEvent() 65 * @param eventData From handleEvent() 66 * @param expectedMessageType The expected 'reservedMessageType' field 67 * when 'eventData' is seen as a chreMessageFromHostData. 68 * @param expectedMessageSize The expected 'messageSize' field 69 * when 'eventData' is seen as a chreMessageFromHostData. 70 * @returns 'eventData'->message, assuming all the sanity checks pass. 71 */ 72 static const void *getMessageDataFromHostEvent( 73 uint32_t senderInstanceId, uint16_t eventType, const void* eventData, 74 nanoapp_testing::MessageType expectedMessageType, 75 uint32_t expectedMessageSize); 76 77 virtual void handleEvent(uint32_t senderInstanceId, uint16_t eventType, 78 const void* eventData) = 0; 79 virtual void setUp(uint32_t messageSize, const void *message) = 0; 80 81 /** 82 * The platform reported CHRE API version. 83 * 84 * Nanoapps may use this to determine what version they are running 85 * on and perform any version specific behaviours. 86 */ 87 const uint32_t mApiVersion; 88 89 private: 90 /** 91 * Is the nanoapp supported by the platform reported CHRE API version. 92 * 93 * Nanoapps specify the minimum CHRE API version required during 94 * construction. If it is at least the version that is being reported 95 * by the platform then mIsSupported will be true. Else, the nanoapp 96 * will skip the test. 97 */ 98 const bool mIsSupported; 99 }; 100 101 } // namespace general_test 102 103 104 #endif // _GTS_NANOAPPS_GENERAL_TEST_TEST_H_ 105