[xiph-cvs] cvs commit: ogg/src bitwise.c mutex.h

Monty xiphmont at xiph.org
Mon Feb 3 15:01:47 PST 2003



xiphmont    03/02/03 18:01:47

  Modified:    src      Tag: libogg2-zerocopy bitwise.c mutex.h
  Log:
  Incremental, more unit tests, more fixes.

Revision  Changes    Path
No                   revision

<p>No                   revision

<p>1.14.2.5  +152 -10   ogg/src/bitwise.c

Index: bitwise.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/bitwise.c,v
retrieving revision 1.14.2.4
retrieving revision 1.14.2.5
diff -u -r1.14.2.4 -r1.14.2.5
--- bitwise.c	22 Jan 2003 21:17:48 -0000	1.14.2.4
+++ bitwise.c	3 Feb 2003 23:01:47 -0000	1.14.2.5
@@ -11,7 +11,7 @@
  ********************************************************************
 
   function: pack variable sized words into an octet stream
-  last mod: $Id: bitwise.c,v 1.14.2.4 2003/01/22 21:17:48 xiphmont Exp $
+  last mod: $Id: bitwise.c,v 1.14.2.5 2003/02/03 23:01:47 xiphmont Exp $
 
  ********************************************************************/
 
@@ -197,14 +197,17 @@
   memset(b,0,sizeof(*b));
 
   b->owner=r->owner;
-  b->head=b->tail=r->buffer;
+  b->head=r->buffer;
 
   /* advance head ptr to beginning of reference */
   while(begin>=b->head->used){
+    ogg_buffer *next=b->head->next;
     begin-=b->head->used;
-    b->head=b->head->next;
+    //oggbuffer_release(b->head);
+    b->head=next;
   }
-  
+
+  b->tail=r->buffer;  
   b->count= -begin;
   b->length=r->length+begin;
   b->headptr=b->head->data+begin;
@@ -212,7 +215,7 @@
   if(b->head->used>b->length){
     b->headend=b->length;
   }else{
-    b->headend=b->head->used;
+    b->headend=b->head->used-begin;
   }
 }
 
@@ -634,6 +637,8 @@
 oggpack_buffer o;
 oggpack_buffer r;
 ogg_buffer_state bs;
+ogg_buffer_reference or;
+#define TESTWORDS 4096
 
 void report(char *in){
   fprintf(stderr,"%s",in);
@@ -755,6 +760,58 @@
   oggpackB_writeclear(&o);
 }
 
+int flatten (unsigned char *flat){
+  unsigned char *ptr=flat;
+  ogg_buffer *head;
+  oggpack_writebuffer(&o,&or);
+  head=or.buffer;
+  while(head){
+    memcpy(ptr,head->data,head->used);
+    ptr+=head->used;
+    head=head->next;
+  }
+  return ptr-flat;
+}
+
+void lsbverify(unsigned long *values,int *len,unsigned char *flat) {
+  int j,k;
+  int flatbyte=0;
+  int flatbit=0;
+  
+  /* verify written buffer is correct bit-by-bit */
+  for(j=0;j<TESTWORDS;j++){
+    for(k=0;k<len[j];k++){
+      int origbit=(values[j]>>k)&1;
+      int bit=(flat[flatbyte]>>flatbit)&1;
+      flatbit++;
+      if(flatbit>7){
+	flatbit=0;
+	++flatbyte;
+      }
+      
+      if(origbit!=bit){
+	fprintf(stderr,"\n\tERROR: bit mismatch!  "
+		"word %d, bit %d, value %lx, len %d\n",
+		j,k,values[j],len[j]);
+	exit(1);
+      }
+      
+    }
+  }
+
+  /* verify that trailing packing is zeroed */
+  while(flatbit && flatbit<8){
+    int bit=(flat[flatbyte]>>flatbit++)&1;
+  
+    if(0!=bit){
+      fprintf(stderr,"\n\tERROR: trailing byte padding not zero!\n");
+      exit(1);
+    }
+  }  
+  
+
+}
+
 int main(void){
   long bytes,i;
   static unsigned long testbuffer1[]=
@@ -820,8 +877,6 @@
   static int six[7]={17,177,170,242,169,19,148};
   static int sixB[7]={136,141,85,79,149,200,41};
 
-  ogg_buffer_reference or;
-
   /* Test read/write together */
   /* Later we test against pregenerated bitstreams */
   ogg_buffer_init(&bs);
@@ -1011,14 +1066,101 @@
     }
     fprintf(stderr,"ok.\n\n");
   }
+  oggpackB_writeclear(&o);
 
   /* now the scary shit: randomized testing */
-  for(i=0;i<100;i++){
-    
 
+  for(i=0;i<1000;i++){
+    int j,count=0,count2=0;
+    unsigned long values[TESTWORDS];
+    int len[TESTWORDS];
+    unsigned char flat[4*TESTWORDS]; /* max possible needed size */
+
+    fprintf(stderr,"\rRandomized testing (LSb)... (%ld)   ",1000-i);
+    oggpack_writeinit(&o,&bs);
+
+    /* generate a list of words and lengths */
+    /* write the required number of bits out to packbuffer */
+    for(j=0;j<TESTWORDS;j++){
+      values[j]=rand();
+      len[j]=(rand()%32)+1;
+      count+=len[j];
+      oggpack_write(&o,values[j],len[j]);
+    }
+
+    /* flatten the packbuffer out to a vector */
+    count2=flatten(flat);
+
+    /* verify against original list */
+    lsbverify(values,len,flat);
+
+    /* construct random-length buffer chain from flat vector; random
+       byte starting offset within the length of the vector */
+    {
+      ogg_buffer *obl=NULL,*ob=NULL;
+      unsigned char *ptr=flat;
+      
+      /* build buffer chain */
+      while(count2){
+	int ilen;
+	ogg_buffer *temp=_ogg_malloc(sizeof(*temp)); /* we don't bother
+                                                      freeing later;
+                                                      this is just a
+                                                      unit test */
+	if(obl)
+	  obl->next=temp;
+	else
+	  ob=temp;
+
+	ilen=(rand()%8)*4+4;
+	if(ilen>count2)ilen=count2;
+	obl=temp;
+	obl->data=ptr;
+	obl->size=count2;
+	obl->used=ilen;
+	
+	count2-=ilen;
+	ptr+=ilen;
+      }
+      /* build reference; choose a starting offset. */
+      {
+	int begin=(rand()%TESTWORDS);
+	int ilen=(rand()%(TESTWORDS-begin));
+	int bitoffset,bitcount=0;
+	unsigned long temp;
+	or.buffer=ob;
+
+	for(j=0;j<begin;j++)
+	  bitcount+=len[j];
+	or.begin=bitcount/8;
+	bitoffset=bitcount%8;
+	for(;j<begin+ilen;j++)
+	  bitcount+=len[j];
+	or.length=((bitcount+7)/8)-or.begin;
 
+	oggpack_readinit(&o,&or);
 
+	for(j=0;j<bitoffset;j++)
+	  oggpack_read1(&o);
+	
+	/* read and compare to original list */
+	for(j=begin;j<begin+ilen;j++){
+	  if(oggpack_read(&o,len[j],&temp)){
+	    fprintf(stderr,"\nERROR: End of stream too soon! word: %d\n",
+		    j-begin);
+	    exit(1);
+	  }
+	  if(temp!=(values[j]&mask[len[j]])){
+	    fprintf(stderr,"\nERROR: Incorrect read %lx != %lx, word %d, len %d\n",
+		    values[j]&mask[len[j]],temp,j-begin,len[j]);
+	    exit(1);
+	  }
+	}
+      }
+    }
+    oggpack_writeinit(&o,&bs);
   }
+  fprintf(stderr,"\rRandomized n-bit testing (LSb)... ok.   \n");
 
   oggpackB_writeclear(&o);
 

<p><p>1.1.2.4   +2 -2      ogg/src/Attic/mutex.h

Index: mutex.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/mutex.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- mutex.h	21 Jan 2003 10:23:08 -0000	1.1.2.3
+++ mutex.h	3 Feb 2003 23:01:47 -0000	1.1.2.4
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: #ifdef jail for basic thread mutexing
- last mod: $Id: mutex.h,v 1.1.2.3 2003/01/21 10:23:08 xiphmont Exp $
+ last mod: $Id: mutex.h,v 1.1.2.4 2003/02/03 23:01:47 xiphmont Exp $
 
  ********************************************************************/
 
@@ -43,7 +43,7 @@
 #define ogg_mutex_unlock(m) (noop())
 
 #else
-#error "this platform has no threading primitive wrappers in ogg/mutex.c"
+#error "configure proper threading wrappers for this platform, or compile with -DUSE_NO_THREADS to build without threading support."
 
 #endif
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list