Add test for get_or_add
for linkmap
This commit is contained in:
parent
0a210b4e7e
commit
f05040ff2b
3 changed files with 38 additions and 3 deletions
|
@ -150,7 +150,7 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
||||||
ino_t val;
|
ino_t val;
|
||||||
u8 bytes[sizeof(ino_t)];
|
u8 bytes[sizeof(ino_t)];
|
||||||
} key;
|
} key;
|
||||||
char * target = "";
|
char * target = NULL;
|
||||||
size_t idx, hash;
|
size_t idx, hash;
|
||||||
haggis_bucket *b;
|
haggis_bucket *b;
|
||||||
|
|
||||||
|
@ -159,9 +159,10 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
||||||
haggis_linkmap_expand(map);
|
haggis_linkmap_expand(map);
|
||||||
key.val = inode;
|
key.val = inode;
|
||||||
hash = hash_fnv1a_64(key.bytes, sizeof(ino_t));
|
hash = hash_fnv1a_64(key.bytes, sizeof(ino_t));
|
||||||
idx = map->capacity % hash;
|
idx = hash % map->capacity;
|
||||||
if (map->buckets[idx].key.val == inode) {
|
if (map->buckets[idx].key.val == inode) {
|
||||||
target = strndup(target, PATH_MAX - 1);
|
target = strndup(map->buckets[idx].path, PATH_MAX - 1);
|
||||||
|
map->buckets[idx].path = path;
|
||||||
} else if (map->buckets[idx].key.val == 0) {
|
} else if (map->buckets[idx].key.val == 0) {
|
||||||
map->buckets[idx].key.val = inode;
|
map->buckets[idx].key.val = inode;
|
||||||
map->buckets[idx].hash = hash;
|
map->buckets[idx].hash = hash;
|
||||||
|
|
|
@ -62,6 +62,7 @@ tests += load_file_sha256
|
||||||
tests += fnv1a_hash_inode
|
tests += fnv1a_hash_inode
|
||||||
tests += fnv1a_hash_str
|
tests += fnv1a_hash_str
|
||||||
tests += linkmap_init
|
tests += linkmap_init
|
||||||
|
tests += linkmap_put
|
||||||
|
|
||||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||||
|
|
||||||
|
|
33
test/linkmap_put.c
Normal file
33
test/linkmap_put.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <assert.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "haggis.h"
|
||||||
|
#include "haggis_private.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
haggis_linkmap *map;
|
||||||
|
struct stat s0, s1;
|
||||||
|
char *path;
|
||||||
|
char *tgt = "Makefile";
|
||||||
|
char *lnk = "output/Makefile";
|
||||||
|
|
||||||
|
map = haggis_linkmap_init();
|
||||||
|
assert(map != NULL);
|
||||||
|
assert(stat(tgt, &s0) == 0);
|
||||||
|
|
||||||
|
if (access(lnk, AT_EACCESS) != 0)
|
||||||
|
link(tgt, lnk);
|
||||||
|
|
||||||
|
assert(stat(lnk, &s1) == 0);
|
||||||
|
path = haggis_linkmap_get_or_add(map, s0.st_ino, tgt);
|
||||||
|
assert(path == NULL);
|
||||||
|
path = haggis_linkmap_get_or_add(map, s1.st_ino, lnk);
|
||||||
|
//printf("\nPath: %s\n", path);
|
||||||
|
assert(memcmp(path, tgt, 9) == 0);
|
||||||
|
haggis_linkmap_deinit(map);
|
||||||
|
unlink(lnk);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue