Skip to content

Commit 6fc1439

Browse files
Test: add Run coverage tests as a separate step
1 parent 2f9e5d9 commit 6fc1439

2 files changed

Lines changed: 80 additions & 35 deletions

File tree

.github/workflows/generate_coverage.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Generate coverage and push to Coveralls.io
1212

1313
runs-on: ubuntu-latest
14-
timeout-minutes: 150
14+
timeout-minutes: 180
1515

1616
permissions:
1717
# Needed to cancel any previous runs that are not completed for a given workflow
@@ -149,12 +149,27 @@ jobs:
149149
. $CONDA/etc/profile.d/conda.sh
150150
conda activate coverage
151151
[ -f /opt/intel/oneapi/setvars.sh ] && source /opt/intel/oneapi/setvars.sh
152-
python scripts/gen_coverage.py --build-step skip-tensor
152+
python scripts/gen_coverage.py --build-step skip-tensor --skip-pytest
153+
154+
- name: Run coverage tests
155+
id: run_tests
156+
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
157+
with:
158+
shell: bash
159+
timeout_minutes: 90
160+
max_attempts: 5
161+
retry_on: error
162+
command: |
163+
. $CONDA/etc/profile.d/conda.sh
164+
conda activate coverage
165+
[ -f /opt/intel/oneapi/setvars.sh ] && source /opt/intel/oneapi/setvars.sh
166+
python scripts/gen_coverage.py --tests-only
153167
154168
- name: Total number of coverage attempts
155169
run: |
156170
echo "Total tensor build attempts: ${{ steps.build_tensor.outputs.total_attempts }}"
157171
echo "Total skip-tensor build attempts: ${{ steps.build_skip_tensor.outputs.total_attempts }}"
172+
echo "Total test run attempts: ${{ steps.run_tests.outputs.total_attempts }}"
158173
159174
- name: Upload coverage data to coveralls.io
160175
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7

scripts/gen_coverage.py

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def parse_args():
127127
"skip-tensor (everything except tensor, assumes tensor headers exist), "
128128
"or both (default: both)",
129129
)
130+
p.add_argument(
131+
"--tests-only",
132+
action="store_true",
133+
help="Skip build and only run tests with coverage collection",
134+
)
130135

131136
return p.parse_args()
132137

@@ -163,44 +168,67 @@ def main():
163168
args = parse_args()
164169
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
165170

166-
c_compiler, cxx_compiler = resolve_compilers(
167-
args.oneapi,
168-
args.c_compiler,
169-
args.cxx_compiler,
170-
args.compiler_root,
171-
)
171+
env = os.environ.copy()
172+
173+
# If tests-only mode, skip build and jump to test execution
174+
if args.tests_only:
175+
c_compiler, cxx_compiler = resolve_compilers(
176+
args.oneapi,
177+
args.c_compiler,
178+
args.cxx_compiler,
179+
args.compiler_root,
180+
)
181+
if args.bin_llvm:
182+
bin_llvm = args.bin_llvm
183+
else:
184+
bin_llvm = find_bin_llvm(c_compiler)
185+
print(
186+
f"[gen_coverage] Path to folder with llvm-cov/llvm-profdata: {bin_llvm}"
187+
)
188+
if bin_llvm:
189+
env["PATH"] = ":".join((env.get("PATH", ""), bin_llvm))
190+
env["LLVM_TOOLS_HOME"] = bin_llvm
172191

173-
dpctl_cmake_dir = get_dpctl_cmake_dir()
174-
print(f"[gen_coverage] Found DPCTL CMake dir: {dpctl_cmake_dir}")
192+
print("[gen_coverage] Skipping build (--tests-only mode)")
193+
# Jump to test execution below
194+
else:
195+
# Normal build mode
196+
c_compiler, cxx_compiler = resolve_compilers(
197+
args.oneapi,
198+
args.c_compiler,
199+
args.cxx_compiler,
200+
args.compiler_root,
201+
)
175202

176-
if args.clean:
177-
clean_build_dir(setup_dir)
203+
dpctl_cmake_dir = get_dpctl_cmake_dir()
204+
print(f"[gen_coverage] Found DPCTL CMake dir: {dpctl_cmake_dir}")
178205

179-
cmake_args = make_cmake_args(
180-
c_compiler=c_compiler,
181-
cxx_compiler=cxx_compiler,
182-
dpctl_cmake_dir=dpctl_cmake_dir,
183-
verbose=args.verbose,
184-
)
185-
cmake_args.append("-DDPNP_GENERATE_COVERAGE=ON")
206+
if args.clean:
207+
clean_build_dir(setup_dir)
186208

187-
env = os.environ.copy()
209+
cmake_args = make_cmake_args(
210+
c_compiler=c_compiler,
211+
cxx_compiler=cxx_compiler,
212+
dpctl_cmake_dir=dpctl_cmake_dir,
213+
verbose=args.verbose,
214+
)
215+
cmake_args.append("-DDPNP_GENERATE_COVERAGE=ON")
188216

189-
if args.bin_llvm:
190-
bin_llvm = args.bin_llvm
191-
else:
192-
bin_llvm = find_bin_llvm(c_compiler)
193-
print(
194-
f"[gen_coverage] Path to folder with llvm-cov/llvm-profdata: {bin_llvm}"
195-
)
217+
if args.bin_llvm:
218+
bin_llvm = args.bin_llvm
219+
else:
220+
bin_llvm = find_bin_llvm(c_compiler)
221+
print(
222+
f"[gen_coverage] Path to folder with llvm-cov/llvm-profdata: {bin_llvm}"
223+
)
196224

197-
if bin_llvm:
198-
env["PATH"] = ":".join((env.get("PATH", ""), bin_llvm))
199-
env["LLVM_TOOLS_HOME"] = bin_llvm
225+
if bin_llvm:
226+
env["PATH"] = ":".join((env.get("PATH", ""), bin_llvm))
227+
env["LLVM_TOOLS_HOME"] = bin_llvm
200228

201-
log_cmake_args(cmake_args, "gen_coverage")
229+
log_cmake_args(cmake_args, "gen_coverage")
202230

203-
if args.build_step in ["tensor", "both"]:
231+
if not args.tests_only and args.build_step in ["tensor", "both"]:
204232
# Build tensor only to generate Cython headers
205233
tensor_cmake_args = cmake_args.copy()
206234
tensor_cmake_args.append("-DDPNP_BUILD_COMPONENTS=TENSOR_ONLY")
@@ -214,7 +242,7 @@ def main():
214242
build_type="Coverage",
215243
)
216244

217-
if args.build_step in ["skip-tensor", "both"]:
245+
if not args.tests_only and args.build_step in ["skip-tensor", "both"]:
218246
# Build everything except tensor (assumes tensor headers already exist)
219247
skip_tensor_cmake_args = cmake_args.copy()
220248
skip_tensor_cmake_args.append("-DDPNP_BUILD_COMPONENTS=SKIP_TENSOR")
@@ -229,8 +257,10 @@ def main():
229257
)
230258
install_editable(setup_dir, env)
231259

232-
# Only run tests when we have a complete build (skip-tensor or both)
233-
if args.run_pytest and args.build_step in ["skip-tensor", "both"]:
260+
# Run tests when: tests-only mode OR (run_pytest AND complete build)
261+
if args.tests_only or (
262+
args.run_pytest and args.build_step in ["skip-tensor", "both"]
263+
):
234264
env["LLVM_PROFILE_FILE"] = "dpnp_pytest.profraw"
235265
pytest_cmd = [
236266
"pytest",

0 commit comments

Comments
 (0)