Skip to content

Commit c8e24d0

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

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
make bpf-lib
3941
go generate ./...
@@ -64,13 +66,13 @@ stages:
6466
#
6567
# $GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/linux-coverage.gocov.json
6668
# $GOCOV_XML_BIN < "$REPORT_DIR"/linux-coverage.gocov.json > "$REPORT_DIR"/linux-coverage.gocov.xml
67-
#
69+
#
6870
# - task: UsePythonVersion@0
6971
# retryCountOnTaskFailure: 3
7072
# inputs:
7173
# versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
7274
# addToPath: true
73-
#
75+
#
7476
# - task: PythonScript@0
7577
# displayName: "Generate Test Reporting"
7678
# name: report
@@ -80,26 +82,26 @@ stages:
8082
# script: |
8183
# import os
8284
# import zlib
83-
#
85+
#
8486
# def output_var(var_name, is_output, var_value):
8587
# os.environ[var_name] = var_value
8688
# print(f"##vso[task.setvariable variable={var_name};isOutput={is_output}]{var_value}")
87-
#
89+
#
8890
# def encode_and_compress(file_path):
8991
# with open(file_path, 'rb') as file:
9092
# compressed_data = zlib.compress(file.read(), level=9)
9193
# return compressed_data.hex()
92-
#
94+
#
9395
# report_dir = os.environ['REPORT_DIR']
9496
# report_dir = os.path.realpath(report_dir)
95-
#
97+
#
9698
# convert_vars = [
9799
# { 'var_name': 'LINUX_GOCOV_OUT', 'file_path': f'{report_dir}/linux-coverage.out' },
98100
# { 'var_name': 'LINUX_COVERAGE_OUT_XML', 'file_path': f'{report_dir}/linux-coverage.gocov.xml' },
99101
# { 'var_name': 'LINUX_COVERAGE_OUT_JSON', 'file_path': f'{report_dir}/linux-coverage.gocov.json' },
100102
# { 'var_name': 'LINUX_JUNIT_XML', 'file_path': f'{report_dir}/report.xml' }
101103
# ]
102-
#
104+
#
103105
# for item in convert_vars:
104106
# val = encode_and_compress(item['file_path'])
105107
# output_var(item['var_name'], True, val)
@@ -125,13 +127,13 @@ stages:
125127
- task: GoTool@0
126128
inputs:
127129
version: '$(GOVERSION)'
128-
130+
129131
- task: UsePythonVersion@0
130132
retryCountOnTaskFailure: 3
131133
inputs:
132134
versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
133135
addToPath: true
134-
136+
135137
- task: PythonScript@0
136138
displayName: "Run Unit Tests - Windows"
137139
retryCountOnTaskFailure: 3
@@ -142,65 +144,65 @@ stages:
142144
import os
143145
import subprocess
144146
import sys
145-
147+
146148
# Set environment variables and directories
147149
cwd = sys.argv[1]
148150
cwd = os.path.realpath(cwd)
149151
gotest_packages = sys.argv[2]
150152
bin_install_dir = os.path.join(cwd, 'bin')
151153
os.environ['GOBIN'] = bin_install_dir
152-
154+
153155
report_dir = os.environ['REPORT_DIR']
154156
report_dir = os.path.realpath(report_dir)
155-
157+
156158
log_file = os.path.join(report_dir, 'test.stdout.log')
157-
159+
158160
coverage_file = os.environ['COVERAGE_OUT']
159161
coverage_out = os.path.join(report_dir, coverage_file)
160-
162+
161163
gocover_file = os.environ['GOCOV_OUT']
162164
gocover_out = os.path.join(report_dir, gocover_file)
163-
165+
164166
junit_file = os.environ['REPORT_XML']
165167
junit_xml = os.path.join(report_dir, junit_file)
166-
168+
167169
# Install the go-junit-report tool
168170
subprocess.check_call(['go', 'install', 'github.com/jstemmer/go-junit-report/v2@latest'])
169171
junit_report_bin = os.path.join(bin_install_dir, 'go-junit-report')
170-
172+
171173
# Create report directory and touch report XML file
172174
os.makedirs(report_dir, exist_ok=True)
173-
175+
174176
# Run make tools
175177
subprocess.run('make tools', shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
176-
178+
177179
# Function to run the test and capture output
178180
def run_test(packages_to_test):
179181
go_pkgs = ' '.join(packages_to_test) if isinstance(packages_to_test, list) else packages_to_test
180182
181183
cmd_gotest = f"go test -timeout 30m -covermode atomic -coverprofile={coverage_out} {go_pkgs}"
182184
cmd_junitreport = f'{junit_report_bin} -set-exit-code -in {log_file} -out {junit_xml} -iocopy'
183185
cmd_gocover = f'go tool cover -func={coverage_out}'
184-
186+
185187
print(cmd_gotest)
186188
gotest_process = subprocess.run(cmd_gotest, shell=True, stdout=open(log_file, 'w'), text=True, cwd=cwd)
187-
189+
188190
print(cmd_junitreport)
189191
junit_process = subprocess.run(cmd_junitreport, shell=True, stdout=sys.stdout, stderr=sys.stderr, text=True, cwd=cwd)
190-
192+
191193
print(cmd_gocover)
192194
gocover_process = subprocess.run(cmd_gocover, shell=True, text=True, stdout=open(gocover_out, "w"), cwd=cwd)
193-
195+
194196
return gotest_process.returncode
195-
197+
196198
# Run the test function
197199
return_code = run_test(gotest_packages)
198-
200+
199201
# List report directory contents again
200202
print(os.listdir(report_dir))
201203
202204
sys.exit(return_code)
203-
205+
204206
# - task: PythonScript@0
205207
# displayName: "Generate Test Reporting"
206208
# name: report
@@ -212,70 +214,70 @@ stages:
212214
# import subprocess
213215
# import sys
214216
# import zlib
215-
#
217+
#
216218
# # Define the necessary variables
217219
# cwd = sys.argv[1]
218220
# cwd = os.path.realpath(cwd)
219221
# bin_install_dir = os.path.join(cwd, 'bin')
220222
# os.environ['GOBIN'] = bin_install_dir
221-
#
223+
#
222224
# report_dir = os.environ['REPORT_DIR']
223225
# report_dir = os.path.realpath(report_dir)
224-
#
226+
#
225227
# coverage_file = os.environ['COVERAGE_OUT']
226228
# coverage_out = os.path.join(report_dir, coverage_file)
227229
# coverage_json = os.path.join(report_dir, 'windows-coverage.json')
228230
# coverage_xml = os.path.join(report_dir, 'windows-coverage.xml')
229-
#
231+
#
230232
# gocover_file = os.environ['GOCOV_OUT']
231233
# gocover_out = os.path.join(report_dir, gocover_file)
232-
#
234+
#
233235
# junit_file = os.environ['REPORT_XML']
234236
# junit_xml = os.path.join(report_dir, junit_file)
235-
#
237+
#
236238
# # Install gocov and gocov-xml
237239
# subprocess.run(['go', 'install', 'github.com/axw/gocov/gocov@latest'], check=True)
238240
# subprocess.run(['go', 'install', 'github.com/AlekSi/gocov-xml@latest'], check=True)
239-
#
241+
#
240242
# # Define the paths to the installed binaries
241243
# gocov_bin = os.path.join(bin_install_dir, 'gocov')
242244
# gocov_xml_bin = os.path.join(bin_install_dir, 'gocov-xml')
243-
#
245+
#
244246
# # Create the report directory if it doesn't exist
245247
# os.makedirs(report_dir, exist_ok=True)
246-
#
248+
#
247249
# # Convert coverage output to JSON
248250
# with open(coverage_json, 'w') as json_file:
249251
# subprocess.run([gocov_bin, 'convert', coverage_out], stdout=json_file, check=True)
250-
#
252+
#
251253
# # create coverage xml
252254
# with open(coverage_xml, 'w') as xml_file:
253255
# with open(coverage_json, 'r') as json_file:
254256
# subprocess.run([gocov_xml_bin], stdin=json_file, stdout=xml_file, check=True)
255-
#
256-
#
257+
#
258+
#
257259
# def output_var(var_name, is_output, var_value):
258260
# os.environ[var_name] = var_value
259261
# print(f"##vso[task.setvariable variable={var_name};isOutput={is_output}]{var_value}")
260-
#
262+
#
261263
# def encode_and_compress(file_path):
262264
# with open(file_path, 'rb') as file:
263265
# compressed_data = zlib.compress(file.read(), level=9)
264266
# return compressed_data.hex()
265-
#
266-
#
267+
#
268+
#
267269
# # coverage json
268270
# coverage_json_content = encode_and_compress(coverage_json)
269271
# output_var('COVERAGE_OUT_JSON', True, coverage_json_content)
270-
#
272+
#
271273
# # coverage xml
272274
# coverage_xml_content = encode_and_compress(coverage_xml)
273275
# output_var('COVERAGE_OUT_XML', True, coverage_xml_content)
274-
#
275-
# # go cover
276+
#
277+
# # go cover
276278
# gocover_out_content = encode_and_compress(gocover_out)
277279
# output_var('GOCOV_OUT', True, gocover_out_content)
278-
#
280+
#
279281
# # junit xml
280282
# junit_xml_content = encode_and_compress(junit_xml)
281283
# output_var('JUNIT_XML', True, junit_xml_content)
@@ -309,7 +311,7 @@ stages:
309311
# inputs:
310312
# versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
311313
# addToPath: true
312-
#
314+
#
313315
# - task: PythonScript@0
314316
# displayName: "Write Test Output Artifacts"
315317
# retryCountOnTaskFailure: 3
@@ -320,11 +322,11 @@ stages:
320322
# import os
321323
# import sys
322324
# import zlib
323-
#
325+
#
324326
# # Define the necessary variables
325327
# cwd = sys.argv[1]
326328
# cwd = os.path.realpath(cwd)
327-
#
329+
#
328330
# report_dir = os.environ['REPORT_DIR']
329331
# report_dir = os.path.realpath(report_dir)
330332
#

0 commit comments

Comments
 (0)