Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial CI setup and a few tests #21

Merged
merged 12 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Test'
on:
pull_request:
branches: [ "master" ]
push:
branches: [ "master" ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:

integration-tests:
name: "Integration tests"
runs-on: [self-hosted, linux, normal]
steps:
- name: 'Check out code'
uses: actions/checkout@v4
with:
# Check out pull request HEAD instead of merge commit.
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive

- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-08-28

- name: 'Set up tree for rust dependency'
run: make setup

- name: 'Cache smir_pretty and rustc'
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
deps/rust/src
cache-directories: |
target
deps/rust/src/build
deps/rust/src/target

- name: 'Build smir_pretty and its rustc dependency'
run: | # rustc bootstrap checks this and refuses stage 1 in "CI"
export GITHUB_ACTIONS="in denial" && \
echo "GITHUB_ACTIONS = ${GITHUB_ACTIONS}" && \
make build_all

- name: 'Run smir integration tests'
run: |
make integration-test
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,31 @@ generate_ui_tests:
cd "${RUST_SRC}"; ./get_runpass.sh tests/ui > "${RUST_DIR}"/tests_ui_sources
-cd "${RUST_SRC}"; ./ui_compiletest.sh "${RUST_SRC}" "${RUST_DIR}"/tests/ui/upstream "${RUST_DIR}"/tests_ui_sources --pass check --force-rerun 2>&1 > "${RUST_DIR}"/tests_ui_upstream.log
-cd "${RUST_SRC}"; RUST_BIN="${PWD}"/run.sh ./ui_compiletest.sh "${RUST_SRC}" "${RUST_DIR}"/tests/ui/smir "${RUST_DIR}"/tests_ui_sources --pass check --force-rerun 2>&1 > "${RUST_DIR}"/tests_ui_smir.log

TESTDIR=$(CURDIR)/tests/integration/programs

.PHONY: integration-test
integration-test: TESTS ?= $(shell find $(TESTDIR) -type f -name "*.rs")
integration-test: SMIR ?= $(CURDIR)/run.sh -Z no-codegen
# override this to tweak how expectations are formatted
integration-test: NORMALIZE ?= jq -S -e -f $(TESTDIR)/../normalise-filter.jq
# override this to re-make golden files
integration-test: DIFF ?= | diff -
integration-test: build
errors=""; \
report() { echo "$$1: $$2"; errors="$$errors\n$$1: $$2"; }; \
for rust in ${TESTS}; do \
target=$${rust%.rs}.smir.json; \
dir=$$(dirname $${rust}); \
echo "$$rust"; \
${SMIR} --out-dir $${dir} $${rust} || report "$$rust" "Conversion failed"; \
[ -f $${target} ] \
&& ${NORMALIZE} $${target} ${DIFF} $${target}.expected \
&& rm $${target} \
|| report "$$rust" "Unexpected json output"; \
done; \
[ -z "$$errors" ] || (echo "===============\nFAILING TESTS:$$errors"; exit 1)


golden:
make integration-test DIFF=">"
3 changes: 0 additions & 3 deletions panic_example.rs

This file was deleted.

1 change: 1 addition & 0 deletions panic_example.rs
1 change: 0 additions & 1 deletion panic_example.smir.json

This file was deleted.

1 change: 1 addition & 0 deletions panic_example.smir.json
18 changes: 18 additions & 0 deletions tests/integration/normalise-filter.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ allocs:
( [ .allocs[] ]
# sort allocs by their ID
| sort_by(.[0])
# TODO this should be removed
| map ( select( .[1] | has("Static") | not ) )
jberthold marked this conversation as resolved.
Show resolved Hide resolved
),
functions:
( [ .functions[] ]
# sort functions by their ID (int, first in list)
| sort_by(.[0])
),
items:
( [ .items[] ]
# sort items by symbol name they refer to
| sort_by(.symbol_name)
)
}
3 changes: 3 additions & 0 deletions tests/integration/programs/panic_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
panic!()
}
Loading
Loading