-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR closes #43 by making the following changes - move DSL tests from `bin/main.ml` to `test/well_formed.ml` - set up CI according to issue #43 and @anshumanmohan's comment below - fill in `dune-project`
- Loading branch information
1 parent
96c20f6
commit fd378a1
Showing
10 changed files
with
197 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Format | ||
|
||
on: | ||
push: | ||
pull_request: | ||
branches: [main] | ||
|
||
# Ensures that only the latest commit of a PR can execute the actions. | ||
# Useful for cancelling job when a sequence of commits are quickly added. | ||
concurrency: | ||
group: ${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set-up OCaml | ||
uses: ocaml/setup-ocaml@v3 | ||
with: | ||
ocaml-compiler: 5 | ||
- name: Install ocamlformat | ||
working-directory: dsl_lang | ||
run: opam install ocamlformat | ||
- name: Check format | ||
working-directory: dsl_lang | ||
run: | | ||
[ $(opam exec -- dune fmt 2> >(wc -c)) -eq 0 ] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
branches: [main] | ||
|
||
# Ensures that only the latest commit of a PR can execute the actions. | ||
# Useful for cancelling job when a sequence of commits are quickly added. | ||
concurrency: | ||
group: ${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set-up OCaml | ||
uses: ocaml/setup-ocaml@v3 | ||
with: | ||
ocaml-compiler: 5 | ||
- name: Install dependencies | ||
working-directory: dsl_lang | ||
run: | | ||
opam install . --deps-only | ||
- name: DSL tests | ||
working-directory: dsl_lang | ||
run: | | ||
opam exec -- dune build | ||
opam exec -- dune test | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(executable | ||
(public_name dsl_lang) | ||
(name main) | ||
(libraries dsl_core ounit2)) | ||
(libraries dsl_core)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +0,0 @@ | ||
open Dsl_core | ||
open OUnit2 | ||
|
||
(* The test suite for running our interpreter. *) | ||
|
||
let eval_prog (filename : string) = | ||
let res = Parse.parse_file filename in | ||
Eval.eval res | ||
|
||
let make_test (name : string) (filename : string) (val_str : string) = | ||
name >:: fun _ -> | ||
assert_equal val_str | ||
(Util.string_of_policy (eval_prog filename)) | ||
~printer:(fun x -> x) | ||
|
||
let make_error_test (name : string) (filename : string) (exn : exn) = | ||
name >:: fun _ -> | ||
assert_raises exn (fun () -> | ||
try Util.string_of_policy (eval_prog filename) | ||
with Eval.UnboundVariable _ -> raise exn) | ||
|
||
let tests = | ||
[ | ||
make_test "single class policy" "../../dsl/progs/now/drop_a_class.sched" "A"; | ||
make_test "fifo sugar 1 class" | ||
"../../dsl/progs/now/fifo_1_class_sugar.sched" "A"; | ||
make_test "fifo 1 class" "../../dsl/progs/now/fifo_1_class.sched" "A"; | ||
make_test "fifo of 3" "../../dsl/progs/now/fifo_n_classes.sched" | ||
"fifo[A, B, C]"; | ||
make_test "rr of 1" "../../dsl/progs/now/rr_1_class.sched" "rr[A]"; | ||
make_test "rr of 2" "../../dsl/progs/now/rr_2_classes.sched" "rr[A, B]"; | ||
make_test "multiple assignments" | ||
"../../dsl/progs/now/rr_hier_merge_sugar.sched" | ||
"rr[fifo[BX, BY], rr[RP, RT]]"; | ||
make_test "2 assignments w/ substitutions" | ||
"../../dsl/progs/now/rr_hier.sched" "rr[B, rr[RP, RT]]"; | ||
make_test "3 classes with substitutions" | ||
"../../dsl/progs/soon/rr_n_class_hier.sched" | ||
"rr[A, B, rr[rr[CU, CV], rr[CW, CX]]]"; | ||
make_test "rr of 3" "../../dsl/progs/soon/rr_n_classes.sched" "rr[A, B, C]"; | ||
make_test "rr and strict substitutions" | ||
"../../dsl/progs/soon/rr_strict_n_classes_hier.sched" | ||
"strict[A, B, rr[rr[CU, CV], strict[CW, CX]]]"; | ||
make_test "strict of 3" "../../dsl/progs/soon/strict_n_classes.sched" | ||
"strict[A, B, C]"; | ||
make_test "leaky bucket of 2" "../../dsl/progs/nwc/leaky_2_classes.sched" | ||
"leaky[[A, B], width = 5, buffer = 10]"; | ||
make_test "token bucket of 2 round robins" "../../dsl/progs/nwc/token_2_rr_children.sched" | ||
"token[[rr[A, B], rr[C, D]], width = 20, time = 50]"; | ||
make_test "stop and go with 3 classes" "../../dsl/progs/nwc/sg_3_classes.sched" | ||
"stopandgo[[stopandgo[[A, B], width = 10], stopandgo[[C], width = 10]], width = 5]"; | ||
make_test "rcsp for 4 classes" "../../dsl/progs/nwc/rcsp_4_classes.sched" | ||
"rcsp[A, B, C, D]"; | ||
|
||
] | ||
|
||
let error_tests = | ||
[ | ||
make_error_test "undeclared class" | ||
"../../dsl/progs/incorrect/undeclared_classes.sched" | ||
(Eval.UnboundVariable "..."); | ||
make_error_test "unbound variable" | ||
"../../dsl/progs/incorrect/unbound_var.sched" (Eval.UnboundVariable "..."); | ||
make_error_test "unbound var in middle of list of assignments" | ||
"../../dsl/progs/incorrect/unbound_var_hier.sched" | ||
(Eval.UnboundVariable "..."); | ||
] | ||
|
||
let suite = "suite" >::: tests @ error_tests | ||
let () = run_test_tt_main suite | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
(lang dune 3.10) | ||
(using menhir 2.1) | ||
(lang dune 3.16) | ||
|
||
(name dsl_lang) | ||
|
||
(generate_opam_files true) | ||
|
||
(source | ||
(github cucapra/packet-scheduling)) | ||
|
||
(authors | ||
"Anshuman Mohan" | ||
"Cassandra Sziklai" | ||
"Kabir Samsi" | ||
"Akash Dhiraj") | ||
|
||
(maintainers | ||
"Anshuman Mohan" | ||
"Cassandra Sziklai" | ||
"Kabir Samsi" | ||
"Akash Dhiraj") | ||
|
||
(license MIT) | ||
|
||
(using menhir 3.0) | ||
|
||
(package | ||
(name dsl_lang) | ||
(synopsis "DSL for Programmable Packet Scheduling") | ||
(description "TBD") | ||
(depends ocaml dune ounit2 menhir)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(tests | ||
(names well_formed) | ||
(libraries dsl_core ounit2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
open Dsl_core | ||
open OUnit2 | ||
|
||
(* The test suite for running our interpreter. *) | ||
|
||
let prefix = "../../../../dsl/progs/" | ||
|
||
let eval_prog (filename : string) = | ||
let res = Parse.parse_file (prefix ^ filename) in | ||
Eval.eval res | ||
|
||
let make_test (name : string) (filename : string) (val_str : string) = | ||
name >:: fun _ -> | ||
assert_equal val_str | ||
(Util.string_of_policy (eval_prog filename)) | ||
~printer:(fun x -> x) | ||
|
||
let make_error_test (name : string) (filename : string) (exn : exn) = | ||
name >:: fun _ -> | ||
assert_raises exn (fun () -> | ||
try Util.string_of_policy (eval_prog filename) | ||
with Eval.UnboundVariable _ -> raise exn) | ||
|
||
let tests = | ||
[ | ||
make_test "single class policy" "now/drop_a_class.sched" "A"; | ||
make_test "fifo sugar 1 class" "now/fifo_1_class_sugar.sched" "A"; | ||
make_test "fifo 1 class" "now/fifo_1_class.sched" "A"; | ||
make_test "fifo of 3" "now/fifo_n_classes.sched" "fifo[A, B, C]"; | ||
make_test "rr of 1" "now/rr_1_class.sched" "rr[A]"; | ||
make_test "rr of 2" "now/rr_2_classes.sched" "rr[A, B]"; | ||
make_test "multiple assignments" "now/rr_hier_merge_sugar.sched" | ||
"rr[fifo[BX, BY], rr[RP, RT]]"; | ||
make_test "2 assignments w/ substitutions" "now/rr_hier.sched" | ||
"rr[B, rr[RP, RT]]"; | ||
make_test "3 classes with substitutions" "soon/rr_n_class_hier.sched" | ||
"rr[A, B, rr[rr[CU, CV], rr[CW, CX]]]"; | ||
make_test "rr of 3" "soon/rr_n_classes.sched" "rr[A, B, C]"; | ||
make_test "rr and strict substitutions" | ||
"soon/rr_strict_n_classes_hier.sched" | ||
"strict[A, B, rr[rr[CU, CV], strict[CW, CX]]]"; | ||
make_test "strict of 3" "soon/strict_n_classes.sched" "strict[A, B, C]"; | ||
] | ||
|
||
let error_tests = | ||
[ | ||
make_error_test "undeclared class" "incorrect/undeclared_classes.sched" | ||
(Eval.UnboundVariable "..."); | ||
make_error_test "unbound variable" "incorrect/unbound_var.sched" | ||
(Eval.UnboundVariable "..."); | ||
make_error_test "unbound var in middle of list of assignments" | ||
"incorrect/unbound_var_hier.sched" (Eval.UnboundVariable "..."); | ||
] | ||
|
||
let suite = "suite" >::: tests @ error_tests | ||
let () = run_test_tt_main suite |