5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
23 extern const char * eepromFile
;
25 #if !defined(EEPROM) && defined(SDCARD)
28 #include "datastructs.h"
29 PACK(struct RamBackupUncompressed
{
35 extern Backup::RamBackupUncompressed ramBackupUncompressed
;
36 TEST(Storage
, BackupAndRestore
)
40 Backup::RamBackupUncompressed ramBackupRestored
;
41 if (uncompress((uint8_t *)&ramBackupRestored
, sizeof(ramBackupRestored
), ramBackup
->data
, ramBackup
->size
) != sizeof(ramBackupUncompressed
))
42 TRACE("ERROR uncompress");
43 if (memcmp(&ramBackupUncompressed
, &ramBackupRestored
, sizeof(ramBackupUncompressed
)) != 0)
44 TRACE("ERROR restore");
48 #if defined(EEPROM_RLC)
49 TEST(Eeprom
, 100_random_writes
)
51 eepromFile
= NULL
; // in memory
58 for(int i
=0; i
<100; i
++) {
59 int size
= rand()%800;
60 for(int j
=0; j
<size
; j
++) {
61 buf
[j
] = rand() < (RAND_MAX
/10000*i
) ? 0 : (j
&0xff);
63 f
.writeRlc(5, 5, buf
, size
, 100);
64 // printf("size=%4d red=%4d\n\n\n", size, f.size());
66 uint16_t n
= f
.readRlc(buf2
,size
+1);
68 EXPECT_EQ(memcmp(buf
, buf2
, size
), 0);
74 eepromFile
= NULL
; // in memory
80 for(int i
=0; i
<1000; i
++) buf
[i
]='6'+i
%4;
82 f
.writeRlc(6, 6, buf
, 300, 100);
86 for(int i
=0; i
<500; i
++){
88 uint16_t n
=f
.readRlc(&b
,1);
89 if(n
) EXPECT_EQ(b
, ('6'+sz
%4));
95 TEST(Eeprom
, storageCheckImmediately
)
97 eepromFile
= NULL
; // in memory
103 for(int i
=0; i
<1000; i
++) buf
[i
]='6'+i
%4;
105 theFile
.writeRlc(6, 6, buf
, 300, false);
111 for(int i
=0; i
<500; i
++){
113 uint16_t n
=theFile
.readRlc(&b
,1);
114 if(n
) EXPECT_EQ(b
, ('6'+sz
%4));
122 eepromFile
= NULL
; // in memory
128 for(int i
=0; i
<1000; i
++) buf
[i
]='6'+i
%4;
130 theFile
.writeRlc(5, 6, buf
, 300, true);
136 for(int i
=0; i
<500; i
++){
138 uint16_t n
=theFile
.readRlc(&b
,1);
139 if(n
) EXPECT_EQ(b
, ('6'+sz
%4));
147 eepromFile
= NULL
; // in memory
153 for(int i
=0; i
<1000; i
++) buf
[i
]='6'+i
%4;
155 theFile
.writeRlc(5, 6, buf
, 300, true);
157 EXPECT_EQ(EFile::exists(5), true);
161 EXPECT_EQ(EFile::exists(5), false);
165 for(int i
=0; i
<500; i
++){
167 uint16_t n
=theFile
.readRlc(&b
,1);
168 if(n
) EXPECT_EQ(b
, ('6'+sz
%4));