summaryrefslogtreecommitdiffstats
path: root/src/test/librgw_file_gp.cc
diff options
context:
space:
mode:
authorMatt Benjamin <mbenjamin@redhat.com>2015-10-26 03:33:54 +0100
committerMatt Benjamin <mbenjamin@redhat.com>2016-02-12 18:05:05 +0100
commit1254f34f5c423290829140607733c53ff7e9f8b9 (patch)
treef3cc91e3b20a747e4d9de7718b36d1d2cb69221a /src/test/librgw_file_gp.cc
parentxxHash: add as submodule (diff)
downloadceph-1254f34f5c423290829140607733c53ff7e9f8b9.tar.xz
ceph-1254f34f5c423290829140607733c53ff7e9f8b9.zip
librgw: add ZPage/ZPageSet abstraction (gp unit tests)
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
Diffstat (limited to 'src/test/librgw_file_gp.cc')
-rw-r--r--src/test/librgw_file_gp.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/test/librgw_file_gp.cc b/src/test/librgw_file_gp.cc
index 958d79a7c08..068c10bbc93 100644
--- a/src/test/librgw_file_gp.cc
+++ b/src/test/librgw_file_gp.cc
@@ -15,6 +15,10 @@
#include <stdint.h>
#include <tuple>
#include <iostream>
+#include <vector>
+#include <map>
+#include <random>
+#include "xxhash.h"
#include "include/rados/librgw.h"
#include "include/rados/rgw_file.h"
@@ -42,6 +46,77 @@ namespace {
struct rgw_file_handle *fh = nullptr;
+ std::uniform_int_distribution<uint8_t> uint_dist;
+ std::mt19937 rng;
+
+ struct ZPage
+ {
+ char data[65536];
+ uint64_t cksum;
+ }; /* ZPage */
+
+ struct ZPageSet
+ {
+ std::vector<ZPage*> pages;
+ struct iovec* iovs;
+
+ ZPageSet(int n) {
+ pages.reserve(n);
+ iovs = (struct iovec*) calloc(n, sizeof(struct iovec));
+ for (int page_ix = 0; page_ix < n; ++page_ix) {
+ ZPage* p = new ZPage();
+ for (int data_ix = 0; data_ix < 65536; ++data_ix) {
+ p->data[data_ix] = uint_dist(rng);
+ } // data_ix
+ p->cksum = XXH64(p->data, 65536, 8675309);
+ pages.emplace_back(p);
+ // and iovs
+ struct iovec* iov = &iovs[page_ix];
+ iov->iov_base = p->data;
+ iov->iov_len = 65536;
+ } // page_ix
+ }
+
+ int size() { return pages.size(); }
+
+ struct iovec* get_iovs() { return iovs; }
+
+ bool operator==(const ZPageSet& rhs) {
+ int n = size();
+ for (int page_ix = 0; page_ix < n; ++page_ix) {
+ ZPage* p1 = pages[page_ix];
+ ZPage* p2 = rhs.pages[page_ix];
+ if (p1->cksum != p2->cksum)
+ return false;
+ }
+ return true;
+ }
+
+ void cksum() {
+ int n = size();
+ for (int page_ix = 0; page_ix < n; ++page_ix) {
+ ZPage* p = pages[page_ix];
+ p->cksum = XXH64(p->data, 65536, 8675309);
+ }
+ }
+
+ void reset_iovs() { // VOP_READ and VOP_WRITE update
+ int n = size();
+ for (int page_ix = 0; page_ix < n; ++page_ix) {
+ ZPage* p = pages[page_ix];
+ struct iovec* iov = &iovs[page_ix];
+ iov->iov_base = p->data;
+ iov->iov_len = 65536;
+ }
+ }
+
+ ~ZPageSet() {
+ for (int ix = 0; ix < pages.size(); ++ix)
+ delete pages[ix];
+ free(iovs);
+ }
+ }; /* ZPageSet */
+
struct {
int argc;
char **argv;