Author: nextgens
Date: 2006-12-16 20:22:10 +0000 (Sat, 16 Dec 2006)
New Revision: 11453
Added:
branches/native_fec/CodeTest.java
Removed:
branches/native_fec/w32
Modified:
branches/native_fec/Makefile
Log:
cleanup useless files, add a testcase
Added: branches/native_fec/CodeTest.java
===================================================================
--- branches/native_fec/CodeTest.java (rev 0)
+++ branches/native_fec/CodeTest.java 2006-12-16 20:22:10 UTC (rev 11453)
@@ -0,0 +1,164 @@
+// (c) Copyright 2000 Justin F. Chapweske
+// (c) Copyright 2000 Ry4an C. Brase
+
+import com.onionnetworks.fec.*;
+
+import com.onionnetworks.util.Util;
+import com.onionnetworks.util.Buffer;
+/*
+ * Java port of test code for the fec codes.
+ * Original is (C) 1997-98 Luigi Rizzo (luigi at iet.unipi.it)
+ *
+ * @author Justin F. Chapweske (orasis at acm.cs.umn.edu)
+ */
+public class CodeTest {
+
+ public static FECMath fecMath = new FECMath(8);
+
+ public static final int KK = 192; // 255
+ public static final int PACKET_SIZE = 4096;
+
+ public static void printMatrix(char[] matrix, int rows, int cols,
+ String msg) {
+ System.err.println(msg);
+ for (int r=0; r<rows; r++) {
+ for (int c=0; c<cols; c++) {
+ System.err.print(((int) matrix[r*cols+c])+" ");
+ }
+ System.err.println("");
+ }
+ System.err.println("");
+ }
+
+ /**
+ * Creates k packets of size sz of random data, encodes them,
+ * and tries to decode.
+ * Index contains the permutation entry.
+ */
+ public static final void testDecode(FECCode code, int k, int index[],
+ int packetSize, String s) {
+
+ byte[] src = new byte[k*packetSize];
+ Util.rand.nextBytes(src);
+ Buffer[] srcBufs = new Buffer[k];
+ for (int i=0;i<srcBufs.length;i++) {
+ srcBufs[i] = new Buffer(src,i*packetSize,packetSize);
+ }
+
+ byte[] repair = new byte[k*packetSize];
+ Buffer[] repairBufs = new Buffer[k];
+ for (int i=0;i<repairBufs.length;i++) {
+ repairBufs[i] = new Buffer(repair,i*packetSize,packetSize);
+ }
+
+ int reconstruct = 0 ;
+ for(int i = 0 ; i < k ; i++) {
+ if (index[i] >= k ) {
+ reconstruct++;
+ }
+ }
+
+ long time1 = System.currentTimeMillis();
+ code.encode(srcBufs, repairBufs, index);
+ time1 = System.currentTimeMillis() - time1;
+
+ long time2 = System.currentTimeMillis();
+ code.decode(repairBufs, index);
+ time2 = System.currentTimeMillis() - time2;
+
+ /* for (int i=0; i<k; i++) {
+ if (!Util.byteArraysEqual
+ (srcBufs[i].b,srcBufs[i].off,repairBufs[i].b,repairBufs[i].off,
+ packetSize)) {
+
+ System.err.println("error reconstructing block "+i);
+ System.out.println
+ ("orig="+
+ new String(srcBufs[i].b,srcBufs[i].off,packetSize));
+ System.out.println
+ ("new ="+new
String(repairBufs[i].b,repairBufs[i].off,packetSize));
+ System.exit(-1);
+ }
+ }*/
+
+ if (!Util.arraysEqual(src,0,repair,0,packetSize*k)) {
+ System.err.println("error reconstructing packet.");
+ System.err.println("orig="+new String(src));
+ System.err.println("new="+new String(repair));
+ System.exit(-1);
+ }
+
+
+ if (time1 == 0 || time2 == 0) {
+ System.err.print("Too fast too measure.\r");
+ return;
+ }
+
+ System.err.print(" k "+
+ Util.getSpaces(3-new Integer(k).toString().length())+
+ k+", l "+
+ Util.getSpaces(3-new Integer(reconstruct).toString().
+ length())+
+ reconstruct+
+ " c_enc "+
+ (((k*packetSize*reconstruct)/time1)/(float) 1000)
+ +" MB/s c_dec "
+ + (((k*packetSize*reconstruct)/time2)/(float) 1000)
+ +" MB/s \r");
+ }
+
+ public static void printEncoded(char[] c) {
+ for (int i=0;i<c.length;i++) {
+ System.out.print(((int) c[i])+",");
+ }
+ System.out.println("");
+ }
+
+
+ public static void test() {
+ int lim = fecMath.gfSize + 1;
+
+ for (int k = KK; k > 2; k--) {
+ FECCode code = FECCodeFactory.getDefault().createFECCode(k,lim);
+ if (code == null) {
+ throw new IllegalStateException("FECCode is null!");
+ }
+ System.out.println("Library loaded!");
+ int[] index = new int[k];
+
+ int i;
+
+ for (i=0; i<k; i++) {
+ index[i] = k - i;
+ }
+
+ String buf = "k="+k+", k - i";
+ testDecode(code, k, index, PACKET_SIZE, buf);
+
+ for (i=0; i<k; i++) {
+ index[i] = i ;
+ }
+ testDecode(code, k, index, PACKET_SIZE, "i");
+
+ int j, max_i0 = KK/2 ;
+ if (max_i0 + KK > lim) {
+ max_i0 = lim - KK ;
+ }
+ for (i= 0 ; i <= max_i0 ; i++) {
+ for (j=0; j<k; j++) {
+ index[j] = j + i ;
+ }
+ testDecode(code, k, index, PACKET_SIZE, "shifted j");
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String[] args) {
+ try {
+ test();
+ } catch (ExceptionInInitializerError e) {
+ e.getException().printStackTrace();
+ }
+ }
+}
Modified: branches/native_fec/Makefile
===================================================================
--- branches/native_fec/Makefile 2006-12-16 20:20:20 UTC (rev 11452)
+++ branches/native_fec/Makefile 2006-12-16 20:22:10 UTC (rev 11453)
@@ -16,8 +16,8 @@
CC=gcc
# COPT= -O9 -funroll-loops
-COPT= -O1
-CFLAGS=$(COPT) -Wall # -DTEST
+COPT= -O1
+CFLAGS=$(COPT) -Wall -fPIC# -DTEST -pedantic
SRCS= fec.c Makefile test.c fec.s.980621e \
fec.S.980624a \
fec.S16.980624a
@@ -31,9 +31,8 @@
$(CC) $(CFLAGS) -DGF_BITS=8 -c -I$(JAVA_HOME)/include/ \
-I$(JAVA_HOME)/include/linux fec8-jinterf.c \
-o fec8-jinterf.o ; \
- mkdir -p ../../lib/fec-linux-x86/lib/linux/x86 ; \
ld -shared fec8-jinterf.o fec8.o -o \
- ../../lib/fec-linux-x86/lib/linux/x86/libfec8.so
+ libfec8.so
fec8.o: fec.h fec8.S
$(CC) $(CFLAGS) -DGF_BITS=8 -c -o fec8.o fec8.S
@@ -45,9 +44,8 @@
$(CC) $(CFLAGS) -DGF_BITS=16 -c -I$(JAVA_HOME)/include/ \
-I$(JAVA_HOME)/include/linux fec16-jinterf.c \
-o fec16-jinterf.o ; \
- mkdir -p ../../lib/fec-linux-x86/lib/linux/x86 ; \
ld -shared fec16-jinterf.o fec16.o -o \
- ../../lib/fec-linux-x86/lib/linux/x86/libfec16.so
+ libfec16.so
fec16.o: fec.h fec16.S
$(CC) $(CFLAGS) -DGF_BITS=16 -c -o fec16.o fec16.S
@@ -56,7 +54,7 @@
$(CC) $(CFLAGS) -DGF_BITS=16 -S -o fec16.S fec.c
clean:
- - rm *.o *.S fec
+ - rm -f *.o *.S fec *so
tgz: $(ALLSRCS)
tar cvzf vdm`date +%y%m%d`.tgz $(ALLSRCS)
Deleted: branches/native_fec/w32
===================================================================
--- branches/native_fec/w32 2006-12-16 20:20:20 UTC (rev 11452)
+++ branches/native_fec/w32 2006-12-16 20:22:10 UTC (rev 11453)
@@ -1,65 +0,0 @@
-MAKE := make -f w32
-
-CPP := cl.exe
-
-MODE ?= Debug
-
-CPP_OPTS := /nologo /I c:/jdk1.3/include /I c:/jdk1.3/include/win32 \
- /D WIN32 /D _WINDOWS /D _MBCS /D _USRDLL /D FEC_EXPORTS
-
-ifeq ($(MODE),Debug)
-Mode := Debug
-CPP_OPTS := /nologo /MTd /W3 /GZ /ZI /Od /D DEBUG $(CPP_OPTS)
-else
-MODE := Release
-CPP_OPTS := /nologo /MT /W3 /O1 /D NDEBUG $(CPP_OPTS)
-endif
-
-LIBS := kernel32 user32 #advapi32 shell32 gdi32 winspool cmdlg32 ole32
oleaut32 uuid odbc32 odbccp32
-
-LDFLAGS=$(patsubt %,%.lib,$(LIBS)) /nologo /dll /incremental:no /machine:I386 \
- /out:$(MODE)/fec$(BITS).dll /implib:$(MODE)/fec$(BITS).lib \
- /OPT:REF /MAP
-
-LD=link.exe
-
-LDOBJS= $(MODE)/fec_win32.obj $(MODE)/fec$(BITS)-jinterf.obj
-
-
-.PHONY: all feclib debug-all release-all bits8-all bits16-all clean
-
-all: debug-all release-all
-
-feclib: $(MODE)/fec$(BITS).dll
-
-debug-all: Debug
- $(MAKE) BITS=8 MODE=Debug feclib
- $(MAKE) BITS=16 MODE=Debug feclib
-
-release-all: Release
- $(MAKE) BITS=8 MODE=Release feclib
- $(MAKE) BITS=16 MODE=Release feclib
-
-bits8-all: Debug Release
- $(MAKE) BITS=8 MODE=Debug feclib
- $(MAKE) BITS=8 MODE=Release feclib
-
-bits16-all: Debug Release
- $(MAKE) BITS=16 MODE=Debug feclib
- $(MAKE) BITS=16 MODE=Release feclib
-
-clean:
- rm -f Debug Release
-
-Debug:
- mkdir -p Debug
-
-Release:
- mkdir -p Release
-
-$(MODE)/fec$(BITS).dll : $(MODE) $(DEF_FILE) $(LDOBJS)
- $(LD) $(LDFLAGS) $(LDOBJS)
-
-
-$(MODE)/%.obj: %.c
- $(CPP) $(CPP_OPTS) /c /Fo"$@" $<