• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 <stdio.h>
18 #include <stdlib.h>
19 #include <time.h>
20 #include <unistd.h>
21 
22 #include <gtest/gtest.h>
23 #define LOG_TAG "VtsSelfTestFlakyTest"
24 #include <log/log.h>
25 
26 class VtsSelfTestFlakyTest : public ::testing::Test {
27  public:
SetUp()28   virtual void SetUp() override {
29     struct timeval time;
30     gettimeofday(&time, NULL);
31 
32     srand((time.tv_sec * 1000) + (time.tv_usec / 1000));
33   }
34 
TearDown()35   virtual void TearDown() override {}
36 };
37 
38 /**
39  * Always passing.
40  */
TEST_F(VtsSelfTestFlakyTest,TestAlwaysPassing1)41 TEST_F(VtsSelfTestFlakyTest, TestAlwaysPassing1) {
42   printf("PASS (with 100%% chance)\n");
43 }
44 
TEST_F(VtsSelfTestFlakyTest,TestAlwaysPassing2)45 TEST_F(VtsSelfTestFlakyTest, TestAlwaysPassing2) {
46   printf("PASS (with 100%% chance)\n");
47 }
48 
49 /**
50  * Fails with 50% of chance.
51  */
TEST_F(VtsSelfTestFlakyTest,TestFlaky1)52 TEST_F(VtsSelfTestFlakyTest, TestFlaky1) {
53   int number = abs(rand());
54   printf("number: %d\n", number);
55   ASSERT_TRUE((number % 2) == 0);
56 }
57 
TEST_F(VtsSelfTestFlakyTest,TestFlaky2)58 TEST_F(VtsSelfTestFlakyTest, TestFlaky2) {
59   int number = abs(rand());
60   printf("number: %d\n", number);
61   ASSERT_TRUE((number % 2) == 0);
62 }
63 
TEST_F(VtsSelfTestFlakyTest,TestFlaky3)64 TEST_F(VtsSelfTestFlakyTest, TestFlaky3) {
65   int number = abs(rand());
66   printf("number: %d\n", number);
67   ASSERT_TRUE((number % 2) == 0);
68 }
69 
TEST_F(VtsSelfTestFlakyTest,TestFlaky4)70 TEST_F(VtsSelfTestFlakyTest, TestFlaky4) {
71   int number = abs(rand());
72   printf("number: %d\n", number);
73   ASSERT_TRUE((number % 2) == 0);
74 }
75 
TEST_F(VtsSelfTestFlakyTest,TestFlaky5)76 TEST_F(VtsSelfTestFlakyTest, TestFlaky5) {
77   int number = abs(rand());
78   printf("number: %d\n", number);
79   ASSERT_TRUE((number % 2) == 0);
80 }
81 
main(int argc,char ** argv)82 int main(int argc, char **argv) {
83   ::testing::InitGoogleTest(&argc, argv);
84   return RUN_ALL_TESTS();
85 }
86