[73] | 1 | /* $Id: atarwbuf.c 74 2015-12-21 00:40:51Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * Tests writing the ATA buffer.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (c) 2015 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
---|
| 8 | *
|
---|
| 9 | * This program is free software; you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation; either version 3 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * This program is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with This program. If not, see <http://www.gnu.org/licenses/>
|
---|
| 21 | *
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | #include <stdio.h>
|
---|
| 26 | #include <stdlib.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <stdint.h>
|
---|
| 29 | #include <io.h>
|
---|
| 30 | #include <conio.h>
|
---|
[74] | 31 | #include <time.h>
|
---|
[73] | 32 |
|
---|
| 33 | #include "atalib.h"
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | int main(int argc, char **argv)
|
---|
| 38 | {
|
---|
| 39 | static uint8_t s_abBuf1[512];
|
---|
| 40 | static uint8_t s_abBuf2[512];
|
---|
| 41 | int rc;
|
---|
| 42 | unsigned i;
|
---|
[74] | 43 | uint32_t cSectors;
|
---|
| 44 | clock_t tsStart;
|
---|
| 45 | clock_t cTicksElapsed;
|
---|
[73] | 46 |
|
---|
| 47 | rc = AtaInitFromArgv(1, argc, argv);
|
---|
| 48 | if (rc != 0)
|
---|
| 49 | return 2;
|
---|
| 50 |
|
---|
| 51 | /*
|
---|
| 52 | * Write and read back.
|
---|
| 53 | */
|
---|
| 54 | for (i = 0; i < 512; i++)
|
---|
| 55 | s_abBuf1[i] = (uint8_t)i;
|
---|
| 56 | rc = AtaWriteBuffer(s_abBuf1, 1 /*fExtraChecks*/);
|
---|
| 57 | if (rc != 0)
|
---|
| 58 | return 1;
|
---|
| 59 | rc = AtaReadBuffer(s_abBuf2, 1 /*fExtraChecks*/);
|
---|
| 60 | if (rc != 0)
|
---|
| 61 | return 1;
|
---|
| 62 | if (memcmp(s_abBuf1, s_abBuf2, sizeof(s_abBuf1)) == 0)
|
---|
| 63 | printf("Initial buffer write and read-back worked\n");
|
---|
| 64 | else
|
---|
| 65 | {
|
---|
| 66 | fprintf(stderr, "error: Initial buffer write and read-back failed!\n");
|
---|
| 67 | return 1;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[74] | 70 | /*
|
---|
| 71 | * Do some performance testing.
|
---|
| 72 | */
|
---|
| 73 | /* read */
|
---|
| 74 | cSectors = 0;
|
---|
| 75 | cTicksElapsed = clock();
|
---|
| 76 | do
|
---|
| 77 | tsStart = clock();
|
---|
| 78 | while (tsStart == cTicksElapsed);
|
---|
| 79 | do
|
---|
| 80 | {
|
---|
| 81 | rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/);
|
---|
| 82 | if (rc == 0)
|
---|
| 83 | rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/);
|
---|
| 84 | if (rc != 0)
|
---|
| 85 | return 1;
|
---|
| 86 | cSectors += 2;
|
---|
| 87 | cTicksElapsed = clock() - tsStart;
|
---|
| 88 | } while (cTicksElapsed < CLOCKS_PER_SEC * 2);
|
---|
| 89 | cSectors >>= 1;
|
---|
| 90 | printf("Read: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors);
|
---|
| 91 |
|
---|
| 92 | /* write */
|
---|
| 93 | cSectors = 0;
|
---|
| 94 | cTicksElapsed = clock();
|
---|
| 95 | do
|
---|
| 96 | tsStart = clock();
|
---|
| 97 | while (tsStart == cTicksElapsed);
|
---|
| 98 | do
|
---|
| 99 | {
|
---|
| 100 | rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/);
|
---|
| 101 | if (rc == 0)
|
---|
| 102 | rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/);
|
---|
| 103 | if (rc != 0)
|
---|
| 104 | return 1;
|
---|
| 105 | cSectors += 2;
|
---|
| 106 | cTicksElapsed = clock() - tsStart;
|
---|
| 107 | } while (cTicksElapsed < CLOCKS_PER_SEC * 2);
|
---|
| 108 | cSectors >>= 1;
|
---|
| 109 | printf("Write: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors);
|
---|
| 110 |
|
---|
| 111 |
|
---|
[73] | 112 | return 0;
|
---|
| 113 | }
|
---|
| 114 |
|
---|