From 89016b4bb0ccb3cabf10859194db3bfa19859e5c Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Tue, 11 Jun 2024 11:32:07 +0200 Subject: [PATCH 01/18] Initial commit --- tests/lit/lit.cfg | 18 ++++++++++++++++++ tests/lit/single/arithmetic/addition.st | 23 +++++++++++++++++++++++ tests/lit/single/lit.local.cfg | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 tests/lit/lit.cfg create mode 100644 tests/lit/single/arithmetic/addition.st create mode 100644 tests/lit/single/lit.local.cfg diff --git a/tests/lit/lit.cfg b/tests/lit/lit.cfg new file mode 100644 index 0000000000..259b532793 --- /dev/null +++ b/tests/lit/lit.cfg @@ -0,0 +1,18 @@ +import lit.formats, os, os.path, sys +srcDir = os.path.dirname(__file__) +config.test_format = lit.formats.ShTest(True) +config.pipefail = False + +# TODO: These need to be adjusted to the action runner / build.sh file +# compiler = lit_config.params["COMPILER"] +# lib = lit_config.params["STDLIBPATH"] +# arch = lit_config.params["ARCH"] +# config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out -liec61131std -L{lib}{arch}/lib/ -i "{lib}/include/*.st" -i {srcDir}/helpers/printf.pli --linker=cc')) +# config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{lib}{arch}/lib" /tmp/%basename_t.out')) +# config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes GREY,CHECK --allow-unused-prefixes --match-full-lines')) + +# ~/.local/bin/lit -v -DCOMPILER=/home/vosa@bachmann.at/Development/rusty/target/debug/plc ./tests/lit +compiler = lit_config.params["COMPILER"] +config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out --linker=cc')) +config.substitutions.append(('%RUN', f'/tmp/%basename_t.out')) +config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines')) \ No newline at end of file diff --git a/tests/lit/single/arithmetic/addition.st b/tests/lit/single/arithmetic/addition.st new file mode 100644 index 0000000000..e332cf6802 --- /dev/null +++ b/tests/lit/single/arithmetic/addition.st @@ -0,0 +1,23 @@ +// TODO: The printf should be a standalone ST file which we link with each other ST file +{external} +FUNCTION printf : DINT + VAR_INPUT {ref} + format : STRING; + END_VAR + VAR_INPUT + args : ...; + END_VAR +END_FUNCTION + +// RUN: (%COMPILE %s && %RUN) | %CHECK %s +FUNCTION main + VAR + x : DINT; + y : DINT; + END_VAR + + x := 60; + y := 9; + printf('%d$N', x + y); + // CHECK: 69 +END_FUNCTION \ No newline at end of file diff --git a/tests/lit/single/lit.local.cfg b/tests/lit/single/lit.local.cfg new file mode 100644 index 0000000000..4b8df7dec5 --- /dev/null +++ b/tests/lit/single/lit.local.cfg @@ -0,0 +1,2 @@ +# Declare any *.st file as a standlone test file +config.suffixes = ['.st'] \ No newline at end of file From c50833e1f467319deba0b2ef1330faf4febfb11a Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Tue, 11 Jun 2024 12:08:20 +0200 Subject: [PATCH 02/18] ci: Linux workflow --- .github/workflows/rust.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cc9edf4f75..d8bffe5959 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,6 +21,24 @@ jobs: run: | ./scripts/build.sh --check + test-linux-lit: + name: LIT + runs-on: ubuntu-latest + container: ghcr.io/plc-lang/rust-llvm:latest + steps: + - uses: actions/checkout@v3 + + - name: Install pipx + shell: bash + run: | + apt-get -y install pipx + pipx ensurepath + + + - name: Install lit + shell: bash + run: pipx install lit + test-linux: name: Test Linux runs-on: ubuntu-latest From ca5b7f0190b2165198e329c3554b5b316fce04a4 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 11:06:35 +0200 Subject: [PATCH 03/18] ci: Adjust build.sh --- scripts/build.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index 14ece3a910..a5eb8976a6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -168,6 +168,10 @@ function run_test() { else cargo test $CARGO_OPTIONS --workspace + + # We need a binary to execute the lit tests + cargo build + lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ fi } From ab94a1970d04510a65398ed8efef1891352e1147 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 11:11:45 +0200 Subject: [PATCH 04/18] ci: Isolated lit workflow --- .github/workflows/lit.yml | 22 ++++++++++++++++++++++ .github/workflows/rust.yml | 18 ------------------ 2 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/lit.yml diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml new file mode 100644 index 0000000000..398a648793 --- /dev/null +++ b/.github/workflows/lit.yml @@ -0,0 +1,22 @@ +name: Build + +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + lit-linux: + name: LIT + runs-on: ubuntu-latest + container: ghcr.io/plc-lang/rust-llvm:latest + steps: + - uses: actions/checkout@v3 + + - name: Run lit + shell: bash + run: ./scripts/build.sh --test \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d8bffe5959..cc9edf4f75 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,24 +21,6 @@ jobs: run: | ./scripts/build.sh --check - test-linux-lit: - name: LIT - runs-on: ubuntu-latest - container: ghcr.io/plc-lang/rust-llvm:latest - steps: - - uses: actions/checkout@v3 - - - name: Install pipx - shell: bash - run: | - apt-get -y install pipx - pipx ensurepath - - - - name: Install lit - shell: bash - run: pipx install lit - test-linux: name: Test Linux runs-on: ubuntu-latest From 007d377c3c6c07c7f3bcde966f7f5d633637bc06 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 11:15:10 +0200 Subject: [PATCH 05/18] chore: Add lit generated file to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index cb17664f45..3d60db547f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ *.a *.elf *.out + +# Garbage generated by llvm-lit +tests/lit/**/*.txt +tests/lit/**/Output/ \ No newline at end of file From e0a8615674e0c8d8714ae6ac77ec5db386880f8f Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 12:36:43 +0200 Subject: [PATCH 06/18] Add --lit flag --- scripts/build.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index a5eb8976a6..c3273ab75d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -8,6 +8,7 @@ check_style=0 build=0 doc=0 test=0 +lit=0 coverage=0 release=0 debug=0 @@ -140,6 +141,15 @@ function run_check_style() { cargo fmt -- --check } +function run_lit_test() { + # We need a binary to execute the lit tests + cargo build + cargo build --release + + lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ + lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ +} + function run_test() { CARGO_OPTIONS=$(set_cargo_options) log "Running cargo test" @@ -168,10 +178,6 @@ function run_test() { else cargo test $CARGO_OPTIONS --workspace - - # We need a binary to execute the lit tests - cargo build - lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ fi } @@ -295,6 +301,9 @@ function run_in_container() { if [[ $test -ne 0 ]]; then params="$params --test" fi + if [[ $lit -ne 0 ]]; then + params="$params --lit" + fi if [[ $junit -ne 0 ]]; then params="$params --junit" fi @@ -334,7 +343,7 @@ function run_in_container() { set -o errexit -o pipefail -o noclobber -o nounset OPTIONS=sorbvc -LONGOPTS=sources,offline,release,check,check-style,build,doc,test,junit,verbose,container,linux,container-name:,coverage,package,target: +LONGOPTS=sources,offline,release,check,check-style,build,doc,lit,test,junit,verbose,container,linux,container-name:,coverage,package,target: check_env # -activate quoting/enhanced mode (e.g. by writing out “--options”) @@ -386,6 +395,9 @@ while true; do --test) test=1 ;; + --lit) + lit=1 + ;; --junit) junit=1 ;; @@ -461,6 +473,10 @@ if [[ $test -ne 0 ]]; then run_test fi +if [[ $lit -ne 0 ]]; then + run_lit_test +fi + if [[ $doc -ne 0 ]]; then run_doc fi From d0cb6900e67a0236ad3e90c5b330b4ef31cbb12c Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 13:28:57 +0200 Subject: [PATCH 07/18] Hardcode test --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index c3273ab75d..2c541a2ce5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -146,7 +146,7 @@ function run_lit_test() { cargo build cargo build --release - lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ + /root/.local/bin/lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ } From 3b239cc5f08dfe38215511acdfa8c1c35030c7e9 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 13:33:59 +0200 Subject: [PATCH 08/18] Revert "Hardcode test" This reverts commit d0cb6900e67a0236ad3e90c5b330b4ef31cbb12c. --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 2c541a2ce5..c3273ab75d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -146,7 +146,7 @@ function run_lit_test() { cargo build cargo build --release - /root/.local/bin/lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ + lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ } From bdbeebed159a75840337fe7e4148258b8534a07e Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 13:35:37 +0200 Subject: [PATCH 09/18] pipx ensurepath --- .github/workflows/lit.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml index 6dc6d0ac0a..cdf9ceae43 100644 --- a/.github/workflows/lit.yml +++ b/.github/workflows/lit.yml @@ -19,4 +19,7 @@ jobs: - name: Run lit shell: bash - run: ./scripts/build.sh --lit \ No newline at end of file + run: | + /opt/venv/bin/pipx ensurepath + /opt/venv/bin/pipx ensurepath --global + ./scripts/build.sh --lit \ No newline at end of file From 2fc7b1bd90d0f6b7ba06e4d316be131306d82904 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 13:49:48 +0200 Subject: [PATCH 10/18] doing some sherlock type of shit --- .github/workflows/lit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml index cdf9ceae43..5eca0457bc 100644 --- a/.github/workflows/lit.yml +++ b/.github/workflows/lit.yml @@ -20,6 +20,8 @@ jobs: - name: Run lit shell: bash run: | - /opt/venv/bin/pipx ensurepath + echo $PATH + /opt/venv/bin/pipx ensurepath && echo $PATH /opt/venv/bin/pipx ensurepath --global + echo $PATH ./scripts/build.sh --lit \ No newline at end of file From 9fab1fe2a6d48d8f266082ddeb5c5235593b6966 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 16:27:37 +0200 Subject: [PATCH 11/18] lets give this another chance --- .github/workflows/lit.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml index 5eca0457bc..30465455a6 100644 --- a/.github/workflows/lit.yml +++ b/.github/workflows/lit.yml @@ -11,7 +11,7 @@ on: jobs: lit-linux: - name: LIT + name: Lit (Linux) runs-on: ubuntu-latest container: ghcr.io/plc-lang/rust-llvm:latest steps: @@ -21,7 +21,5 @@ jobs: shell: bash run: | echo $PATH - /opt/venv/bin/pipx ensurepath && echo $PATH - /opt/venv/bin/pipx ensurepath --global - echo $PATH - ./scripts/build.sh --lit \ No newline at end of file + ./scripts/build.sh --lit + echo $PATH \ No newline at end of file From 7c80402bf9c51ccdfbe32c861b7483877d7ce886 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 16:33:36 +0200 Subject: [PATCH 12/18] What about incorrect tests? --- tests/lit/single/arithmetic/addition.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lit/single/arithmetic/addition.st b/tests/lit/single/arithmetic/addition.st index e332cf6802..9f1b8c6706 100644 --- a/tests/lit/single/arithmetic/addition.st +++ b/tests/lit/single/arithmetic/addition.st @@ -19,5 +19,5 @@ FUNCTION main x := 60; y := 9; printf('%d$N', x + y); - // CHECK: 69 -END_FUNCTION \ No newline at end of file + // CHECK: 68 +END_FUNCTION From 8a397d800e5d846a5218d5dd52a11be48d10307c Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 12 Jun 2024 16:41:53 +0200 Subject: [PATCH 13/18] Update to working state --- .github/workflows/lit.yml | 6 ++---- scripts/build.sh | 4 ++-- tests/lit/single/arithmetic/addition.st | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml index 30465455a6..254a064b8b 100644 --- a/.github/workflows/lit.yml +++ b/.github/workflows/lit.yml @@ -17,9 +17,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Run lit + - name: Run `build.sh --lit` shell: bash run: | - echo $PATH - ./scripts/build.sh --lit - echo $PATH \ No newline at end of file + ./scripts/build.sh --lit \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index c3273ab75d..e2d5089bbd 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -146,8 +146,8 @@ function run_lit_test() { cargo build cargo build --release - lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ - lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ + lit -DCOMPILER=$project_location/target/debug/plc tests/lit/ + lit -DCOMPILER=$project_location/target/release/plc tests/lit/ } function run_test() { diff --git a/tests/lit/single/arithmetic/addition.st b/tests/lit/single/arithmetic/addition.st index 9f1b8c6706..ac997c0b8f 100644 --- a/tests/lit/single/arithmetic/addition.st +++ b/tests/lit/single/arithmetic/addition.st @@ -16,8 +16,8 @@ FUNCTION main y : DINT; END_VAR - x := 60; - y := 9; + x := 5; + y := 5; printf('%d$N', x + y); - // CHECK: 68 + // CHECK: 10 END_FUNCTION From 9aa4e8b09f9e21635b8936dbac3b1f4955590bbd Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Thu, 13 Jun 2024 11:09:16 +0200 Subject: [PATCH 14/18] Provide printf function --- tests/lit/lit.cfg | 5 +++-- tests/lit/single/arithmetic/addition.st | 11 ----------- tests/lit/util/printf.pli | 9 +++++++++ 3 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 tests/lit/util/printf.pli diff --git a/tests/lit/lit.cfg b/tests/lit/lit.cfg index 259b532793..5be5d0b6ae 100644 --- a/tests/lit/lit.cfg +++ b/tests/lit/lit.cfg @@ -1,7 +1,8 @@ -import lit.formats, os, os.path, sys +import lit.formats, os, os.path, sys, subprocess srcDir = os.path.dirname(__file__) config.test_format = lit.formats.ShTest(True) config.pipefail = False +rustyRootDirectory = subprocess.check_output("dirname `cargo locate-project --message-format plain`", shell=True).decode("utf-8").strip() # TODO: These need to be adjusted to the action runner / build.sh file # compiler = lit_config.params["COMPILER"] @@ -13,6 +14,6 @@ config.pipefail = False # ~/.local/bin/lit -v -DCOMPILER=/home/vosa@bachmann.at/Development/rusty/target/debug/plc ./tests/lit compiler = lit_config.params["COMPILER"] -config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out --linker=cc')) +config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc')) config.substitutions.append(('%RUN', f'/tmp/%basename_t.out')) config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines')) \ No newline at end of file diff --git a/tests/lit/single/arithmetic/addition.st b/tests/lit/single/arithmetic/addition.st index ac997c0b8f..6ee546ed3e 100644 --- a/tests/lit/single/arithmetic/addition.st +++ b/tests/lit/single/arithmetic/addition.st @@ -1,14 +1,3 @@ -// TODO: The printf should be a standalone ST file which we link with each other ST file -{external} -FUNCTION printf : DINT - VAR_INPUT {ref} - format : STRING; - END_VAR - VAR_INPUT - args : ...; - END_VAR -END_FUNCTION - // RUN: (%COMPILE %s && %RUN) | %CHECK %s FUNCTION main VAR diff --git a/tests/lit/util/printf.pli b/tests/lit/util/printf.pli new file mode 100644 index 0000000000..16036e0cf3 --- /dev/null +++ b/tests/lit/util/printf.pli @@ -0,0 +1,9 @@ +{external} +FUNCTION printf: DINT +VAR_INPUT {ref} + str : STRING; +END_VAR +VAR_INPUT + args: ...; +END_VAR +END_FUNCTION \ No newline at end of file From 69965854fe82472c72efe29357d68d76ea991a5a Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Thu, 13 Jun 2024 11:09:27 +0200 Subject: [PATCH 15/18] Make test runs verbose --- scripts/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index e2d5089bbd..c3273ab75d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -146,8 +146,8 @@ function run_lit_test() { cargo build cargo build --release - lit -DCOMPILER=$project_location/target/debug/plc tests/lit/ - lit -DCOMPILER=$project_location/target/release/plc tests/lit/ + lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ + lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ } function run_test() { From c1e94f51ab4a0e2764b1af356974c10f4384271d Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Thu, 13 Jun 2024 11:54:21 +0200 Subject: [PATCH 16/18] Include stdlib --- .github/workflows/lit.yml | 18 +++++++++++++++--- scripts/build.sh | 21 +++++++++++---------- tests/lit/lit.cfg | 15 ++++----------- tests/lit/single/arithmetic/addition.st | 2 +- tests/lit/single/arithmetic/sqrt.st | 8 ++++++++ 5 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 tests/lit/single/arithmetic/sqrt.st diff --git a/.github/workflows/lit.yml b/.github/workflows/lit.yml index 254a064b8b..4858e5864b 100644 --- a/.github/workflows/lit.yml +++ b/.github/workflows/lit.yml @@ -10,8 +10,8 @@ on: workflow_dispatch: jobs: - lit-linux: - name: Lit (Linux) + lit-linux-debug: + name: lit tests (Linux, debug build) runs-on: ubuntu-latest container: ghcr.io/plc-lang/rust-llvm:latest steps: @@ -20,4 +20,16 @@ jobs: - name: Run `build.sh --lit` shell: bash run: | - ./scripts/build.sh --lit \ No newline at end of file + ./scripts/build.sh --lit + + lit-linux-release: + name: lit tests (Linux, release build) + runs-on: ubuntu-latest + container: ghcr.io/plc-lang/rust-llvm:latest + steps: + - uses: actions/checkout@v3 + + - name: Run `build.sh --lit --release` + shell: bash + run: | + ./scripts/build.sh --lit --release \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index c3273ab75d..ab431fc90f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -142,12 +142,16 @@ function run_check_style() { } function run_lit_test() { - # We need a binary to execute the lit tests - cargo build - cargo build --release + # We need a binary as well as the stdlib and its *.so file before running lit tests + run_build + run_std_build + run_package_std - lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/ - lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/ + if [[ $release -eq 0 ]]; then + lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/debug/plc tests/lit/ + else + lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/release/plc tests/lit/ + fi } function run_test() { @@ -201,6 +205,8 @@ function set_offline() { function run_package_std() { cc=$(get_compiler) + OUTPUT_DIR=$project_location/output + make_dir "$OUTPUT_DIR" log "Packaging Standard functions" log "Removing previous output folder" rm -rf $OUTPUT_DIR @@ -433,11 +439,6 @@ if [[ $container -ne 0 ]]; then exit 0 fi -if [[ $package -ne 0 ]]; then - OUTPUT_DIR=$project_location/output - make_dir "$OUTPUT_DIR" -fi - if [[ $vendor -ne 0 ]]; then generate_sources exit 0 diff --git a/tests/lit/lit.cfg b/tests/lit/lit.cfg index 5be5d0b6ae..eb46b868c4 100644 --- a/tests/lit/lit.cfg +++ b/tests/lit/lit.cfg @@ -4,16 +4,9 @@ config.test_format = lit.formats.ShTest(True) config.pipefail = False rustyRootDirectory = subprocess.check_output("dirname `cargo locate-project --message-format plain`", shell=True).decode("utf-8").strip() -# TODO: These need to be adjusted to the action runner / build.sh file -# compiler = lit_config.params["COMPILER"] -# lib = lit_config.params["STDLIBPATH"] -# arch = lit_config.params["ARCH"] -# config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out -liec61131std -L{lib}{arch}/lib/ -i "{lib}/include/*.st" -i {srcDir}/helpers/printf.pli --linker=cc')) -# config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{lib}{arch}/lib" /tmp/%basename_t.out')) -# config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes GREY,CHECK --allow-unused-prefixes --match-full-lines')) - # ~/.local/bin/lit -v -DCOMPILER=/home/vosa@bachmann.at/Development/rusty/target/debug/plc ./tests/lit -compiler = lit_config.params["COMPILER"] -config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc')) -config.substitutions.append(('%RUN', f'/tmp/%basename_t.out')) +stdlibLocation = lit_config.params["LIB"] +compilerLocation = lit_config.params["COMPILER"] +config.substitutions.append(('%COMPILE', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" {compilerLocation} -o /tmp/%basename_t.out -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st" -i {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc')) +config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" /tmp/%basename_t.out')) config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines')) \ No newline at end of file diff --git a/tests/lit/single/arithmetic/addition.st b/tests/lit/single/arithmetic/addition.st index 6ee546ed3e..79d620ec0e 100644 --- a/tests/lit/single/arithmetic/addition.st +++ b/tests/lit/single/arithmetic/addition.st @@ -1,4 +1,5 @@ // RUN: (%COMPILE %s && %RUN) | %CHECK %s +// CHECK: 10 FUNCTION main VAR x : DINT; @@ -8,5 +9,4 @@ FUNCTION main x := 5; y := 5; printf('%d$N', x + y); - // CHECK: 10 END_FUNCTION diff --git a/tests/lit/single/arithmetic/sqrt.st b/tests/lit/single/arithmetic/sqrt.st new file mode 100644 index 0000000000..5bedfc48fd --- /dev/null +++ b/tests/lit/single/arithmetic/sqrt.st @@ -0,0 +1,8 @@ +// RUN: (%COMPILE %s && %RUN) | %CHECK %s +// CHECK: 2 +FUNCTION main + VAR + res : LREAL; + END_VAR + printf('%d$N', REAL_TO_DINT(SQRT(4.0))); +END_FUNCTION From 5d9b3f289c99088b9f39eeca6754c41071621783 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Thu, 13 Jun 2024 14:27:15 +0200 Subject: [PATCH 17/18] Add multi-file test and beautify lit.cfg --- tests/lit/lit.cfg | 12 +++++++-- .../enum__month_to_int/month_to_int.itest | 2 ++ .../multi/enum__month_to_int/month_to_int.st | 26 +++++++++++++++++++ tests/lit/multi/enum__month_to_int/months.dt | 3 +++ tests/lit/multi/lit.local.cfg | 1 + 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/lit/multi/enum__month_to_int/month_to_int.itest create mode 100644 tests/lit/multi/enum__month_to_int/month_to_int.st create mode 100644 tests/lit/multi/enum__month_to_int/months.dt create mode 100644 tests/lit/multi/lit.local.cfg diff --git a/tests/lit/lit.cfg b/tests/lit/lit.cfg index eb46b868c4..6b07c4aa42 100644 --- a/tests/lit/lit.cfg +++ b/tests/lit/lit.cfg @@ -4,9 +4,17 @@ config.test_format = lit.formats.ShTest(True) config.pipefail = False rustyRootDirectory = subprocess.check_output("dirname `cargo locate-project --message-format plain`", shell=True).decode("utf-8").strip() -# ~/.local/bin/lit -v -DCOMPILER=/home/vosa@bachmann.at/Development/rusty/target/debug/plc ./tests/lit stdlibLocation = lit_config.params["LIB"] compilerLocation = lit_config.params["COMPILER"] -config.substitutions.append(('%COMPILE', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" {compilerLocation} -o /tmp/%basename_t.out -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st" -i {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc')) + +# ...to make the compile command more reable we build it over multiple lines +compile = f'{compilerLocation}' +compile = f'{compile} -o /tmp/%basename_t.out' +compile = f'{compile} -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st"' +compile = f'{compile} -i {rustyRootDirectory}/tests/lit/util/*.pli' +compile = f'{compile} --linker=cc' +print(f'Compile command: {compile}') + +config.substitutions.append(('%COMPILE', f'{compile}')) config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" /tmp/%basename_t.out')) config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines')) \ No newline at end of file diff --git a/tests/lit/multi/enum__month_to_int/month_to_int.itest b/tests/lit/multi/enum__month_to_int/month_to_int.itest new file mode 100644 index 0000000000..fe9a8d88f3 --- /dev/null +++ b/tests/lit/multi/enum__month_to_int/month_to_int.itest @@ -0,0 +1,2 @@ +RUN: %COMPILE %S/month_to_int.st %S/months.dt && %RUN | %CHECK %s +CHECK:6 \ No newline at end of file diff --git a/tests/lit/multi/enum__month_to_int/month_to_int.st b/tests/lit/multi/enum__month_to_int/month_to_int.st new file mode 100644 index 0000000000..aeb9658971 --- /dev/null +++ b/tests/lit/multi/enum__month_to_int/month_to_int.st @@ -0,0 +1,26 @@ +FUNCTION main : DINT + printf('%d', month_to_int(MONTH#June)); +END_FUNCTION + + +FUNCTION month_to_int : INT + VAR_INPUT + month_var : MONTH; + END_VAR + + CASE month_var OF + MONTH.January: month_to_int := 1; + MONTH.February: month_to_int := 2; + MONTH.March: month_to_int := 3; + MONTH.April: month_to_int := 4; + MONTH.May: month_to_int := 5; + MONTH.June: month_to_int := 6; + MONTH.July: month_to_int := 7; + MONTH.August: month_to_int := 8; + MONTH.September: month_to_int := 9; + MONTH.October: month_to_int := 10; + MONTH.November: month_to_int := 11; + MONTH.December: month_to_int := 12; + else month_to_int := 0; + END_CASE; +END_FUNCTION diff --git a/tests/lit/multi/enum__month_to_int/months.dt b/tests/lit/multi/enum__month_to_int/months.dt new file mode 100644 index 0000000000..d1ff02e602 --- /dev/null +++ b/tests/lit/multi/enum__month_to_int/months.dt @@ -0,0 +1,3 @@ +TYPE + MONTH: (January, February, March, April, May, June, July, August, September, October, November, December); +END_TYPE \ No newline at end of file diff --git a/tests/lit/multi/lit.local.cfg b/tests/lit/multi/lit.local.cfg new file mode 100644 index 0000000000..9895838f8f --- /dev/null +++ b/tests/lit/multi/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.itest'] \ No newline at end of file From 7828d7ec7dce4d6da7fff650464b0064ecece355 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Mon, 17 Jun 2024 10:42:56 +0200 Subject: [PATCH 18/18] Rename .itest to .test --- .../{month_to_int.itest => month_to_int.test} | 0 tests/lit/multi/lit.local.cfg | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/lit/multi/enum__month_to_int/{month_to_int.itest => month_to_int.test} (100%) diff --git a/tests/lit/multi/enum__month_to_int/month_to_int.itest b/tests/lit/multi/enum__month_to_int/month_to_int.test similarity index 100% rename from tests/lit/multi/enum__month_to_int/month_to_int.itest rename to tests/lit/multi/enum__month_to_int/month_to_int.test diff --git a/tests/lit/multi/lit.local.cfg b/tests/lit/multi/lit.local.cfg index 9895838f8f..4b89c231b9 100644 --- a/tests/lit/multi/lit.local.cfg +++ b/tests/lit/multi/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.itest'] \ No newline at end of file +config.suffixes = ['.test'] \ No newline at end of file