Skip to content

Commit

Permalink
Include stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
volsa committed Jun 13, 2024
1 parent 6996585 commit 780a43b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/lit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ 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:
- uses: actions/checkout@v3

- name: Run `build.sh --lit`
- name: `build.sh --lit`
shell: bash
run: |
./scripts/build.sh --lit
./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: `build.sh --lit --release`
shell: bash
run: |
./scripts/build.sh --lit --release
21 changes: 11 additions & 10 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions tests/lit/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
2 changes: 1 addition & 1 deletion tests/lit/single/arithmetic/addition.st
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
// CHECK: 10
FUNCTION main
VAR
x : DINT;
Expand All @@ -8,5 +9,4 @@ FUNCTION main
x := 5;
y := 5;
printf('%d$N', x + y);
// CHECK: 10
END_FUNCTION
8 changes: 8 additions & 0 deletions tests/lit/single/arithmetic/sqrt.st
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 780a43b

Please sign in to comment.