#include "runtime.h"
#include "CuTest.h"
#include "common.h"
-#include "ht.h"
+#include "struct.h"
#include "mem.h"
+#include "lwt.h"
#define ASSERT_EQUAL(x, y) CuAssertIntEquals(tc, x, y)
typedef struct worker_data {
int id;
CuTest *tc;
- hash_table_t *ht;
+ hashtable_t *ht;
int *wait;
} worker_data_t;
-int64_t ht_set (hash_table_t *ht, const char *key, uint32_t key_len, int64_t val) {
- return ht_compare_and_set(ht, key, key_len, HT_EXPECT_WHATEVER, val);
+int64_t ht_set (hashtable_t *ht, const char *key, uint32_t key_len, int64_t val) {
+ return ht_compare_and_set(ht, key, key_len, EXPECT_WHATEVER, val);
}
-int64_t ht_add (hash_table_t *ht, const char *key, uint32_t key_len, int64_t val) {
- return ht_compare_and_set(ht, key, key_len, HT_EXPECT_NOT_EXISTS, val);
+int64_t ht_add (hashtable_t *ht, const char *key, uint32_t key_len, int64_t val) {
+ return ht_compare_and_set(ht, key, key_len, EXPECT_DOES_NOT_EXIST, val);
}
-int64_t ht_replace (hash_table_t *ht, const char *key, uint32_t key_len, int64_t val) {
- return ht_compare_and_set(ht, key, key_len, HT_EXPECT_EXISTS, val);
+int64_t ht_replace (hashtable_t *ht, const char *key, uint32_t key_len, int64_t val) {
+ return ht_compare_and_set(ht, key, key_len, EXPECT_EXISTS, val);
}
// Test some basic stuff; add a few keys, remove a few keys
void basic_test (CuTest* tc) {
- hash_table_t *ht = ht_alloc();
+ hashtable_t *ht = ht_alloc();
ASSERT_EQUAL( 0, ht_count(ht) );
ASSERT_EQUAL( DOES_NOT_EXIST, ht_add(ht,"a",2,10) );
void *simple_worker (void *arg) {
worker_data_t *wd = (worker_data_t *)arg;
- hash_table_t *ht = wd->ht;
+ hashtable_t *ht = wd->ht;
CuTest* tc = wd->tc;
uint64_t d = wd->id;
int iters = 1000000;
SYNC_ADD(wd->wait, -1);
do { } while (*((volatile worker_data_t *)wd)->wait); // wait for all workers to be ready
- int i, j;
- for (j = 0; j < 10; ++j) {
- for (i = d; i < iters; i+=2) {
- char key[8];
+ for (int j = 0; j < 10; ++j) {
+ for (int i = d; i < iters; i+=2) {
+ char key[10];
sprintf(key, "k%u", i);
- ASSERT_EQUAL( DOES_NOT_EXIST, ht_add(ht, key, strlen(key)+1, d+1) );
+ TRACE("t0", "test ht_add() iteration (%llu, %llu)", j, i);
+ CuAssertIntEquals_Msg(tc, key, DOES_NOT_EXIST, ht_add(ht, key, strlen(key)+1, d+1) );
}
- for (i = d; i < iters; i+=2) {
- char key[8];
+ for (int i = d; i < iters; i+=2) {
+ char key[10];
sprintf(key, "k%u", i);
- ASSERT_EQUAL( d+1, ht_remove(ht, key, strlen(key)+1) );
+ TRACE("t0", "test ht_remove() iteration (%llu, %llu)", j, i);
+ CuAssertIntEquals_Msg(tc, key, d+1, ht_remove(ht, key, strlen(key)+1) );
}
rcu_update();
}
pthread_t thread[2];
worker_data_t wd[2];
int wait = 2;
- hash_table_t *ht = ht_alloc();
+ hashtable_t *ht = ht_alloc();
// In 2 threads, add & remove even & odd elements concurrently
int i;
void *inserter_worker (void *arg) {
//pthread_t thread[NUM_THREADS];
- //hash_table_t *ht = ht_alloc();
+ //hashtable_t *ht = ht_alloc();
return NULL;
}
int main (void) {
nbd_init();
- //lwt_set_trace_level("h4");
+ //lwt_set_trace_level("h0");
// Create and run test suite
CuString *output = CuStringNew();