Skip to content

Commit

Permalink
hw(2-6): Add a global path prefix (#24)
Browse files Browse the repository at this point in the history
Since the test suite contains tests for multiple homeworks, it is
benefitial to place it outside of any specific homework to prevent
duplication. For this to work, one needs a way to specify the relative
path between any homework and this repo.

This change provides such a way.
  • Loading branch information
Multimodcrafter committed Nov 23, 2021
1 parent c2a6129 commit 87aa91b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions 03/dbernhard.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

let prefix = "./compiler-design-eth-tests/03/dbernhard/"
let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/03/dbernhard/"

let dbernhard_tests = [
prefix ^ "load_simple.ll", 23L
Expand All @@ -18,4 +18,4 @@ let dbernhard_tests = [
; prefix ^ "gep_inside_struct.ll", 42L (* index inside a struct which contains an array *)
; prefix ^ "gep_inside_struct_array.ll", 11L (* index inside an array which is inside a struct *)
; prefix ^ "gep_twice.ll", 199L
]
]
2 changes: 1 addition & 1 deletion 03/haenniro.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Assert

let prefix = "./compiler-design-eth-tests/03/haenniro/"
let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/03/haenniro/"

let my_tests =
(* Warning 1: The first test works only on Linux as it contains raw assembly with invalid labels. To make it work on mac, change the labels in stacktest_asm.s to have an underscore in front of them.*)
Expand Down
2 changes: 1 addition & 1 deletion 03/nicdard.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let executed tests =

(* Add prefix to tests *)
let prefix = List.map (fun (fname, expected_result) ->
("./compiler-design-eth-tests/03/nicdard/" ^ fname, expected_result))
(Test_config.global_prefix ^ "./compiler-design-eth-tests/03/nicdard/" ^ fname, expected_result))

let gep_tests = prefix
[ "gep0.ll", 1L
Expand Down
4 changes: 2 additions & 2 deletions 03/zikai.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let prefix = "./compiler-design-eth-tests/03/zikai/"
let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/03/zikai/"

let zikai_tests = [
prefix ^ "nested_structs.ll", 16L
; prefix ^ "nested_structs2.ll", 8L
; prefix ^ "nested_structs3.ll", 127L
]
]
2 changes: 1 addition & 1 deletion 04/dbernhard.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Assert

let prefix = "./compiler-design-eth-tests/04/dbernhard/"
let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/04/dbernhard/"

let simple_tests = [
(prefix ^ "simple_while.oat", "", "10")
Expand Down
2 changes: 1 addition & 1 deletion 04/nicdard.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Add path to test files *)
let prefix = List.map (fun (fname, args, expected_result) ->
("./compiler-design-eth-tests/04/nicdard/" ^ fname, args, expected_result))
(Test_config.global_prefix ^ "./compiler-design-eth-tests/04/nicdard/" ^ fname, args, expected_result))

let easy_tests =
[ ("easyrun0.oat", "", "10")
Expand Down
2 changes: 1 addition & 1 deletion 04/thbwd.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Assert

let prefix = "./compiler-design-eth-tests/04/thbwd/"
let prefix = Test_config.global_prefix ^ "./compiler-design-eth-tests/04/thbwd/"

let simple_tests =
[ (prefix ^ "nested_return_array.oat", "", "0")
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,32 @@ In any case, I will keep an eye at the course's forum in orther to gather all te
## Setup
If you want to integrate these tests into your project instead of copying the files you can follow these steps:

1. Clone this repo into the folder containing the `Makefile` of hw{2,3,4}.
2. Adapt the Makefile to include these tests:
```
1. Clone this repo anywhere you like (let the path to the cloned repo be called `<repo_path>` and let `<project_path>` be the directory, which contains the makefile for the current homework)
2. Create a symbolic link to `<repo_path>` called `sharedtests` in `<project_path>`
3. Adapt the Makefile to include these tests:
```diff
main.native: gradedtests.ml studenttests.ml main.ml driver.ml backend.ml util/platform.ml
- ocamlbuild -Is util,x86,ll,grading -libs unix,str,nums main.native -use-menhir
+ ocamlbuild -Is util,x86,ll,grading,compiler-design-eth-tests/0{2,3,4} -libs unix,str,nums main.native -use-menhir
+ ocamlbuild -Is util,x86,ll,grading,sharedtests,sharedtests/0{2,3,4,5,6} -libs unix,str,nums main.native -use-menhir

main.byte: gradedtests.ml studenttests.ml main.ml driver.ml backend.ml util/platform.ml
- ocamlbuild -Is util,x86,ll,grading -libs unix,str,nums main.byte -use-menhir
+ ocamlbuild -Is util,x86,ll,grading,compiler-design-eth-tests/0{2,3,4} -libs unix,str,nums main.byte -use-menhir
```

2a. *Optional*: If you use merlin you should add these lines to the `.merlin` file:
```
+B _build/compiler-design-eth-tests
+B _build/compiler-design-eth-tests/0{2,3,4}
```
3. Add our shared suite to `main.ml`:
+ ocamlbuild -Is util,x86,ll,grading,sharedtests,sharedtests/0{2,3,4,5,6} -libs unix,str,nums main.byte -use-menhir
```
(Note: depending on the makefile, the additional directories might need to be added at the top in a _DIRS_ variable or similar)
4. Add our shared suite to `main.ml`:
```diff
-let suite = ref (Studenttests.provided_tests @ Gradedtests.graded_tests)
+let suite = ref (
+ Studenttests.provided_tests @
+ Gradedtests.graded_tests @
+ Sharedtests.shared_suite)
```
```
5. Edit the `global_prefix` in the file `Test_config` of this repo to represent the relative path from inside `<project_path>` to `<repo_path>`. By default it is setup such that `<repo_path>` and `<project_path>` have the same parent directory.
6. *Optional*: If you use merlin you should add these lines to the `.merlin` file:
```diff
+B _build/sharedtests/**
+S sharedtests/**
```

And now `make test` should also run our tests :)
And now `make test` should also run our tests :)
1 change: 1 addition & 0 deletions test_config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let global_prefix = "../"

0 comments on commit 87aa91b

Please sign in to comment.