Skip to content

Commit ca9c045

Browse files
rscohn2normallytangent
authored andcommitted
selective test (#10) (#513)
1 parent 0d301e6 commit ca9c045

File tree

2 files changed

+162
-16
lines changed

2 files changed

+162
-16
lines changed

.github/scripts/domain-check.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// This script is used by pr.yml to determine if a domain must be tested based
3+
// on the files modified in the pull request.
4+
//
5+
6+
// Given a domain name and set of files, return true if the domain should be
7+
// tested
8+
function matchesPattern(domain, filePaths) {
9+
// filter files that end in .md
10+
filePaths = filePaths.filter(
11+
(filePath) =>
12+
!filePath.endsWith(".md") &&
13+
!filePath.startsWith("docs/") &&
14+
!filePath.startsWith("third-party-programs/"),
15+
);
16+
// These directories contain domain specific code
17+
const dirs = "(tests/unit_tests|examples|src|include/oneapi/mkl)";
18+
const domains = "(blas|lapack|rng|dft)";
19+
// matches changes to the domain of interest or non domain-specific code
20+
const re = new RegExp(`^(${dirs}/${domain}|(?!${dirs}/${domains}))`);
21+
const match = filePaths.some((filePath) => re.test(filePath));
22+
return match;
23+
}
24+
25+
// Return the list of files modified in the pull request
26+
async function prFiles(github, context) {
27+
const response = await github.rest.pulls.listFiles({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
pull_number: context.payload.pull_request.number,
31+
});
32+
const prFiles = response.data.map((file) => file.filename);
33+
return prFiles;
34+
}
35+
36+
// Called by pr.yml. See:
37+
// https://github.com/actions/github-script/blob/main/README.md for more
38+
// information on the github and context parameters
39+
module.exports = async ({ github, context, domain }) => {
40+
if (!context.payload.pull_request) {
41+
console.log("Not a pull request. Testing all domains.");
42+
return true;
43+
}
44+
const files = await prFiles(github, context);
45+
const match = matchesPattern(domain, files);
46+
console.log("Domain: ", domain);
47+
console.log("PR files: ", files);
48+
console.log("Match: ", match);
49+
return match;
50+
};
51+
52+
//
53+
// Test the matchesPattern function
54+
//
55+
// Run this script with `node domain-check.js` It should exit with code 0 if
56+
// all tests pass.
57+
//
58+
// If you need to change the set of files that are ignored, add a test pattern
59+
// below with positive and negative examples. It is also possible to test by
60+
// setting up a fork and then submitting pull requests that modify files, but
61+
// it requires a lot of manual work.
62+
//
63+
test_patterns = [
64+
{
65+
domain: "blas",
66+
files: ["tests/unit_tests/blas/test_blas.cpp"],
67+
expected: true,
68+
},
69+
{
70+
domain: "rng",
71+
files: ["examples/rng/example_rng.cpp"],
72+
expected: true,
73+
},
74+
{
75+
domain: "lapack",
76+
files: ["include/oneapi/mkl/lapack/lapack.hpp"],
77+
expected: true,
78+
},
79+
{
80+
domain: "dft",
81+
files: ["src/dft/lapack.hpp"],
82+
expected: true,
83+
},
84+
{
85+
domain: "dft",
86+
files: ["src/dft/lapack.md"],
87+
expected: false,
88+
},
89+
{
90+
domain: "blas",
91+
files: ["tests/unit_tests/dft/test_blas.cpp"],
92+
expected: false,
93+
},
94+
{
95+
domain: "rng",
96+
files: ["examples/blas/example_rng.cpp"],
97+
expected: false,
98+
},
99+
{
100+
domain: "lapack",
101+
files: ["include/oneapi/mkl/rng/lapack.hpp"],
102+
expected: false,
103+
},
104+
{
105+
domain: "dft",
106+
files: ["src/lapack/lapack.hpp"],
107+
expected: false,
108+
},
109+
{
110+
domain: "dft",
111+
files: ["docs/dft/dft.rst"],
112+
expected: false,
113+
},
114+
{
115+
domain: "dft",
116+
files: ["third-party-programs/dft/dft.rst"],
117+
expected: false,
118+
},
119+
];
120+
121+
function testPattern(test) {
122+
const result = matchesPattern(test.domain, test.files);
123+
if (result !== test.expected) {
124+
console.log("Fail:");
125+
console.log(" domain:", test.domain);
126+
console.log(" files:", test.files);
127+
console.log(" expected:", test.expected);
128+
console.log(" result:", result);
129+
process.exit(1);
130+
}
131+
}
132+
133+
if (require.main === module) {
134+
// invoke test for each test pattern
135+
test_patterns.forEach(testPattern);
136+
console.log("All tests pass");
137+
}

.github/workflows/pr.yml

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "PR Tests"
22
permissions: read-all
33

4-
# Trigger for PR an merge to develop branch
4+
# Trigger for PR and merge to develop branch
55
on:
66
push:
77
branches: develop
@@ -21,34 +21,40 @@ jobs:
2121
matrix:
2222
include:
2323
- config: portBLAS
24-
options: -DTARGET_DOMAINS=blas -DREF_BLAS_ROOT=${PWD}/lapack/install -DENABLE_PORTBLAS_BACKEND=ON -DENABLE_MKLCPU_BACKEND=OFF -DPORTBLAS_TUNING_TARGET=INTEL_CPU
25-
tests: '.*'
24+
domain: blas
25+
build_options: -DREF_BLAS_ROOT=${PWD}/lapack/install -DENABLE_PORTBLAS_BACKEND=ON -DENABLE_MKLCPU_BACKEND=OFF -DPORTBLAS_TUNING_TARGET=INTEL_CPU
2626
- config: portFFT
27-
options: -DENABLE_PORTFFT_BACKEND=ON -DENABLE_MKLCPU_BACKEND=OFF -DTARGET_DOMAINS=dft
28-
tests: 'DFT/CT/.*ComputeTests_in_place_COMPLEX.COMPLEX_SINGLE_in_place_buffer.sizes_8_batches_1*'
27+
domain: dft
28+
build_options: -DENABLE_PORTFFT_BACKEND=ON -DENABLE_MKLCPU_BACKEND=OFF
29+
test_options: -R 'DFT/CT/.*ComputeTests_in_place_COMPLEX.COMPLEX_SINGLE_in_place_buffer.sizes_8_batches_1*'
2930
- config: MKL BLAS
30-
options: -DTARGET_DOMAINS=blas -DREF_BLAS_ROOT=${PWD}/lapack/install
31-
tests: '.*'
31+
domain: blas
32+
build_options: -DREF_BLAS_ROOT=${PWD}/lapack/install
3233
- config: MKL DFT
33-
options: -DTARGET_DOMAINS=dft
34-
tests: '.*'
34+
domain: dft
3535
- config: MKL LAPACK
36-
options: -DTARGET_DOMAINS=lapack -DREF_LAPACK_ROOT=${PWD}/lapack/install
37-
tests: '.*'
36+
domain: lapack
37+
build_options: -DREF_LAPACK_ROOT=${PWD}/lapack/install
3838
- config: MKL RNG
39-
options: -DTARGET_DOMAINS=rng
40-
tests: '.*'
39+
domain: rng
4140
name: unit tests ${{ matrix.config }} CPU
4241
steps:
4342
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
43+
- name: Check if the changes affect this domain
44+
id: domain_check
45+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
46+
with:
47+
script: |
48+
const domainCheck = require('.github/scripts/domain-check.js')
49+
return domainCheck({github, context, domain: "${{ matrix.domain }}"})
4450
- name: Restore netlib from cache
4551
id: cache-lapack
4652
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
4753
with:
4854
path: lapack/install
4955
key: lapack-${{ env.LAPACK_VERSION }}
5056
- name: Install netlib
51-
if: steps.cache-lapack.outputs.cache-hit != 'true'
57+
if: steps.domain_check.outputs.result == 'true' && steps.cache-lapack.outputs.cache-hit != 'true'
5258
run: |
5359
curl -sL https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v${LAPACK_VERSION}.tar.gz | tar zx
5460
SHARED_OPT="lapack-${LAPACK_VERSION} -DBUILD_SHARED_LIBS=on -DCBLAS=on -DLAPACKE=on -DCMAKE_INSTALL_PREFIX=${PWD}/lapack/install"
@@ -59,17 +65,20 @@ jobs:
5965
cmake ${SHARED_OPT} -DBUILD_INDEX64=on -B lapack/build64
6066
cmake --build lapack/build64 ${PARALLEL} --target install
6167
- name: Install oneapi
68+
if: steps.domain_check.outputs.result == 'true'
6269
uses: rscohn2/setup-oneapi@2ad0cf6b74bc2426bdcee825cf88f9db719dd727 # v0.1.0
6370
with:
6471
components: |
6572
6673
6774
- name: Configure/Build for a domain
75+
if: steps.domain_check.outputs.result == 'true'
6876
run: |
6977
source /opt/intel/oneapi/setvars.sh
70-
cmake -DENABLE_MKLGPU_BACKEND=off -DCMAKE_VERBOSE_MAKEFILE=on ${{ matrix.options }} -B build
78+
cmake -DTARGET_DOMAINS=${{ matrix.domain }} -DENABLE_MKLGPU_BACKEND=off -DCMAKE_VERBOSE_MAKEFILE=on ${{ matrix.build_options }} -B build
7179
cmake --build build ${PARALLEL}
7280
- name: Run tests
81+
if: steps.domain_check.outputs.result == 'true'
7382
run: |
7483
source /opt/intel/oneapi/setvars.sh
75-
ctest --test-dir build -R ${{ matrix.tests }}
84+
ctest --test-dir build ${{ matrix.test_options }}

0 commit comments

Comments
 (0)