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 #ifndef _GTS_NANOAPPS_SHARED_TEST_SUCCESS_MARKER_H_
18 #define _GTS_NANOAPPS_SHARED_TEST_SUCCESS_MARKER_H_
19 
20 #include <cinttypes>
21 
22 namespace nanoapp_testing {
23 
24 /**
25  * A class which marks the success of each test stage.
26  * Sends success to host, when all test stages are marked.
27  */
28 class TestSuccessMarker {
29  public:
30   /**
31    * @param numStages The total number of test stages (must be < 33)
32    */
33   TestSuccessMarker(uint32_t numStages);
34 
35   /**
36    * Sends fatal failure to host, if a bad stage passed in.
37    * Marks the bit of a stage to 1.
38    *
39    * @param stage test stage index
40    */
41   void markStage(uint32_t stage);
42 
43   /**
44    * Marks success of a stage.
45    * Sends success to host if all stages are finished.
46    *
47    * @param stage test stage index
48    */
49   void markStageAndSuccessOnFinish(uint32_t stage);
50 
51   /**
52    * @return true if all stages are done, false otherwise
53    */
54   bool isAllFinished();
55 
56   /**
57    * @param stage test stage index
58    * @return true if the stage has been marked, false otherwise
59    */
60   bool isStageMarked(uint32_t stage);
61 
62  private:
63   //! Flag to denote all test stages are finished.
64   uint32_t mAllFinished;
65 
66   //! Used to mark which stage has been finished.
67   uint32_t mFinishedBitmask = 0;
68 };
69 
70 }  // namespace nanoapp_testing
71 
72 #endif  // _GTS_NANOAPPS_SHARED_TEST_SUCCESS_MARKER_H_
73