Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | package com.android.tradefed.cluster; |
| 17 | |
| 18 | import org.json.JSONException; |
| 19 | import org.json.JSONObject; |
| 20 | |
| 21 | /** |
| 22 | * A class to store status of a test group. |
| 23 | * |
| 24 | * <p>A test group corresponds to a group of test cases reported under a same test run name. |
| 25 | */ |
| 26 | public class TestGroupStatus { |
| 27 | |
| 28 | private String mName; |
| 29 | private int mTotalTestCount; |
| 30 | private int mCompletedTestCount; |
| 31 | private int mFailedTestCount; |
Daniel Peykov | 0cb492a | 2019-12-13 10:49:35 -0800 | [diff] [blame] | 32 | private int mPassedTestCount; |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 33 | private boolean mIsComplete; |
| 34 | private long mElapsedTime; |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 35 | |
| 36 | public TestGroupStatus( |
| 37 | final String name, |
| 38 | final int totalTestCount, |
| 39 | final int completedTestCount, |
| 40 | final int failedTestCount, |
Daniel Peykov | 0cb492a | 2019-12-13 10:49:35 -0800 | [diff] [blame] | 41 | final int passedTestCount, |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 42 | final boolean isComplete, |
Moon Kim | d15525e | 2020-04-28 16:49:10 -0700 | [diff] [blame] | 43 | final long elapsedTime) { |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 44 | mName = name; |
| 45 | mTotalTestCount = totalTestCount; |
| 46 | mCompletedTestCount = completedTestCount; |
| 47 | mFailedTestCount = failedTestCount; |
Daniel Peykov | 0cb492a | 2019-12-13 10:49:35 -0800 | [diff] [blame] | 48 | mPassedTestCount = passedTestCount; |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 49 | mIsComplete = isComplete; |
| 50 | mElapsedTime = elapsedTime; |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public String getName() { |
| 54 | return mName; |
| 55 | } |
| 56 | |
| 57 | public int getTotalTestCount() { |
| 58 | return mTotalTestCount; |
| 59 | } |
| 60 | |
| 61 | public int getCompletedTestCount() { |
| 62 | return mCompletedTestCount; |
| 63 | } |
| 64 | |
| 65 | public int getFailedTestCount() { |
| 66 | return mFailedTestCount; |
| 67 | } |
| 68 | |
Daniel Peykov | 0cb492a | 2019-12-13 10:49:35 -0800 | [diff] [blame] | 69 | public int getPassedTestCount() { |
| 70 | return mPassedTestCount; |
| 71 | } |
| 72 | |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 73 | public boolean isComplete() { |
| 74 | return mIsComplete; |
| 75 | } |
| 76 | |
| 77 | public long getElapsedTime() { |
| 78 | return mElapsedTime; |
| 79 | } |
| 80 | |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 81 | public JSONObject toJSON() throws JSONException { |
| 82 | final JSONObject json = new JSONObject(); |
| 83 | json.put("name", mName); |
| 84 | json.put("total_test_count", mTotalTestCount); |
| 85 | json.put("completed_test_count", mCompletedTestCount); |
| 86 | json.put("failed_test_count", mFailedTestCount); |
Daniel Peykov | 0cb492a | 2019-12-13 10:49:35 -0800 | [diff] [blame] | 87 | json.put("passed_test_count", mPassedTestCount); |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 88 | json.put("is_complete", mIsComplete); |
| 89 | json.put("elapsed_time", mElapsedTime); |
Di Qian | 38c02a7 | 2019-11-18 19:14:07 -0800 | [diff] [blame] | 90 | return json; |
| 91 | } |
| 92 | } |