aboutsummaryrefslogtreecommitdiff
path: root/db/skiplist_test.cu
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-01-08 21:44:12 +0800
committerKunoiSayami <[email protected]>2022-01-08 21:44:12 +0800
commit215a297b19f72f8ce7fb2e217c0266220678c8b2 (patch)
tree42426531e9eadc74f27298cca42b4a87bfdb8791 /db/skiplist_test.cu
parentf596c6fdb36b1c499a51037bb230ffad47ee1e7e (diff)
test(skiplist): Add iter checker
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'db/skiplist_test.cu')
-rw-r--r--db/skiplist_test.cu35
1 files changed, 28 insertions, 7 deletions
diff --git a/db/skiplist_test.cu b/db/skiplist_test.cu
index 1827ab7..512c6f7 100644
--- a/db/skiplist_test.cu
+++ b/db/skiplist_test.cu
@@ -407,13 +407,14 @@ __global__ void init(Arena ** pArena, SkipList<Key, Comparator> ** pSkipList) {
printf("init3\n");
}
-constexpr size_t SKIPLIST_TEST_SIZE = 100;
+constexpr size_t SKIPLIST_TEST_SIZE = 10000;
constexpr size_t TEST_STEP = SKIPLIST_TEST_SIZE / 10;
__global__ void testParallel(SkipList<Key, Comparator> * skipList, Key * keys) {
unsigned int start = threadIdx.x;
printf("start: %u\n", start);
for (unsigned i = start * TEST_STEP; i < (start + 1) * TEST_STEP; i++) {
+ //printf("%u %02u %lu\n", start, i, keys[i]);
//printf("key: %lu\n", keys[i]);
skipList->Insert(keys[i]);
}
@@ -421,6 +422,19 @@ __global__ void testParallel(SkipList<Key, Comparator> * skipList, Key * keys) {
}
+__global__ void test_keys_is_sort(SkipList<Key, Comparator> * skiplist, const Key * sorted_keys) {
+ SkipList<Key, Comparator>::Iterator iter(skiplist);
+
+ iter.SeekToFirst();
+
+ for (unsigned i = 0; i < SKIPLIST_TEST_SIZE ; i++ ) {
+ printf("%lu %lu\n", iter.key(), sorted_keys[i]);
+ assert(iter.key() == sorted_keys[i]);
+ iter.Next();
+ }
+ assert(!iter.Valid());
+}
+
void host_insert_test() {
//Key * keys;
//SkipList<Key, Comparator> list(cmp, &arena);
@@ -428,7 +442,7 @@ void host_insert_test() {
for (int i = 0; i < 1000; i++) {
keys[i] = .Next();
}*/
- Key * keys = new Key[SKIPLIST_TEST_SIZE];
+ Key * keys = new Key[SKIPLIST_TEST_SIZE], * sorted_keys = new Key[SKIPLIST_TEST_SIZE];
Arena ** pArena;
SkipList<Key, Comparator> ** skipList;
std::set<Key> k;
@@ -456,10 +470,17 @@ void host_insert_test() {
//printf("%ld\n", tmp);
}
+/* for (int i = 0; i< SKIPLIST_TEST_SIZE; i++) {
+ keys[i] = i;
+ }*/
+
+ memcpy(sorted_keys, keys, SKIPLIST_TEST_SIZE * sizeof(Key));
cudaMemcpy(device_keys, keys, SKIPLIST_TEST_SIZE * sizeof(Key), cudaMemcpyHostToDevice);
+ std::sort(sorted_keys, &sorted_keys[SKIPLIST_TEST_SIZE - 1]);
+
dim3 gridSize(1, 1);
- dim3 blockSize(10, 1);
+ dim3 blockSize(1, 1);
init<<<1, 1>>>(pArena, skipList);
//sleep(5);
@@ -467,8 +488,10 @@ void host_insert_test() {
//insert_skiplist<<<gridSize, blockSize>>>(skipList, device_rnd);
testParallel<<<gridSize, blockSize>>>(*skipList, device_keys);
- //cudaDeviceSynchronize();
+ cudaDeviceSynchronize();
+ cudaMemcpy(device_keys, sorted_keys, SKIPLIST_TEST_SIZE * sizeof(Key), cudaMemcpyHostToDevice);
+ test_keys_is_sort<<<1, 1>>>(*skipList, device_keys);
//insert_and_lookup<<<gridSize, blockSize>>>(skipList);
cudaDeviceSynchronize();
cudaFree(device_keys);
@@ -592,7 +615,5 @@ TEST(SkipTest, Concurrent5) { RunConcurrent(5); }
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- int i = RUN_ALL_TESTS();
- sleep(1);
- return i;
+ return RUN_ALL_TESTS();
}