Monday 31 January 2011

Left Unfinished


Can build a simple and useful unit test system in python exploiting first class functions, dynamic checks on the names of functions, and a naming convention.


See codepad.org for coloured src and a sample run, or github for a "gist" with highlighted source.

### Begin unit test code


def test_function1():
    # Do some test code
    # return True on Pass, False on Fail


def test_function2_EXPECTED_FAIL():
    # Do some test (more) code
    # return True on Pass, False on Fail


def test_functionN():
    # Do some test (more) code
    # return True on Pass, False on Fail


# Build a list of test functions to run
# as test cases
tests = [ test_function1
        , test_function2_EXPECTED_FAIL
        # as many as you like...
        , test_functionN
        ]


def main():
    failed  = []
    # Invoke each test case in turn
    for t in tests:
        if not t():
            # Can check names of test functions 
            # to detect expected fails
            if t.__name__.endswith("_EXPECTED_FAIL"):
                continue
            # Record fails for later report
            failed.append(t.__name__)
            # Can stop on 1st fail if desired
            # return 1
    # Print the list of tests that failed, if any
    for f in failed:
        print "FAIL:",f
        
# Invoke the test runner
if __name__ == "__main__":
    main()


### End unit test code


Tile based game development tutorial.

A series of blog articles on Maze generation algorithms.

A C pre processor (cpp) in python. A programmers text editor Kod for OSX based on the google chrome tab UI.

Tuesday 25 January 2011

Lore of the Arcane

Compilation of Offload C++ code for the Cell BE processor and the Linux OS entirely within a Linux environment is complicated by the fact that the Offload C++ compiler ("offloadcpp") is a Windows executable. This compiler compiles programs to run on the Cell processor by first compiling Offload C++ code into Cell specific C code; the C is then compiled for the Cell processor using a Cell BE GCC tool chain (GCC and associated utilities) on Windows, via Cygwin. The result is that, on Windows, the compiler can generate a Cell Linux executable with embedded SPU sub-programs automatically.
The below process (described by Paul Keir, thanks!) outlines how the Offload C++ compiler can be used to compile for the Cell from within Linux using Wine. The first stage is to compile the Offload C++ code (your original program) into C code targeting the Cell. The second stage is to compile that generated C code on the Cell using the Cell SDK on the PS3 running Linux.
Note that depending on how your Linux PS3 is setup, it is possible to create a script (e.g. via scp and ssh) to push the generated code onto the PS3, and to subsequently invoke the PS3 compilation process on the PS3 automatically.                                 
                                             
--------------  Stage 1: Linux/Windows ------------

1.  Install Wine on your Linux system.

2.  Copy the Codeplay Offload C++ installation directory from Windows to somewhere convenient on your Linux system.
   
3.  On Linux, set the SIEVESDK environment variable to the offload-cell-linux-sdk directory contained within the installation directory.

4.  Offload may install a Cygwin-compatible Cell Toolchain. By default it will be installed in C:\cygwin\opt\cell .
Place the entire cell directory tree within the /opt/ directory of your Linux system. The Cygwin-compatible PS3 toolchain is also available here: http://sourceforge.net/projects/cellwindowssdk/
The toolchain.7z file there also contains the /opt/cell/... directory tree.

5.  The Offload compiler is now ready to run, though only with the -nomake switch. If you have placed the Offload installation directory at $HOME/apps/codeplay, offloadcpp may be used to compile hello.cpp using the following command:

$ wine $HOME/apps/codeplay/offloadcpp.exe -I$SIEVESDK/include -I/opt/cell/toolchain/include/c++/4.1.1 -I/opt/cell/sysroot/usr/include -I/opt/cell/toolchain/lib/gcc/powerpc-linux/4.1.1/include/c++/powerpc-linux -I/opt/cell/toolchain/lib/gcc/powerpc-linux/4.1.1/include -nomake hello.cpp

An alias may be useful, say "oll":

$ alias oll='wine $HOME/apps/codeplay/offloadcpp.exe -I$SIEVESDK/include -I/opt/cell/toolchain/include/c++/4.1.1 -I/opt/cell/sysroot/usr/include -I/opt/cell/toolchain/lib/gcc/powerpc-linux/4.1.1/include/c++/powerpc-linux -I/opt/cell/toolchain/lib/gcc/powerpc-linux/4.1.1/include'

$ oll -nomake hello.cpp

6.  The result will be a directory called "outputc". This directory must now be transferred to the PS3, before issuing the make command, as described in Step 3. below.

--------------  Stage 2: PlayStation 3 ------------

1.  Copy the offload-cell-linux-sdk directory to the PS3, and set the SIEVESDK environment variable to that location.

2.  Mars should already be installed (mars-1.1.4-1.ppc.rpm), but the development libraries are now also needed, so:

$ wget ftp://ftp.infradead.org/pub/Sony-PS3/mars/1.1.4/mars-devel-1.1.4-1.ppc.rpm
$ rpm -ivh mars-devel-1.1.4-1.ppc.rpm

3.  An "outputc" directory, obtained as in step 5. above, contains a makefile. To complete the compilation of hello.cpp:
    
$ cd outputc
$ make
$ cd ..
$ ./hello