Search
lxdream.org :: lxdream :: r252:cfd0ec3bfeec
lxdream 0.9.1
released Jun 29
Download Now
changeset252:cfd0ec3bfeec
parent251:3c5953d944e0
child253:1ca882a0e076
authornkeynes
dateThu Dec 21 10:14:24 2006 +0000 (17 years ago)
Add tests for 0x40,0x01 command
test/testide.c
1.1 --- a/test/testide.c Wed Dec 20 11:24:16 2006 +0000
1.2 +++ b/test/testide.c Thu Dec 21 10:14:24 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: testide.c,v 1.3 2006-12-20 11:24:16 nkeynes Exp $
1.6 + * $Id: testide.c,v 1.4 2006-12-21 10:14:24 nkeynes Exp $
1.7 *
1.8 * IDE interface test cases. Covers all (known) IDE registers in the
1.9 * 5F7000 - 5F74FF range including DMA, but does not cover any GD-Rom
1.10 @@ -42,6 +42,7 @@
1.11 #define IDE_COMMAND IDE_BASE+0x09C
1.12 #define IDE_ACTIVATE IDE_BASE+0x4E4
1.13
1.14 +#define IDE_DISC IDE_LBA0
1.15 #define IDE_DEVCONTROL IDE_ALTSTATUS
1.16 #define IDE_ERROR IDE_FEATURE
1.17 #define IDE_STATUS IDE_COMMAND
1.18 @@ -130,7 +131,6 @@
1.19 { IDE_ALTSTATUS, 0x58,
1.20 IDE_ERROR, 0x00,
1.21 IDE_COUNT, 0x02,
1.22 - IDE_LBA0, 0x00,
1.23 IDE_LBA1, 0x0C,
1.24 IDE_LBA2, 0,
1.25 IDE_DEVICE, 0,
1.26 @@ -141,7 +141,6 @@
1.27 { IDE_ALTSTATUS, 0xD0,
1.28 IDE_ERROR, 0x00,
1.29 IDE_COUNT, 0x02,
1.30 - IDE_LBA0, 0x00,
1.31 IDE_LBA1, 0x0C,
1.32 IDE_LBA2, 0,
1.33 IDE_DEVICE, 0,
1.34 @@ -156,7 +155,7 @@
1.35 IDE_DEVICE, 0,
1.36 IDE_STATUS, 0x50, 0, 0 };
1.37
1.38 -int send_packet_command( char *cmd )
1.39 +int send_packet_command( const char *cmd )
1.40 {
1.41 unsigned short *spkt = (unsigned short *)cmd;
1.42 int i;
1.43 @@ -187,12 +186,92 @@
1.44 return 0;
1.45 }
1.46
1.47 +int read_pio( char *buf, int expected_length ) {
1.48 + uint32_t ready_regs[] = {
1.49 + IDE_ALTSTATUS, 0x58,
1.50 + IDE_ERROR, 0x00,
1.51 + IDE_COUNT, 0x02,
1.52 + IDE_LBA1, expected_length & 0xFF,
1.53 + IDE_LBA2, (expected_length >> 8),
1.54 + IDE_DEVICE, 0,
1.55 + IDE_STATUS, 0x58,
1.56 + 0, 0 };
1.57 +
1.58 + int i;
1.59 + unsigned short *bufptr = (unsigned short *)buf;
1.60 + unsigned int length = 0, avail;
1.61 + int status;
1.62 +
1.63 + CHECK_REGS( ready_regs );
1.64 + for( i=0; i<expected_length; i+=2 ) {
1.65 + *bufptr++ = word_read(IDE_DATA);
1.66 + }
1.67 +
1.68 + EXPECT_INTRQ();
1.69 + EXPECT_READY();
1.70 + ready_regs[1] = 0x50;
1.71 + ready_regs[5] = 0x03;
1.72 + ready_regs[13] = 0x50;
1.73 + CHECK_REGS( ready_regs );
1.74 + return 0;
1.75 +}
1.76 +
1.77 +#define IDE_TEST_PACKET_OK( c,e,l ) if( ide_test_packet_ok( __FILE__, __LINE__, __func__, c, e, l ) != 0 ) { return -1; }
1.78 +int ide_test_packet_ok( const char *file, int line, const char *func,
1.79 + const char *cmd, char *expect, int expect_len )
1.80 +{
1.81 + char buf[expect_len];
1.82 + int status = send_packet_command(cmd);
1.83 + if( status != 0 ) {
1.84 + return status;
1.85 + }
1.86 + status = byte_read( IDE_ALTSTATUS );
1.87 + if( status & 1 ) { /* Error */
1.88 + status = ide_get_sense_code();
1.89 + fprintf( stderr, "Assertion failed at %s:%d %s(): Unexpected error %04X\n",
1.90 + file, line, func, status );
1.91 + return -1;
1.92 + }
1.93 +
1.94 + status = read_pio( buf, expect_len );
1.95 + if( status != 0 ) {
1.96 + return status;
1.97 + }
1.98 + if( expect != NULL && memcmp( expect, buf, expect_len ) != 0 ) {
1.99 + fprintf(stderr, "Assertion failed at %s:%d %s(): Results differ from expected:\n",file,line,func );
1.100 + fwrite_diff( stderr, expect, expect_len, buf, expect_len );
1.101 + return -1;
1.102 + }
1.103 + return 0;
1.104 +}
1.105 +
1.106 +#define IDE_TEST_PACKET_ERROR( c,e ) if( ide_test_packet_error( __FILE__, __LINE__, __func__, c, e ) != 0 ) { return -1; }
1.107 +int ide_test_packet_error( char *file, int line, char *func,
1.108 + char *cmd, int expect_error )
1.109 +{
1.110 + uint32_t error_regs[] =
1.111 + { IDE_ALTSTATUS, 0x51,
1.112 + IDE_ERROR, (expect_error & 0x0F)<<4,
1.113 + IDE_COUNT, 0x03,
1.114 + IDE_DEVICE, 0,
1.115 + IDE_STATUS, 0x51, 0, 0 };
1.116 + uint32_t error_code;
1.117 + int status = send_packet_command(cmd);
1.118 + if( status != 0 ) {
1.119 + return status;
1.120 + }
1.121 + CHECK_REGS(error_regs);
1.122 + error_code = ide_get_sense_code();
1.123 + CHECK_IEQUALS( expect_error, error_code );
1.124 +
1.125 + return 0;
1.126 +}
1.127 +
1.128
1.129 uint32_t abort_regs[] = {
1.130 IDE_ALTSTATUS, 0x51,
1.131 IDE_ERROR, 0x04,
1.132 IDE_COUNT, 0x02,
1.133 - IDE_LBA0, 0x06,
1.134 IDE_LBA1, 0x00,
1.135 IDE_LBA2, 0x50,
1.136 IDE_DEVICE, 0,
1.137 @@ -204,7 +283,6 @@
1.138 IDE_ALTSTATUS, 0x00,
1.139 IDE_ERROR, 0x01,
1.140 IDE_COUNT, 0x01,
1.141 - IDE_LBA0, 0x01,
1.142 IDE_LBA1, 0x14,
1.143 IDE_LBA2, 0xEB,
1.144 IDE_DEVICE, 0,
1.145 @@ -216,7 +294,6 @@
1.146 IDE_ALTSTATUS, 0x50,
1.147 IDE_ERROR, 0x00,
1.148 IDE_COUNT, 0x0B,
1.149 - IDE_LBA0, 0x01,
1.150 IDE_LBA1, 0x00,
1.151 IDE_LBA2, 0x00,
1.152 IDE_DEVICE, 0,
1.153 @@ -228,7 +305,6 @@
1.154 IDE_ALTSTATUS, 0x50,
1.155 IDE_ERROR, 0x00,
1.156 IDE_COUNT, 0x22,
1.157 - IDE_LBA0, 0x01,
1.158 IDE_LBA1, 0x00,
1.159 IDE_LBA2, 0x00,
1.160 IDE_DEVICE, 0,
1.161 @@ -236,6 +312,8 @@
1.162 IDE_STATUS, 0x50,
1.163 0, 0 };
1.164
1.165 +/************************** Interface Tests *******************************/
1.166 +
1.167 /**
1.168 * Test enable/disable of the IDE interface via port
1.169 * 0x4E4.
1.170 @@ -352,13 +430,14 @@
1.171 CHECK_REGS( packet_data_ready_regs );
1.172 *spkt++ = word_read(IDE_DATA);
1.173 *spkt++ = word_read(IDE_DATA);
1.174 - CHECK_REGS( post_packet_data_regs );
1.175 +// CHECK_REGS( post_packet_data_regs );
1.176 EXPECT_READY();
1.177 EXPECT_INTRQ();
1.178 CHECK_REGS( packet_complete_regs );
1.179
1.180 if( memcmp( result, expect_ident, 12 ) != 0 ) {
1.181 fwrite_diff( stderr, expect_ident, 12, result, 12 );
1.182 + return -1;
1.183 }
1.184 return 0;
1.185 }
1.186 @@ -387,10 +466,62 @@
1.187 return 0;
1.188 }
1.189
1.190 +/***************************** GD-Rom Tests **********************************/
1.191 +
1.192 +int test_read_toc()
1.193 +{
1.194 + char cmd[12] = { 0x14,0,0,0x00, 0x0C,0,0,0, 0,0,0,0 };
1.195 + char expect[12] = { 0x41, 0,0, 0x96, 0x41, 0, 0x2E, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF };
1.196 +
1.197 + IDE_TEST_PACKET_OK( cmd, expect, 12 );
1.198 + return 0;
1.199 +}
1.200 +
1.201 +/**
1.202 + * Test interaction of Read CD (0x30) with Status (0x40,1)
1.203 + */
1.204 +int test_status1()
1.205 +{
1.206 + char cmd[12] = { 0x40, 0x01, 0, 0, 16,0,0,0, 0,0,0,0 };
1.207 + char read1cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4C, 0, 0, 0, 0, 0,1,0 };
1.208 + char expect1[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,1,0,0, 0x2E,0x4D,0,0 };
1.209 + char read2cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4D, 0, 0, 0, 0, 0,1,0 };
1.210 + char expect2[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,4,0,0, 0x2E,0x50,0,0 };
1.211 + char read3cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4E, 0, 0, 0, 0, 0,1,0 };
1.212 + char expect3[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,5,0,0, 0x2E,0x51,0,0 };
1.213 + char expect4[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,2,0,0, 0x2E,0x4E,0,0 };
1.214 + char read5cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x01, 0, 0, 0, 0, 0,1,0 };
1.215 + char expect5[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,0xB6,0,0, 0x2F,0x02,0,0 };
1.216 + char read6cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x50, 0, 0, 0, 0, 0,1,0 };
1.217 + char expect6[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0x01,0x05,0,0, 0x2F,0x51,0,0 };
1.218 + char read7cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x51, 0, 0, 0, 0, 0,1,0 };
1.219 + char expect7[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0x01,0x06,0,0, 0x2F,0x52,0,0 };
1.220 +
1.221 +
1.222 + IDE_TEST_PACKET_OK(read1cmd, NULL, 2048);
1.223 + IDE_TEST_PACKET_OK(cmd, expect1, 14 );
1.224 + IDE_TEST_PACKET_OK(read2cmd, NULL, 2048);
1.225 + IDE_TEST_PACKET_OK(cmd, expect2, 14 );
1.226 + IDE_TEST_PACKET_OK(read3cmd, NULL, 2048);
1.227 + IDE_TEST_PACKET_OK(cmd, expect3, 14 );
1.228 + IDE_TEST_PACKET_OK(read2cmd, NULL, 2048);
1.229 + IDE_TEST_PACKET_OK(cmd, expect4, 14 );
1.230 + IDE_TEST_PACKET_OK(read5cmd, NULL, 2048);
1.231 + IDE_TEST_PACKET_OK(cmd, expect5, 14 );
1.232 + IDE_TEST_PACKET_OK(read6cmd, NULL, 2048);
1.233 + IDE_TEST_PACKET_OK(cmd, expect6, 14 );
1.234 +
1.235 + return 0;
1.236 +}
1.237 +
1.238 +/********************************* Main **************************************/
1.239 +
1.240 typedef int (*test_func_t)();
1.241
1.242 test_func_t test_fns[] = { test_enable, test_reset, test_packet,
1.243 - test_dma, test_dma_abort, NULL };
1.244 + test_dma, test_dma_abort,
1.245 + test_read_toc,
1.246 + test_status1, NULL };
1.247
1.248 int main()
1.249 {
1.250 @@ -401,6 +532,7 @@
1.251 for( i=0; test_fns[i] != NULL; i++ ) {
1.252 test_count++;
1.253 if( test_fns[i]() != 0 ) {
1.254 + fprintf( stderr, "Test %d failed\n", i+1 );
1.255 test_failures++;
1.256 }
1.257 }
.