/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2007 Jens Arnold * * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "plugin.h" #include "lib/helper.h" PLUGIN_HEADER #define TESTBASEDIR "/__TEST__" #define TEST_FILE TESTBASEDIR "/test_disk.tmp" #define FRND_SEED 0x78C3 /* arbirary */ #if (CONFIG_STORAGE & STORAGE_MMC) #define TEST_SIZE (20*1024*1024) #else #define TEST_SIZE (300*1024*1024) #endif #define TEST_TIME 10 /* in seconds */ static unsigned char* audiobuf; static ssize_t audiobuflen; static unsigned short frnd_buffer; static int line = 0; static int max_line = 0; static int log_fd; static char logfilename[MAX_PATH]; static const char testbasedir[] = TESTBASEDIR; static void mem_fill_frnd(unsigned char *addr, int len) { unsigned char *end = addr + len; unsigned random = frnd_buffer; while (addr < end) { random = 75 * random + 74; *addr++ = random >> 8; } frnd_buffer = random; } static bool mem_cmp_frnd(unsigned char *addr, int len) { unsigned char *end = addr + len; unsigned random = frnd_buffer; while (addr < end) { random = 75 * random + 74; if (*addr++ != ((random >> 8) & 0xff)) return false; } frnd_buffer = random; return true; } static bool log_init(void) { int h; rb->lcd_getstringsize("A", NULL, &h); max_line = LCD_HEIGHT / h; line = 0; rb->lcd_clear_display(); rb->lcd_update(); rb->create_numbered_filename(logfilename, "/", "test_disk_log_", ".txt", 2 IF_CNFN_NUM_(, NULL)); log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC); return log_fd >= 0; } static void log_text(char *text, bool advance) { rb->lcd_puts(0, line, text); rb->lcd_update(); if (advance) { if (++line >= max_line) line = 0; rb->fdprintf(log_fd, "%s\n", text); } } static void log_close(void) { rb->close(log_fd); } static bool test_fs(void) { unsigned char text_buf[32]; int total, current, align; int fd; log_init(); log_text("test_disk WRITE&VERIFY", true); #ifndef SIMULATOR rb->snprintf(text_buf, sizeof(text_buf), "CPU clock: %ld Hz", *rb->cpu_frequency); log_text(text_buf, true); #endif log_text("----------------------", true); rb->snprintf(text_buf, sizeof text_buf, "Data size: %dKB", (TEST_SIZE>>10)); log_text(text_buf, true); fd = rb->creat(TEST_FILE); if (fd < 0) { rb->splash(HZ, "creat() failed."); goto error; } frnd_buffer = FRND_SEED; total = TEST_SIZE; while (total > 0) { current = rb->rand() % (audiobuflen - 4); current = MIN(current, total); align = rb->rand() & 3; rb->snprintf(text_buf, sizeof text_buf, "Wrt %dKB, %dKB left", current >> 10, total >> 10); log_text(text_buf, false); mem_fill_frnd(audiobuf + align, current); if (current != /* ** $Id$ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ #ifndef lapi_h #define lapi_h #include "lobject.h" LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); #endif