Running unit tests?
Is there a way to run unit tests? I haven't found it yet. I feel like I must be missing something obvious but reading over the installation notes I don't see anything about test suites or test vectors.

Mainly I'm asking because I'm loving playing D2 in this awesome port, it is so beautiful and the gameplay feel is so authentic, but the crashes are pretty disheartening.
There are no unit tests. No one has ever written any, that I know of. Due to the extensive (ab)use of globals, they would likely be more trouble to write than in programs that follow more modern conventions.

There are numerous paths where out of range input can crash the game, due to a general lack of historical validation. I've converted many UB paths into exceptions, so it still crashes, but in a deterministic manner. Converting all those paths to handle invalid input gracefully is time consuming. What crashes are you seeing? I generally fix all other crashes as fast as I find them.
Well, I've seen several in D2X. There was a pretty consistent game-over crash if you ran out of lives, quite apropos I thought. I haven't seen that crash since the last build so maybe it got resolved. I've had a handful of in-level crashes at random spots. I recently played level 13 and the game crashed just after completion of the level, I think it was just after entering the exit shaft. Should I take the Apple Crash Report output and post that? It has a fair bit of data, on the most recent crash I could at least tell that the crashpoint was a double-free inside the physics engine. Or is there a way to get the actual core? It's stable enough to be playable so not a big issue but something that would be nice to smooth out.

No tests - that's extra tough. I've never been able to maintain a stable codebase of more than 10,000 lines without 'em. I see the difficulty though. And I agree that bad tests are worse than no tests. Maybe if I learn more of the code base it'll become more clear.
I know the game can be crashed by feeding it ill-formed level files, ill-formed save files, or ill-formed multiplayer messages. There is an unresolved report (status: needinfo) of a crash on entering level 17 of the Descent 2 campaign. I suspect it to be related to using ill-formed v1.0 game data, which was corrected by the v1.2 patch. I am awaiting further diagnostic data on that one.

I am not aware of any way to crash the game using only unmodified game clients consuming well-formed levels and save games. If you find such a crash, please report it and include whatever diagnostics you can capture. That crash on level 13 sounds like it qualifies. I don't know if Apple saves core files. A stack backtrace, with line numbers and arguments, would be nice. Include locals too, if you can.

I tested your game-over crash. I hit an AddressSanitizer trap on regular deaths when the AI pathfinding underflows. I fixed that. Next, I get an assertion failure on dismissing the gameover (common/include/gr.h:148: grs_canvas::~grs_canvas(): Assertion `this != grd_curcanv' failed.). That is an assertion I added after discovering that various places in the code would set the global canvas pointer to a local variable, then destroy the local without clearing the global. The next call to use the global canvas would then access the freed stack memory, causing various problems. The short-term fix is to reset the global canvas pointer before destroying the local. The long-term fix is to eliminate the global canvas pointer. If you aren't using assertions, your crash might be due to the memory corruption that the assertion is meant to detect/prevent.

If you want to write tests, I can add some hooks to SCons to run them. I think you will find them difficult to write readily due to the dependence on globals; linking in the files that supply the globals will often require you to link in more files, which snowballs.
Add unit tests for valptridx parameter validation adds (a few) unit tests. The SCons infrastructure for adding more now exists.

Forum Jump:

Users browsing this thread: 1 Guest(s)