1 /* 2 * Copyright (C) 2018 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 <chre/util/nanoapp/log.h> 18 #include <shared/send_message.h> 19 #include <shared/test_success_marker.h> 20 21 #define LOG_TAG "[SuccessMarkerTest]" 22 23 namespace nanoapp_testing { 24 TestSuccessMarker(uint32_t numStages)25TestSuccessMarker::TestSuccessMarker(uint32_t numStages) { 26 if (numStages > 32) { 27 sendFatalFailureToHost( 28 "Total number of stage should be less than 33, got %d", &numStages); 29 } 30 mAllFinished = (UINT64_C(1) << numStages) - 1; 31 } 32 markStage(uint32_t stage)33void TestSuccessMarker::markStage(uint32_t stage) { 34 uint32_t finishedBit = (1 << stage); 35 if ((mAllFinished & finishedBit) == 0) { 36 sendFatalFailureToHost("markSuccess invalid stage", &stage); 37 } 38 if ((mFinishedBitmask & finishedBit) == 0) { 39 LOGD("Stage %" PRIu32 " succeeded", stage); 40 mFinishedBitmask |= finishedBit; 41 } 42 } 43 isAllFinished()44bool TestSuccessMarker::isAllFinished() { 45 return (mFinishedBitmask == mAllFinished); 46 } 47 isStageMarked(uint32_t stage)48bool TestSuccessMarker::isStageMarked(uint32_t stage) { 49 bool marked = false; 50 if (stage <= 32) { 51 uint32_t finishedBit = (1 << stage); 52 marked = ((mFinishedBitmask & finishedBit) != 0); 53 } 54 return marked; 55 } 56 markStageAndSuccessOnFinish(uint32_t stage)57void TestSuccessMarker::markStageAndSuccessOnFinish(uint32_t stage) { 58 if (!isStageMarked(stage)) { 59 markStage(stage); 60 if (isAllFinished()) { 61 sendSuccessToHost(); 62 } 63 } 64 } 65 66 } // namespace nanoapp_testing 67