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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/* unittests.c: unit testing framework for Fuse
Copyright (c) 2008 Philip Kendall
$Id: unittests.c 3649 2008-06-03 10:03:11Z pak21 $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <libspectrum.h>
#include "fuse.h"
#include "machine.h"
#include "mempool.h"
#include "settings.h"
#include "ula.h"
static int
contention_test( void )
{
libspectrum_dword i, checksum = 0, target;
int error = 0;
for( i = 0; i < ULA_CONTENTION_SIZE; i++ ) {
/* Naive, but it will do for now */
checksum += ula_contention[ i ] * ( i + 1 );
}
if( settings_current.late_timings ) {
switch( machine_current->machine ) {
case LIBSPECTRUM_MACHINE_16:
case LIBSPECTRUM_MACHINE_48:
case LIBSPECTRUM_MACHINE_SE:
target = 2308927488UL;
break;
case LIBSPECTRUM_MACHINE_128:
case LIBSPECTRUM_MACHINE_PLUS2:
target = 2335248384UL;
break;
case LIBSPECTRUM_MACHINE_PLUS2A:
case LIBSPECTRUM_MACHINE_PLUS3:
case LIBSPECTRUM_MACHINE_PLUS3E:
target = 3113840640UL;
break;
case LIBSPECTRUM_MACHINE_TC2048:
case LIBSPECTRUM_MACHINE_TC2068:
target = 2307959808UL;
break;
case LIBSPECTRUM_MACHINE_TS2068:
target = 1976561664UL;
break;
case LIBSPECTRUM_MACHINE_PENT:
case LIBSPECTRUM_MACHINE_PENT512:
case LIBSPECTRUM_MACHINE_PENT1024:
case LIBSPECTRUM_MACHINE_SCORP:
target = 0;
break;
default:
target = -1;
break;
}
} else {
switch( machine_current->machine ) {
case LIBSPECTRUM_MACHINE_16:
case LIBSPECTRUM_MACHINE_48:
case LIBSPECTRUM_MACHINE_SE:
target = 2308862976UL;
break;
case LIBSPECTRUM_MACHINE_128:
case LIBSPECTRUM_MACHINE_PLUS2:
target = 2335183872UL;
break;
case LIBSPECTRUM_MACHINE_PLUS2A:
case LIBSPECTRUM_MACHINE_PLUS3:
case LIBSPECTRUM_MACHINE_PLUS3E:
target = 3113754624UL;
break;
case LIBSPECTRUM_MACHINE_TC2048:
case LIBSPECTRUM_MACHINE_TC2068:
target = 2307895296UL;
break;
case LIBSPECTRUM_MACHINE_TS2068:
target = 1976497152UL;
break;
case LIBSPECTRUM_MACHINE_PENT:
case LIBSPECTRUM_MACHINE_PENT512:
case LIBSPECTRUM_MACHINE_PENT1024:
case LIBSPECTRUM_MACHINE_SCORP:
target = 0;
break;
default:
target = -1;
break;
}
}
if( checksum != target ) {
fprintf( stderr, "%s: contention test: checksum = %u, expected = %u\n", fuse_progname, checksum, target );
error = 1;
}
return error;
}
static int
floating_bus_test( void )
{
libspectrum_dword checksum = 0, target;
libspectrum_word offset;
int error = 0;
for( offset = 0; offset < 8192; offset++ )
RAM[ memory_current_screen ][ offset ] = offset % 0x100;
for( tstates = 0; tstates < ULA_CONTENTION_SIZE; tstates++ )
checksum += machine_current->unattached_port() * ( tstates + 1 );
if( settings_current.late_timings ) {
switch( machine_current->machine ) {
case LIBSPECTRUM_MACHINE_16:
case LIBSPECTRUM_MACHINE_48:
target = 3426156480UL;
break;
case LIBSPECTRUM_MACHINE_128:
case LIBSPECTRUM_MACHINE_PLUS2:
target = 2852995008UL;
break;
case LIBSPECTRUM_MACHINE_PLUS2A:
case LIBSPECTRUM_MACHINE_PLUS3:
case LIBSPECTRUM_MACHINE_PLUS3E:
case LIBSPECTRUM_MACHINE_TC2048:
case LIBSPECTRUM_MACHINE_TC2068:
case LIBSPECTRUM_MACHINE_TS2068:
case LIBSPECTRUM_MACHINE_SE:
case LIBSPECTRUM_MACHINE_PENT:
case LIBSPECTRUM_MACHINE_PENT512:
case LIBSPECTRUM_MACHINE_PENT1024:
case LIBSPECTRUM_MACHINE_SCORP:
target = 4261381056UL;
break;
default:
target = -1;
break;
}
} else {
switch( machine_current->machine ) {
case LIBSPECTRUM_MACHINE_16:
case LIBSPECTRUM_MACHINE_48:
target = 3427723200UL;
break;
case LIBSPECTRUM_MACHINE_128:
case LIBSPECTRUM_MACHINE_PLUS2:
target = 2854561728UL;
break;
case LIBSPECTRUM_MACHINE_PLUS2A:
case LIBSPECTRUM_MACHINE_PLUS3:
case LIBSPECTRUM_MACHINE_PLUS3E:
case LIBSPECTRUM_MACHINE_TC2048:
case LIBSPECTRUM_MACHINE_TC2068:
case LIBSPECTRUM_MACHINE_TS2068:
case LIBSPECTRUM_MACHINE_SE:
case LIBSPECTRUM_MACHINE_PENT:
case LIBSPECTRUM_MACHINE_PENT512:
case LIBSPECTRUM_MACHINE_PENT1024:
case LIBSPECTRUM_MACHINE_SCORP:
target = 4261381056UL;
break;
default:
target = -1;
break;
}
}
if( checksum != target ) {
fprintf( stderr, "%s: floating bus test: checksum = %u, expected = %u\n", fuse_progname, checksum, target );
error = 1;
}
return error;
}
#define TEST_ASSERT(x) do { if( !(x) ) { printf("Test assertion failed at %s:%d: %s\n", __FILE__, __LINE__, #x ); return 1; } } while( 0 )
static int
mempool_test( void )
{
int pool1, pool2;
int initial_pools = mempool_get_pools();
pool1 = mempool_register_pool();
TEST_ASSERT( mempool_get_pools() == initial_pools + 1 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 0 );
mempool_alloc( pool1, 23 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 1 );
mempool_alloc( pool1, 42 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 2 );
mempool_free( pool1 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 0 );
pool2 = mempool_register_pool();
TEST_ASSERT( mempool_get_pools() == initial_pools + 2 );
TEST_ASSERT( mempool_get_pool_size( pool2 ) == 0 );
mempool_alloc( pool1, 23 );
TEST_ASSERT( mempool_get_pool_size( pool2 ) == 0 );
mempool_alloc( pool2, 42 );
TEST_ASSERT( mempool_get_pool_size( pool2 ) == 1 );
mempool_free( pool2 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 1 );
TEST_ASSERT( mempool_get_pool_size( pool2 ) == 0 );
mempool_free( pool1 );
TEST_ASSERT( mempool_get_pool_size( pool1 ) == 0 );
TEST_ASSERT( mempool_get_pool_size( pool2 ) == 0 );
return 0;
}
int
unittests_run( void )
{
int r = 0;
r += contention_test();
r += floating_bus_test();
r += mempool_test();
return r;
}
|