Skip to content

Commit 76a168b

Browse files
committed
[clangd] Add lit tests for remote index
Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D90291
1 parent 6d15a28 commit 76a168b

File tree

8 files changed

+123
-2
lines changed

8 files changed

+123
-2
lines changed

clang-tools-extra/clangd/index/remote/server/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int main(int argc, char *argv[]) {
330330

331331
std::thread HotReloadThread([&Index, &Status, &FS]() {
332332
llvm::vfs::Status LastStatus = *Status;
333-
static constexpr auto RefreshFrequency = std::chrono::seconds(90);
333+
static constexpr auto RefreshFrequency = std::chrono::seconds(30);
334334
while (!clang::clangd::shutdownRequested()) {
335335
hotReload(*Index, llvm::StringRef(IndexPath), LastStatus, FS);
336336
std::this_thread::sleep_for(RefreshFrequency);

clang-tools-extra/clangd/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUN
1111
set(CLANGD_TEST_DEPS
1212
clangd
1313
ClangdTests
14-
# No tests for these, but we should still make sure they build.
1514
clangd-indexer
15+
# No tests for it, but we should still make sure they build.
1616
dexp
1717
)
1818

clang-tools-extra/clangd/test/lit.cfg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
lit.llvm.initialize(lit_config, config)
44
lit.llvm.llvm_config.use_clang()
5+
lit.llvm.llvm_config.use_default_substitutions()
56

67
config.name = 'Clangd'
78
config.suffixes = ['.test']
@@ -26,3 +27,6 @@ def calculate_arch_features(arch_string):
2627

2728
if config.clangd_build_xpc:
2829
config.available_features.add('clangd-xpc-support')
30+
31+
if config.clangd_enable_remote:
32+
config.available_features.add('clangd-remote-index')

clang-tools-extra/clangd/test/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config.clang_libs_dir = "@CLANG_LIBS_DIR@"
88
config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
99
config.target_triple = "@TARGET_TRIPLE@"
1010
config.host_triple = "@LLVM_HOST_TRIPLE@"
11+
config.python_executable = "@Python3_EXECUTABLE@"
1112

1213
# Support substitution of the tools and libs dirs with user parameters. This is
1314
# used when we can't determine the tool dir at configuration time.
@@ -23,6 +24,7 @@ except KeyError:
2324
config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.."
2425
config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.."
2526
config.clangd_build_xpc = @CLANGD_BUILD_XPC@
27+
config.clangd_enable_remote = @CLANGD_ENABLE_REMOTE@
2628

2729
# Delegate logic to lit.cfg.py.
2830
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace clang {
2+
namespace clangd {
3+
namespace remote {
4+
int getFoo(bool Argument);
5+
char Character;
6+
} // namespace remote
7+
} // namespace clangd
8+
} // namespace clang
9+
10+
namespace llvm {} // namespace llvm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "Header.h"
2+
3+
namespace {} // namespace
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RUN: rm -rf %t
2+
# RUN: clangd-indexer %S/Inputs/Source.cpp > %t.idx
3+
# RUN: %python %S/pipeline_helper.py --input-file-name=%s --project-root=%S --index-file=%t.idx | FileCheck %s
4+
# REQUIRES: clangd-remote-index
5+
6+
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
7+
# CHECK: "id": 0,
8+
# CHECK-NEXT: "jsonrpc": "2.0",
9+
---
10+
{"jsonrpc":"2.0","id":1,"method":"workspace/symbol","params":{"query":"Character"}}
11+
# CHECK: "id": 1,
12+
# CHECK-NEXT: "jsonrpc": "2.0",
13+
# CHECK-NEXT: "result": [
14+
# CHECK-NEXT: {
15+
# CHECK-NEXT: "containerName": "clang::clangd::remote",
16+
# CHECK-NEXT: "kind": 13,
17+
# CHECK-NEXT: "location": {
18+
# CHECK-NEXT: "range": {
19+
# CHECK-NEXT: "end": {
20+
# CHECK-NEXT: "character": {{.*}},
21+
# CHECK-NEXT: "line": {{.*}}
22+
# CHECK-NEXT: },
23+
# CHECK-NEXT: "start": {
24+
# CHECK-NEXT: "character": {{.*}},
25+
# CHECK-NEXT: "line": {{.*}}
26+
# CHECK-NEXT: }
27+
# CHECK-NEXT: },
28+
# CHECK-NEXT: "uri": "file://{{.*}}/Header.h"
29+
# CHECK-NEXT: },
30+
# CHECK-NEXT: "name": "Character",
31+
# CHECK-NEXT: "score": {{.*}}
32+
# CHECK-NEXT: }
33+
# CHECK-NEXT: ]
34+
# CHECK-NEXT:}
35+
---
36+
{"jsonrpc":"2.0","id":4,"method":"shutdown"}
37+
---
38+
{"jsonrpc":"2.0","method":"exit"}
39+
---
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
#
3+
#===- pipeline_helper.py - Remote Index pipeline Helper *- python -------*--===#
4+
#
5+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
# See https://llvm.org/LICENSE.txt for license information.
7+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
#
9+
#===------------------------------------------------------------------------===#
10+
11+
import argparse
12+
import os
13+
import subprocess
14+
from socket import socket
15+
import sys
16+
import time
17+
import signal
18+
19+
20+
def main():
21+
parser = argparse.ArgumentParser()
22+
parser.add_argument('--input-file-name', required=True)
23+
parser.add_argument('--project-root', required=True)
24+
parser.add_argument('--index-file', required=True)
25+
26+
args = parser.parse_args()
27+
28+
# Grab an available port.
29+
with socket() as s:
30+
s.bind(('localhost', 0))
31+
server_address = 'localhost:' + str(s.getsockname()[1])
32+
33+
index_server_process = subprocess.Popen([
34+
'clangd-index-server', '--server-address=' + server_address,
35+
args.index_file, args.project_root
36+
],
37+
stderr=subprocess.PIPE)
38+
39+
# Wait for the server to warm-up.
40+
time.sleep(4)
41+
found_init_message = False
42+
for line in index_server_process.stderr:
43+
if b'Server listening' in line:
44+
found_init_message = True
45+
break
46+
47+
if not found_init_message:
48+
sys.exit(1)
49+
50+
in_file = open(args.input_file_name)
51+
52+
clangd_process = subprocess.Popen([
53+
'clangd', '--remote-index-address=' + server_address,
54+
'--project-root=' + args.project_root, '--lit-test', '--sync'
55+
],
56+
stdin=in_file)
57+
58+
clangd_process.wait()
59+
os.kill(index_server_process.pid, signal.SIGINT)
60+
61+
62+
if __name__ == '__main__':
63+
main()

0 commit comments

Comments
 (0)