-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathcache.cpp
More file actions
98 lines (83 loc) · 2.57 KB
/
cache.cpp
File metadata and controls
98 lines (83 loc) · 2.57 KB
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
#include <stdlib.h>
#include <time.h>
#include <occa/internal/io.hpp>
#include <occa/internal/utils/env.hpp>
#include <occa/internal/utils/testing.hpp>
void testCacheInfoMethods();
void testHashDir();
void testBuild();
int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = occa::io::dirname(__FILE__);
occa::env::OCCA_SOURCE_CACHE_DIR = occa::env::OCCA_CACHE_DIR;
#endif
srand(time(NULL));
testCacheInfoMethods();
testHashDir();
testBuild();
occa::sys::rmdir(occa::env::OCCA_CACHE_DIR + "locks",
true);
return 0;
}
void testCacheInfoMethods() {
// isCached
ASSERT_FALSE(occa::io::isCached(""));
ASSERT_FALSE(occa::io::isCached("foo"));
ASSERT_FALSE(occa::io::isCached("occa://foo.okl"));
ASSERT_FALSE(occa::io::isCached("occa://lib/foo.okl"));
ASSERT_FALSE(occa::io::isCached(
occa::env::OCCA_CACHE_DIR + "foo.okl"
));
ASSERT_TRUE(occa::io::isCached(
occa::env::OCCA_CACHE_DIR + "cache/foo.okl"
));
}
void testHashDir() {
occa::hash_t hash = occa::hash(occa::toString(rand()));
const std::string cacheDir = (
occa::io::cachePath() + hash.getString() + "/"
);
const std::string manualCacheDir = (
occa::io::cachePath() + "1234/"
);
// Default
ASSERT_EQ(occa::io::hashDir(hash),
cacheDir);
ASSERT_EQ(occa::io::hashDir("", hash),
cacheDir);
// Non-cached files
ASSERT_EQ(occa::io::hashDir("foo.okl", hash),
cacheDir);
ASSERT_EQ(occa::io::hashDir("dir/foo.okl", hash),
cacheDir);
ASSERT_EQ(occa::io::hashDir("occa://foo.okl", hash),
cacheDir);
ASSERT_EQ(occa::io::hashDir("occa://lib/foo.okl", hash),
cacheDir);
ASSERT_EQ(occa::io::hashDir("occa://lib/dir/foo.okl", hash),
cacheDir);
// Cached files
ASSERT_EQ(occa::io::hashDir(manualCacheDir + "foo.okl", hash),
manualCacheDir);
ASSERT_EQ(occa::io::hashDir(manualCacheDir + "dir/foo.okl", hash),
manualCacheDir);
}
void testBuild() {
// Build props
occa::json props;
ASSERT_EQ(props.size(),
0);
occa::io::setBuildProps(props);
ASSERT_EQ(props.size(),
3);
ASSERT_TRUE(props.has("date"));
ASSERT_TRUE(props.has("human_date"));
// Counts as 1
ASSERT_TRUE(props.has("version/occa"));
ASSERT_TRUE(props.has("version/okl"));
// Write build file
occa::hash_t hash = occa::hash(occa::toString(rand()));
occa::io::writeBuildFile("build.json", props);
ASSERT_TRUE(occa::io::isFile("build.json"));
occa::sys::rmrf("build.json");
}