aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/codesearch/testdata
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-26 17:56:07 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-26 18:02:51 +0000
commit28819515a548ec25957603ae1fac0620c3eaa9a0 (patch)
treeba12494a0daf650d2d03ae77873a6c54e62ac444 /pkg/codesearch/testdata
parentfa7953d4ea9f5b7e5147ff086ac5a67bc2d2675b (diff)
pkg/codesearch: support finding field reads/writes
Diffstat (limited to 'pkg/codesearch/testdata')
-rw-r--r--pkg/codesearch/testdata/query-def-source-struct73
-rw-r--r--pkg/codesearch/testdata/query-def-source-struct88
-rw-r--r--pkg/codesearch/testdata/query-def-source-struct92
-rw-r--r--pkg/codesearch/testdata/query-file-index-source1
-rw-r--r--pkg/codesearch/testdata/query-find-references-field034
-rw-r--r--pkg/codesearch/testdata/query-find-references-field110
-rw-r--r--pkg/codesearch/testdata/query-find-references-field210
-rw-r--r--pkg/codesearch/testdata/query-find-references-struct7
-rw-r--r--pkg/codesearch/testdata/source0.c9
-rw-r--r--pkg/codesearch/testdata/source0.c.json89
-rw-r--r--pkg/codesearch/testdata/source0.h1
11 files changed, 162 insertions, 12 deletions
diff --git a/pkg/codesearch/testdata/query-def-source-struct7 b/pkg/codesearch/testdata/query-def-source-struct7
index 3d6212614..12f1955b3 100644
--- a/pkg/codesearch/testdata/query-def-source-struct7
+++ b/pkg/codesearch/testdata/query-def-source-struct7
@@ -5,4 +5,5 @@ union some_union is defined in source0.h:
40: union some_union {
41: int x;
42: void* p;
- 43: };
+ 43: struct some_struct s;
+ 44: };
diff --git a/pkg/codesearch/testdata/query-def-source-struct8 b/pkg/codesearch/testdata/query-def-source-struct8
index 93c7c6516..40dcfbd65 100644
--- a/pkg/codesearch/testdata/query-def-source-struct8
+++ b/pkg/codesearch/testdata/query-def-source-struct8
@@ -2,7 +2,7 @@ def-source source0.c some_enum yes
enum some_enum is defined in source0.h:
- 45: enum some_enum {
- 46: enum_foo = 1,
- 47: enum_bar = 2,
- 48: };
+ 46: enum some_enum {
+ 47: enum_foo = 1,
+ 48: enum_bar = 2,
+ 49: };
diff --git a/pkg/codesearch/testdata/query-def-source-struct9 b/pkg/codesearch/testdata/query-def-source-struct9
index 20056963a..a652d0f42 100644
--- a/pkg/codesearch/testdata/query-def-source-struct9
+++ b/pkg/codesearch/testdata/query-def-source-struct9
@@ -2,4 +2,4 @@ def-source source0.c some_enum_t yes
typedef some_enum_t is defined in source0.h:
- 50: typedef enum some_enum some_enum_t;
+ 51: typedef enum some_enum some_enum_t;
diff --git a/pkg/codesearch/testdata/query-file-index-source b/pkg/codesearch/testdata/query-file-index-source
index edfe4616f..bf7c20b22 100644
--- a/pkg/codesearch/testdata/query-file-index-source
+++ b/pkg/codesearch/testdata/query-file-index-source
@@ -3,6 +3,7 @@ file-index source0.c
file source0.c defines the following entities:
function close
+function field_refs
function func_accepting_a_struct
function function_with_comment_in_header
function function_with_quotes_in_type
diff --git a/pkg/codesearch/testdata/query-find-references-field0 b/pkg/codesearch/testdata/query-find-references-field0
new file mode 100644
index 000000000..e7a82ca47
--- /dev/null
+++ b/pkg/codesearch/testdata/query-find-references-field0
@@ -0,0 +1,34 @@
+find-references source0.c some_struct::x "" 1 10
+
+some_struct::x has 5 references:
+
+function field_refs writes it at source0.c:41
+ 40: {
+ 41: p->x = p->y;
+ 42: *(&p->x) = 1;
+
+
+function field_refs takes-address-of it at source0.c:42
+ 41: p->x = p->y;
+ 42: *(&p->x) = 1;
+ 43: u->p = 0;
+
+
+function field_refs writes it at source0.c:44
+ 43: u->p = 0;
+ 44: u->s.x = 2;
+ 45: return p->x;
+
+
+function field_refs reads it at source0.c:45
+ 44: u->s.x = 2;
+ 45: return p->x;
+ 46: }
+
+
+function func_accepting_a_struct reads it at source0.c:31
+ 30: {
+ 31: return ((some_struct_t*)p)->x +
+ 32: ((union some_union*)p)->x;
+
+
diff --git a/pkg/codesearch/testdata/query-find-references-field1 b/pkg/codesearch/testdata/query-find-references-field1
new file mode 100644
index 000000000..933d14b33
--- /dev/null
+++ b/pkg/codesearch/testdata/query-find-references-field1
@@ -0,0 +1,10 @@
+find-references source0.c some_struct::y "" 1 10
+
+some_struct::y has 1 references:
+
+function field_refs reads it at source0.c:41
+ 40: {
+ 41: p->x = p->y;
+ 42: *(&p->x) = 1;
+
+
diff --git a/pkg/codesearch/testdata/query-find-references-field2 b/pkg/codesearch/testdata/query-find-references-field2
new file mode 100644
index 000000000..08e1c27c5
--- /dev/null
+++ b/pkg/codesearch/testdata/query-find-references-field2
@@ -0,0 +1,10 @@
+find-references source0.c some_union::p "" 1 10
+
+some_union::p has 1 references:
+
+function field_refs writes it at source0.c:43
+ 42: *(&p->x) = 1;
+ 43: u->p = 0;
+ 44: u->s.x = 2;
+
+
diff --git a/pkg/codesearch/testdata/query-find-references-struct b/pkg/codesearch/testdata/query-find-references-struct
index cfb266dc7..ba51c5e53 100644
--- a/pkg/codesearch/testdata/query-find-references-struct
+++ b/pkg/codesearch/testdata/query-find-references-struct
@@ -1,6 +1,11 @@
find-references source0.c some_struct "" 1 10
-some_struct has 2 references:
+some_struct has 3 references:
+
+function field_refs uses it at source0.c:39
+ 39: int field_refs(struct some_struct* p, union some_union* u)
+ 40: {
+
function func_accepting_a_struct uses it at source0.c:29
29: int func_accepting_a_struct(struct some_struct* p)
diff --git a/pkg/codesearch/testdata/source0.c b/pkg/codesearch/testdata/source0.c
index e5b47841b..9482908c9 100644
--- a/pkg/codesearch/testdata/source0.c
+++ b/pkg/codesearch/testdata/source0.c
@@ -35,3 +35,12 @@ int func_accepting_a_struct(struct some_struct* p)
void function_with_quotes_in_type(void __attribute__((btf_type_tag("user"))) *)
{
}
+
+int field_refs(struct some_struct* p, union some_union* u)
+{
+ p->x = p->y;
+ *(&p->x) = 1;
+ u->p = 0;
+ u->s.x = 2;
+ return p->x;
+}
diff --git a/pkg/codesearch/testdata/source0.c.json b/pkg/codesearch/testdata/source0.c.json
index 5d347ae1b..451ab58cc 100644
--- a/pkg/codesearch/testdata/source0.c.json
+++ b/pkg/codesearch/testdata/source0.c.json
@@ -12,6 +12,73 @@
"comment": {}
},
{
+ "name": "field_refs",
+ "type": "int (struct some_struct *, union some_union *)",
+ "kind": "function",
+ "body": {
+ "file": "source0.c",
+ "start_line": 39,
+ "end_line": 46
+ },
+ "comment": {},
+ "refs": [
+ {
+ "name": "some_struct",
+ "kind": "uses",
+ "entity_kind": "struct",
+ "line": 39
+ },
+ {
+ "name": "some_union",
+ "kind": "uses",
+ "entity_kind": "union",
+ "line": 39
+ },
+ {
+ "name": "some_struct::x",
+ "kind": "writes",
+ "entity_kind": "field",
+ "line": 41
+ },
+ {
+ "name": "some_struct::y",
+ "kind": "reads",
+ "entity_kind": "field",
+ "line": 41
+ },
+ {
+ "name": "some_struct::x",
+ "kind": "takes-address-of",
+ "entity_kind": "field",
+ "line": 42
+ },
+ {
+ "name": "some_union::p",
+ "kind": "writes",
+ "entity_kind": "field",
+ "line": 43
+ },
+ {
+ "name": "some_struct::x",
+ "kind": "writes",
+ "entity_kind": "field",
+ "line": 44
+ },
+ {
+ "name": "some_union::s",
+ "kind": "reads",
+ "entity_kind": "field",
+ "line": 44
+ },
+ {
+ "name": "some_struct::x",
+ "kind": "reads",
+ "entity_kind": "field",
+ "line": 45
+ }
+ ]
+ },
+ {
"name": "func_accepting_a_struct",
"type": "int (struct some_struct *)",
"kind": "function",
@@ -29,6 +96,12 @@
"line": 29
},
{
+ "name": "some_struct::x",
+ "kind": "reads",
+ "entity_kind": "field",
+ "line": 31
+ },
+ {
"name": "some_struct_t",
"kind": "uses",
"entity_kind": "typedef",
@@ -41,6 +114,12 @@
"line": 31
},
{
+ "name": "some_union::x",
+ "kind": "reads",
+ "entity_kind": "field",
+ "line": 32
+ },
+ {
"name": "some_union",
"kind": "uses",
"entity_kind": "union",
@@ -155,7 +234,7 @@
"body": {
"file": "source0.h",
"start_line": 40,
- "end_line": 43
+ "end_line": 44
},
"comment": {}
},
@@ -164,8 +243,8 @@
"kind": "enum",
"body": {
"file": "source0.h",
- "start_line": 45,
- "end_line": 48
+ "start_line": 46,
+ "end_line": 49
},
"comment": {}
},
@@ -184,8 +263,8 @@
"kind": "typedef",
"body": {
"file": "source0.h",
- "start_line": 50,
- "end_line": 50
+ "start_line": 51,
+ "end_line": 51
},
"comment": {}
},
diff --git a/pkg/codesearch/testdata/source0.h b/pkg/codesearch/testdata/source0.h
index 9549feb9d..c4ee661e5 100644
--- a/pkg/codesearch/testdata/source0.h
+++ b/pkg/codesearch/testdata/source0.h
@@ -40,6 +40,7 @@ typedef struct another_struct {
union some_union {
int x;
void* p;
+ struct some_struct s;
};
enum some_enum {