-
Notifications
You must be signed in to change notification settings - Fork 300
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 Test Coverage for create_inst_dict
Function
#285
Conversation
Pull Request: Update Test Cases and Refactor Encoding FunctionsSummary of Changes:1. Added Test Cases for Constants:
2. Refactored Encoding Functions in Parse:
3. Commented Out Failing Tests:
Rationale:These changes enhance the robustness of the test suite by ensuring that constants are correctly defined and validated. The refactoring of encoding functions improves code quality and maintainability. |
@aswaterman Can you please have a look at it? |
@@ -924,6 +924,7 @@ def make_sverilog(instr_dict): | |||
endpackage | |||
''') | |||
sverilog_file.close() | |||
print("9999999999999999",names_str) |
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.
unneeded debug code?
# localparam logic [11:0] CSR_CSR32 = 12'h2; | ||
# endpackage | ||
# ''' | ||
# self.assertIn(expected_content.strip(), written_content.strip()) # Check if the expected content is in the written content |
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.
delete unused code rather than commenting it out.
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.
@IIITM-Jay May I defer reviewal of this PR to you?
yeah sure! |
def test_lui(self): | ||
name, data = process_enc_line('lui rd imm20 6..2=0x0D 1=1 0=1', 'rv_i') | ||
class TestProcessEncLine(unittest.TestCase): | ||
@patch('builtins.open', new_callable=mock_open, read_data='lui rd 6..2=0x0D 1=1 0=1') |
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.
@TraXIcoN here I would suggest moving the test data i.e., lui rd 6..2=0x0D 1=1 0=1
, to a global variable or in the constants and referring that variable here, so that in the future if we need to change the test data, it could be done easily by modifying the assigned data to the variable.
This will also add up to the cleaner code.
self.assertIn('encoding', result) | ||
self.assertIn('variable_fields', result) | ||
self.assertIn('extension', result) | ||
self.assertIn('match', result) | ||
self.assertIn('mask', result) |
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.
@TraXIcoN Here also, a list is a suitable approach containing the strings match, mask...
followed by the running of loop as these are some constants useful strings which can be referred to multiple places.
from unittest.mock import patch, mock_open | ||
import parse | ||
import logging | ||
import unittest | ||
import constants | ||
import csv |
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.
@TraXIcoN This seems that a pre-commit
is not being run here.
def test_create_inst_dict(self): | ||
"""Test the create_inst_dict function.""" | ||
with patch('glob.glob', return_value=['mock_file.rv32_i']): | ||
with patch('builtins.open', new_callable=mock_open, read_data='lui rd 6..2=0x0D 1=1 0=1'): |
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.
As suggested earlier in my comments about lui rd 6..2=0x0D 1=1 0=1
to move to a global variable, we can see the usefulness here. We can just refer that test data at multiple places. This is a best approach and also more readable. Additionally, it will help for quick fix and modifications at later stages.
"""Test the same_base_isa function.""" | ||
self.assertTrue(parse.same_base_isa('rv32', ['rv32_i', 'rv64'])) | ||
self.assertFalse(parse.same_base_isa('rv32', ['rv64'])) | ||
|
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.
Here as you are using class, some more methods could be written which are valid and make sense. Something like , you can add more test cases to test it with empty list, with case sensitive and so on.
The reason why I am suggesting this here is that a class containing only one method doesn't seem to be a best practice to select the class
approach and if it's not interdependent with multiple methods or class to use inheritance feature
I have just made an overview comments which comes to my way while review as an overlook. @TraXIcoN I have observed one thing that you used I have written in one of my comment to add more related test cases that could fit in for the use of |
Additionally, @TraXIcoN I noticed a mention of encoding functions in the description of PR
are they present into this PR? |
This pull request adds test coverage for the create_inst_dict function in the TestCreateInstDict class. It includes mock data to validate the correct creation of the instruction dictionary, ensuring expected values for variables, encoding, and other fields.