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

[embedded] Add QEMU-based testing configs for ARM and AVR for runtime testing #75427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kubamracek
Copy link
Contributor

This PR adds lit test configurations that execute runtime tests inside QEMU, one at a time, in the "baremetal" mode of QEMU.

More concretely:

  • A lit configuration can now be "EXTERNAL_EMBEDDED_PLATFORM", which means that compilation, linking and execution will consult a new test support tool called embedded-test-support.py and ask for compiler flags, linker flags and execution for a particular device type.
  • For ARM and AVR CPUs, a super minimal baremetal runtime support is added (interrupt vectors, stack setup code, linker script, etc.) and used for building valid standalone firmwares for each lit test.
  • The embedded-test-support.py script is intended to be easily extensible with new devices, CPU architectures, and even other simulators besides QEMU.
  • All Embedded Swift tests (in the test/embedded/ directory) now opt-in to the new Swift Driver (as the old driver is not really maintained anymore and has unfixed bugs).

Currently, this setup is not going to run automatically anywhere. It will only be available for manual usage by (1) enabling SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING, and (2) running tests e.g. with:

$ ../llvm-macosx-arm64/bin/llvm-lit -v ./test-embedded-armv7 --filter embedded/

Not all the embedded tests pass under the ARM and AVR configs, but the plan is to fix them (or disable when appropriate) and eventually start running these test configurations in Swift CI.

@kubamracek
Copy link
Contributor Author

CC @carlos4242


int putchar(int c) {
// AVR's UART0 DR register
*((volatile char *)0xc6) = c;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This should work fine in QEMU although it probably wouldn't work on a device, as you need to wait for the byte to transmit through the UART, something like: https://github.com/microswift-packages/HAL/blob/develop/module/UART.swift#L472 (we got caught out by this a few times as swift often optimised this check away!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: that repo is private and access through a volatile pointer should never be optimized away. Could you share the source?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an extract from our hardware library...

static var dataRegisterEmpty: Bool {
        get {
            return !((USARTControlAndStatusRegisterA & 0b00100000) == 0)
        }
}

static func write(_ byte: PortDataType) {
        while !dataRegisterEmpty { }
        USARTIODataRegister = byte
    }

Copy link
Contributor

@carlos4242 carlos4242 Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it's written in swift as we use swift for our hardware libraries these days but you get the idea)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm you should use swift-mmio and the svd2swift code generator once more parts of the swift compiler/swiftpm build system are working

@carlos4242
Copy link
Contributor

carlos4242 commented Jul 24, 2024 via email

@kubamracek
Copy link
Contributor Author

I think I'm going to just hardcode the assumption that this code is only suitable for the emulator, and explain that in a comment.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@rauhul rauhul mentioned this pull request Aug 2, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants