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_TIMER_CANCEL_TEST_H_ 18 #define _GTS_NANOAPPS_GENERAL_TEST_TIMER_CANCEL_TEST_H_ 19 20 #include <general_test/test.h> 21 #include <chre.h> 22 23 namespace general_test { 24 25 /** 26 * Checks that chreTimerCancel() works by trying various usages. 27 * 28 * Simple Protocol. 29 */ 30 class TimerCancelTest : public Test { 31 public: 32 TimerCancelTest(); 33 34 protected: 35 void handleEvent(uint32_t senderInstanceId, uint16_t eventType, 36 const void* eventData) override; 37 void setUp(uint32_t messageSize, const void *message) override; 38 39 private: 40 struct Stage { 41 uint32_t stage; 42 uint32_t timerId; 43 bool oneShot; 44 bool expectCallback; 45 46 // Leave timerId invalid. StageStage47 Stage(uint32_t stage_, bool oneShot_, bool expectCallback_) : 48 stage(stage_), timerId(CHRE_TIMER_INVALID), oneShot(oneShot_), 49 expectCallback(expectCallback_) {} 50 }; 51 52 bool mInMethod; 53 54 static constexpr size_t kStageCount = 4; 55 Stage mStages[kStageCount]; 56 57 static constexpr uint32_t kAllFinished = (1 << kStageCount) - 1; 58 uint32_t mFinishedBitmask; 59 60 void startStages(); 61 void handleStageEvent(Stage *stage); 62 void markSuccess(uint32_t stage); 63 }; 64 65 } // namespace general_test 66 67 68 #endif // _GTS_NANOAPPS_GENERAL_TEST_TIMER_CANCEL_TEST_H_ 69