Skip to content

Commit d0cef8f

Browse files
committed
chore: generate bpf-lib(s) for block-iptables in signed UTs
1 parent ccb551a commit d0cef8f

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

.pipelines/templates/run-unit-tests.stages.yaml

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ stages:
3434
3535
mkdir -p "$REPORT_DIR"
3636
touch "$REPORT_XML"
37+
make bpf-lib
38+
go generate ./...
3739
make tools
3840
3941
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml),
@@ -62,13 +64,13 @@ stages:
6264
#
6365
# $GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/linux-coverage.gocov.json
6466
# $GOCOV_XML_BIN < "$REPORT_DIR"/linux-coverage.gocov.json > "$REPORT_DIR"/linux-coverage.gocov.xml
65-
#
67+
#
6668
# - task: UsePythonVersion@0
6769
# retryCountOnTaskFailure: 3
6870
# inputs:
6971
# versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
7072
# addToPath: true
71-
#
73+
#
7274
# - task: PythonScript@0
7375
# displayName: "Generate Test Reporting"
7476
# name: report
@@ -78,26 +80,26 @@ stages:
7880
# script: |
7981
# import os
8082
# import zlib
81-
#
83+
#
8284
# def output_var(var_name, is_output, var_value):
8385
# os.environ[var_name] = var_value
8486
# print(f"##vso[task.setvariable variable={var_name};isOutput={is_output}]{var_value}")
85-
#
87+
#
8688
# def encode_and_compress(file_path):
8789
# with open(file_path, 'rb') as file:
8890
# compressed_data = zlib.compress(file.read(), level=9)
8991
# return compressed_data.hex()
90-
#
92+
#
9193
# report_dir = os.environ['REPORT_DIR']
9294
# report_dir = os.path.realpath(report_dir)
93-
#
95+
#
9496
# convert_vars = [
9597
# { 'var_name': 'LINUX_GOCOV_OUT', 'file_path': f'{report_dir}/linux-coverage.out' },
9698
# { 'var_name': 'LINUX_COVERAGE_OUT_XML', 'file_path': f'{report_dir}/linux-coverage.gocov.xml' },
9799
# { 'var_name': 'LINUX_COVERAGE_OUT_JSON', 'file_path': f'{report_dir}/linux-coverage.gocov.json' },
98100
# { 'var_name': 'LINUX_JUNIT_XML', 'file_path': f'{report_dir}/report.xml' }
99101
# ]
100-
#
102+
#
101103
# for item in convert_vars:
102104
# val = encode_and_compress(item['file_path'])
103105
# output_var(item['var_name'], True, val)
@@ -123,13 +125,13 @@ stages:
123125
- task: GoTool@0
124126
inputs:
125127
version: '$(GOVERSION)'
126-
128+
127129
- task: UsePythonVersion@0
128130
retryCountOnTaskFailure: 3
129131
inputs:
130132
versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
131133
addToPath: true
132-
134+
133135
- task: PythonScript@0
134136
displayName: "Run Unit Tests - Windows"
135137
retryCountOnTaskFailure: 3
@@ -140,65 +142,65 @@ stages:
140142
import os
141143
import subprocess
142144
import sys
143-
145+
144146
# Set environment variables and directories
145147
cwd = sys.argv[1]
146148
cwd = os.path.realpath(cwd)
147149
gotest_packages = sys.argv[2]
148150
bin_install_dir = os.path.join(cwd, 'bin')
149151
os.environ['GOBIN'] = bin_install_dir
150-
152+
151153
report_dir = os.environ['REPORT_DIR']
152154
report_dir = os.path.realpath(report_dir)
153-
155+
154156
log_file = os.path.join(report_dir, 'test.stdout.log')
155-
157+
156158
coverage_file = os.environ['COVERAGE_OUT']
157159
coverage_out = os.path.join(report_dir, coverage_file)
158-
160+
159161
gocover_file = os.environ['GOCOV_OUT']
160162
gocover_out = os.path.join(report_dir, gocover_file)
161-
163+
162164
junit_file = os.environ['REPORT_XML']
163165
junit_xml = os.path.join(report_dir, junit_file)
164-
166+
165167
# Install the go-junit-report tool
166168
subprocess.check_call(['go', 'install', 'github.com/jstemmer/go-junit-report/v2@latest'])
167169
junit_report_bin = os.path.join(bin_install_dir, 'go-junit-report')
168-
170+
169171
# Create report directory and touch report XML file
170172
os.makedirs(report_dir, exist_ok=True)
171-
173+
172174
# Run make tools
173175
subprocess.run('make tools', shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
174-
176+
175177
# Function to run the test and capture output
176178
def run_test(packages_to_test):
177179
go_pkgs = ' '.join(packages_to_test) if isinstance(packages_to_test, list) else packages_to_test
178180
179181
cmd_gotest = f"go test -timeout 30m -covermode atomic -coverprofile={coverage_out} {go_pkgs}"
180182
cmd_junitreport = f'{junit_report_bin} -set-exit-code -in {log_file} -out {junit_xml} -iocopy'
181183
cmd_gocover = f'go tool cover -func={coverage_out}'
182-
184+
183185
print(cmd_gotest)
184186
gotest_process = subprocess.run(cmd_gotest, shell=True, stdout=open(log_file, 'w'), text=True, cwd=cwd)
185-
187+
186188
print(cmd_junitreport)
187189
junit_process = subprocess.run(cmd_junitreport, shell=True, stdout=sys.stdout, stderr=sys.stderr, text=True, cwd=cwd)
188-
190+
189191
print(cmd_gocover)
190192
gocover_process = subprocess.run(cmd_gocover, shell=True, text=True, stdout=open(gocover_out, "w"), cwd=cwd)
191-
193+
192194
return gotest_process.returncode
193-
195+
194196
# Run the test function
195197
return_code = run_test(gotest_packages)
196-
198+
197199
# List report directory contents again
198200
print(os.listdir(report_dir))
199201
200202
sys.exit(return_code)
201-
203+
202204
# - task: PythonScript@0
203205
# displayName: "Generate Test Reporting"
204206
# name: report
@@ -210,70 +212,70 @@ stages:
210212
# import subprocess
211213
# import sys
212214
# import zlib
213-
#
215+
#
214216
# # Define the necessary variables
215217
# cwd = sys.argv[1]
216218
# cwd = os.path.realpath(cwd)
217219
# bin_install_dir = os.path.join(cwd, 'bin')
218220
# os.environ['GOBIN'] = bin_install_dir
219-
#
221+
#
220222
# report_dir = os.environ['REPORT_DIR']
221223
# report_dir = os.path.realpath(report_dir)
222-
#
224+
#
223225
# coverage_file = os.environ['COVERAGE_OUT']
224226
# coverage_out = os.path.join(report_dir, coverage_file)
225227
# coverage_json = os.path.join(report_dir, 'windows-coverage.json')
226228
# coverage_xml = os.path.join(report_dir, 'windows-coverage.xml')
227-
#
229+
#
228230
# gocover_file = os.environ['GOCOV_OUT']
229231
# gocover_out = os.path.join(report_dir, gocover_file)
230-
#
232+
#
231233
# junit_file = os.environ['REPORT_XML']
232234
# junit_xml = os.path.join(report_dir, junit_file)
233-
#
235+
#
234236
# # Install gocov and gocov-xml
235237
# subprocess.run(['go', 'install', 'github.com/axw/gocov/gocov@latest'], check=True)
236238
# subprocess.run(['go', 'install', 'github.com/AlekSi/gocov-xml@latest'], check=True)
237-
#
239+
#
238240
# # Define the paths to the installed binaries
239241
# gocov_bin = os.path.join(bin_install_dir, 'gocov')
240242
# gocov_xml_bin = os.path.join(bin_install_dir, 'gocov-xml')
241-
#
243+
#
242244
# # Create the report directory if it doesn't exist
243245
# os.makedirs(report_dir, exist_ok=True)
244-
#
246+
#
245247
# # Convert coverage output to JSON
246248
# with open(coverage_json, 'w') as json_file:
247249
# subprocess.run([gocov_bin, 'convert', coverage_out], stdout=json_file, check=True)
248-
#
250+
#
249251
# # create coverage xml
250252
# with open(coverage_xml, 'w') as xml_file:
251253
# with open(coverage_json, 'r') as json_file:
252254
# subprocess.run([gocov_xml_bin], stdin=json_file, stdout=xml_file, check=True)
253-
#
254-
#
255+
#
256+
#
255257
# def output_var(var_name, is_output, var_value):
256258
# os.environ[var_name] = var_value
257259
# print(f"##vso[task.setvariable variable={var_name};isOutput={is_output}]{var_value}")
258-
#
260+
#
259261
# def encode_and_compress(file_path):
260262
# with open(file_path, 'rb') as file:
261263
# compressed_data = zlib.compress(file.read(), level=9)
262264
# return compressed_data.hex()
263-
#
264-
#
265+
#
266+
#
265267
# # coverage json
266268
# coverage_json_content = encode_and_compress(coverage_json)
267269
# output_var('COVERAGE_OUT_JSON', True, coverage_json_content)
268-
#
270+
#
269271
# # coverage xml
270272
# coverage_xml_content = encode_and_compress(coverage_xml)
271273
# output_var('COVERAGE_OUT_XML', True, coverage_xml_content)
272-
#
273-
# # go cover
274+
#
275+
# # go cover
274276
# gocover_out_content = encode_and_compress(gocover_out)
275277
# output_var('GOCOV_OUT', True, gocover_out_content)
276-
#
278+
#
277279
# # junit xml
278280
# junit_xml_content = encode_and_compress(junit_xml)
279281
# output_var('JUNIT_XML', True, junit_xml_content)
@@ -307,7 +309,7 @@ stages:
307309
# inputs:
308310
# versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
309311
# addToPath: true
310-
#
312+
#
311313
# - task: PythonScript@0
312314
# displayName: "Write Test Output Artifacts"
313315
# retryCountOnTaskFailure: 3
@@ -318,11 +320,11 @@ stages:
318320
# import os
319321
# import sys
320322
# import zlib
321-
#
323+
#
322324
# # Define the necessary variables
323325
# cwd = sys.argv[1]
324326
# cwd = os.path.realpath(cwd)
325-
#
327+
#
326328
# report_dir = os.environ['REPORT_DIR']
327329
# report_dir = os.path.realpath(report_dir)
328330
#

0 commit comments

Comments
 (0)