only added a google test
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gtests.h"
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
TEST(EEPROM, 100_random_writes)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
uint8_t buf2[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<100; i++) {
|
||||
int size = rand()%800;
|
||||
for(int j=0; j<size; j++) {
|
||||
buf[j] = rand() < (RAND_MAX/10000*i) ? 0 : (j&0xff);
|
||||
}
|
||||
f.writeRlc(5, 5, buf, size, 100);
|
||||
// printf("size=%4d red=%4d\n\n\n", size, f.size());
|
||||
f.openRd(5);
|
||||
uint16_t n = f.readRlc(buf2,size+1);
|
||||
EXPECT_EQ(n, size);
|
||||
EXPECT_EQ(memcmp(buf, buf2, size), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EEPROM, test2)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
f.writeRlc(6, 6, buf, 300, 100);
|
||||
|
||||
f.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=f.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, eeCheckImmediately)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
// RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(6, 6, buf, 300, false);
|
||||
|
||||
eeCheck(true);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, copy)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
theFile.copy(6, 5);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, rm)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), true);
|
||||
|
||||
EFile::rm(5);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), false);
|
||||
|
||||
theFile.openRd(5);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 0);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user