/* $Id: atarwbuf.c 74 2015-12-21 00:40:51Z bird $ */ /** @file * Tests writing the ATA buffer. */ /* * Copyright (c) 2015 knut st. osmundsen * * 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 3 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, see * */ #include #include #include #include #include #include #include #include "atalib.h" int main(int argc, char **argv) { static uint8_t s_abBuf1[512]; static uint8_t s_abBuf2[512]; int rc; unsigned i; uint32_t cSectors; clock_t tsStart; clock_t cTicksElapsed; rc = AtaInitFromArgv(1, argc, argv); if (rc != 0) return 2; /* * Write and read back. */ for (i = 0; i < 512; i++) s_abBuf1[i] = (uint8_t)i; rc = AtaWriteBuffer(s_abBuf1, 1 /*fExtraChecks*/); if (rc != 0) return 1; rc = AtaReadBuffer(s_abBuf2, 1 /*fExtraChecks*/); if (rc != 0) return 1; if (memcmp(s_abBuf1, s_abBuf2, sizeof(s_abBuf1)) == 0) printf("Initial buffer write and read-back worked\n"); else { fprintf(stderr, "error: Initial buffer write and read-back failed!\n"); return 1; } /* * Do some performance testing. */ /* read */ cSectors = 0; cTicksElapsed = clock(); do tsStart = clock(); while (tsStart == cTicksElapsed); do { rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/); if (rc == 0) rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/); if (rc != 0) return 1; cSectors += 2; cTicksElapsed = clock() - tsStart; } while (cTicksElapsed < CLOCKS_PER_SEC * 2); cSectors >>= 1; printf("Read: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors); /* write */ cSectors = 0; cTicksElapsed = clock(); do tsStart = clock(); while (tsStart == cTicksElapsed); do { rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/); if (rc == 0) rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/); if (rc != 0) return 1; cSectors += 2; cTicksElapsed = clock() - tsStart; } while (cTicksElapsed < CLOCKS_PER_SEC * 2); cSectors >>= 1; printf("Write: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors); return 0; }