< prev index next >

test/hotspot/gtest/gc/shenandoah/test_shenandoahNumberSeq.cpp

Print this page
*** 1,8 ***
  /*
!  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
-  * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2022, Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 32,47 ***
  
  #include "unittest.hpp"
  
  class ShenandoahNumberSeqTest: public ::testing::Test {
   protected:
!   HdrSeq seq;
  };
  
  class BasicShenandoahNumberSeqTest: public ShenandoahNumberSeqTest {
!  protected:
-   const double err = 0.5;
    BasicShenandoahNumberSeqTest() {
!     seq.add(0);
!     seq.add(1);
!     seq.add(10);
      for (int i = 0; i < 7; i++) {
!       seq.add(100);
      }
!     std::cout << " p0 = " << seq.percentile(0);
!     std::cout << " p10 = " << seq.percentile(10);
!     std::cout << " p20 = " << seq.percentile(20);
!     std::cout << " p30 = " << seq.percentile(30);
!     std::cout << " p50 = " << seq.percentile(50);
!     std::cout << " p80 = " << seq.percentile(80);
!     std::cout << " p90 = " << seq.percentile(90);
!     std::cout << " p100 = " << seq.percentile(100);
    }
  };
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, maximum_test) {
!   EXPECT_EQ(seq.maximum(), 100);
  }
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, minimum_test) {
!   EXPECT_EQ(0, seq.percentile(0));
  }
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, percentile_test) {
!   EXPECT_NEAR(0, seq.percentile(10), err);
!   EXPECT_NEAR(1, seq.percentile(20), err);
!   EXPECT_NEAR(10, seq.percentile(30), err);
!   EXPECT_NEAR(100, seq.percentile(40), err);
!   EXPECT_NEAR(100, seq.percentile(50), err);
!   EXPECT_NEAR(100, seq.percentile(75), err);
!   EXPECT_NEAR(100, seq.percentile(90), err);
!   EXPECT_NEAR(100, seq.percentile(100), err);
  }
--- 31,107 ---
  
  #include "unittest.hpp"
  
  class ShenandoahNumberSeqTest: public ::testing::Test {
   protected:
!   const double err = 0.5;
+ 
+   HdrSeq seq1;
+   HdrSeq seq2;
+   HdrSeq seq3;
+ 
+   void print() {
+     if (seq1.num() > 0) {
+       print(seq1, "seq1");
+     }
+     if (seq2.num() > 0) {
+       print(seq2, "seq2");
+     }
+     if (seq3.num() > 0) {
+       print(seq3, "seq3");
+     }
+   }
+ 
+   void print(HdrSeq& seq, const char* msg) {
+     std::cout << "[";
+     for (int i = 0; i <= 100; i += 10) {
+       std::cout << "\t" << seq.percentile(i);
+     }
+     std::cout << " ] : " << msg << "\n";
+   }
  };
  
  class BasicShenandoahNumberSeqTest: public ShenandoahNumberSeqTest {
!  public:
    BasicShenandoahNumberSeqTest() {
!     seq1.add(0);
!     seq1.add(1);
!     seq1.add(10);
      for (int i = 0; i < 7; i++) {
!       seq1.add(100);
      }
!     ShenandoahNumberSeqTest::print();
!   }
! };
! 
! class ShenandoahNumberSeqMergeTest: public ShenandoahNumberSeqTest {
!  public:
!   ShenandoahNumberSeqMergeTest() {
!     for (int i = 0; i < 80; i++) {
+       seq1.add(1);
+       seq3.add(1);
+     }
+ 
+     for (int i = 0; i < 20; i++) {
+       seq2.add(100);
+       seq3.add(100);
+     }
+     ShenandoahNumberSeqTest::print();
    }
  };
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, maximum_test) {
!   EXPECT_EQ(seq1.maximum(), 100);
  }
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, minimum_test) {
!   EXPECT_EQ(0, seq1.percentile(0));
  }
  
  TEST_VM_F(BasicShenandoahNumberSeqTest, percentile_test) {
!   EXPECT_NEAR(0, seq1.percentile(10), err);
!   EXPECT_NEAR(1, seq1.percentile(20), err);
!   EXPECT_NEAR(10, seq1.percentile(30), err);
!   EXPECT_NEAR(100, seq1.percentile(40), err);
!   EXPECT_NEAR(100, seq1.percentile(50), err);
!   EXPECT_NEAR(100, seq1.percentile(75), err);
!   EXPECT_NEAR(100, seq1.percentile(90), err);
!   EXPECT_NEAR(100, seq1.percentile(100), err);
+ }
+ 
+ TEST_VM_F(ShenandoahNumberSeqMergeTest, merge_test) {
+   EXPECT_EQ(seq1.num(), 80);
+   EXPECT_EQ(seq2.num(), 20);
+   EXPECT_FALSE(isnan(seq2.davg()));  // Exercise the path; not a nan
+   EXPECT_FALSE(isnan(seq2.dsd()));
+   EXPECT_FALSE(isnan(seq2.dvariance()));
+ 
+   std::cout << "Pre-merge: \n";
+   print();
+   seq1.merge(seq2);    // clears seq1, after merging into seq2
+   std::cout << "Post-merge: \n";
+   print();
+ 
+   EXPECT_EQ(seq1.num(), 0);
+   EXPECT_EQ(seq2.num(), 100);
+   EXPECT_EQ(seq2.num(), seq3.num());
+   EXPECT_TRUE(isnan(seq2.davg()));  // until we fix decayed stats
+   EXPECT_TRUE(isnan(seq2.dvariance()));
+ 
+   EXPECT_EQ(seq2.maximum(), seq3.maximum());
+   EXPECT_EQ(seq2.percentile(0), seq3.percentile(0));
+   for (int i = 0; i <= 100; i += 10) {
+     EXPECT_NEAR(seq2.percentile(i), seq3.percentile(i), err);
+   }
+   EXPECT_NEAR(seq2.avg(), seq3.avg(), err);
+   EXPECT_NEAR(seq2.sd(),  seq3.sd(),  err);
  }
< prev index next >