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 <chre.h> 21 #include <general_test/test.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_), 49 timerId(CHRE_TIMER_INVALID), 50 oneShot(oneShot_), 51 expectCallback(expectCallback_) {} 52 }; 53 54 bool mInMethod; 55 56 static constexpr size_t kStageCount = 4; 57 Stage mStages[kStageCount]; 58 59 static constexpr uint32_t kAllFinished = (1 << kStageCount) - 1; 60 uint32_t mFinishedBitmask; 61 62 void startStages(); 63 void handleStageEvent(Stage *stage); 64 void markSuccess(uint32_t stage); 65 }; 66 67 } // namespace general_test 68 69 #endif // _GTS_NANOAPPS_GENERAL_TEST_TIMER_CANCEL_TEST_H_ 70