Skip to content

Commit 21e1b2a

Browse files
authored
Merge branch 'master' into for-loops
2 parents fe2fb9e + 45f487f commit 21e1b2a

File tree

12 files changed

+149
-6
lines changed

12 files changed

+149
-6
lines changed

.github/workflows/lit.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Build
2+
3+
on:
4+
# Triggers the workflow on push or pull request events but only for the master branch
5+
push:
6+
pull_request:
7+
branches: [ master ]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
lit-linux-debug:
14+
name: lit tests (Linux, debug build)
15+
runs-on: ubuntu-latest
16+
container: ghcr.io/plc-lang/rust-llvm:latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Run `build.sh --lit`
21+
shell: bash
22+
run: |
23+
./scripts/build.sh --lit
24+
25+
lit-linux-release:
26+
name: lit tests (Linux, release build)
27+
runs-on: ubuntu-latest
28+
container: ghcr.io/plc-lang/rust-llvm:latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- name: Run `build.sh --lit --release`
33+
shell: bash
34+
run: |
35+
./scripts/build.sh --lit --release

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
*.a
1212
*.elf
1313
*.out
14+
15+
# Garbage generated by llvm-lit
16+
tests/lit/**/*.txt
17+
tests/lit/**/Output/

scripts/build.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ check_style=0
88
build=0
99
doc=0
1010
test=0
11+
lit=0
1112
coverage=0
1213
release=0
1314
debug=0
@@ -140,6 +141,19 @@ function run_check_style() {
140141
cargo fmt -- --check
141142
}
142143

144+
function run_lit_test() {
145+
# We need a binary as well as the stdlib and its *.so file before running lit tests
146+
run_build
147+
run_std_build
148+
run_package_std
149+
150+
if [[ $release -eq 0 ]]; then
151+
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/debug/plc tests/lit/
152+
else
153+
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/release/plc tests/lit/
154+
fi
155+
}
156+
143157
function run_test() {
144158
CARGO_OPTIONS=$(set_cargo_options)
145159
log "Running cargo test"
@@ -191,6 +205,8 @@ function set_offline() {
191205

192206
function run_package_std() {
193207
cc=$(get_compiler)
208+
OUTPUT_DIR=$project_location/output
209+
make_dir "$OUTPUT_DIR"
194210
log "Packaging Standard functions"
195211
log "Removing previous output folder"
196212
rm -rf $OUTPUT_DIR
@@ -291,6 +307,9 @@ function run_in_container() {
291307
if [[ $test -ne 0 ]]; then
292308
params="$params --test"
293309
fi
310+
if [[ $lit -ne 0 ]]; then
311+
params="$params --lit"
312+
fi
294313
if [[ $junit -ne 0 ]]; then
295314
params="$params --junit"
296315
fi
@@ -330,7 +349,7 @@ function run_in_container() {
330349
set -o errexit -o pipefail -o noclobber -o nounset
331350

332351
OPTIONS=sorbvc
333-
LONGOPTS=sources,offline,release,check,check-style,build,doc,test,junit,verbose,container,linux,container-name:,coverage,package,target:
352+
LONGOPTS=sources,offline,release,check,check-style,build,doc,lit,test,junit,verbose,container,linux,container-name:,coverage,package,target:
334353

335354
check_env
336355
# -activate quoting/enhanced mode (e.g. by writing out “--options”)
@@ -382,6 +401,9 @@ while true; do
382401
--test)
383402
test=1
384403
;;
404+
--lit)
405+
lit=1
406+
;;
385407
--junit)
386408
junit=1
387409
;;
@@ -417,11 +439,6 @@ if [[ $container -ne 0 ]]; then
417439
exit 0
418440
fi
419441

420-
if [[ $package -ne 0 ]]; then
421-
OUTPUT_DIR=$project_location/output
422-
make_dir "$OUTPUT_DIR"
423-
fi
424-
425442
if [[ $vendor -ne 0 ]]; then
426443
generate_sources
427444
exit 0
@@ -457,6 +474,10 @@ if [[ $test -ne 0 ]]; then
457474
run_test
458475
fi
459476

477+
if [[ $lit -ne 0 ]]; then
478+
run_lit_test
479+
fi
480+
460481
if [[ $doc -ne 0 ]]; then
461482
run_doc
462483
fi

tests/lit/lit.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import lit.formats, os, os.path, sys, subprocess
2+
srcDir = os.path.dirname(__file__)
3+
config.test_format = lit.formats.ShTest(True)
4+
config.pipefail = False
5+
rustyRootDirectory = subprocess.check_output("dirname `cargo locate-project --message-format plain`", shell=True).decode("utf-8").strip()
6+
7+
stdlibLocation = lit_config.params["LIB"]
8+
compilerLocation = lit_config.params["COMPILER"]
9+
10+
# ...to make the compile command more reable we build it over multiple lines
11+
compile = f'{compilerLocation}'
12+
compile = f'{compile} -o /tmp/%basename_t.out'
13+
compile = f'{compile} -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st"'
14+
compile = f'{compile} -i {rustyRootDirectory}/tests/lit/util/*.pli'
15+
compile = f'{compile} --linker=cc'
16+
print(f'Compile command: {compile}')
17+
18+
config.substitutions.append(('%COMPILE', f'{compile}'))
19+
config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" /tmp/%basename_t.out'))
20+
config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines'))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FUNCTION main : DINT
2+
printf('%d', month_to_int(MONTH#June));
3+
END_FUNCTION
4+
5+
6+
FUNCTION month_to_int : INT
7+
VAR_INPUT
8+
month_var : MONTH;
9+
END_VAR
10+
11+
CASE month_var OF
12+
MONTH.January: month_to_int := 1;
13+
MONTH.February: month_to_int := 2;
14+
MONTH.March: month_to_int := 3;
15+
MONTH.April: month_to_int := 4;
16+
MONTH.May: month_to_int := 5;
17+
MONTH.June: month_to_int := 6;
18+
MONTH.July: month_to_int := 7;
19+
MONTH.August: month_to_int := 8;
20+
MONTH.September: month_to_int := 9;
21+
MONTH.October: month_to_int := 10;
22+
MONTH.November: month_to_int := 11;
23+
MONTH.December: month_to_int := 12;
24+
else month_to_int := 0;
25+
END_CASE;
26+
END_FUNCTION
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUN: %COMPILE %S/month_to_int.st %S/months.dt && %RUN | %CHECK %s
2+
CHECK:6
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TYPE
2+
MONTH: (January, February, March, April, May, June, July, August, September, October, November, December);
3+
END_TYPE

tests/lit/multi/lit.local.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.suffixes = ['.test']
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
2+
// CHECK: 10
3+
FUNCTION main
4+
VAR
5+
x : DINT;
6+
y : DINT;
7+
END_VAR
8+
9+
x := 5;
10+
y := 5;
11+
printf('%d$N', x + y);
12+
END_FUNCTION

tests/lit/single/arithmetic/sqrt.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
2+
// CHECK: 2
3+
FUNCTION main
4+
VAR
5+
res : LREAL;
6+
END_VAR
7+
printf('%d$N', REAL_TO_DINT(SQRT(4.0)));
8+
END_FUNCTION

tests/lit/single/lit.local.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Declare any *.st file as a standlone test file
2+
config.suffixes = ['.st']

tests/lit/util/printf.pli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{external}
2+
FUNCTION printf: DINT
3+
VAR_INPUT {ref}
4+
str : STRING;
5+
END_VAR
6+
VAR_INPUT
7+
args: ...;
8+
END_VAR
9+
END_FUNCTION

0 commit comments

Comments
 (0)