зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1135022 - Extend UrlClassifier ChunkSet test with stress test. r=francois
MozReview-Commit-ID: LMbINiQpxLR --HG-- extra : rebase_source : cc29fd5c78e40a45166ade722c79caa0d53f1c4b
This commit is contained in:
Родитель
29777e1dc5
Коммит
8b190b9241
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <set>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ChunkSet.h"
|
||||
|
@ -89,6 +90,131 @@ TEST(UrlClassifierChunkSet, Merge)
|
|||
ASSERT_FALSE(chunkSet.Has(19));
|
||||
}
|
||||
|
||||
TEST(UrlClassifierChunkSet, Merge2)
|
||||
{
|
||||
static int testVals[] = {2, 1, 5, 6, 8, 7, 14, 10, 12, 13};
|
||||
static int mergeVals[] = {9, 3, 4, 20, 14, 16};
|
||||
static int mergeVals2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||
|
||||
mozilla::safebrowsing::ChunkSet chunkSet;
|
||||
mozilla::safebrowsing::ChunkSet mergeSet;
|
||||
mozilla::safebrowsing::ChunkSet mergeSet2;
|
||||
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(testVals); i++) {
|
||||
chunkSet.Set(testVals[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(mergeVals); i++) {
|
||||
mergeSet.Set(mergeVals[i]);
|
||||
}
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(mergeVals2); i++) {
|
||||
mergeSet2.Set(mergeVals2[i]);
|
||||
}
|
||||
|
||||
chunkSet.Merge(mergeSet);
|
||||
chunkSet.Merge(mergeSet2);
|
||||
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(testVals); i++) {
|
||||
ASSERT_TRUE(chunkSet.Has(testVals[i]));
|
||||
}
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(mergeVals); i++) {
|
||||
ASSERT_TRUE(chunkSet.Has(mergeVals[i]));
|
||||
}
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(mergeVals2); i++) {
|
||||
ASSERT_TRUE(chunkSet.Has(mergeVals2[i]));
|
||||
}
|
||||
|
||||
ASSERT_FALSE(chunkSet.Has(15));
|
||||
ASSERT_FALSE(chunkSet.Has(17));
|
||||
ASSERT_FALSE(chunkSet.Has(18));
|
||||
ASSERT_FALSE(chunkSet.Has(19));
|
||||
}
|
||||
|
||||
TEST(UrlClassifierChunkSet, Stress)
|
||||
{
|
||||
mozilla::safebrowsing::ChunkSet chunkSet;
|
||||
mozilla::safebrowsing::ChunkSet mergeSet;
|
||||
std::set<int> refSet;
|
||||
std::set<int> refMergeSet;
|
||||
static const int TEST_ITERS = 7000;
|
||||
static const int REMOVE_ITERS = 3000;
|
||||
static const int TEST_RANGE = 10000;
|
||||
|
||||
// Construction by Set
|
||||
for (int i = 0; i < TEST_ITERS; i++) {
|
||||
int chunk = rand() % TEST_RANGE;
|
||||
chunkSet.Set(chunk);
|
||||
refSet.insert(chunk);
|
||||
}
|
||||
|
||||
// Same elements as reference set
|
||||
for (auto it = refSet.begin(); it != refSet.end(); ++it) {
|
||||
ASSERT_TRUE(chunkSet.Has(*it));
|
||||
}
|
||||
|
||||
// Hole punching via Remove
|
||||
for (int i = 0; i < REMOVE_ITERS; i++) {
|
||||
int chunk = rand() % TEST_RANGE;
|
||||
mozilla::safebrowsing::ChunkSet helpChunk;
|
||||
helpChunk.Set(chunk);
|
||||
|
||||
chunkSet.Remove(helpChunk);
|
||||
refSet.erase(chunk);
|
||||
|
||||
ASSERT_FALSE(chunkSet.Has(chunk));
|
||||
}
|
||||
|
||||
// Should have chunks present in reference set
|
||||
// Should not have chunks absent in reference set
|
||||
for (int it = 0; it < TEST_RANGE; ++it) {
|
||||
auto found = refSet.find(it);
|
||||
if (chunkSet.Has(it)) {
|
||||
ASSERT_FALSE(found == refSet.end());
|
||||
} else {
|
||||
ASSERT_TRUE(found == refSet.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Construct set to merge with
|
||||
for (int i = 0; i < TEST_ITERS; i++) {
|
||||
int chunk = rand() % TEST_RANGE;
|
||||
mergeSet.Set(chunk);
|
||||
refMergeSet.insert(chunk);
|
||||
}
|
||||
|
||||
// Merge set constructed correctly
|
||||
for (auto it = refMergeSet.begin(); it != refMergeSet.end(); ++it) {
|
||||
ASSERT_TRUE(mergeSet.Has(*it));
|
||||
}
|
||||
|
||||
mozilla::safebrowsing::ChunkSet origSet;
|
||||
origSet = chunkSet;
|
||||
|
||||
chunkSet.Merge(mergeSet);
|
||||
refSet.insert(refMergeSet.begin(), refMergeSet.end());
|
||||
|
||||
// Check for presence of elements from both source
|
||||
// Should not have chunks absent in reference set
|
||||
for (int it = 0; it < TEST_RANGE; ++it) {
|
||||
auto found = refSet.find(it);
|
||||
if (chunkSet.Has(it)) {
|
||||
ASSERT_FALSE(found == refSet.end());
|
||||
} else {
|
||||
ASSERT_TRUE(found == refSet.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Unmerge
|
||||
chunkSet.Remove(origSet);
|
||||
for (int it = 0; it < TEST_RANGE; ++it) {
|
||||
if (origSet.Has(it)) {
|
||||
ASSERT_FALSE(chunkSet.Has(it));
|
||||
} else if (mergeSet.Has(it)) {
|
||||
ASSERT_TRUE(chunkSet.Has(it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UrlClassifierChunkSet, RemoveClear)
|
||||
{
|
||||
static int testVals[] = {2, 1, 5, 6, 8, 7, 14, 10, 12, 13};
|
||||
|
|
Загрузка…
Ссылка в новой задаче