Skip to content

Commit 87f1556

Browse files
committed
Add parity test
Signed-off-by: Jonatan Waern <[email protected]>
1 parent 4fd11ab commit 87f1556

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

.github/workflows/binaries.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ on:
1414
description: "Name of uploaded binary artifact"
1515
type: string
1616
default: "dls"
17+
parity_test_path:
18+
description: "If set, will run parser parity test on .dml files under path (see parser/test.rs for details on ignored folders and tests)"
19+
type: string
20+
default: ""
1721
log-dir:
1822
description: "Folder to put cargo logs in"
1923
required: false
@@ -46,6 +50,18 @@ jobs:
4650
run: |
4751
set -o pipefail
4852
cargo test --verbose 2>&1 | tee -a ${{ inputs.log-dir }}/test.log
53+
- name: Prepare Parity Test
54+
if: ${{ inputs.parity_test_path != '' }}
55+
uses: actions/checkout@v4
56+
with:
57+
repository: https://github.com/intel/device-modeling-language
58+
path: ${{ inputs.parity_test_path }}
59+
- name: Parity Test
60+
shell: bash
61+
if: ${{ inputs.parity_test_path != '' }}
62+
run: |
63+
set -o pipefail
64+
PARITY_TEST_ROOT=${{ inputs.parity_test_path }} cargo test --verbose -- --ignored --nocapture 2>&1 | tee -a ${{ inputs.log-dir }}/test.log
4965
- name: Clippy
5066
shell: bash
5167
if: ${{ success() || failure() }}

.github/workflows/nightly.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Nightly Test
2+
3+
permissions: read-all
4+
5+
on:
6+
schedule:
7+
- cron: "0 0 * * *"
8+
workflow_dispatch:
9+
jobs:
10+
build-package:
11+
strategy:
12+
matrix:
13+
os:
14+
- ubuntu-latest
15+
- windows-latest
16+
include:
17+
- os: ubuntu-latest
18+
binary: dls
19+
- os: windows-latest
20+
binary: dls.exe
21+
uses: ./.github/workflows/binaries.yml
22+
with:
23+
binary_name: ${{ matrix.binary }}
24+
output_binary_name: dml-server-${{ matrix.os }}
25+
parity_test_path: ./dmlc-repo/test
26+
log-dir: ${{ matrix.binary }}-logs
27+
os: ${{ matrix.os }}
28+
check-package:
29+
uses: ./.github/workflows/scans.yml
30+
with:
31+
os: ubuntu-latest
32+
log-dir: checking-logs
33+
merge-package:
34+
runs-on:
35+
- ubuntu-latest
36+
needs: build-package
37+
steps:
38+
- name: Merge Artifacts
39+
uses: actions/upload-artifact/merge@v4
40+
with:
41+
name: dml-server
42+
pattern: dml-server-*

.github/workflows/rust.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
pull_request:
99
branches: [ "main" ]
1010
workflow_dispatch:
11-
schedule:
12-
- cron: "0 0 * * *"
1311
jobs:
1412
build-package:
1513
strategy:

src/analysis/parsing/parser.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,4 +759,48 @@ mod test {
759759
kind: TokenKind::CondOp,
760760
}, TokenKind::IntConstant.description())]);
761761
}
762+
763+
// Sanity to check we never break simple parsing
764+
#[test]
765+
#[ignore]
766+
fn parity_test() {
767+
let test_root = std::env::var("PARITY_TEST_ROOT").unwrap();
768+
let mut file_count = 0;
769+
let failed_files: Vec<_> = walkdir::WalkDir::new(test_root)
770+
.into_iter()
771+
.filter_map(|r|r.ok())
772+
.filter(|e|!e.file_type().is_dir())
773+
.filter_map(|e|e.path().to_str().map(ToString::to_string))
774+
.filter(|f|!f.contains("errors")
775+
&& !f.contains("1.2")
776+
&& !f.contains("bugs")
777+
&& !f.contains("legacy")
778+
&& f.ends_with(".dml"))
779+
.filter_map(|f|{
780+
let read_file = std::fs::read_to_string(&f);
781+
if let Err(e) = read_file {
782+
return Some(format!("Failed to read {}; {}", f, e));
783+
}
784+
let read_file = read_file.unwrap();
785+
let lexer = TokenKind::lexer(&read_file);
786+
let errors: Vec<_> = lexer.filter(
787+
|tok|matches!(
788+
tok,
789+
Ok(TokenKind::LexerError) | Err(_))).collect();
790+
if !errors.is_empty() {
791+
return Some(format!(
792+
"Failed to parse {} with the following errors: {}",
793+
f,
794+
errors.into_iter().map(|e|format!("{:?}", e))
795+
.collect::<Vec<_>>().join(", ")));
796+
}
797+
file_count += 1;
798+
None
799+
}).collect();
800+
assert!(failed_files.is_empty(),
801+
"{}",
802+
failed_files.join("\n"));
803+
println!("Succesfully parsed {} files from PARITY_TEST_ROOT",
804+
file_count);
805+
}
762806
}

0 commit comments

Comments
 (0)