16

It seems that unit testing has become all the rage these days and I know many of you are going to think: "Well why not just use language X with framework Y already?" But I'm proposing this idea more as a proof of concept, or out of nostalgic remembrance for my earlier years with computer programming.

I'm namely working on BSD running on x86 with NASM, and have mulled over the use of shell scripting with expect(1) to do unit testing but I wanted to know beforehand:

What unit testing frameworks are available for applications written in x86 assembly?

Stefan Paul Noack
  • 3,654
  • 1
  • 27
  • 38
Dwight Spencer
  • 1,472
  • 16
  • 22

2 Answers2

3

If your assembler routines have or can be given a 'C' interface, then any C/C++ unit testing framework can be employed.

You should move the vast majority of your application into a library which can be called from 'C' programs (ie a testing framework). To finally build your application you write an assembler front-end that just calls your new library.

quamrana
  • 37,849
  • 12
  • 53
  • 71
  • Honestly, that is a generally great practice and quite portable. So may just work well considering the Unix platform I'm working with. But the application would still incur the over head from C and I was hoping to have as few dependencies as possible. – Dwight Spencer Mar 02 '12 at 23:10
  • You can organise your code so that your assembler code is in one or more libraries, your 'C' wrappers in a set of parallel libraries just called by the tests, and your application just directly calls the assembler code. – quamrana Mar 04 '12 at 16:41
  • @DwightSpencer You should decouple your module dependencies (even those inside your application) anyways. The result will be pieces of code that are caller-agnostic (except across incompatible calling conventions). Dynamic linking might also do you a great favor with these... – Powerslave Jun 20 '13 at 11:24
1

IMHO The notion of unit testing is not applicable to low-level languages such as assemblers. Unit testing associates with testing unit functionality of a method, class, procedure. In my opinion such things do not exist in assembly code - of course, it is possible to declare procedures in some assemblers (it was possible in TASM and MASM), but they are not something that do exist in machine code.

However, I think that we still can consider automated testing of assembly code. Personally, I haven't heard of any framework that would allow that.

Lukasz
  • 7,572
  • 4
  • 41
  • 50
  • It also appears that yasm/nasm has that same tasm/masm capability though the use of macros; I've been putting together an implementation of stdlib for those for mentioned assemblers. But I do agree there really should be more automated testing for assembly code. Especially being that close to bare metal. – Dwight Spencer Mar 02 '12 at 20:50
  • Well, ideal mode struct handling for example is pretty much object-ish and objects, at low level, are just indirections anyways, so it is pretty much feasible to have such frameworks. I've never heard of any though. Good news is, being C/C++ compatible is up to the programmer so in the end of the day a C++ lib will just do the job. – Powerslave Jun 20 '13 at 11:11