-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add Instruction Test #120
base: master
Are you sure you want to change the base?
Add Instruction Test #120
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work so far. I only have some organizational comments.
src/machine/instruction.test.cpp
Outdated
// QCOMPARE(Instruction(0x4432146), Instruction(1, 2, 3, 4, 5, 6)); | ||
// QCOMPARE(Instruction(0x4430004), Instruction(1, 2, 3, 4)); | ||
// QCOMPARE(Instruction(0x4000002), Instruction(1, 2_addr)); | ||
QCOMPARE(Instruction(0x0), Instruction(Instruction(0x0))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused by Instruction(Instruction(...))
. What is it supposed to mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for this constructor
Instruction::Instruction(const Instruction &i) {
this->dt = i.data();
}
indeed seems useless, I'll delete it.
src/machine/instruction.cpp
Outdated
@@ -1514,3 +1514,133 @@ TokenizedInstruction::TokenizedInstruction( | |||
, address(address) | |||
, filename(std::move(filename)) | |||
, line(line) {} | |||
|
|||
|
|||
void gen_instruction_code_and_expected_str(QTextStream& outfile, const InstructionMap* im, uint32_t code, int count, int offset, int subclass_i, int depth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the instruction.test.cpp file. It has no use during normal operation of the simulator. Also I would prefer the name "generate_code_and_string_data" and a little docstring explaining the usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
src/machine/instruction.cpp
Outdated
|
||
QString test_code = QString::asprintf("QCOMPARE(Instruction(0x%x).to_str(), \"%s\");", code, qPrintable(res)); | ||
outfile << test_code; | ||
if (Instruction(code).to_str() != res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why this is here. I would expect the test generation and execution to be separate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be in a separate file as an executable? (for generating test cases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great.
src/machine/instruction.cpp
Outdated
#include <iostream> | ||
#include <fstream> | ||
#include <qfile.h> | ||
void gen() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make the name more descriptive? Also, there should be an empty line after the includes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also move it to the test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
I will address the other questions shortly. |
I don't think we need to dig into the instructions here. We need to test the loading functionality. I think it would be nice to come up with one executable with various sections and then "randomly" check the contents of the memory. |
I like your approach. Since you have the pairs already generated, I would love to add also the other direction ( After that, there are many commented-out MIPS tests in the |
We will be able to close #7 once all QSKIP calls are gone. |
e77d427
to
1e6e49f
Compare
Good work so far. Some notes.
|
e72c604
to
a248b5c
Compare
Completely refactored Now instruction.test.gendata.cpp iterates through all the instructions on instruction_map, tries to generate 100 (code and string_data)pair for each, then checks The current generation logic relies on arg_desc's min and max. This is an executable file, the output looks like this:
Since it can't generate a fixed test case every time you run this script, the file name shouldn't be gendata anymore. I tried to move the code from main to instruction.test.cpp, but fails. Because there are too many structures used here that instruction.cpp doesn't expose (e.g. ArgumentDesc, C_inst_map, fill_argdesbycode ...), So I include @jdupak could you give me some advise? |
Related to #7
This demo currently adds some test cases for instruction_to_str(), and also includes a demo function to generate test cases
@jdupak