Skip to content

Commit ebb61a5

Browse files
[CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (#166481)
Add a command-line tool `llvm-cas` to inspect the OnDisk CAS for debugging purpose. It can be used to lookup/update ObjectStore or put/get cache entries from ActionCache, together with other debugging capabilities.
1 parent 917d815 commit ebb61a5

File tree

16 files changed

+673
-0
lines changed

16 files changed

+673
-0
lines changed

llvm/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ llvm_canonicalize_cmake_booleans(
3030
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
3131
LLVM_APPEND_VC_REV
3232
LLVM_HAS_LOGF128
33+
LLVM_ENABLE_ONDISK_CAS
3334
)
3435

3536
configure_lit_site_cfg(
@@ -81,6 +82,7 @@ set(LLVM_TEST_DEPENDS
8182
llvm-bcanalyzer
8283
llvm-bitcode-strip
8384
llvm-c-test
85+
llvm-cas
8486
llvm-cat
8587
llvm-cfi-verify
8688
llvm-cgdata

llvm/test/lit.cfg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def get_asan_rtlib():
233233
"llvm-addr2line",
234234
"llvm-bcanalyzer",
235235
"llvm-bitcode-strip",
236+
"llvm-cas",
236237
"llvm-cgdata",
237238
"llvm-config",
238239
"llvm-cov",
@@ -796,6 +797,9 @@ def host_unwind_supports_jit():
796797
if config.expensive_checks:
797798
config.available_features.add("expensive_checks")
798799

800+
if config.have_ondisk_cas:
801+
config.available_features.add("ondisk_cas")
802+
799803
if "MemoryWithOrigins" in config.llvm_use_sanitizer:
800804
config.available_features.add("use_msan_with_origins")
801805

llvm/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
6666
config.have_vc_rev = @LLVM_APPEND_VC_REV@
6767
config.force_vc_rev = "@LLVM_FORCE_VC_REVISION@"
6868
config.has_logf128 = @LLVM_HAS_LOGF128@
69+
config.have_ondisk_cas = @LLVM_ENABLE_ONDISK_CAS@
6970

7071
import lit.llvm
7172
lit.llvm.initialize(lit_config, config)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
RUN: rm -rf %t %t.cas
2+
RUN: mkdir %t
3+
4+
RUN: llvm-cas --cas %t.cas --make-blob \
5+
RUN: --data %S/Inputs/oneline >%t/oneline.casid
6+
RUN: llvm-cas --cas %t.cas --make-blob \
7+
RUN: --data %S/Inputs/oneline-nonewline >%t/oneline-nonewline.casid
8+
9+
RUN: llvm-cas --cas %t.cas --put-cache-key @%t/oneline.casid @%t/oneline-nonewline.casid
10+
RUN: llvm-cas --cas %t.cas --get-cache-result @%t/oneline.casid > %t/result.casid
11+
RUN: diff %t/oneline-nonewline.casid %t/result.casid
12+
13+
RUN: not llvm-cas --cas %t.cas --get-cache-result @%t/oneline-nonewline.casid 2>&1 | FileCheck %s
14+
CHECK: result not found
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
RUN: rm -rf %t %t.cas
2+
RUN: mkdir %t
3+
4+
RUN: llvm-cas --cas %t.cas --make-blob \
5+
RUN: --data /dev/null > %t/empty.casid
6+
RUN: echo "abc" | \
7+
RUN: llvm-cas --cas %t.cas --make-blob \
8+
RUN: --data - >%t/abc.casid
9+
10+
RUN: llvm-cas --cas %t/cas --put-cache-key @%t/abc.casid @%t/empty.casid
11+
RUN: llvm-cas --cas %t/cas --get-cache-result @%t/abc.casid > %t/empty2.casid
12+
RUN: diff %t/empty.casid %t/empty2.casid
13+
14+
RUN: not llvm-cas --cas %t/cas --get-cache-result @%t/empty.casid

llvm/test/tools/llvm-cas/dump.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
RUN: rm -rf %t
2+
RUN: mkdir %t
3+
4+
RUN: llvm-cas --cas %t/cas --make-blob \
5+
RUN: --data - </dev/null
6+
7+
RUN: llvm-cas --cas %t/cas --make-blob \
8+
RUN: --data %s
9+
10+
RUN: llvm-cas --cas %t/cas --dump | FileCheck %s
11+
12+
// check the dump format.
13+
CHECK: index:
14+
CHECK-NEXT: hash-num-bits=
15+
CHECK-NEXT: root addr=
16+
// it should has at least one index
17+
CHECK-NEXT: - index=
18+
19+
// two records
20+
CHECK: record
21+
CHECK-NEXT: - addr=
22+
CHECK-NEXT: - addr=
23+
24+
// both should be small enough to be in data pool
25+
CHECK: pool:
26+
CHECK-NEXT: - addr=
27+
CHECK-NEXT: - addr=
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not config.have_ondisk_cas:
2+
config.unsupported = True
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
RUN: rm -rf %t %t.cas
2+
RUN: mkdir %t
3+
4+
RUN: llvm-cas --cas %t.cas --make-blob \
5+
RUN: --data - </dev/null >%t/empty.casid
6+
RUN: sed -e 's,^.,CHECK: ,' <%t/empty.casid >%t/empty.check
7+
RUN: llvm-cas --cas %t.cas --make-blob \
8+
RUN: --data /dev/null | FileCheck %t/empty.check
9+
RUN: echo "abc" | \
10+
RUN: llvm-cas --cas %t.cas --make-blob \
11+
RUN: --data - >%t/abc.casid
12+
RUN: llvm-cas --cas %t.cas --make-blob \
13+
RUN: --data %S/Inputs/oneline >%t/oneline.casid
14+
RUN: llvm-cas --cas %t.cas --make-blob \
15+
RUN: --data %S/Inputs/oneline-nonewline >%t/oneline-nonewline.casid
16+
17+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/empty.casid |\
18+
RUN: FileCheck %s -check-prefix CHECK-EMPTY -allow-empty
19+
CHECK-EMPTY-NOT: {{.}}
20+
21+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/abc.casid |\
22+
RUN: FileCheck %s -check-prefix CHECK-ABC
23+
CHECK-ABC: abc
24+
25+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/oneline-nonewline.casid |\
26+
RUN: FileCheck %s -check-prefix CHECK-ONELINE
27+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/oneline.casid |\
28+
RUN: FileCheck %s -check-prefix CHECK-ONELINE
29+
CHECK-ONELINE: content
30+
31+
# Double-check newlines.
32+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/oneline-nonewline.casid \
33+
RUN: >%t/oneline-nonewline
34+
RUN: diff %S/Inputs/oneline-nonewline %t/oneline-nonewline
35+
RUN: llvm-cas --cas %t.cas --cat-node-data @%t/oneline.casid \
36+
RUN: >%t/oneline
37+
RUN: diff %S/Inputs/oneline %t/oneline
38+
39+
# Validate
40+
RUN: llvm-cas --cas %t.cas --validate-object @%t/oneline-nonewline.casid
41+
RUN: llvm-cas --cas %t.cas --validate-object @%t/oneline.casid

0 commit comments

Comments
 (0)