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
)
39 Backup::RamBackupUncompressed ramBackupRestored
;
40 if (uncompress((uint8_t *)&ramBackupRestored
, sizeof(ramBackupRestored
), ramBackup
->data
, ramBackup
->size
) != sizeof(ramBackupUncompressed
))
41 TRACE("ERROR uncompress");
42 if (memcmp(&ramBackupUncompressed
, &ramBackupRestored
, sizeof(ramBackupUncompressed
)) != 0)
43 TRACE("ERROR restore");
47 #if defined(EEPROM_RLC)
48 TEST(Eeprom
, 100_random_writes
)
50 eepromFile
= NULL
; // in memory
57 for (int i
= 0; i
< 100; i
++) {
58 int size
= rand() % 800;
59 for (int j
= 0; j
< size
; j
++) {
60 buf
[j
] = rand() < (RAND_MAX
/ 10000 * i
) ? 0 : (j
& 0xff);
62 f
.writeRlc(5, 5, buf
, size
, 100);
63 // printf("size=%4d red=%4d\n\n\n", size, f.size());
65 uint16_t n
= f
.readRlc(buf2
,size
+1);
67 EXPECT_EQ(memcmp(buf
, buf2
, size
), 0);
73 eepromFile
= NULL
; // in memory
79 for (int i
= 0; i
< 1000; i
++)
82 f
.writeRlc(6, 6, buf
, 300, 100);
86 for(int i
=0; i
<500; i
++){
88 uint16_t n
=f
.readRlc(&b
,1);
90 EXPECT_EQ(b
, ('6' + sz
% 4));
97 TEST(Eeprom
, storageCheckImmediately
)
99 eepromFile
= NULL
; // in memory
105 for (int i
= 0; i
< 1000; i
++)
108 theFile
.writeRlc(6, 6, buf
, 300, false);
114 for (int i
= 0; i
< 500; i
++) {
116 uint16_t n
= theFile
.readRlc(&b
, 1);
118 EXPECT_EQ(b
, ('6' + sz
% 4));
127 eepromFile
= NULL
; // in memory
133 for (int i
= 0; i
< 1000; i
++)
134 buf
[i
] = '6' + i
% 4;
136 theFile
.writeRlc(5, 6, buf
, 300, true);
142 for (int i
= 0; i
< 500; i
++) {
144 uint16_t n
= theFile
.readRlc(&b
, 1);
146 EXPECT_EQ(b
, ('6' + sz
% 4));
155 eepromFile
= NULL
; // in memory
161 for (int i
= 0; i
< 1000; i
++)
162 buf
[i
] = '6' + i
% 4;
164 theFile
.writeRlc(5, 6, buf
, 300, true);
166 EXPECT_EQ(EFile::exists(5), true);
170 EXPECT_EQ(EFile::exists(5), false);
174 for(int i
=0; i
<500; i
++){
176 uint16_t n
= theFile
.readRlc(&b
, 1);
178 EXPECT_EQ(b
, ('6' + sz
% 4));