-
Notifications
You must be signed in to change notification settings - Fork 8
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 MIPS with MARS 4.5 #195
Comments
Created a repo https://github.com/DonaldKellett/codewars-mips to experiment with the idea Initial idea: instead of integrating with MARS directly with Java JUnit (like what MIPSUnit does), use a multi-file setup and develop assertions that print Codewars output format in MIPS, then invoke MARS with the project files and use its output as the final runner output |
@kazk I've written a minimal unit testing framework in MIPS that provides basic assertions for integer values, and an example I'll probably also add basic string and (maybe) array assertions shortly, which should cover most typical cases. EDIT (2022-07-24 14:53 GMT+8): I realized that transferring repo ownership to @codewars requires permissions to create a new public repo on their behalf so I've initiated transfer to @kazk instead. UPDATE (2022-07-24 20:16 GMT +8): Basic string assertions have also been implemented and demoed in |
What are the differences from MIPS (#22)? Just testing it differently? I get that the easiest way to implement is to write tests in MIPS, but isn't it annoying to write? I'd like to know what potential authors think. |
Mostly. The approach we tried 2 years ago was to adapt the existing MIPSUnit framework to output Codewars output format and migrate it from JUnit 4 to JUnit 5, which proved to be too tedious and cumbersome. MIPSUnit integrates directly with MARS, which means it can inspect the state of the (emulated) processor directly, allowing assertions to be written about values of specific registers etc. However, this method of testing is vastly different from that taken by NASM (and pretty much every other language) on Codewars, where we only care about the return value of the solution for the most part.
If you mean compared to #22 , no difference at all. The two most well-known MIPS emulators MARS and SPIM both emulate (a substantial subset of) MIPS32 only, with the former being more feature-complete. There might be MIPS64 emulators out there, but they're nowhere near as popular as those two and the ones I found seem to be GUI-only, or at least do not have a sufficiently documented command-line interface.
It's not that much different from writing assertions in a higher-level language, actually. The general flow for writing an assertion is (1) compute the expected value (trivial for fixed tests), (2) invoke the solver's solution to compute the actual value, then (3) set up the argument registers correctly and (4) invoke the assertion method. For fixed tests at least, that is often under 10 instructions per assertion and much of it is repetitive work that can be copy-pasted. |
Cross-posting from Discord for reference:
donaldsebleung (@DonaldKellett ) wrote:
|
I just re-discovered this StackOverflow question from #22 : Calling MIPS from C. The top-voted solution suggests that Open Virtual Platforms (OVP) provides a full-blown MIPS simulator that boots and runs Linux. However, upon digging further into OVP, here are a few concerns I uncovered which suggest the solutions offered by OVP may not be suitable at all for our use case:
Since the primary objective of Codewars is education, I personally think that it isn't worth going the extra mile to find a full-blown emulator that models every tiny little detail of hardware proper. Most CS/CPEG/EE students having taken a computer organization course have probably been exposed to MARS or SPIM, and the former is effectively a superset of the latter, so I think using MARS should be good enough, not to mention that documentation and external resources for MARS MIPS are abundant and probably even better than that for Linux on MIPS. As for the original approach in #22 of adapting MIPSUnit for Codewars and migrating it from JUnit 4 to JUnit 5, I'm not sufficiently well-versed in the Java ecosystem to undertake the work, so if someone else would like to take over, they're welcome to do so. The source code for MIPSUnit could be obtained by contacting @kurmasz , though we might need to ask for permission again to adapt it for Codewars since it's not released as open-source and it's been 2 full years since we last asked. But if no one is willing to step up and undertake the work related to MIPSUnit, I'll go with perfecting my custom assertion framework in MIPS in the meantime since that seems to be the next sensible option, and one that doesn't require me to learn the ins and outs of the Java ecosystem. |
Further discussion on Discord replicated here for reference. donaldsebleung (@DonaldKellett ) wrote:
|
@kazk Common array assertions have been implemented and demoed as well. If everything over at https://github.com/DonaldKellett/codewars-mips looks good to you and there are no strong last-minute objections to the approach used there, we should be ready to officially deploy MIPS (Beta) support to Codewars. |
Can you run failing examples in CI? |
How the assertions work is obviously similar, but the tests are difficult to read without duplicating static strings in comments like you did. But like you wrote above, I can't think of a reasonable alternative for MIPS.
I think we can support RISC-V instead with a similar setup as ARM I experimented in #197 (comment). By running ARM/RISC-V container with QEMU emulation, I think we can test using Criterion like NASM. (I'm assuming Criterion can be compiled from the source when building the image.) |
Thanks for the feedback - I'll implement them tonight if time allows.
Do you mean that each
Sure, I'll probably look into adding RISC-V support afterwards, but IMHO MIPS and RISC-V support need not be mutually exclusive as they are distinct architectures, like how C# and Java are distinct programming languages. |
Yeah,
It doesn't need to be. But what are some reasons to support MIPS in addition to RISC-V? I don't think we should add MIPS just because we can, especially if the user experience isn't great (I don't think tests in assembly will be for both authors/maintainers and solvers). We can consider adding it later if we find a better way as well.
Isn't it more like ActionScript and TypeScript? |
Closing in favor of #199 The link posted in #197 (comment) also mentions |
Please complete the following information about the language:
The following are optional, but will help us add the language:
java -jar /path/to/Mars4_5.jar ...
where...
denotes command line arguments passed to MARS. Useh
for help:java -jar /path/to/Mars4_5.jar h
MIPS is a RISC ISA which is commonly used in computer architecture courses taught in universities, for its simplicity compared to CISC ISAs such as the mainstream x86 architecture. RISC ISAs such as RISC-V and LoongArch are also gaining traction in the industry in recent years, so I think support for a RISC assembly language on Codewars would be an interesting addition.
Addendum: MIPS support was previously requested in #22 but fizzled out due to lack of interest and expertise in migrating MIPSUnit from JUnit 4 to JUnit 5. This time, I'll look into writing a minimal custom test framework wrapping command-line versions of existing simulators such as MARS or SPIM, and post updates here when there is progress.
👍 reaction might help to get this request prioritized.
The text was updated successfully, but these errors were encountered: