nepx / halfix

x86 PC emulator that runs both natively and in the browser, via WebAssembly
https://nepx.github.io/halfix-demo/
GNU General Public License v3.0
682 stars 88 forks source link

Regression testing? #9

Open DCNick3 opened 4 years ago

DCNick3 commented 4 years ago

It would be nice to have some instruction regression tests to be sure that the implementation would be consistent with real x86.

nepx commented 4 years ago

I "test" for regressions by booting the following operating systems:

These operating systems are pretty complete in their usage of the entire x86 instruction set. Now, they won't check for edge-case shift instructions like the ones described in #7 and #8, but they do tell me if some major bug has been introduced.

Another option is to randomly "fuzz" a bunch of instructions with random assignment of operands and inputs, but the process is too unpredictable and non-deterministic for me, and quite a few operations cause undefined behavior or faults, usually in flags (i.e. af for shifts) but occasionally in outputs as well. With all these constraints, you're better off just going with hard-coded inputs and outputs.

For a more rigorous test, I use the QEMU TCG test suite for i386, which can be found here. I use a version set up on this disk image, which includes test output created on a real processor. It exercises a large variety of arithmetic instructions, but is limited due to the fact that it runs entirely in user mode (so nothing crazy like far calls/far returns).

I've always wanted a series of tests for x86 like the ones that NESDev developers use. I'll have a go at writing some; it'll be fun to write some x86 assembly.

I'll create a separate repository for these tests so that other emulators can use them too; testing an x86 CPU is a project in itself.

nepx commented 4 years ago

Unit tests: https://github.com/nepx/verr.