[sheepdog] [PATCH] tests/unit: unit test failed because interfaces were changed.
Ruoyu
liangry at ucweb.com
Tue Apr 15 05:37:27 CEST 2014
This patch only let 'make check' workable, does not add any cases.
Signed-off-by: Ruoyu <liangry at ucweb.com>
---
tests/unit/sheep/test_hash.c | 94 +++++++++++++++++++++++++++++++++++++++++++-
tests/unit/sheep/test_vdi.c | 6 +--
2 files changed, 96 insertions(+), 4 deletions(-)
diff --git a/tests/unit/sheep/test_hash.c b/tests/unit/sheep/test_hash.c
index 26386b9..04c4079 100644
--- a/tests/unit/sheep/test_hash.c
+++ b/tests/unit/sheep/test_hash.c
@@ -1,7 +1,10 @@
#include <check.h>
#include <math.h>
-#include "md.c"
+#include "compiler.h"
+#include "sheepdog_proto.h"
+#include "internal_proto.h"
+#include "sheep.h"
/* Constant values for the chi-squared test */
#define DATA_SIZE 1024
@@ -9,6 +12,95 @@
#define CV 16.919 /* a critical value (p=0.05, df=9) */
#define EXP ((double)DATA_SIZE / (DF + 1)) /* an expected value */
+#define MD_VDISK_SIZE ((uint64_t)1*1024*1024*1024) /* 1G */
+
+struct disk {
+ struct rb_node rb;
+ char path[PATH_MAX];
+ uint64_t space;
+};
+
+struct vdisk {
+ struct rb_node rb;
+ struct disk *disk;
+ uint64_t hash;
+};
+
+struct md {
+ struct rb_root vroot;
+ struct rb_root root;
+ struct sd_rw_lock lock;
+ uint64_t space;
+ uint32_t nr_disks;
+};
+
+static struct md md = {
+ .vroot = RB_ROOT,
+ .root = RB_ROOT,
+ .lock = SD_RW_LOCK_INITIALIZER,
+};
+
+static inline int vdisk_number(const struct disk *disk)
+{
+ return DIV_ROUND_UP(disk->space, MD_VDISK_SIZE);
+}
+
+static int vdisk_cmp(const struct vdisk *d1, const struct vdisk *d2)
+{
+ return intcmp(d1->hash, d2->hash);
+}
+
+static struct vdisk *vdisk_insert(struct vdisk *new)
+{
+ return rb_insert(&md.vroot, new, rb, vdisk_cmp);
+}
+
+/* If v1_hash < hval <= v2_hash, then oid is resident in v2 */
+static struct vdisk *hval_to_vdisk(uint64_t hval)
+{
+ struct vdisk dummy = { .hash = hval };
+
+ return rb_nsearch(&md.vroot, &dummy, rb, vdisk_cmp);
+}
+
+static void create_vdisks(struct disk *disk)
+{
+ uint64_t hval = sd_hash(disk->path, strlen(disk->path));
+ int nr = vdisk_number(disk);
+
+ for (int i = 0; i < nr; i++) {
+ struct vdisk *v = xmalloc(sizeof(*v));
+
+ hval = sd_hash_next(hval);
+ v->hash = hval;
+ v->disk = disk;
+ if (unlikely(vdisk_insert(v)))
+ panic("vdisk hash collison");
+ }
+}
+
+static inline void vdisk_free(struct vdisk *v)
+{
+ rb_erase(&v->rb, &md.vroot);
+ free(v);
+}
+
+static void remove_vdisks(const struct disk *disk)
+{
+ uint64_t hval = sd_hash(disk->path, strlen(disk->path));
+ int nr = vdisk_number(disk);
+
+ for (int i = 0; i < nr; i++) {
+ struct vdisk *v;
+
+ hval = sd_hash_next(hval);
+ v = hval_to_vdisk(hval);
+ assert(v->hash == hval);
+
+ vdisk_free(v);
+ }
+}
+
/* uniform distribution */
const double uniform_dist[DF + 1] = {
0,
diff --git a/tests/unit/sheep/test_vdi.c b/tests/unit/sheep/test_vdi.c
index f55dcf4..2f8946b 100644
--- a/tests/unit/sheep/test_vdi.c
+++ b/tests/unit/sheep/test_vdi.c
@@ -17,9 +17,9 @@
START_TEST(test_vdi)
{
- add_vdi_state(1, 1, true);
- add_vdi_state(2, 1, true);
- add_vdi_state(3, 2, false);
+ add_vdi_state(1, 1, true, 0);
+ add_vdi_state(2, 1, true, 0);
+ add_vdi_state(3, 2, false, 0);
ck_assert_int_eq(get_vdi_copy_number(1), 1);
ck_assert_int_eq(get_vdi_copy_number(2), 1);
--
1.8.3.2
More information about the sheepdog
mailing list