From 9aaa81fd08689bb78cd698d94490d363a62eb392 Mon Sep 17 00:00:00 2001 From: Yen Fu Chen Date: Mon, 13 Mar 2023 11:12:41 +0800 Subject: [PATCH 1/2] Add adaptive replacement cache Current basic block management consumes a significant amount of memory, which leads to unnecessary waste due to frequent map allocation and release. Adaptive Replacement Cache (ARC) is a page replacement algorithm with better performance than least recently used (LRU). After the translated blocks are handled by ARC, better memory usage and hit rates can be achieved by keeping track of frequently used and recently used pages, as well as a recent eviction history for both. According to the cache information obtained while running CoreMark, the cache hit rate of ARC can reach over 99%. --- .clang-format | 4 + src/cache.c | 393 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/cache.h | 40 +++++ src/common.h | 25 ++++ 4 files changed, 462 insertions(+) create mode 100644 src/cache.c create mode 100644 src/cache.h diff --git a/.clang-format b/.clang-format index 9705d27f..b05ebd0d 100644 --- a/.clang-format +++ b/.clang-format @@ -13,3 +13,7 @@ UseTab: Never IndentWidth: 4 BreakBeforeBraces: Linux AccessModifierOffset: -4 +ForEachMacros: + - list_for_each_entry + - list_for_each_entry_safe + - hlist_for_each_entry diff --git a/src/cache.c b/src/cache.c new file mode 100644 index 00000000..30b44cf2 --- /dev/null +++ b/src/cache.c @@ -0,0 +1,393 @@ +/* + * rv32emu is freely redistributable under the MIT License. See the file + * "LICENSE" for information on usage and redistribution of this file. + */ + +#include +#include +#include +#include +#include + +#include "cache.h" + +#define MIN(a, b) ((a < b) ? a : b) +#define GOLDEN_RATIO_32 0x61C88647 +#define HASH(val) \ + (((val) * (GOLDEN_RATIO_32)) >> (32 - (cache_size_bits))) & (cache_size - 1) + +static uint32_t cache_size, cache_size_bits; + +/* + * Adaptive Replacement Cache (ARC) improves the fundamental LRU strategy + * by dividing the cache into two lists, T1 and T2. list T1 is for LRU + * strategy and list T2 is for LFU strategy. Moreover, it keeps two ghost + * lists, B1 and B2, with replaced entries from the LRU list going into B1 + * and the LFU list going into B2. + * + * Based on B1 and B2, ARC will modify the size of T1 and T2. When a cache + * hit occurs in B1, it indicates that T1's capacity is too little, therefore + * we increase T1's size while decreasing T2. But, if the cache hit occurs in + * B2, we would increase the size of T2 and decrease the size of T1. + */ +typedef enum { + LRU_list, + LFU_list, + LRU_ghost_list, + LFU_ghost_list, + N_CACHE_LIST_TYPES +} cache_list_t; + +struct list_head { + struct list_head *prev, *next; +}; + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +/* + * list maintains four cache lists T1, T2, B1, and B2. + * ht_list maintains hashtable and improves the performance of cache searching. + */ +typedef struct { + void *value; + uint32_t key; + cache_list_t type; + struct list_head list; + struct hlist_node ht_list; +} arc_entry_t; + +typedef struct { + struct hlist_head *ht_list_head; +} hashtable_t; + +typedef struct cache { + struct list_head *lists[N_CACHE_LIST_TYPES]; + uint32_t list_size[N_CACHE_LIST_TYPES]; + hashtable_t *map; + uint32_t capacity; + uint32_t lru_capacity; +} cache_t; + +static inline void INIT_LIST_HEAD(struct list_head *head) +{ + head->next = head; + head->prev = head; +} + +static inline void list_add(struct list_head *node, struct list_head *head) +{ + struct list_head *next = head->next; + + next->prev = node; + node->next = next; + node->prev = head; + head->next = node; +} + +static inline void list_del(struct list_head *node) +{ + struct list_head *next = node->next; + struct list_head *prev = node->prev; + + next->prev = prev; + prev->next = next; +} + +static inline void list_del_init(struct list_head *node) +{ + list_del(node); + INIT_LIST_HEAD(node); +} + +#define list_entry(node, type, member) container_of(node, type, member) + +#define list_last_entry(head, type, member) \ + list_entry((head)->prev, type, member) + +#ifdef __HAVE_TYPEOF +#define list_for_each_entry_safe(entry, safe, head, member) \ + for (entry = list_entry((head)->next, __typeof__(*entry), member), \ + safe = list_entry(entry->member.next, __typeof__(*entry), member); \ + &entry->member != (head); entry = safe, \ + safe = list_entry(safe->member.next, __typeof__(*entry), member)) +#else +#define list_for_each_entry_safe(entry, safe, head, member, type) \ + for (entry = list_entry((head)->next, type, member), \ + safe = list_entry(entry->member.next, type, member); \ + &entry->member != (head); \ + entry = safe, safe = list_entry(safe->member.next, type, member)) +#endif + +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) + +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int hlist_empty(const struct hlist_head *h) +{ + return !h->first; +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + + h->first = n; + n->pprev = &h->first; +} + +static inline bool hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + + *pprev = next; + if (next) + next->pprev = pprev; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (hlist_unhashed(n)) + return; + hlist_del(n); + INIT_HLIST_NODE(n); +} + +#define hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#ifdef __HAVE_TYPEOF +#define hlist_entry_safe(ptr, type, member) \ + ({ \ + typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) +#else +#define hlist_entry_safe(ptr, type, member) \ + (ptr) ? hlist_entry(ptr, type, member) : NULL +#endif + +#ifdef __HAVE_TYPEOF +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) +#else +#define hlist_for_each_entry(pos, head, member, type) \ + for (pos = hlist_entry_safe((head)->first, type, member); pos; \ + pos = hlist_entry_safe((pos)->member.next, type, member)) +#endif + +cache_t *cache_create(int size_bits) +{ + cache_t *cache = malloc(sizeof(cache_t)); + if (!cache) + return NULL; + cache_size_bits = size_bits; + cache_size = 1 << size_bits; + + for (int i = 0; i < N_CACHE_LIST_TYPES; i++) { + cache->lists[i] = malloc(sizeof(struct list_head)); + INIT_LIST_HEAD(cache->lists[i]); + cache->list_size[i] = 0; + } + + cache->map = malloc(sizeof(hashtable_t)); + if (!cache->map) { + free(cache->lists); + free(cache); + return NULL; + } + cache->map->ht_list_head = malloc(cache_size * sizeof(struct hlist_head)); + if (!cache->map->ht_list_head) { + free(cache->map); + free(cache->lists); + free(cache); + return NULL; + } + for (uint32_t i = 0; i < cache_size; i++) { + INIT_HLIST_HEAD(&cache->map->ht_list_head[i]); + } + + cache->capacity = cache_size; + cache->lru_capacity = cache_size / 2; + return cache; +} + +/* Rules of ARC + * 1. size of LRU_list + size of LFU_list <= c + * 2. size of LRU_list + size of LRU_ghost_list <= c + * 3. size of LFU_list + size of LFU_ghost_list <= 2c + * 4. size of LRU_list + size of LFU_list + size of LRU_ghost_list + size of + * LFU_ghost_list <= 2c + */ +#define CACHE_ASSERT(cache) \ + assert(cache->list_size[LRU_list] + cache->list_size[LFU_list] <= \ + cache->capacity); \ + assert(cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list] <= \ + cache->capacity); \ + assert(cache->list_size[LFU_list] + cache->list_size[LFU_ghost_list] <= \ + 2 * cache->capacity); \ + assert(cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list] + \ + cache->list_size[LFU_list] + \ + cache->list_size[LFU_ghost_list] <= \ + 2 * cache->capacity); + +static inline void move_to_mru(cache_t *cache, + arc_entry_t *entry, + const cache_list_t type) +{ + cache->list_size[entry->type]--; + cache->list_size[type]++; + entry->type = type; + list_del_init(&entry->list); + list_add(&entry->list, cache->lists[type]); +} + +static inline void replace_list(cache_t *cache) +{ + if (cache->list_size[LRU_list] >= cache->lru_capacity) + move_to_mru(cache, + list_last_entry(cache->lists[LRU_list], arc_entry_t, list), + LRU_ghost_list); + else if (cache->list_size[LFU_list] >= + (cache->capacity - cache->lru_capacity)) + move_to_mru(cache, + list_last_entry(cache->lists[LFU_list], arc_entry_t, list), + LFU_ghost_list); +} + +void *cache_get(cache_t *cache, uint32_t key) +{ + if (!cache->capacity || hlist_empty(&cache->map->ht_list_head[HASH(key)])) + return NULL; + + arc_entry_t *entry = NULL; +#ifdef __HAVE_TYPEOF + hlist_for_each_entry (entry, &cache->map->ht_list_head[HASH(key)], ht_list) +#else + hlist_for_each_entry (entry, &cache->map->ht_list_head[HASH(key)], ht_list, + arc_entry_t) +#endif + { + if (entry->key == key) + break; + } + if (!entry || entry->key != key) + return NULL; + /* cache hit in LRU_list */ + if (entry->type == LRU_list) { + replace_list(cache); + move_to_mru(cache, entry, LFU_list); + } + + /* cache hit in LFU_list */ + if (entry->type == LFU_list) + move_to_mru(cache, entry, LFU_list); + + /* cache hit in LRU_ghost_list */ + if (entry->type == LRU_ghost_list) { + cache->lru_capacity = MIN(cache->lru_capacity + 1, cache->capacity); + replace_list(cache); + move_to_mru(cache, entry, LFU_list); + } + + /* cache hit in LFU_ghost_list */ + if (entry->type == LFU_ghost_list) { + cache->lru_capacity = cache->lru_capacity ? cache->lru_capacity - 1 : 0; + replace_list(cache); + move_to_mru(cache, entry, LFU_list); + } + CACHE_ASSERT(cache); + /* return NULL if cache miss */ + return entry->value; +} + +void *cache_put(cache_t *cache, uint32_t key, void *value) +{ + void *delete_value = NULL; + assert(cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list] <= + cache->capacity); + /* Before adding new element to cach, we should check the status + * of cache. + */ + if ((cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list]) == + cache->capacity) { + if (cache->list_size[LRU_list] < cache->capacity) { + arc_entry_t *delete_target = list_last_entry( + cache->lists[LRU_ghost_list], arc_entry_t, list); + list_del_init(&delete_target->list); + hlist_del_init(&delete_target->ht_list); + delete_value = delete_target->value; + free(delete_target); + cache->list_size[LRU_ghost_list]--; + replace_list(cache); + } else { + arc_entry_t *delete_target = + list_last_entry(cache->lists[LRU_list], arc_entry_t, list); + list_del_init(&delete_target->list); + hlist_del_init(&delete_target->ht_list); + delete_value = delete_target->value; + free(delete_target); + cache->list_size[LRU_list]--; + } + } else { + assert(cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list] < + cache->capacity); + uint32_t size = + cache->list_size[LRU_list] + cache->list_size[LRU_ghost_list] + + cache->list_size[LFU_list] + cache->list_size[LFU_ghost_list]; + if (size == cache->capacity * 2) { + arc_entry_t *delete_target = list_last_entry( + cache->lists[LFU_ghost_list], arc_entry_t, list); + list_del_init(&delete_target->list); + hlist_del_init(&delete_target->ht_list); + delete_value = delete_target->value; + free(delete_target); + cache->list_size[LFU_ghost_list]--; + } + replace_list(cache); + } + arc_entry_t *new_entry = malloc(sizeof(arc_entry_t)); + new_entry->key = key; + new_entry->value = value; + new_entry->type = LRU_list; + list_add(&new_entry->list, cache->lists[LRU_list]); + hlist_add_head(&new_entry->ht_list, &cache->map->ht_list_head[HASH(key)]); + cache->list_size[LRU_list]++; + CACHE_ASSERT(cache); + return delete_value; +} + +void cache_free(cache_t *cache, void (*callback)(void *)) +{ + for (int i = 0; i < N_CACHE_LIST_TYPES; i++) { + arc_entry_t *entry, *safe; +#ifdef __HAVE_TYPEOF + list_for_each_entry_safe (entry, safe, cache->lists[i], list) +#else + list_for_each_entry_safe (entry, safe, cache->lists[i], list, + arc_entry_t) +#endif + callback(entry->value); + } + free(cache->map->ht_list_head); + free(cache->map); + free(cache); +} \ No newline at end of file diff --git a/src/cache.h b/src/cache.h new file mode 100644 index 00000000..f8cb7d94 --- /dev/null +++ b/src/cache.h @@ -0,0 +1,40 @@ +/* + * rv32emu is freely redistributable under the MIT License. See the file + * "LICENSE" for information on usage and redistribution of this file. + */ + +#pragma once + +#include + +struct cache; + +/** cache_create - crate a new cache + * @size_bits: cache size is 2^size_bits + * @return: a pointer points to new cache + */ +struct cache *cache_create(int size_bits); + +/** + * cache_get - retrieve the specified entry from the cache + * @cache: a pointer points to target cache + * @key: the key of the specified entry + * @return: the specified entry or NULL + */ +void *cache_get(struct cache *cache, uint32_t key); + +/** + * cache_put - insert a new entry into the cache + * @cache: a pointer points to target cache + * @key: the key of the inserted entry + * @value: the value of the inserted entry + * @return: the replaced entry or NULL + */ +void *cache_put(struct cache *cache, uint32_t key, void *value); + +/** + * cache_free - free a cache + * @cache: a pointer points to target cache + * @callback: a function for freeing cache entry completely + */ +void cache_free(struct cache *cache, void (*callback)(void *)); \ No newline at end of file diff --git a/src/common.h b/src/common.h index e59816f3..bbdd6906 100644 --- a/src/common.h +++ b/src/common.h @@ -49,3 +49,28 @@ #define IIF_0(t, ...) __VA_ARGS__ /* run the 1st parameter */ #define IIF_1(t, ...) t + +#if defined(__GNUC__) || defined(__clang__) +#define __HAVE_TYPEOF 1 +#endif + +/** + * container_of() - Calculate address of object that contains address ptr + * @ptr: pointer to member variable + * @type: type of the structure containing ptr + * @member: name of the member variable in struct @type + * + * Return: @type pointer of object containing ptr + */ +#ifndef container_of +#ifdef __HAVE_TYPEOF +#define container_of(ptr, type, member) \ + __extension__({ \ + const __typeof__(((type *) 0)->member) *__pmember = (ptr); \ + (type *) ((char *) __pmember - offsetof(type, member)); \ + }) +#else +#define container_of(ptr, type, member) \ + ((type *) ((char *) (ptr) - (offsetof(type, member)))) +#endif +#endif \ No newline at end of file From 32cfd329562fcf6fa7853e5c8a54151b93cc7198 Mon Sep 17 00:00:00 2001 From: Yen Fu Chen Date: Mon, 13 Mar 2023 11:27:04 +0800 Subject: [PATCH 2/2] Add cache-test --- .github/workflows/main.yml | 6 +- Makefile | 4 +- mk/tests.mk | 46 + tests/cache/cache-get.expect | 5 + tests/cache/cache-get.in | 6 + tests/cache/cache-lfu-ghost-replace.expect | 259 +++++ tests/cache/cache-lfu-ghost-replace.in | 771 +++++++++++++++ tests/cache/cache-lfu-replace.expect | 515 ++++++++++ tests/cache/cache-lfu-replace.in | 1027 ++++++++++++++++++++ tests/cache/cache-lru-replace.expect | 3 + tests/cache/cache-lru-replace.in | 259 +++++ tests/cache/cache-new.expect | 2 + tests/cache/cache-new.in | 2 + tests/cache/cache-put.expect | 3 + tests/cache/cache-put.in | 259 +++++ tests/cache/test-cache.c | 69 ++ 16 files changed, 3233 insertions(+), 3 deletions(-) create mode 100644 mk/tests.mk create mode 100644 tests/cache/cache-get.expect create mode 100644 tests/cache/cache-get.in create mode 100644 tests/cache/cache-lfu-ghost-replace.expect create mode 100644 tests/cache/cache-lfu-ghost-replace.in create mode 100644 tests/cache/cache-lfu-replace.expect create mode 100644 tests/cache/cache-lfu-replace.in create mode 100644 tests/cache/cache-lru-replace.expect create mode 100644 tests/cache/cache-lru-replace.in create mode 100644 tests/cache/cache-new.expect create mode 100644 tests/cache/cache-new.in create mode 100644 tests/cache/cache-put.expect create mode 100644 tests/cache/cache-put.in create mode 100644 tests/cache/test-cache.c diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d5d3e8b3..f5ba3944 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,10 @@ jobs: sudo apt-get install libsdl2-dev - name: default build run: make - - name: check - run: make check + - name: check + tests + run: | + make check + make tests - name: diverse configurations run: | make distclean ENABLE_COMPUTED_GOTO=0 diff --git a/Makefile b/Makefile index 159be32b..0fd272c0 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,7 @@ OBJS := \ emulate.o \ riscv.o \ elf.o \ + cache.o \ $(OBJS_EXT) \ main.o @@ -109,6 +110,7 @@ $(BIN): $(OBJS) # RISC-V Architecture Tests include mk/riscv-arch-test.mk +include mk/tests.mk CHECK_ELF_FILES := \ hello \ @@ -143,7 +145,7 @@ endif endif clean: - $(RM) $(BIN) $(OBJS) $(deps) + $(RM) $(BIN) $(OBJS) $(deps) $(CACHE_OUT) distclean: clean -$(RM) $(DOOM_DATA) $(QUAKE_DATA) $(RM) -r $(OUT)/id1 diff --git a/mk/tests.mk b/mk/tests.mk new file mode 100644 index 00000000..bd1a9c93 --- /dev/null +++ b/mk/tests.mk @@ -0,0 +1,46 @@ +CACHE_TEST_DIR := tests/cache +CACHE_BUILD_DIR := build/cache +TARGET := test-cache + +CACHE_OBJS := \ + test-cache.o + +CACHE_OBJS := $(addprefix $(CACHE_BUILD_DIR)/, $(CACHE_OBJS)) +OBJS += $(CACHE_OBJS) +deps += $(CACHE_OBJS:%.o=%.o.d) + + +CACHE_CHECK_ELF_FILES := \ + cache-new \ + cache-put \ + cache-get \ + cache-lru-replace \ + cache-lfu-replace \ + cache-lfu-ghost-replace + +CACHE_OUT = $(addprefix $(CACHE_BUILD_DIR)/, $(CACHE_CHECK_ELF_FILES:%=%.out)) + +tests : $(CACHE_OUT) + $(Q)$(foreach e,$(CACHE_CHECK_ELF_FILES),\ + $(PRINTF) "Running $(e) ... "; \ + if cmp $(CACHE_TEST_DIR)/$(e).expect $(CACHE_BUILD_DIR)/$(e).out; then \ + $(call notice, [OK]); \ + else \ + $(PRINTF) "Failed.\n"; \ + exit 1; \ + fi; \ + ) + +$(CACHE_OUT): $(TARGET) + $(Q)$(foreach e,$(CACHE_CHECK_ELF_FILES),\ + $(CACHE_BUILD_DIR)/$(TARGET) $(CACHE_TEST_DIR)/$(e).in > $(CACHE_BUILD_DIR)/$(e).out; \ + ) + +$(TARGET): $(CACHE_OBJS) + $(VECHO) " CC\t$@\n" + $(Q)$(CC) $^ build/cache.o -o $(CACHE_BUILD_DIR)/$(TARGET) + +$(CACHE_BUILD_DIR)/%.o: $(CACHE_TEST_DIR)/%.c + $(VECHO) " CC\t$@\n" + $(Q)mkdir -p $(dir $@) + $(Q)$(CC) -o $@ $(CFLAGS) -I./src -c -MMD -MF $@.d $< \ No newline at end of file diff --git a/tests/cache/cache-get.expect b/tests/cache/cache-get.expect new file mode 100644 index 00000000..3c48e062 --- /dev/null +++ b/tests/cache/cache-get.expect @@ -0,0 +1,5 @@ +NEW CACHE +NULL +NULL +3 +FREE CACHE diff --git a/tests/cache/cache-get.in b/tests/cache/cache-get.in new file mode 100644 index 00000000..e4cac51b --- /dev/null +++ b/tests/cache/cache-get.in @@ -0,0 +1,6 @@ +NEW +GET 1 +GET 2 +PUT 3 3 +GET 3 +FREE \ No newline at end of file diff --git a/tests/cache/cache-lfu-ghost-replace.expect b/tests/cache/cache-lfu-ghost-replace.expect new file mode 100644 index 00000000..b62769b6 --- /dev/null +++ b/tests/cache/cache-lfu-ghost-replace.expect @@ -0,0 +1,259 @@ +NEW CACHE +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +REPLACE 1 +FREE CACHE diff --git a/tests/cache/cache-lfu-ghost-replace.in b/tests/cache/cache-lfu-ghost-replace.in new file mode 100644 index 00000000..733b4d65 --- /dev/null +++ b/tests/cache/cache-lfu-ghost-replace.in @@ -0,0 +1,771 @@ +NEW +PUT 1 1 +PUT 2 2 +PUT 3 3 +PUT 4 4 +PUT 5 5 +PUT 6 6 +PUT 7 7 +PUT 8 8 +PUT 9 9 +PUT 10 10 +PUT 11 11 +PUT 12 12 +PUT 13 13 +PUT 14 14 +PUT 15 15 +PUT 16 16 +PUT 17 17 +PUT 18 18 +PUT 19 19 +PUT 20 20 +PUT 21 21 +PUT 22 22 +PUT 23 23 +PUT 24 24 +PUT 25 25 +PUT 26 26 +PUT 27 27 +PUT 28 28 +PUT 29 29 +PUT 30 30 +PUT 31 31 +PUT 32 32 +PUT 33 33 +PUT 34 34 +PUT 35 35 +PUT 36 36 +PUT 37 37 +PUT 38 38 +PUT 39 39 +PUT 40 40 +PUT 41 41 +PUT 42 42 +PUT 43 43 +PUT 44 44 +PUT 45 45 +PUT 46 46 +PUT 47 47 +PUT 48 48 +PUT 49 49 +PUT 50 50 +PUT 51 51 +PUT 52 52 +PUT 53 53 +PUT 54 54 +PUT 55 55 +PUT 56 56 +PUT 57 57 +PUT 58 58 +PUT 59 59 +PUT 60 60 +PUT 61 61 +PUT 62 62 +PUT 63 63 +PUT 64 64 +PUT 65 65 +PUT 66 66 +PUT 67 67 +PUT 68 68 +PUT 69 69 +PUT 70 70 +PUT 71 71 +PUT 72 72 +PUT 73 73 +PUT 74 74 +PUT 75 75 +PUT 76 76 +PUT 77 77 +PUT 78 78 +PUT 79 79 +PUT 80 80 +PUT 81 81 +PUT 82 82 +PUT 83 83 +PUT 84 84 +PUT 85 85 +PUT 86 86 +PUT 87 87 +PUT 88 88 +PUT 89 89 +PUT 90 90 +PUT 91 91 +PUT 92 92 +PUT 93 93 +PUT 94 94 +PUT 95 95 +PUT 96 96 +PUT 97 97 +PUT 98 98 +PUT 99 99 +PUT 100 100 +PUT 101 101 +PUT 102 102 +PUT 103 103 +PUT 104 104 +PUT 105 105 +PUT 106 106 +PUT 107 107 +PUT 108 108 +PUT 109 109 +PUT 110 110 +PUT 111 111 +PUT 112 112 +PUT 113 113 +PUT 114 114 +PUT 115 115 +PUT 116 116 +PUT 117 117 +PUT 118 118 +PUT 119 119 +PUT 120 120 +PUT 121 121 +PUT 122 122 +PUT 123 123 +PUT 124 124 +PUT 125 125 +PUT 126 126 +PUT 127 127 +PUT 128 128 +PUT 129 129 +PUT 130 130 +PUT 131 131 +PUT 132 132 +PUT 133 133 +PUT 134 134 +PUT 135 135 +PUT 136 136 +PUT 137 137 +PUT 138 138 +PUT 139 139 +PUT 140 140 +PUT 141 141 +PUT 142 142 +PUT 143 143 +PUT 144 144 +PUT 145 145 +PUT 146 146 +PUT 147 147 +PUT 148 148 +PUT 149 149 +PUT 150 150 +PUT 151 151 +PUT 152 152 +PUT 153 153 +PUT 154 154 +PUT 155 155 +PUT 156 156 +PUT 157 157 +PUT 158 158 +PUT 159 159 +PUT 160 160 +PUT 161 161 +PUT 162 162 +PUT 163 163 +PUT 164 164 +PUT 165 165 +PUT 166 166 +PUT 167 167 +PUT 168 168 +PUT 169 169 +PUT 170 170 +PUT 171 171 +PUT 172 172 +PUT 173 173 +PUT 174 174 +PUT 175 175 +PUT 176 176 +PUT 177 177 +PUT 178 178 +PUT 179 179 +PUT 180 180 +PUT 181 181 +PUT 182 182 +PUT 183 183 +PUT 184 184 +PUT 185 185 +PUT 186 186 +PUT 187 187 +PUT 188 188 +PUT 189 189 +PUT 190 190 +PUT 191 191 +PUT 192 192 +PUT 193 193 +PUT 194 194 +PUT 195 195 +PUT 196 196 +PUT 197 197 +PUT 198 198 +PUT 199 199 +PUT 200 200 +PUT 201 201 +PUT 202 202 +PUT 203 203 +PUT 204 204 +PUT 205 205 +PUT 206 206 +PUT 207 207 +PUT 208 208 +PUT 209 209 +PUT 210 210 +PUT 211 211 +PUT 212 212 +PUT 213 213 +PUT 214 214 +PUT 215 215 +PUT 216 216 +PUT 217 217 +PUT 218 218 +PUT 219 219 +PUT 220 220 +PUT 221 221 +PUT 222 222 +PUT 223 223 +PUT 224 224 +PUT 225 225 +PUT 226 226 +PUT 227 227 +PUT 228 228 +PUT 229 229 +PUT 230 230 +PUT 231 231 +PUT 232 232 +PUT 233 233 +PUT 234 234 +PUT 235 235 +PUT 236 236 +PUT 237 237 +PUT 238 238 +PUT 239 239 +PUT 240 240 +PUT 241 241 +PUT 242 242 +PUT 243 243 +PUT 244 244 +PUT 245 245 +PUT 246 246 +PUT 247 247 +PUT 248 248 +PUT 249 249 +PUT 250 250 +PUT 251 251 +PUT 252 252 +PUT 253 253 +PUT 254 254 +PUT 255 255 +PUT 256 256 +GET 1 +GET 2 +GET 3 +GET 4 +GET 5 +GET 6 +GET 7 +GET 8 +GET 9 +GET 10 +GET 11 +GET 12 +GET 13 +GET 14 +GET 15 +GET 16 +GET 17 +GET 18 +GET 19 +GET 20 +GET 21 +GET 22 +GET 23 +GET 24 +GET 25 +GET 26 +GET 27 +GET 28 +GET 29 +GET 30 +GET 31 +GET 32 +GET 33 +GET 34 +GET 35 +GET 36 +GET 37 +GET 38 +GET 39 +GET 40 +GET 41 +GET 42 +GET 43 +GET 44 +GET 45 +GET 46 +GET 47 +GET 48 +GET 49 +GET 50 +GET 51 +GET 52 +GET 53 +GET 54 +GET 55 +GET 56 +GET 57 +GET 58 +GET 59 +GET 60 +GET 61 +GET 62 +GET 63 +GET 64 +GET 65 +GET 66 +GET 67 +GET 68 +GET 69 +GET 70 +GET 71 +GET 72 +GET 73 +GET 74 +GET 75 +GET 76 +GET 77 +GET 78 +GET 79 +GET 80 +GET 81 +GET 82 +GET 83 +GET 84 +GET 85 +GET 86 +GET 87 +GET 88 +GET 89 +GET 90 +GET 91 +GET 92 +GET 93 +GET 94 +GET 95 +GET 96 +GET 97 +GET 98 +GET 99 +GET 100 +GET 101 +GET 102 +GET 103 +GET 104 +GET 105 +GET 106 +GET 107 +GET 108 +GET 109 +GET 110 +GET 111 +GET 112 +GET 113 +GET 114 +GET 115 +GET 116 +GET 117 +GET 118 +GET 119 +GET 120 +GET 121 +GET 122 +GET 123 +GET 124 +GET 125 +GET 126 +GET 127 +GET 128 +GET 129 +GET 130 +GET 131 +GET 132 +GET 133 +GET 134 +GET 135 +GET 136 +GET 137 +GET 138 +GET 139 +GET 140 +GET 141 +GET 142 +GET 143 +GET 144 +GET 145 +GET 146 +GET 147 +GET 148 +GET 149 +GET 150 +GET 151 +GET 152 +GET 153 +GET 154 +GET 155 +GET 156 +GET 157 +GET 158 +GET 159 +GET 160 +GET 161 +GET 162 +GET 163 +GET 164 +GET 165 +GET 166 +GET 167 +GET 168 +GET 169 +GET 170 +GET 171 +GET 172 +GET 173 +GET 174 +GET 175 +GET 176 +GET 177 +GET 178 +GET 179 +GET 180 +GET 181 +GET 182 +GET 183 +GET 184 +GET 185 +GET 186 +GET 187 +GET 188 +GET 189 +GET 190 +GET 191 +GET 192 +GET 193 +GET 194 +GET 195 +GET 196 +GET 197 +GET 198 +GET 199 +GET 200 +GET 201 +GET 202 +GET 203 +GET 204 +GET 205 +GET 206 +GET 207 +GET 208 +GET 209 +GET 210 +GET 211 +GET 212 +GET 213 +GET 214 +GET 215 +GET 216 +GET 217 +GET 218 +GET 219 +GET 220 +GET 221 +GET 222 +GET 223 +GET 224 +GET 225 +GET 226 +GET 227 +GET 228 +GET 229 +GET 230 +GET 231 +GET 232 +GET 233 +GET 234 +GET 235 +GET 236 +GET 237 +GET 238 +GET 239 +GET 240 +GET 241 +GET 242 +GET 243 +GET 244 +GET 245 +GET 246 +GET 247 +GET 248 +GET 249 +GET 250 +GET 251 +GET 252 +GET 253 +GET 254 +GET 255 +GET 256 +PUT 257 257 +PUT 258 258 +PUT 259 259 +PUT 260 260 +PUT 261 261 +PUT 262 262 +PUT 263 263 +PUT 264 264 +PUT 265 265 +PUT 266 266 +PUT 267 267 +PUT 268 268 +PUT 269 269 +PUT 270 270 +PUT 271 271 +PUT 272 272 +PUT 273 273 +PUT 274 274 +PUT 275 275 +PUT 276 276 +PUT 277 277 +PUT 278 278 +PUT 279 279 +PUT 280 280 +PUT 281 281 +PUT 282 282 +PUT 283 283 +PUT 284 284 +PUT 285 285 +PUT 286 286 +PUT 287 287 +PUT 288 288 +PUT 289 289 +PUT 290 290 +PUT 291 291 +PUT 292 292 +PUT 293 293 +PUT 294 294 +PUT 295 295 +PUT 296 296 +PUT 297 297 +PUT 298 298 +PUT 299 299 +PUT 300 300 +PUT 301 301 +PUT 302 302 +PUT 303 303 +PUT 304 304 +PUT 305 305 +PUT 306 306 +PUT 307 307 +PUT 308 308 +PUT 309 309 +PUT 310 310 +PUT 311 311 +PUT 312 312 +PUT 313 313 +PUT 314 314 +PUT 315 315 +PUT 316 316 +PUT 317 317 +PUT 318 318 +PUT 319 319 +PUT 320 320 +PUT 321 321 +PUT 322 322 +PUT 323 323 +PUT 324 324 +PUT 325 325 +PUT 326 326 +PUT 327 327 +PUT 328 328 +PUT 329 329 +PUT 330 330 +PUT 331 331 +PUT 332 332 +PUT 333 333 +PUT 334 334 +PUT 335 335 +PUT 336 336 +PUT 337 337 +PUT 338 338 +PUT 339 339 +PUT 340 340 +PUT 341 341 +PUT 342 342 +PUT 343 343 +PUT 344 344 +PUT 345 345 +PUT 346 346 +PUT 347 347 +PUT 348 348 +PUT 349 349 +PUT 350 350 +PUT 351 351 +PUT 352 352 +PUT 353 353 +PUT 354 354 +PUT 355 355 +PUT 356 356 +PUT 357 357 +PUT 358 358 +PUT 359 359 +PUT 360 360 +PUT 361 361 +PUT 362 362 +PUT 363 363 +PUT 364 364 +PUT 365 365 +PUT 366 366 +PUT 367 367 +PUT 368 368 +PUT 369 369 +PUT 370 370 +PUT 371 371 +PUT 372 372 +PUT 373 373 +PUT 374 374 +PUT 375 375 +PUT 376 376 +PUT 377 377 +PUT 378 378 +PUT 379 379 +PUT 380 380 +PUT 381 381 +PUT 382 382 +PUT 383 383 +PUT 384 384 +PUT 385 358 +PUT 386 386 +PUT 387 387 +PUT 388 388 +PUT 389 389 +PUT 390 390 +PUT 391 391 +PUT 392 392 +PUT 393 393 +PUT 394 394 +PUT 395 395 +PUT 396 396 +PUT 397 397 +PUT 398 398 +PUT 399 399 +PUT 400 400 +PUT 401 401 +PUT 402 402 +PUT 403 403 +PUT 404 404 +PUT 405 405 +PUT 406 406 +PUT 407 407 +PUT 408 408 +PUT 409 409 +PUT 410 410 +PUT 411 411 +PUT 412 412 +PUT 413 413 +PUT 414 414 +PUT 415 415 +PUT 416 416 +PUT 417 417 +PUT 418 418 +PUT 419 419 +PUT 420 420 +PUT 421 421 +PUT 422 422 +PUT 423 423 +PUT 424 424 +PUT 425 425 +PUT 426 426 +PUT 427 427 +PUT 428 428 +PUT 429 429 +PUT 430 430 +PUT 431 431 +PUT 432 432 +PUT 433 433 +PUT 434 434 +PUT 435 435 +PUT 436 436 +PUT 437 437 +PUT 438 438 +PUT 439 439 +PUT 440 440 +PUT 441 441 +PUT 442 442 +PUT 443 443 +PUT 444 444 +PUT 445 445 +PUT 446 446 +PUT 447 447 +PUT 448 448 +PUT 449 449 +PUT 450 450 +PUT 451 451 +PUT 452 452 +PUT 453 453 +PUT 454 454 +PUT 455 455 +PUT 456 456 +PUT 457 457 +PUT 458 458 +PUT 459 459 +PUT 460 460 +PUT 461 461 +PUT 462 462 +PUT 463 463 +PUT 464 464 +PUT 465 465 +PUT 466 466 +PUT 467 467 +PUT 468 468 +PUT 469 469 +PUT 470 470 +PUT 471 471 +PUT 472 472 +PUT 473 473 +PUT 474 474 +PUT 475 475 +PUT 476 476 +PUT 477 477 +PUT 478 478 +PUT 479 479 +PUT 480 480 +PUT 481 481 +PUT 482 482 +PUT 483 483 +PUT 484 484 +PUT 485 485 +PUT 486 486 +PUT 487 487 +PUT 488 488 +PUT 489 489 +PUT 490 490 +PUT 491 491 +PUT 492 492 +PUT 493 493 +PUT 494 494 +PUT 495 495 +PUT 496 496 +PUT 497 497 +PUT 498 498 +PUT 499 499 +PUT 500 500 +PUT 501 501 +PUT 502 502 +PUT 503 503 +PUT 504 504 +PUT 505 505 +PUT 506 506 +PUT 507 507 +PUT 508 508 +PUT 509 509 +PUT 510 510 +PUT 511 511 +PUT 512 512 +PUT 513 513 +FREE \ No newline at end of file diff --git a/tests/cache/cache-lfu-replace.expect b/tests/cache/cache-lfu-replace.expect new file mode 100644 index 00000000..00f32a3f --- /dev/null +++ b/tests/cache/cache-lfu-replace.expect @@ -0,0 +1,515 @@ +NEW CACHE +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 +507 +508 +509 +510 +511 +512 +REPLACE 1 +FREE CACHE diff --git a/tests/cache/cache-lfu-replace.in b/tests/cache/cache-lfu-replace.in new file mode 100644 index 00000000..2fc4c3a8 --- /dev/null +++ b/tests/cache/cache-lfu-replace.in @@ -0,0 +1,1027 @@ +NEW +PUT 1 1 +PUT 2 2 +PUT 3 3 +PUT 4 4 +PUT 5 5 +PUT 6 6 +PUT 7 7 +PUT 8 8 +PUT 9 9 +PUT 10 10 +PUT 11 11 +PUT 12 12 +PUT 13 13 +PUT 14 14 +PUT 15 15 +PUT 16 16 +PUT 17 17 +PUT 18 18 +PUT 19 19 +PUT 20 20 +PUT 21 21 +PUT 22 22 +PUT 23 23 +PUT 24 24 +PUT 25 25 +PUT 26 26 +PUT 27 27 +PUT 28 28 +PUT 29 29 +PUT 30 30 +PUT 31 31 +PUT 32 32 +PUT 33 33 +PUT 34 34 +PUT 35 35 +PUT 36 36 +PUT 37 37 +PUT 38 38 +PUT 39 39 +PUT 40 40 +PUT 41 41 +PUT 42 42 +PUT 43 43 +PUT 44 44 +PUT 45 45 +PUT 46 46 +PUT 47 47 +PUT 48 48 +PUT 49 49 +PUT 50 50 +PUT 51 51 +PUT 52 52 +PUT 53 53 +PUT 54 54 +PUT 55 55 +PUT 56 56 +PUT 57 57 +PUT 58 58 +PUT 59 59 +PUT 60 60 +PUT 61 61 +PUT 62 62 +PUT 63 63 +PUT 64 64 +PUT 65 65 +PUT 66 66 +PUT 67 67 +PUT 68 68 +PUT 69 69 +PUT 70 70 +PUT 71 71 +PUT 72 72 +PUT 73 73 +PUT 74 74 +PUT 75 75 +PUT 76 76 +PUT 77 77 +PUT 78 78 +PUT 79 79 +PUT 80 80 +PUT 81 81 +PUT 82 82 +PUT 83 83 +PUT 84 84 +PUT 85 85 +PUT 86 86 +PUT 87 87 +PUT 88 88 +PUT 89 89 +PUT 90 90 +PUT 91 91 +PUT 92 92 +PUT 93 93 +PUT 94 94 +PUT 95 95 +PUT 96 96 +PUT 97 97 +PUT 98 98 +PUT 99 99 +PUT 100 100 +PUT 101 101 +PUT 102 102 +PUT 103 103 +PUT 104 104 +PUT 105 105 +PUT 106 106 +PUT 107 107 +PUT 108 108 +PUT 109 109 +PUT 110 110 +PUT 111 111 +PUT 112 112 +PUT 113 113 +PUT 114 114 +PUT 115 115 +PUT 116 116 +PUT 117 117 +PUT 118 118 +PUT 119 119 +PUT 120 120 +PUT 121 121 +PUT 122 122 +PUT 123 123 +PUT 124 124 +PUT 125 125 +PUT 126 126 +PUT 127 127 +PUT 128 128 +GET 1 +GET 2 +GET 3 +GET 4 +GET 5 +GET 6 +GET 7 +GET 8 +GET 9 +GET 10 +GET 11 +GET 12 +GET 13 +GET 14 +GET 15 +GET 16 +GET 17 +GET 18 +GET 19 +GET 20 +GET 21 +GET 22 +GET 23 +GET 24 +GET 25 +GET 26 +GET 27 +GET 28 +GET 29 +GET 30 +GET 31 +GET 32 +GET 33 +GET 34 +GET 35 +GET 36 +GET 37 +GET 38 +GET 39 +GET 40 +GET 41 +GET 42 +GET 43 +GET 44 +GET 45 +GET 46 +GET 47 +GET 48 +GET 49 +GET 50 +GET 51 +GET 52 +GET 53 +GET 54 +GET 55 +GET 56 +GET 57 +GET 58 +GET 59 +GET 60 +GET 61 +GET 62 +GET 63 +GET 64 +GET 65 +GET 66 +GET 67 +GET 68 +GET 69 +GET 70 +GET 71 +GET 72 +GET 73 +GET 74 +GET 75 +GET 76 +GET 77 +GET 78 +GET 79 +GET 80 +GET 81 +GET 82 +GET 83 +GET 84 +GET 85 +GET 86 +GET 87 +GET 88 +GET 89 +GET 90 +GET 91 +GET 92 +GET 93 +GET 94 +GET 95 +GET 96 +GET 97 +GET 98 +GET 99 +GET 100 +GET 101 +GET 102 +GET 103 +GET 104 +GET 105 +GET 106 +GET 107 +GET 108 +GET 109 +GET 110 +GET 111 +GET 112 +GET 113 +GET 114 +GET 115 +GET 116 +GET 117 +GET 118 +GET 119 +GET 120 +GET 121 +GET 122 +GET 123 +GET 124 +GET 125 +GET 126 +GET 127 +GET 128 +PUT 129 129 +PUT 130 130 +PUT 131 131 +PUT 132 132 +PUT 133 133 +PUT 134 134 +PUT 135 135 +PUT 136 136 +PUT 137 137 +PUT 138 138 +PUT 139 139 +PUT 140 140 +PUT 141 141 +PUT 142 142 +PUT 143 143 +PUT 144 144 +PUT 145 145 +PUT 146 146 +PUT 147 147 +PUT 148 148 +PUT 149 149 +PUT 150 150 +PUT 151 151 +PUT 152 152 +PUT 153 153 +PUT 154 154 +PUT 155 155 +PUT 156 156 +PUT 157 157 +PUT 158 158 +PUT 159 159 +PUT 160 160 +PUT 161 161 +PUT 162 162 +PUT 163 163 +PUT 164 164 +PUT 165 165 +PUT 166 166 +PUT 167 167 +PUT 168 168 +PUT 169 169 +PUT 170 170 +PUT 171 171 +PUT 172 172 +PUT 173 173 +PUT 174 174 +PUT 175 175 +PUT 176 176 +PUT 177 177 +PUT 178 178 +PUT 179 179 +PUT 180 180 +PUT 181 181 +PUT 182 182 +PUT 183 183 +PUT 184 184 +PUT 185 185 +PUT 186 186 +PUT 187 187 +PUT 188 188 +PUT 189 189 +PUT 190 190 +PUT 191 191 +PUT 192 192 +PUT 193 193 +PUT 194 194 +PUT 195 195 +PUT 196 196 +PUT 197 197 +PUT 198 198 +PUT 199 199 +PUT 200 200 +PUT 201 201 +PUT 202 202 +PUT 203 203 +PUT 204 204 +PUT 205 205 +PUT 206 206 +PUT 207 207 +PUT 208 208 +PUT 209 209 +PUT 210 210 +PUT 211 211 +PUT 212 212 +PUT 213 213 +PUT 214 214 +PUT 215 215 +PUT 216 216 +PUT 217 217 +PUT 218 218 +PUT 219 219 +PUT 220 220 +PUT 221 221 +PUT 222 222 +PUT 223 223 +PUT 224 224 +PUT 225 225 +PUT 226 226 +PUT 227 227 +PUT 228 228 +PUT 229 229 +PUT 230 230 +PUT 231 231 +PUT 232 232 +PUT 233 233 +PUT 234 234 +PUT 235 235 +PUT 236 236 +PUT 237 237 +PUT 238 238 +PUT 239 239 +PUT 240 240 +PUT 241 241 +PUT 242 242 +PUT 243 243 +PUT 244 244 +PUT 245 245 +PUT 246 246 +PUT 247 247 +PUT 248 248 +PUT 249 249 +PUT 250 250 +PUT 251 251 +PUT 252 252 +PUT 253 253 +PUT 254 254 +PUT 255 255 +PUT 256 256 +GET 129 +GET 130 +GET 131 +GET 132 +GET 133 +GET 134 +GET 135 +GET 136 +GET 137 +GET 138 +GET 139 +GET 140 +GET 141 +GET 142 +GET 143 +GET 144 +GET 145 +GET 146 +GET 147 +GET 148 +GET 149 +GET 150 +GET 151 +GET 152 +GET 153 +GET 154 +GET 155 +GET 156 +GET 157 +GET 158 +GET 159 +GET 160 +GET 161 +GET 162 +GET 163 +GET 164 +GET 165 +GET 166 +GET 167 +GET 168 +GET 169 +GET 170 +GET 171 +GET 172 +GET 173 +GET 174 +GET 175 +GET 176 +GET 177 +GET 178 +GET 179 +GET 180 +GET 181 +GET 182 +GET 183 +GET 184 +GET 185 +GET 186 +GET 187 +GET 188 +GET 189 +GET 190 +GET 191 +GET 192 +GET 193 +GET 194 +GET 195 +GET 196 +GET 197 +GET 198 +GET 199 +GET 200 +GET 201 +GET 202 +GET 203 +GET 204 +GET 205 +GET 206 +GET 207 +GET 208 +GET 209 +GET 210 +GET 211 +GET 212 +GET 213 +GET 214 +GET 215 +GET 216 +GET 217 +GET 218 +GET 219 +GET 220 +GET 221 +GET 222 +GET 223 +GET 224 +GET 225 +GET 226 +GET 227 +GET 228 +GET 229 +GET 230 +GET 231 +GET 232 +GET 233 +GET 234 +GET 235 +GET 236 +GET 237 +GET 238 +GET 239 +GET 240 +GET 241 +GET 242 +GET 243 +GET 244 +GET 245 +GET 246 +GET 247 +GET 248 +GET 249 +GET 250 +GET 251 +GET 252 +GET 253 +GET 254 +GET 255 +GET 256 +PUT 257 257 +PUT 258 258 +PUT 259 259 +PUT 260 260 +PUT 261 261 +PUT 262 262 +PUT 263 263 +PUT 264 264 +PUT 265 265 +PUT 266 266 +PUT 267 267 +PUT 268 268 +PUT 269 269 +PUT 270 270 +PUT 271 271 +PUT 272 272 +PUT 273 273 +PUT 274 274 +PUT 275 275 +PUT 276 276 +PUT 277 277 +PUT 278 278 +PUT 279 279 +PUT 280 280 +PUT 281 281 +PUT 282 282 +PUT 283 283 +PUT 284 284 +PUT 285 285 +PUT 286 286 +PUT 287 287 +PUT 288 288 +PUT 289 289 +PUT 290 290 +PUT 291 291 +PUT 292 292 +PUT 293 293 +PUT 294 294 +PUT 295 295 +PUT 296 296 +PUT 297 297 +PUT 298 298 +PUT 299 299 +PUT 300 300 +PUT 301 301 +PUT 302 302 +PUT 303 303 +PUT 304 304 +PUT 305 305 +PUT 306 306 +PUT 307 307 +PUT 308 308 +PUT 309 309 +PUT 310 310 +PUT 311 311 +PUT 312 312 +PUT 313 313 +PUT 314 314 +PUT 315 315 +PUT 316 316 +PUT 317 317 +PUT 318 318 +PUT 319 319 +PUT 320 320 +PUT 321 321 +PUT 322 322 +PUT 323 323 +PUT 324 324 +PUT 325 325 +PUT 326 326 +PUT 327 327 +PUT 328 328 +PUT 329 329 +PUT 330 330 +PUT 331 331 +PUT 332 332 +PUT 333 333 +PUT 334 334 +PUT 335 335 +PUT 336 336 +PUT 337 337 +PUT 338 338 +PUT 339 339 +PUT 340 340 +PUT 341 341 +PUT 342 342 +PUT 343 343 +PUT 344 344 +PUT 345 345 +PUT 346 346 +PUT 347 347 +PUT 348 348 +PUT 349 349 +PUT 350 350 +PUT 351 351 +PUT 352 352 +PUT 353 353 +PUT 354 354 +PUT 355 355 +PUT 356 356 +PUT 357 357 +PUT 358 358 +PUT 359 359 +PUT 360 360 +PUT 361 361 +PUT 362 362 +PUT 363 363 +PUT 364 364 +PUT 365 365 +PUT 366 366 +PUT 367 367 +PUT 368 368 +PUT 369 369 +PUT 370 370 +PUT 371 371 +PUT 372 372 +PUT 373 373 +PUT 374 374 +PUT 375 375 +PUT 376 376 +PUT 377 377 +PUT 378 378 +PUT 379 379 +PUT 380 380 +PUT 381 381 +PUT 382 382 +PUT 383 383 +PUT 384 384 +GET 257 +GET 258 +GET 259 +GET 260 +GET 261 +GET 262 +GET 263 +GET 264 +GET 265 +GET 266 +GET 267 +GET 268 +GET 269 +GET 270 +GET 271 +GET 272 +GET 273 +GET 274 +GET 275 +GET 276 +GET 277 +GET 278 +GET 279 +GET 280 +GET 281 +GET 282 +GET 283 +GET 284 +GET 285 +GET 286 +GET 287 +GET 288 +GET 289 +GET 290 +GET 291 +GET 292 +GET 293 +GET 294 +GET 295 +GET 296 +GET 297 +GET 298 +GET 299 +GET 300 +GET 301 +GET 302 +GET 303 +GET 304 +GET 305 +GET 306 +GET 307 +GET 308 +GET 309 +GET 310 +GET 311 +GET 312 +GET 313 +GET 314 +GET 315 +GET 316 +GET 317 +GET 318 +GET 319 +GET 320 +GET 321 +GET 322 +GET 323 +GET 324 +GET 325 +GET 326 +GET 327 +GET 328 +GET 329 +GET 330 +GET 331 +GET 332 +GET 333 +GET 334 +GET 335 +GET 336 +GET 337 +GET 338 +GET 339 +GET 340 +GET 341 +GET 342 +GET 343 +GET 344 +GET 345 +GET 346 +GET 347 +GET 348 +GET 349 +GET 350 +GET 351 +GET 352 +GET 353 +GET 354 +GET 355 +GET 356 +GET 357 +GET 358 +GET 359 +GET 360 +GET 361 +GET 362 +GET 363 +GET 364 +GET 365 +GET 366 +GET 367 +GET 368 +GET 369 +GET 370 +GET 371 +GET 372 +GET 373 +GET 374 +GET 375 +GET 376 +GET 377 +GET 378 +GET 379 +GET 380 +GET 381 +GET 382 +GET 383 +GET 384 +PUT 385 385 +PUT 386 386 +PUT 387 387 +PUT 388 388 +PUT 389 389 +PUT 390 390 +PUT 391 391 +PUT 392 392 +PUT 393 393 +PUT 394 394 +PUT 395 395 +PUT 396 396 +PUT 397 397 +PUT 398 398 +PUT 399 399 +PUT 400 400 +PUT 401 401 +PUT 402 402 +PUT 403 403 +PUT 404 404 +PUT 405 405 +PUT 406 406 +PUT 407 407 +PUT 408 408 +PUT 409 409 +PUT 410 410 +PUT 411 411 +PUT 412 412 +PUT 413 413 +PUT 414 414 +PUT 415 415 +PUT 416 416 +PUT 417 417 +PUT 418 418 +PUT 419 419 +PUT 420 420 +PUT 421 421 +PUT 422 422 +PUT 423 423 +PUT 424 424 +PUT 425 425 +PUT 426 426 +PUT 427 427 +PUT 428 428 +PUT 429 429 +PUT 430 430 +PUT 431 431 +PUT 432 432 +PUT 433 433 +PUT 434 434 +PUT 435 435 +PUT 436 436 +PUT 437 437 +PUT 438 438 +PUT 439 439 +PUT 440 440 +PUT 441 441 +PUT 442 442 +PUT 443 443 +PUT 444 444 +PUT 445 445 +PUT 446 446 +PUT 447 447 +PUT 448 448 +PUT 449 449 +PUT 450 450 +PUT 451 451 +PUT 452 452 +PUT 453 453 +PUT 454 454 +PUT 455 455 +PUT 456 456 +PUT 457 457 +PUT 458 458 +PUT 459 459 +PUT 460 460 +PUT 461 461 +PUT 462 462 +PUT 463 463 +PUT 464 464 +PUT 465 465 +PUT 466 466 +PUT 467 467 +PUT 468 468 +PUT 469 469 +PUT 470 470 +PUT 471 471 +PUT 472 472 +PUT 473 473 +PUT 474 474 +PUT 475 475 +PUT 476 476 +PUT 477 477 +PUT 478 478 +PUT 479 479 +PUT 480 480 +PUT 481 481 +PUT 482 482 +PUT 483 483 +PUT 484 484 +PUT 485 485 +PUT 486 486 +PUT 487 487 +PUT 488 488 +PUT 489 489 +PUT 490 490 +PUT 491 491 +PUT 492 492 +PUT 493 493 +PUT 494 494 +PUT 495 495 +PUT 496 496 +PUT 497 497 +PUT 498 498 +PUT 499 499 +PUT 500 500 +PUT 501 501 +PUT 502 502 +PUT 503 503 +PUT 504 504 +PUT 505 505 +PUT 506 506 +PUT 507 507 +PUT 508 508 +PUT 509 509 +PUT 510 510 +PUT 511 511 +PUT 512 512 +GET 385 +GET 386 +GET 387 +GET 388 +GET 389 +GET 390 +GET 391 +GET 392 +GET 393 +GET 394 +GET 395 +GET 396 +GET 397 +GET 398 +GET 399 +GET 400 +GET 401 +GET 402 +GET 403 +GET 404 +GET 405 +GET 406 +GET 407 +GET 408 +GET 409 +GET 410 +GET 411 +GET 412 +GET 413 +GET 414 +GET 415 +GET 416 +GET 417 +GET 418 +GET 419 +GET 420 +GET 421 +GET 422 +GET 423 +GET 424 +GET 425 +GET 426 +GET 427 +GET 428 +GET 429 +GET 430 +GET 431 +GET 432 +GET 433 +GET 434 +GET 435 +GET 436 +GET 437 +GET 438 +GET 439 +GET 440 +GET 441 +GET 442 +GET 443 +GET 444 +GET 445 +GET 446 +GET 447 +GET 448 +GET 449 +GET 450 +GET 451 +GET 452 +GET 453 +GET 454 +GET 455 +GET 456 +GET 457 +GET 458 +GET 459 +GET 460 +GET 461 +GET 462 +GET 463 +GET 464 +GET 465 +GET 466 +GET 467 +GET 468 +GET 469 +GET 470 +GET 471 +GET 472 +GET 473 +GET 474 +GET 475 +GET 476 +GET 477 +GET 478 +GET 479 +GET 480 +GET 481 +GET 482 +GET 483 +GET 484 +GET 485 +GET 486 +GET 487 +GET 488 +GET 489 +GET 490 +GET 491 +GET 492 +GET 493 +GET 494 +GET 495 +GET 496 +GET 497 +GET 498 +GET 499 +GET 500 +GET 501 +GET 502 +GET 503 +GET 504 +GET 505 +GET 506 +GET 507 +GET 508 +GET 509 +GET 510 +GET 511 +GET 512 +PUT 513 513 +FREE \ No newline at end of file diff --git a/tests/cache/cache-lru-replace.expect b/tests/cache/cache-lru-replace.expect new file mode 100644 index 00000000..eae31924 --- /dev/null +++ b/tests/cache/cache-lru-replace.expect @@ -0,0 +1,3 @@ +NEW CACHE +REPLACE 1 +FREE CACHE diff --git a/tests/cache/cache-lru-replace.in b/tests/cache/cache-lru-replace.in new file mode 100644 index 00000000..a89d135a --- /dev/null +++ b/tests/cache/cache-lru-replace.in @@ -0,0 +1,259 @@ +NEW +PUT 1 1 +PUT 2 2 +PUT 3 3 +PUT 4 4 +PUT 5 5 +PUT 6 6 +PUT 7 7 +PUT 8 8 +PUT 9 9 +PUT 10 10 +PUT 11 11 +PUT 12 12 +PUT 13 13 +PUT 14 14 +PUT 15 15 +PUT 16 16 +PUT 17 17 +PUT 18 18 +PUT 19 19 +PUT 20 20 +PUT 21 21 +PUT 22 22 +PUT 23 23 +PUT 24 24 +PUT 25 25 +PUT 26 26 +PUT 27 27 +PUT 28 28 +PUT 29 29 +PUT 30 30 +PUT 31 31 +PUT 32 32 +PUT 33 33 +PUT 34 34 +PUT 35 35 +PUT 36 36 +PUT 37 37 +PUT 38 38 +PUT 39 39 +PUT 40 40 +PUT 41 41 +PUT 42 42 +PUT 43 43 +PUT 44 44 +PUT 45 45 +PUT 46 46 +PUT 47 47 +PUT 48 48 +PUT 49 49 +PUT 50 50 +PUT 51 51 +PUT 52 52 +PUT 53 53 +PUT 54 54 +PUT 55 55 +PUT 56 56 +PUT 57 57 +PUT 58 58 +PUT 59 59 +PUT 60 60 +PUT 61 61 +PUT 62 62 +PUT 63 63 +PUT 64 64 +PUT 65 65 +PUT 66 66 +PUT 67 67 +PUT 68 68 +PUT 69 69 +PUT 70 70 +PUT 71 71 +PUT 72 72 +PUT 73 73 +PUT 74 74 +PUT 75 75 +PUT 76 76 +PUT 77 77 +PUT 78 78 +PUT 79 79 +PUT 80 80 +PUT 81 81 +PUT 82 82 +PUT 83 83 +PUT 84 84 +PUT 85 85 +PUT 86 86 +PUT 87 87 +PUT 88 88 +PUT 89 89 +PUT 90 90 +PUT 91 91 +PUT 92 92 +PUT 93 93 +PUT 94 94 +PUT 95 95 +PUT 96 96 +PUT 97 97 +PUT 98 98 +PUT 99 99 +PUT 100 100 +PUT 101 101 +PUT 102 102 +PUT 103 103 +PUT 104 104 +PUT 105 105 +PUT 106 106 +PUT 107 107 +PUT 108 108 +PUT 109 109 +PUT 110 110 +PUT 111 111 +PUT 112 112 +PUT 113 113 +PUT 114 114 +PUT 115 115 +PUT 116 116 +PUT 117 117 +PUT 118 118 +PUT 119 119 +PUT 120 120 +PUT 121 121 +PUT 122 122 +PUT 123 123 +PUT 124 124 +PUT 125 125 +PUT 126 126 +PUT 127 127 +PUT 128 128 +PUT 129 129 +PUT 130 130 +PUT 131 131 +PUT 132 132 +PUT 133 133 +PUT 134 134 +PUT 135 135 +PUT 136 136 +PUT 137 137 +PUT 138 138 +PUT 139 139 +PUT 140 140 +PUT 141 141 +PUT 142 142 +PUT 143 143 +PUT 144 144 +PUT 145 145 +PUT 146 146 +PUT 147 147 +PUT 148 148 +PUT 149 149 +PUT 150 150 +PUT 151 151 +PUT 152 152 +PUT 153 153 +PUT 154 154 +PUT 155 155 +PUT 156 156 +PUT 157 157 +PUT 158 158 +PUT 159 159 +PUT 160 160 +PUT 161 161 +PUT 162 162 +PUT 163 163 +PUT 164 164 +PUT 165 165 +PUT 166 166 +PUT 167 167 +PUT 168 168 +PUT 169 169 +PUT 170 170 +PUT 171 171 +PUT 172 172 +PUT 173 173 +PUT 174 174 +PUT 175 175 +PUT 176 176 +PUT 177 177 +PUT 178 178 +PUT 179 179 +PUT 180 180 +PUT 181 181 +PUT 182 182 +PUT 183 183 +PUT 184 184 +PUT 185 185 +PUT 186 186 +PUT 187 187 +PUT 188 188 +PUT 189 189 +PUT 190 190 +PUT 191 191 +PUT 192 192 +PUT 193 193 +PUT 194 194 +PUT 195 195 +PUT 196 196 +PUT 197 197 +PUT 198 198 +PUT 199 199 +PUT 200 200 +PUT 201 201 +PUT 202 202 +PUT 203 203 +PUT 204 204 +PUT 205 205 +PUT 206 206 +PUT 207 207 +PUT 208 208 +PUT 209 209 +PUT 210 210 +PUT 211 211 +PUT 212 212 +PUT 213 213 +PUT 214 214 +PUT 215 215 +PUT 216 216 +PUT 217 217 +PUT 218 218 +PUT 219 219 +PUT 220 220 +PUT 221 221 +PUT 222 222 +PUT 223 223 +PUT 224 224 +PUT 225 225 +PUT 226 226 +PUT 227 227 +PUT 228 228 +PUT 229 229 +PUT 230 230 +PUT 231 231 +PUT 232 232 +PUT 233 233 +PUT 234 234 +PUT 235 235 +PUT 236 236 +PUT 237 237 +PUT 238 238 +PUT 239 239 +PUT 240 240 +PUT 241 241 +PUT 242 242 +PUT 243 243 +PUT 244 244 +PUT 245 245 +PUT 246 246 +PUT 247 247 +PUT 248 248 +PUT 249 249 +PUT 250 250 +PUT 251 251 +PUT 252 252 +PUT 253 253 +PUT 254 254 +PUT 255 255 +PUT 256 256 +PUT 257 257 +FREE \ No newline at end of file diff --git a/tests/cache/cache-new.expect b/tests/cache/cache-new.expect new file mode 100644 index 00000000..134d8b8e --- /dev/null +++ b/tests/cache/cache-new.expect @@ -0,0 +1,2 @@ +NEW CACHE +FREE CACHE diff --git a/tests/cache/cache-new.in b/tests/cache/cache-new.in new file mode 100644 index 00000000..f3603c17 --- /dev/null +++ b/tests/cache/cache-new.in @@ -0,0 +1,2 @@ +NEW +FREE \ No newline at end of file diff --git a/tests/cache/cache-put.expect b/tests/cache/cache-put.expect new file mode 100644 index 00000000..eae31924 --- /dev/null +++ b/tests/cache/cache-put.expect @@ -0,0 +1,3 @@ +NEW CACHE +REPLACE 1 +FREE CACHE diff --git a/tests/cache/cache-put.in b/tests/cache/cache-put.in new file mode 100644 index 00000000..a89d135a --- /dev/null +++ b/tests/cache/cache-put.in @@ -0,0 +1,259 @@ +NEW +PUT 1 1 +PUT 2 2 +PUT 3 3 +PUT 4 4 +PUT 5 5 +PUT 6 6 +PUT 7 7 +PUT 8 8 +PUT 9 9 +PUT 10 10 +PUT 11 11 +PUT 12 12 +PUT 13 13 +PUT 14 14 +PUT 15 15 +PUT 16 16 +PUT 17 17 +PUT 18 18 +PUT 19 19 +PUT 20 20 +PUT 21 21 +PUT 22 22 +PUT 23 23 +PUT 24 24 +PUT 25 25 +PUT 26 26 +PUT 27 27 +PUT 28 28 +PUT 29 29 +PUT 30 30 +PUT 31 31 +PUT 32 32 +PUT 33 33 +PUT 34 34 +PUT 35 35 +PUT 36 36 +PUT 37 37 +PUT 38 38 +PUT 39 39 +PUT 40 40 +PUT 41 41 +PUT 42 42 +PUT 43 43 +PUT 44 44 +PUT 45 45 +PUT 46 46 +PUT 47 47 +PUT 48 48 +PUT 49 49 +PUT 50 50 +PUT 51 51 +PUT 52 52 +PUT 53 53 +PUT 54 54 +PUT 55 55 +PUT 56 56 +PUT 57 57 +PUT 58 58 +PUT 59 59 +PUT 60 60 +PUT 61 61 +PUT 62 62 +PUT 63 63 +PUT 64 64 +PUT 65 65 +PUT 66 66 +PUT 67 67 +PUT 68 68 +PUT 69 69 +PUT 70 70 +PUT 71 71 +PUT 72 72 +PUT 73 73 +PUT 74 74 +PUT 75 75 +PUT 76 76 +PUT 77 77 +PUT 78 78 +PUT 79 79 +PUT 80 80 +PUT 81 81 +PUT 82 82 +PUT 83 83 +PUT 84 84 +PUT 85 85 +PUT 86 86 +PUT 87 87 +PUT 88 88 +PUT 89 89 +PUT 90 90 +PUT 91 91 +PUT 92 92 +PUT 93 93 +PUT 94 94 +PUT 95 95 +PUT 96 96 +PUT 97 97 +PUT 98 98 +PUT 99 99 +PUT 100 100 +PUT 101 101 +PUT 102 102 +PUT 103 103 +PUT 104 104 +PUT 105 105 +PUT 106 106 +PUT 107 107 +PUT 108 108 +PUT 109 109 +PUT 110 110 +PUT 111 111 +PUT 112 112 +PUT 113 113 +PUT 114 114 +PUT 115 115 +PUT 116 116 +PUT 117 117 +PUT 118 118 +PUT 119 119 +PUT 120 120 +PUT 121 121 +PUT 122 122 +PUT 123 123 +PUT 124 124 +PUT 125 125 +PUT 126 126 +PUT 127 127 +PUT 128 128 +PUT 129 129 +PUT 130 130 +PUT 131 131 +PUT 132 132 +PUT 133 133 +PUT 134 134 +PUT 135 135 +PUT 136 136 +PUT 137 137 +PUT 138 138 +PUT 139 139 +PUT 140 140 +PUT 141 141 +PUT 142 142 +PUT 143 143 +PUT 144 144 +PUT 145 145 +PUT 146 146 +PUT 147 147 +PUT 148 148 +PUT 149 149 +PUT 150 150 +PUT 151 151 +PUT 152 152 +PUT 153 153 +PUT 154 154 +PUT 155 155 +PUT 156 156 +PUT 157 157 +PUT 158 158 +PUT 159 159 +PUT 160 160 +PUT 161 161 +PUT 162 162 +PUT 163 163 +PUT 164 164 +PUT 165 165 +PUT 166 166 +PUT 167 167 +PUT 168 168 +PUT 169 169 +PUT 170 170 +PUT 171 171 +PUT 172 172 +PUT 173 173 +PUT 174 174 +PUT 175 175 +PUT 176 176 +PUT 177 177 +PUT 178 178 +PUT 179 179 +PUT 180 180 +PUT 181 181 +PUT 182 182 +PUT 183 183 +PUT 184 184 +PUT 185 185 +PUT 186 186 +PUT 187 187 +PUT 188 188 +PUT 189 189 +PUT 190 190 +PUT 191 191 +PUT 192 192 +PUT 193 193 +PUT 194 194 +PUT 195 195 +PUT 196 196 +PUT 197 197 +PUT 198 198 +PUT 199 199 +PUT 200 200 +PUT 201 201 +PUT 202 202 +PUT 203 203 +PUT 204 204 +PUT 205 205 +PUT 206 206 +PUT 207 207 +PUT 208 208 +PUT 209 209 +PUT 210 210 +PUT 211 211 +PUT 212 212 +PUT 213 213 +PUT 214 214 +PUT 215 215 +PUT 216 216 +PUT 217 217 +PUT 218 218 +PUT 219 219 +PUT 220 220 +PUT 221 221 +PUT 222 222 +PUT 223 223 +PUT 224 224 +PUT 225 225 +PUT 226 226 +PUT 227 227 +PUT 228 228 +PUT 229 229 +PUT 230 230 +PUT 231 231 +PUT 232 232 +PUT 233 233 +PUT 234 234 +PUT 235 235 +PUT 236 236 +PUT 237 237 +PUT 238 238 +PUT 239 239 +PUT 240 240 +PUT 241 241 +PUT 242 242 +PUT 243 243 +PUT 244 244 +PUT 245 245 +PUT 246 246 +PUT 247 247 +PUT 248 248 +PUT 249 249 +PUT 250 250 +PUT 251 251 +PUT 252 252 +PUT 253 253 +PUT 254 254 +PUT 255 255 +PUT 256 256 +PUT 257 257 +FREE \ No newline at end of file diff --git a/tests/cache/test-cache.c b/tests/cache/test-cache.c new file mode 100644 index 00000000..f3474b9b --- /dev/null +++ b/tests/cache/test-cache.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +#include "cache.h" + +void print_value(int *val) +{ + if (val) + printf("%d\n", *val); + else + printf("NULL\n"); +} + +void split(char **arr, char *str, const char *del) +{ + char *s = strtok(str, del); + + while (s != NULL) { + *arr++ = s; + s = strtok(NULL, del); + } +} + +/* Commands of test-cache + * 1. NEW: cache_create(8), the cache size is set to 256. + * 2. GET key: cache_get(cache, key) + * 3. PUT key val: cache_put(cache, key, val) + * 4. FREE: cache_free(cache, free) + */ +int main(int argc, char *argv[]) +{ + if (argc < 2) { + printf("Fail\n"); + } + FILE *fp = fopen(argv[1], "r"); + char *line = NULL, *ptr = NULL; + size_t len = 0; + struct cache *cache = NULL; + int key, *ans, *val; + while (getline(&line, &len, fp) != -1) { + char *arr[3]; + split(arr, line, " "); + if (!strcmp(arr[0], "GET")) { + key = (int) strtol(arr[1], &ptr, 10); + ans = cache_get(cache, key); + print_value(ans); + } else if (!strcmp(arr[0], "PUT")) { + key = (int) strtol(arr[1], &ptr, 10); + val = malloc(sizeof(int)); + *val = (int) strtol(arr[2], &ptr, 10); + val = cache_put(cache, key, val); + if (val) { + printf("REPLACE %d\n", *val); + free(val); + } + } else if (!strcmp(arr[0], "NEW\n")) { + cache = cache_create(8); + assert(cache); + printf("NEW CACHE\n"); + } else if (!strcmp(arr[0], "FREE")) { + cache_free(cache, free); + printf("FREE CACHE\n"); + } + } + fclose(fp); + return 0; +} \ No newline at end of file