File: test_interface.c

package info (click to toggle)
cdparanoia 3.10.2%2Bdebian-14
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,936 kB
  • sloc: ansic: 8,026; sh: 2,642; makefile: 11
file content (224 lines) | stat: -rw-r--r-- 4,881 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/******************************************************************
 * CopyPolicy: GNU Lessger General Public License 2.1 applies
 * Copyright (C) Monty xiphmont@mit.edu
 *
 * Fake interface backend for testing paranoia layer
 *
 ******************************************************************/

#ifdef CDDA_TEST
#include "low_interface.h"
#include "utils.h"

/* Build which test model? */
#define  CDDA_TEST_OK
#undef  CDDA_TEST_JITTER_SMALL
#undef  CDDA_TEST_JITTER_LARGE
#undef  CDDA_TEST_JITTER_MASSIVE
#undef  CDDA_TEST_FRAG_SMALL
#undef  CDDA_TEST_FRAG_LARGE
#undef  CDDA_TEST_FRAG_MASSIVE
#undef  CDDA_TEST_BOGUS_BYTES
#undef  CDDA_TEST_DROPDUPE_BYTES
#undef  CDDA_TEST_SCRATCH
#undef  CDDA_TEST_UNDERRUN

#undef  CDDA_TEST_ALLJITTER
#undef  CDDA_TEST_SOMEJITTER
#undef  CDDA_TEST_SEEKJITTER

static int test_readtoc (cdrom_drive *d){
  int tracks=0;
  long bytes;
  long sectors;

  /* only one track, as many sectors as the file */

  bytes=lseek(d->cdda_fd,0,SEEK_END);
  lseek(d->cdda_fd,0,SEEK_SET);
  sectors=bytes/CD_FRAMESIZE_RAW;

  d->disc_toc[0].bFlags = 0;
  d->disc_toc[0].bTrack = 1;
  d->disc_toc[0].dwStartSector = 37;

  d->disc_toc[1].bFlags = 0x4;
  d->disc_toc[1].bTrack = CDROM_LEADOUT;
  d->disc_toc[1].dwStartSector = sectors+37;

  tracks=2;
  d->cd_extra=0;
  return(--tracks);  /* without lead-out */
}

/* we emulate jitter, scratches, atomic jitter and bogus bytes on
   boundaries, etc */

static long test_read(cdrom_drive *d, void *p, long begin, long sectors){
  int jitter_flag=0;
  int los_flag=0;
  static int jitter=0;
  int bytes_so_far=0;
  long bytestotal;
  static FILE *fd=NULL;
  static long lastread=0;

  if(!fd)fd=fdopen(d->cdda_fd,"r");

  if(begin<lastread)
    d->private_data->last_milliseconds=20;
  else
    d->private_data->last_milliseconds=sectors;

#ifdef CDDA_TEST_UNDERRUN
  sectors-=1;
#endif

#ifdef CDDA_TEST_SEEKJITTER
  if(lastread!=begin)jitter_flag=1;
#else
#ifdef CDDA_TEST_ALLJITTER
  jitter_flag=1;
#else
#ifdef CDDA_TEST_SOMEJITTER
  jitter_flag=(drand48()>.9?1:0);
  los_flag=(drand48()>.9?1:0);
#else
  los_flag=1;
#endif
#endif
#endif

  lastread=begin+sectors;
  bytestotal=sectors*CD_FRAMESIZE_RAW;

  begin*=CD_FRAMESIZE_RAW;

  while(bytes_so_far<bytestotal){
    int inner_bytes=bytestotal-bytes_so_far;
    char *inner_buf=(p ? p+bytes_so_far : NULL);
    long seeki;
    long rbytes;
    long this_bytes=inner_bytes;

#ifdef CDDA_TEST_OK
    
#else
#ifdef CDDA_TEST_JITTER_SMALL
    if(jitter_flag)jitter=4*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_JITTER_LARGE
    if(jitter_flag)jitter=32*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_JITTER_MASSIVE
    if(jitter_flag)jitter=128*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_FRAG_SMALL
    if(los_flag)this_bytes=256*(int)(drand48()*CD_FRAMESIZE_RAW/8);
    if(jitter_flag)jitter=4*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_FRAG_LARGE
    if(los_flag)this_bytes=16*(int)(drand48()*CD_FRAMESIZE_RAW/8);
    if(jitter_flag)jitter=4*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_FRAG_MASSIVE
    if(los_flag)this_bytes=8*(int)(drand48()*CD_FRAMESIZE_RAW/8);
    if(jitter_flag)jitter=32*(int)((drand48()-.5)*CD_FRAMESIZE_RAW/8);

#else
#ifdef CDDA_TEST_DROPDUPE_BYTES
    if(los_flag)this_bytes=CD_FRAMESIZE_RAW;
    if(jitter_flag)
      if (drand48()>.8)
	this_jitter=32;
      else
	this_jitter=0;

#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif


    if(this_bytes>inner_bytes)this_bytes=inner_bytes;
    if(begin+jitter+bytes_so_far<0)jitter=0;    
    seeki=begin+bytes_so_far+jitter;

    if(fseek(fd,seeki,SEEK_SET)<0){
      return(0);
    }
    if(!inner_buf){
      char *temp = malloc(this_bytes);
      rbytes=fread(temp,1,this_bytes,fd);
      free(temp);
    }else
      rbytes=fread(inner_buf,1,this_bytes,fd);


    bytes_so_far+=rbytes;
    if(rbytes==0)break;

#ifdef CDDA_TEST_SEEKJITTER
    jitter_flag=0;
    los_flag=0;
#else
#ifdef CDDA_TEST_ALLJITTER
    jitter_flag=1;
    los_flag=0;
#else
#ifdef CDDA_TEST_SOMEJITTER
    jitter_flag=(drand48()>.9?1:0);
    los_flag=(drand48()>.9?1:0);
#else
    los_flag=1;
#endif
#endif
#endif

  }

#ifdef CDDA_TEST_SCRATCH
  {
    long location=300*CD_FRAMESIZE_RAW+(drand48()*56)+512;

    if(begin<=location && begin+bytestotal>location){
      if(p)memset(p+location-begin,(int)(drand48()*256),1100);
    }
  }
#endif

  return(sectors);
}

/* hook */
static int Dummy (cdrom_drive *d,int Switch){
  return(0);
}

/* set function pointers to use the ioctl routines */
int test_init_drive (cdrom_drive *d){

  d->nsectors=13;
  d->enable_cdda = Dummy;
  d->read_audio = test_read;
  d->read_toc = test_readtoc;
  d->set_speed = Dummy;
  d->tracks=d->read_toc(d);
  if(d->tracks==-1)
    return(d->tracks);
  d->opened=1;
  srand48(0);
  return(0);
}

#endif