File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,34 @@ import (
22
22
{ { end } }
23
23
{ {- end } }
24
24
25
+ { {- if or .Maps (or .Variables .Programs) } }
26
+ // Constant names for all maps, variables, and programs as defined in the ELF file.
27
+ //
28
+ // They can be passed to ebpf.CollectionSpec and ebpf.Collection map fields.
29
+ const (
30
+ { {- if .Maps } }
31
+ // { { .Name } } map names.
32
+ { {- range $name , $id := .Maps } }
33
+ { { $.Name } }MapName{ { $id } } = "{ { $name } }"
34
+ { {- end } }
35
+ { {- end } }
36
+
37
+ { {- if .Variables } }
38
+ // { { .Name } } variable names.
39
+ { {- range $name , $id := .Variables } }
40
+ { { $.Name } }VariableName{ { $id } } = "{ { $name } }"
41
+ { {- end } }
42
+ { {- end } }
43
+
44
+ { {- if .Programs } }
45
+ // { { .Name } } program names.
46
+ { {- range $name , $id := .Programs } }
47
+ { { $.Name } }ProgramName{ { $id } } = "{ { $name } }"
48
+ { {- end } }
49
+ { {- end } }
50
+ )
51
+ { {- end } }
52
+
25
53
// { { .Name.Load } } returns the embedded CollectionSpec for { { .Name } }.
26
54
func { { .Name.Load } }() (*ebpf.CollectionSpec, error) {
27
55
reader := bytes.NewReader({{ .Name.Bytes } })
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ func TestCustomIdentifier(t *testing.T) {
95
95
qt .Assert (t , qt .StringContains (buf .String (), "DO_THING" ))
96
96
}
97
97
98
- func TestObjects (t * testing.T ) {
98
+ func TestObjectsAndConstants (t * testing.T ) {
99
99
var buf bytes.Buffer
100
100
args := GenerateArgs {
101
101
Package : "foo" ,
@@ -117,6 +117,10 @@ func TestObjects(t *testing.T) {
117
117
qt .Assert (t , qt .StringContains (str , "Map1 *ebpf.Map `ebpf:\" map1\" `" ))
118
118
qt .Assert (t , qt .StringContains (str , "Var1 *ebpf.Variable `ebpf:\" var_1\" `" ))
119
119
qt .Assert (t , qt .StringContains (str , "ProgFoo1 *ebpf.Program `ebpf:\" prog_foo_1\" `" ))
120
+
121
+ qt .Assert (t , qt .StringContains (str , "barMapNameMap1 = \" map1\" " ))
122
+ qt .Assert (t , qt .StringContains (str , "barVariableNameVar1 = \" var_1\" " ))
123
+ qt .Assert (t , qt .StringContains (str , "barProgramNameProgFoo1 = \" prog_foo_1\" " ))
120
124
}
121
125
122
126
func TestGenerateStructTypes (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments