bjkrug Posted September 8, 2020 Share Posted September 8, 2020 Does anyone here write unit tests for your Assembly Language projects? What is your preferred coding format for doing so? The below is my approach. ARYINS is the routine being tested. AEQ and ANEQ stand for "Assert Equal" and "Assert Not Equal", respectively. They are comparing the contents of R0 and R1. * * Insert an element at the middle of * an array. * Grow array and move it. * No empty block follows the original. INS5 * Arrange LI R0,INS5Y MOV R0,@BUFADR LI R0,INS5Z MOV R0,@BUFEND * Act LI R0,INS5X+2 LI R1,3 BLWP @ARYINS MOV R0,R9 MOV R1,R10 * Assert LI R0,INS5X+2 MOV R9,R1 BLWP @ANEQ TEXT 'Array should have moved.' BYTE 0 EVEN * MOV R9,R0 AI R0,4+12 MOV R10,R1 BLWP @AEQ TEXT 'Element address should be ' TEXT 'directly after the third ' TEXT 'element.' BYTE 0 EVEN . . . RT 4 Quote Link to comment Share on other sites More sharing options...
Asmusr Posted September 9, 2020 Share Posted September 9, 2020 I do once in a while make something like a unit test when I have an isolated function that's doing something quite complex and returns a simple result. But I delete the test code again instead of building a suite of tests the can be run again later. It's often difficult to isolate your test unit because global state is used, and mocking your dependencies would be quite difficult. Maybe it would be different if I was writing libraries instead of games? In games I often don't even have the option to print the results of asserts on the screen. Perhaps I don't even have an ASCII font? And maybe my function requires keyboard or joystick input? One thing I have been dreaming of is to be able to tell an emulator to print out asserts or expressions to a log at given points in the code. You would place the asserts in you code, and the assembler would output them to a separate file that could be loaded into the emulator. I think that would be a great tool to complement breakpoint debugging, and it could also be used for unit tests. 2 Quote Link to comment Share on other sites More sharing options...
+adamantyr Posted September 9, 2020 Share Posted September 9, 2020 Yeah, unit tests only make sense if you're writing libraries that are independently loaded, or using some kind of complex infrastructure that allows it. My CRPG work has made me WISH for regression tests at times, just so changes I make don't break something I forgot about. 1 Quote Link to comment Share on other sites More sharing options...
bjkrug Posted September 10, 2020 Author Share Posted September 10, 2020 Mocking data in assembly hasn't been a lot harder for me than mocking data in C#. Mocking routines could eventually get hairy; I've only had to do a little bit of that so far. If a mocked routine is supposed to return different values under different circumstances, then something needs to be done in the Arrange portion of the test to specify that. That can sacrifice legibility. And, yeah, I'm writing tests for memory management and array algorithms. If I were writing a game, my test coverage would be way lower, if not zero. As far as I know, modularizing code enough for unit testing could impact game performance. 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.