src/mem/cache/tags/dueling.test.cc
/** Test winner selection with multiple different threshold configurations. */
Test winner selection with multiple different threshold configurations.
Test winner selection with multiple different threshold configurations .
TEST_P(DuelingMonitorTest, WinnerSelection)
{
    SatCounter32 expected_selector(numBits);
    expected_selector.saturate();
    expected_selector >>= 1;
    int team_true_index = -1;
    int team_false_index = -1;
    int no_sample_index = -1;
    for (int index = 0; index < entries.size(); index++) {
        bool team;
        if (entries[index].isSample(1ULL << monitor_id, team)) {
            if (team) {
                team_true_index = index;
            } else {
                team_false_index = index;
            }
        } else {
            no_sample_index = index;
        }
    }
    ASSERT_TRUE(team_true_index >= 0);
    ASSERT_TRUE(team_false_index >= 0);
    bool current_winner = monitor->getWinner();
    double threshold = current_winner ? lowThreshold : highThreshold;
    for (; expected_selector.calcSaturation() < 1.0;
        expected_selector++) {
        ASSERT_EQ(expected_selector.calcSaturation() >= threshold,
            monitor->getWinner());
        monitor->sample(&entries[team_true_index]);
    }
    current_winner = monitor->getWinner();
    ASSERT_TRUE(current_winner);
    if (no_sample_index >= 0) {
        for (int i = 0; i < 200; i++) {
            monitor->sample(&entries[no_sample_index]);
        }
        ASSERT_EQ(current_winner, monitor->getWinner());
    }
    threshold = lowThreshold;
    for (; expected_selector.calcSaturation() > 0.0;
        expected_selector--) {
        ASSERT_EQ(expected_selector.calcSaturation() >= threshold,
            monitor->getWinner());
        monitor->sample(&entries[team_false_index]);
    }
    current_winner = monitor->getWinner();
    ASSERT_FALSE(current_winner);
    if (no_sample_index >= 0) {
        for (int i = 0; i < 200; i++) {
            monitor->sample(&entries[no_sample_index]);
        }
        ASSERT_EQ(current_winner, monitor->getWinner());
    }
}
TEST_P ( DuelingMonitorTest , WinnerSelection ) { SatCounter32 expected_selector ( numBits ) ; expected_selector . saturate ( ) ; expected_selector >>= 1 ; int team_true_index = -1 ; int team_false_index = -1 ; int no_sample_index = -1 ; for ( int index = 0 ; index < entries . size ( ) ; index ++ ) { bool team ; if ( entries [ index ] . isSample ( 1ULL << monitor_id , team ) ) { if ( team ) { team_true_index = index ; } else { team_false_index = index ; } } else { no_sample_index = index ; } } ASSERT_TRUE ( team_true_index >= 0 ) ; ASSERT_TRUE ( team_false_index >= 0 ) ; bool current_winner = monitor -> getWinner ( ) ; double threshold = current_winner ? lowThreshold : highThreshold ; for ( ; expected_selector . calcSaturation ( ) < 1.0 ; expected_selector ++ ) { ASSERT_EQ ( expected_selector . calcSaturation ( ) >= threshold , monitor -> getWinner ( ) ) ; monitor -> sample ( & entries [ team_true_index ] ) ; } current_winner = monitor -> getWinner ( ) ; ASSERT_TRUE ( current_winner ) ; if ( no_sample_index >= 0 ) { for ( int i = 0 ; i < 200 ; i ++ ) { monitor -> sample ( & entries [ no_sample_index ] ) ; } ASSERT_EQ ( current_winner , monitor -> getWinner ( ) ) ; } threshold = lowThreshold ; for ( ; expected_selector . calcSaturation ( ) > 0.0 ; expected_selector -- ) { ASSERT_EQ ( expected_selector . calcSaturation ( ) >= threshold , monitor -> getWinner ( ) ) ; monitor -> sample ( & entries [ team_false_index ] ) ; } current_winner = monitor -> getWinner ( ) ; ASSERT_FALSE ( current_winner ) ; if ( no_sample_index >= 0 ) { for ( int i = 0 ; i < 200 ; i ++ ) { monitor -> sample ( & entries [ no_sample_index ] ) ; } ASSERT_EQ ( current_winner , monitor -> getWinner ( ) ) ; } }
Test winner selection with multiple different threshold configurations.
Test winner selection with multiple different threshold configurations .
// Initialize entries, and save a pointer to a sample of each // team, and one no sample // Duel for team true only. If the monitor starts predicting false // the threshold to use is the higher one. Otherwise, we should // start expecting true to be the winner, and thus we use the // low threshold // Duel for no sample. Should not change winner // Duel for team false only. Now that we know that team true // is winning, the low threshold must be passed in order to // make team false win the duel // Duel for no sample. Should not change winner