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 84c6daf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
15 changes: 8 additions & 7 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() {
run_package_std

# 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/
echo `$project_location/output`
echo `$project_location/output/lib`
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/debug/plc tests/lit/
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/release/plc tests/lit/
}

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/[email protected]/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 84c6daf

Please sign in to comment.