Skip to content

versedmoon/Test_harness

Repository files navigation

Test_harness

Test harness for bhyve instruction emulator

Introduction

Bhyve (beehive) is a type2 hypervisor that runs on FreeBSD. bhyve runs FreeBSD 9+, OpenBSD, NetBSD, Linux and Windows NT--guests. Current development efforts aim at widening support for other operating systems for the x86-64 architecture. It runs guest operating system inside a virtual machine (parameters like the number of CPUs, amount of guest memory and input-output connectivity can be specified with command line parameter). It has a software emulator which needs to emulate some Instructions. Bhyve Test harness is a project of Gsoc 2k18. As it's name suggests, it's purpose is to provide tests for Instructions emulated by bhyve. The tests are tiny guest operating system that generally executes tens of lines of C and assembler test code in order to obtain its Pass/Fail result. With the help of Test harness we can compare the instructions emulated by bhyve and XED. Tests provide bhyve and virtual hardware functional testing by targeting the features through minimal implementations of their use per the hardware specification. The simplicity of tests make them easy to verify they are correct, easy to maintain, and easy to use in timing measurements. Tests are also often used for quick and dirty bug reproducers. The reproducers may then be kept as regression tests. While a single Test is focused on a single feature, all Tests share the minimal system initialization and setup code. There are also several functions, stubs, drivers made shareable across all Tests, comprising a Test API.

Prerequisites

Bhyve Instructions emulation can not only run with bhyve but also in userspace. So you can compare instructions by bhyve and Using XED. For using XED see here Intel_XED

Run tests

For comparing the bhyve emulation with XED run the bhyve emulation in Userland/Userspace and for running the instructions and tests using XED clone the XED repository from here.

Abbreviated building instructions:

git clone https://github.com/intelxed/xed.git xed
git clone https://github.com/intelxed/mbuild.git mbuild
cd xed
./mfile.py

then get your libxed.a from the obj directory. Add " --shared" if you want a shared object build. Add " install" if you want the headers & libraries put in to a kit in the "kits" directory. Add "C:/python27/python " before "./mfile.py" if on windows.

How to build the examples:

There are two options:

  1. When building libxed you can also build the examples, from the main directory (above examples):

    ./mfile.py examples

and the compiled examples will be in obj/examples.

  1. Build a compiled "kit" and the build the examples from within the kit:

    ./mfile.py install cd kits cd cd examples ./mfile.py

  1. Then go to xed/obj/examples and run the xed file using ./xed --help. You will get a list of encoding/decoding options. Select either -d hex-string (decode one instruction, must be last) or -de hex-string (decode-then-encode, must be last) where hex-string is a string of hex-code for that instruction which you want to decode.

    See source build documentation for more information.

Tests for the following bhyve instructions are written.

And r/m16, imm16

And r/m8, imm8

And r/m16/32, imm8

Mov r/m8, r8

Mov r/m16/32, r16/32

Mov eax, moffs16/32

Mov moffs16/32, eax

Mov r/m16, imm16

Mov r/m32, imm32

Mov r/m8, imm8

MovZX r16, r/m8 (mov with zero extend)

MovZX r32, r/m8

Mov ZX r16/32, r/m16

MovSX r16, r/m8 (mov with sign-extension)

MovSX r32, r/m8

MovSB m8, m8 (mov data from string to string)

MovSW m8, m8

MovSD m32, m32

OR r16/32, r/m 16/32

Cmp r/m16/32, r16/32

Cmp r16/32, r/m16/32

BT r/m 16, imm8

BT r/m 32,imm8

SUB r16, r/m16

SUB r32, r/m32

STOS m8, r8

STOS m16, r16

STOS m32, r32

PUSH r/m 16/32

POP r/m 16/32

                             Automation of Tests are in developing process