How to test Memory class?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to test Memory class?

kraftwerk1611
This post was updated on .
Hi,

On pages 274-276 the book shows expected outputs of some OS classes and tells what the tester should expect to see when the program runs correctly. However for Memory.alloc() and Memory.deAlloc() functions of Memory class it says the following on page 274

"A complete test of these memory management functions requires inspecting internal implementation details not visible in user-level testing. Thus it is recommended that you test these two functions using step-by-step debugging in the VM Emulator".


Can someone please explain it more what it means and how to do it? How to test and what to expect to see?

The test directory does have  compare and output files. Will we see a 'comparison ended successfully' message if everything is allright with the code or are those files only for peek() and poke() functions?

I am also hoping that other persons testing this class can share add their experiences to this thread.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: How to test Memory, Array and Math classes?

cadet1620
Administrator
You can look at MemoryTest/Main.jack to see what it tests.

First it tests that poke() and peek() work.
Then it does some Array.new() calls and writes and reads from the Arrays returned from alloc().
Finally, it does some dispose() calls that call deAlloc().

This is not a particularly thorough test.

In fact, this alloc()/deAlloc() will pass the test!
    /** Finds an available RAM block of the given size and returns
     *  a reference to its base address. */
    function int alloc(int size) {
        return 2048;
    }

    /** De-allocates the given object (cast as an array) by making
     *  it available for future allocations. */
    function void deAlloc(Array o) {
        return;
    }

I'll look at writing a new test.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: How to test Memory, Array and Math classes?

kraftwerk1611
thanks
Reply | Threaded
Open this post in threaded view
|

Re: How to test Memory class?

kraftwerk1611
Hi,

It is better to use 'No animation' option in Animate drop down list, otherwise the program seems to run forever.



If the code passes test then we see 'comparison ended successfully message' at the end of code execution in VM Emulator.




Good luck!