1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "tst_machine.h"
#include "instructions/arithmetic.h"
#include "instructions/jumpbranch.h"
#include "instructions/loadstore.h"
#include "instructions/nop.h"
#include "instructions/shift.h"
#include <iostream>
void MachineTests::instruction_arithmetic_data() {
QTest::addColumn<size_t>("type");
QTest::addColumn<std::uint32_t>("res");
QTest::newRow("ADD") << (size_t)IAT_ADD << (unsigned)749;
QTest::newRow("ADDU") << (size_t)IAT_ADDU << (unsigned)749;
QTest::newRow("SUB") << (size_t)IAT_SUB << (unsigned)-665;
QTest::newRow("SUBU") << (size_t)IAT_SUBU << (unsigned)-665;
QTest::newRow("AND") << (size_t)IAT_AND << (unsigned)2;
QTest::newRow("OR") << (size_t)IAT_OR << (unsigned)747;
QTest::newRow("XOR") << (size_t)IAT_XOR << (unsigned)745;
// TODO others
}
void MachineTests::instruction_arithmetic() {
Registers regs;
QFETCH(size_t, type);
QFETCH(std::uint32_t, res);
// TODO meaby one more dataset?
regs.write_gp(12, 42);
regs.write_gp(8, 707);
regs.write_gp(5, 0);
Instruction *i = new InstructionArithmetic((enum InstructionArithmeticT)type, 12, 8, 5);
i->decode(®s);
i->execute();
i->memory(nullptr); // We should not work with memory so segfault here is basically a test
i->write_back(®s);
QCOMPARE(regs.read_gp(5), (std::uint32_t)res);
}
void MachineTests::instruction_arithmetic_immediate_data() {
QTest::addColumn<size_t>("type");
QTest::addColumn<std::uint32_t>("res");
QTest::newRow("ADDI") << (size_t)IAT_ADDI << (unsigned)749;
QTest::newRow("ADDIU") << (size_t)IAT_ADDIU << (unsigned)749;
QTest::newRow("ANDI") << (size_t)IAT_ANDI << (unsigned)-665;
QTest::newRow("ORI") << (size_t)IAT_ORI << (unsigned)-665;
QTest::newRow("XORI") << (size_t)IAT_XORI << (unsigned)2;
// TODO others
}
void MachineTests::instruction_arithmetic_immediate() {
Registers regs;
QFETCH(size_t, type);
QFETCH(std::uint32_t, res);
// TODO meaby one more dataset?
regs.write_gp(9, 42);
regs.write_gp(3, 0);
Instruction *i = new InstructionArithmeticImmediate((enum InstructionArithmeticImmediateT)type, 9, 3, 707);
i->decode(®s);
i->execute();
i->memory(nullptr); // We should not work with memory so segfault here is basically a test
i->write_back(®s);
QCOMPARE(regs.read_gp(3), (std::uint32_t)res);
}
|