-
Notifications
You must be signed in to change notification settings - Fork 22
Assembly Test Program Generation
This package provides a lightweight interface for generating partially directed and partially constrained random program sequences. The generator produces a string of assembly instructions.
In order to generate tests, a ProgramGenerator object needs to be instantiated:
ProgramGenerator(isa: InstructionSet)(constraints: Constraint*)For now the following instruction sets are implemented:
The following constructs make it possible to constrain randomly generated memory and IO addresses as well as randomly generated instructions:
-
CategoryDistribution(dis: (Category, Double)*)
- Randomly generated instruction will follow the given distribution of categories
-
CategoryWhiteList(wl: Category*)
- Randomly generated instructions will only be of any of the given categories
-
CategoryBlackList(bl: Category*)
- Randomly generated instructions will never contain an instruction of any of the given categories
-
MemoryDistribution(dis: (BigRange, Double)*)
- Randomly generated memory addresses will follow the given distribution
-
IODistribution(dis: (BigRange, Double)*)
- (If applicable) randomly generated IO space addresses will follow the given distribution
A BigRange can be constructed using BigRange(min: BigInt, max: BigInt).
Instructions are associated with one or more of the following categories:
- Arithmetic
- Logical
- Load
- Store
- Input
- Output
- JumpAndLink
- Branch
- EnvironmentCall
- Nop
- Immediate
- Label
- Compare
- StateRegister
- Synchronization
Once the program generator is instantiated it can be used to generate a sequence of an approximate size:
val pg = ProgramGenerator(Leros)(
CategoryDistribution(
Category.Arithmetic -> 6,
Category.Logical -> 2,
Category.Input -> 1,
Category.Output -> 1
),
MemoryDistribution(
BigRange(100, 200) -> 1,
BigRange(4000) -> 1
),
IODistribution(
BigRange(20, 30) -> 1,
BigRange(0xFF) -> 1
)
)
val pr0 = pg.generate(200)In order to use semi-directed instruction sequences, which contain some well defined portions whereas others are left to be filled in randomly, a Pattern can be used:
val pattern = Pattern(implicit c => Seq(
Label("Hello"), add(), in(20), Instruction.fill(20),
Instruction.fillWithCategory(10)(Category.Logical),
Instruction.select(add(),addi(20)), read, write
))
val pr1 = pg.generate(pattern)In this case read and write are themselves Pattern's, so nested patterns are allowed.
All instructions have a constructor that allows partial randomization by using None when a instruction field should be kept random.
The following additional constructs are supported inside of a pattern:
-
select: selects uniformly one of the given instructions -
ofCategory: selects one instruction of a given category -
fill: inserts a sequence of a given length with random instructions -
fillWithCategory: inserts a sequence of a given length with instructions of some category
This is the only page on Assembly Test Program Generation. Return home.