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_SET_TEST_H_ 18 #define _GTS_NANOAPPS_GENERAL_TEST_TIMER_SET_TEST_H_ 19 20 #include <general_test/test.h> 21 22 namespace general_test { 23 24 /** 25 * Checks that chreTimerSet() works by trying various timers. 26 * 27 * Simple Protocol. 28 */ 29 class TimerSetTest : public Test { 30 public: 31 TimerSetTest(); 32 ~TimerSetTest(); 33 34 void markSuccess(uint32_t stage); 35 36 protected: 37 void handleEvent(uint32_t senderInstanceId, uint16_t eventType, 38 const void* eventData) override; 39 void setUp(uint32_t messageSize, const void *message) override; 40 41 private: 42 class Stage { 43 public: 44 Stage(uint32_t stage, uint64_t duration, const void *cookie, 45 bool oneShot); 46 void start(); 47 // We take 'test' so we can call markSuccess if appropriate. 48 void processEvent(uint64_t timestamp, TimerSetTest *test); 49 getCookie()50 const void *getCookie() const { return mCookie; } 51 52 private: 53 uint64_t mSetTime; 54 uint64_t mDuration; 55 uint32_t mStage; 56 uint32_t mEventCount; 57 const void *mCookie; 58 bool mOneShot; 59 uint32_t mTimerHandle; 60 }; 61 // In the interest in keeping our static memory usage low (since we 62 // are just one of many, many tests in this nanoapp), we get this 63 // memory from the heap instead of statically declaring an array here. 64 Stage *mStages; 65 static constexpr size_t kStageCount = 6; 66 67 bool mInMethod; 68 static constexpr uint32_t kAllFinished = (1 << kStageCount) - 1; 69 uint32_t mFinishedBitmask; 70 71 void initStages(); 72 Stage *getStageFromCookie(const void *cookie); 73 }; 74 75 } // namespace general_test 76 77 78 #endif // _GTS_NANOAPPS_GENERAL_TEST_TIMER_SET_TEST_H_ 79