mirror of
https://github.com/google/pebble
synced 2026-10-18 01:04:12 +02:00
Import of the watch repository from Pebble
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mfg/mfg_serials.h"
|
||||
#include "console/prompt_commands.h"
|
||||
|
||||
#include "clar.h"
|
||||
|
||||
#include "stubs_passert.h"
|
||||
#include "stubs_logging.h"
|
||||
#include "stubs_prompt.h"
|
||||
#include "fake_otp.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
extern void command_hwver_write(const char*);
|
||||
extern void command_pcba_serial_write(const char*);
|
||||
|
||||
// Tests
|
||||
/////////////////////////////////////////////
|
||||
|
||||
void test_mfg_serials__initialize(void) {
|
||||
fake_otp_reset();
|
||||
}
|
||||
|
||||
void test_mfg_serials__cleanup(void) {
|
||||
}
|
||||
|
||||
void test_mfg_serials__hw_version(void) {
|
||||
const char* hw_version;
|
||||
|
||||
// Initially, bunch of XXs:
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert(strcmp(hw_version, "XXXXXXXX") == 0);
|
||||
|
||||
// Test writing & reading back:
|
||||
const char* written_hw_version1 = "ABCDEFG";
|
||||
command_hwver_write(written_hw_version1);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert(strcmp(written_hw_version1, hw_version) == 0);
|
||||
|
||||
#if (BOARD_SILK_BB || BOARD_CALCULUS)
|
||||
// Write a second time, too long.
|
||||
const char* written_hw_version2_long = "abcdefghijkxyz";
|
||||
command_hwver_write(written_hw_version2_long);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert_equal_s(written_hw_version1, hw_version);
|
||||
|
||||
// Write second time
|
||||
const char* written_hw_version2 = "HIJKLMN";
|
||||
command_hwver_write(written_hw_version2);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert_equal_s(written_hw_version2, hw_version);
|
||||
|
||||
// Write third time
|
||||
const char* written_hw_version3 = "OPQRSTU";
|
||||
command_hwver_write(written_hw_version3);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert_equal_s(written_hw_version3, hw_version);
|
||||
|
||||
// Write fourth time
|
||||
const char* written_hw_version4 = "VWXYZ12";
|
||||
command_hwver_write(written_hw_version4);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert_equal_s(written_hw_version4, hw_version);
|
||||
|
||||
// Write fifth time
|
||||
const char* written_hw_version5 = "3456789";
|
||||
command_hwver_write(written_hw_version5);
|
||||
hw_version = mfg_get_hw_version();
|
||||
cl_assert_equal_s(written_hw_version5, hw_version);
|
||||
#endif // BOARD_SILK || BOARD_CALCULUS
|
||||
}
|
||||
|
||||
void test_mfg_serials__serial_number_console(void) {
|
||||
const char* serial;
|
||||
|
||||
// Initially, bunch of XXs:
|
||||
serial = mfg_get_serial_number();
|
||||
cl_assert_equal_s(serial, "XXXXXXXXXXXX");
|
||||
|
||||
// Test writing & reading back:
|
||||
const char* written_serial1 = "ABCDEFGHIJKL";
|
||||
command_serial_write(written_serial1);
|
||||
serial = mfg_get_serial_number();
|
||||
cl_assert_equal_s(written_serial1, serial);
|
||||
}
|
||||
|
||||
void test_mfg_serials__pcba_serial_number(void) {
|
||||
const char* pcba_serial;
|
||||
|
||||
// Initially, bunch of XXs:
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(pcba_serial, "XXXXXXXXXXXX");
|
||||
|
||||
// Test writing & reading back:
|
||||
const char* written_pcba_serial1 = "01234567901";
|
||||
command_pcba_serial_write(written_pcba_serial1);
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(written_pcba_serial1, pcba_serial);
|
||||
|
||||
// Write second time, but too long
|
||||
const char* written_pcba_serial2_long = "abcdefghijkxyz";
|
||||
command_pcba_serial_write(written_pcba_serial2_long);
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(written_pcba_serial1, pcba_serial);
|
||||
|
||||
// Write second time
|
||||
const char* written_pcba_serial2 = "abcdefghijkx";
|
||||
command_pcba_serial_write(written_pcba_serial2);
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(written_pcba_serial2, pcba_serial);
|
||||
|
||||
// Write third time
|
||||
const char* written_pcba_serial3 = "asdfghjklq";
|
||||
command_pcba_serial_write(written_pcba_serial3);
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(written_pcba_serial3, pcba_serial);
|
||||
|
||||
// No more space: Reading should return the last successfully written value.
|
||||
const char *pcba_serial4 = "XXXXXXXXXXXX";
|
||||
command_pcba_serial_write(pcba_serial4);
|
||||
pcba_serial = mfg_get_pcba_serial_number();
|
||||
cl_assert_equal_s(written_pcba_serial3, pcba_serial);
|
||||
}
|
||||
|
||||
void test_mfg_serials__serial_number_fails(void) {
|
||||
const char * sn;
|
||||
uint8_t index;
|
||||
MfgSerialsResult r;
|
||||
|
||||
// Initially, return bunch of XXs:
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_s(sn, "XXXXXXXXXXXX");
|
||||
|
||||
// String too long:
|
||||
const char *long_sn = "ABCDEFGHIJKLM";
|
||||
r = mfg_write_serial_number(long_sn, strlen(long_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(index, 0);
|
||||
cl_assert_equal_i(r, MfgSerialsResultFailIncorrectLength);
|
||||
cl_assert_equal_s(sn, "XXXXXXXXXXXX");
|
||||
|
||||
// String too short:
|
||||
const char *short_sn = "ABCDEFGHIJK";
|
||||
r = mfg_write_serial_number(short_sn, strlen(short_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(index, 0);
|
||||
cl_assert_equal_i(r, MfgSerialsResultFailIncorrectLength);
|
||||
cl_assert_equal_s(sn, "XXXXXXXXXXXX");
|
||||
}
|
||||
|
||||
void test_mfg_serials__serial_numbers(void) {
|
||||
const char * sn;
|
||||
uint8_t index;
|
||||
MfgSerialsResult r;
|
||||
|
||||
// Initially, return bunch of XXs:
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_s(sn, "XXXXXXXXXXXX");
|
||||
|
||||
// First time:
|
||||
const char *first_sn = "ABCDEFGHIJKL";
|
||||
r = mfg_write_serial_number(first_sn, strlen(first_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(index, 0);
|
||||
cl_assert_equal_i(r, MfgSerialsResultSuccess);
|
||||
cl_assert_equal_s(sn, first_sn);
|
||||
|
||||
// Second time:
|
||||
const char *second_sn = "012345678901";
|
||||
r = mfg_write_serial_number(second_sn, strlen(second_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(index, 3); // SERIAL2 lives at index 3
|
||||
cl_assert_equal_i(r, MfgSerialsResultSuccess);
|
||||
cl_assert_equal_s(sn, second_sn);
|
||||
|
||||
// Third time:
|
||||
const char *third_sn = "!@#$%^&*()-=";
|
||||
r = mfg_write_serial_number(third_sn, strlen(third_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(r, MfgSerialsResultSuccess);
|
||||
cl_assert_equal_s(sn, third_sn);
|
||||
cl_assert_equal_i(index, 4); // SERIAL3 lives at index 4
|
||||
|
||||
// Fourth time:
|
||||
const char *fourth_sn = "mnbvcxzlkjhg";
|
||||
r = mfg_write_serial_number(fourth_sn, strlen(fourth_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(r, MfgSerialsResultSuccess);
|
||||
cl_assert_equal_s(sn, fourth_sn);
|
||||
cl_assert_equal_i(index, 5); // SERIAL4 lives at index 5
|
||||
|
||||
// Fifth time:
|
||||
const char *fifth_sn = "7ujn8ikm9olm";
|
||||
r = mfg_write_serial_number(fifth_sn, strlen(fifth_sn), &index);
|
||||
sn = mfg_get_serial_number();
|
||||
cl_assert_equal_i(r, MfgSerialsResultSuccess);
|
||||
cl_assert_equal_s(sn, fifth_sn);
|
||||
cl_assert_equal_i(index, 6); // SERIAL5 lives at index 6
|
||||
|
||||
// No more space:
|
||||
const char *sixth_sn = "XXXXXXXXXXXX";
|
||||
r = mfg_write_serial_number(sixth_sn, strlen(sixth_sn), &index);
|
||||
cl_assert(r == MfgSerialsResultFailNoMoreSpace);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "clar.h"
|
||||
|
||||
#include "mfg/mfg_info.h"
|
||||
#include "mfg/snowy/mfg_private.h"
|
||||
#include "flash_region/flash_region_s29vs.h"
|
||||
|
||||
#include "fake_spi_flash.c"
|
||||
#include "stubs_logging.h"
|
||||
|
||||
void mfg_info_write_boot_fpga_bitstream(void) {}
|
||||
bool mfg_info_is_boot_fpga_bitstream_written(void) { return true; }
|
||||
|
||||
void test_snowy_mfg_info__initialize(void) {
|
||||
fake_spi_flash_init(FLASH_REGION_MFG_INFO_BEGIN,
|
||||
FLASH_REGION_MFG_INFO_END - FLASH_REGION_MFG_INFO_BEGIN);
|
||||
}
|
||||
|
||||
void test_snowy_mfg_info__cleanup(void) {
|
||||
fake_spi_flash_cleanup();
|
||||
}
|
||||
|
||||
void test_snowy_mfg_info__color(void) {
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 0);
|
||||
|
||||
mfg_info_set_watch_color(WATCH_INFO_COLOR_RED);
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), WATCH_INFO_COLOR_RED);
|
||||
|
||||
mfg_info_set_watch_color(WATCH_INFO_COLOR_GREEN);
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), WATCH_INFO_COLOR_GREEN);
|
||||
}
|
||||
|
||||
void test_snowy_mfg_info__rtc_freq(void) {
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 0);
|
||||
|
||||
mfg_info_set_rtc_freq(0xfefefefe);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 0xfefefefe);
|
||||
|
||||
mfg_info_set_rtc_freq(1337);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 1337);
|
||||
}
|
||||
|
||||
void test_snowy_mfg_info__model(void) {
|
||||
// Intentionally make the buffer too long so we can check for truncation.
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH + 1] = { 0 };
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
|
||||
{
|
||||
char long_string[] = "01234567890123456789";
|
||||
mfg_info_set_model(long_string);
|
||||
|
||||
// We only expect to see the first 15 (MFG_INFO_MODEL_STRING_LENGTH - 1) characters
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "012345678901234");
|
||||
}
|
||||
}
|
||||
|
||||
void test_snowy_mfg_info__1_to_2_conversion(void) {
|
||||
// Force in an old data version.
|
||||
typedef struct {
|
||||
uint32_t data_version;
|
||||
|
||||
uint32_t color;
|
||||
uint32_t rtc_freq;
|
||||
} MfgDataV1;
|
||||
|
||||
MfgDataV1 old_data = {
|
||||
.data_version = 1,
|
||||
.color = 3,
|
||||
.rtc_freq = 4
|
||||
};
|
||||
|
||||
flash_write_bytes((const uint8_t*) &old_data, FLASH_REGION_MFG_INFO_BEGIN, sizeof(old_data));
|
||||
|
||||
// Now use the info functions to read the data and make sure it's sane. A conversion will have
|
||||
// happened behind the scenes to the latest version.
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH] = { 0 };
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Set color and make sure others don't change.
|
||||
mfg_info_set_watch_color(5);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 5);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Make sure we have space for the model.
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 5);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "clar.h"
|
||||
|
||||
#include "applib/graphics/gtypes.h"
|
||||
#include "mfg/mfg_info.h"
|
||||
#include "mfg/snowy/mfg_private.h"
|
||||
#include "flash_region/flash_region_s29vs.h"
|
||||
|
||||
#include "fake_spi_flash.c"
|
||||
#include "stubs_logging.h"
|
||||
#include "stubs_pbl_malloc.h"
|
||||
|
||||
// This will come from overrides and will include a smaller boot fpga image
|
||||
#include "mfg/spalding/spalding_boot.fpga.auto.h"
|
||||
|
||||
// Stubs for fake_crc.c
|
||||
#include "services/normal/filesystem/pfs.h"
|
||||
int pfs_read(int fd, void *buf, size_t size) { return 0; }
|
||||
int pfs_seek(int fd, int offset, FSeekType seek_type) { return 0; }
|
||||
|
||||
// Test Code!
|
||||
|
||||
void test_spalding_mfg_info__initialize(void) {
|
||||
fake_spi_flash_init(FLASH_REGION_MFG_INFO_BEGIN,
|
||||
FLASH_REGION_MFG_INFO_END - FLASH_REGION_MFG_INFO_BEGIN);
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__cleanup(void) {
|
||||
fake_spi_flash_cleanup();
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__color(void) {
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 0);
|
||||
|
||||
mfg_info_set_watch_color(WATCH_INFO_COLOR_RED);
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), WATCH_INFO_COLOR_RED);
|
||||
|
||||
mfg_info_set_watch_color(WATCH_INFO_COLOR_GREEN);
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), WATCH_INFO_COLOR_GREEN);
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__rtc_freq(void) {
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 0);
|
||||
|
||||
mfg_info_set_rtc_freq(0xfefefefe);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 0xfefefefe);
|
||||
|
||||
mfg_info_set_rtc_freq(1337);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 1337);
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__model(void) {
|
||||
// Intentionally make the buffer too long so we can check for truncation.
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH + 1] = { 0 };
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
|
||||
{
|
||||
char long_string[] = "01234567890123456789";
|
||||
mfg_info_set_model(long_string);
|
||||
|
||||
// We only expect to see the first 15 (MFG_INFO_MODEL_STRING_LENGTH - 1) characters
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "012345678901234");
|
||||
}
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__1_to_2_conversion(void) {
|
||||
// Force in an old data version.
|
||||
typedef struct {
|
||||
uint32_t data_version;
|
||||
|
||||
uint32_t color;
|
||||
uint32_t rtc_freq;
|
||||
} MfgDataV1;
|
||||
|
||||
MfgDataV1 old_data = {
|
||||
.data_version = 1,
|
||||
.color = 3,
|
||||
.rtc_freq = 4
|
||||
};
|
||||
|
||||
flash_write_bytes((const uint8_t*) &old_data, FLASH_REGION_MFG_INFO_BEGIN, sizeof(old_data));
|
||||
|
||||
// Now use the info functions to read the data and make sure it's sane. A conversion will have
|
||||
// happened behind the scenes to the latest version.
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH] = { 0 };
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Set color and make sure others don't change.
|
||||
mfg_info_set_watch_color(5);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 5);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Make sure we have space for the model.
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 5);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
}
|
||||
|
||||
|
||||
void test_spalding_mfg_info__1_to_3_conversion(void) {
|
||||
// Force in an old data version.
|
||||
typedef struct {
|
||||
uint32_t data_version;
|
||||
|
||||
uint32_t color;
|
||||
uint32_t rtc_freq;
|
||||
} MfgDataV1;
|
||||
|
||||
MfgDataV1 old_data = {
|
||||
.data_version = 1,
|
||||
.color = 3,
|
||||
.rtc_freq = 4
|
||||
};
|
||||
|
||||
flash_write_bytes((const uint8_t*) &old_data, FLASH_REGION_MFG_INFO_BEGIN, sizeof(old_data));
|
||||
|
||||
// Now use the info functions to read the data and make sure it's sane. A conversion will have
|
||||
// happened behind the scenes to the latest version.
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH] = { 0 };
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, 0);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 0);
|
||||
|
||||
// Set x and y offsets and make sure others don't change.
|
||||
mfg_info_set_disp_offsets((GPoint) {-2, 1});
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, -2);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 1);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Make sure we have space for the model.
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, -2);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 1);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__2_to_3_conversion(void) {
|
||||
// Force in an old data version.
|
||||
typedef struct {
|
||||
uint32_t data_version;
|
||||
|
||||
uint32_t color;
|
||||
uint32_t rtc_freq;
|
||||
char model[MFG_INFO_MODEL_STRING_LENGTH];
|
||||
} MfgDataV2;
|
||||
|
||||
MfgDataV2 old_data = {
|
||||
.data_version = 1,
|
||||
.color = 3,
|
||||
.rtc_freq = 4,
|
||||
.model[0] = '\0'
|
||||
};
|
||||
|
||||
flash_write_bytes((const uint8_t*) &old_data, FLASH_REGION_MFG_INFO_BEGIN, sizeof(old_data));
|
||||
|
||||
// Now use the info functions to read the data and make sure it's sane. A conversion will have
|
||||
// happened behind the scenes to the latest version.
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
char buffer[MFG_INFO_MODEL_STRING_LENGTH] = { 0 };
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, 0);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 0);
|
||||
|
||||
// Set x and y offsets and make sure others don't change.
|
||||
mfg_info_set_disp_offsets((GPoint) {-2, 1});
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, -2);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 1);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "");
|
||||
|
||||
// Make sure we have space for the model.
|
||||
mfg_info_set_model("test_model");
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, -2);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 1);
|
||||
|
||||
cl_assert_equal_i(mfg_info_get_watch_color(), 3);
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 4);
|
||||
|
||||
mfg_info_get_model(buffer);
|
||||
cl_assert_equal_s(buffer, "test_model");
|
||||
}
|
||||
|
||||
void test_spalding_mfg_info__boot_fpga_persistence(void) {
|
||||
// Make sure no FPGA image is stored
|
||||
const uintptr_t BOOT_FPGA_FLASH_ADDR = FLASH_REGION_MFG_INFO_BEGIN + 0x10000;
|
||||
const uint32_t HEADER_SIZE = 4; // sizeof(BootFPGAHeader)
|
||||
|
||||
uint8_t fpga_buffer[HEADER_SIZE + sizeof(s_boot_fpga)];
|
||||
flash_read_bytes(fpga_buffer, BOOT_FPGA_FLASH_ADDR, sizeof(fpga_buffer));
|
||||
for (int i = 0; i < sizeof(s_boot_fpga); ++i) {
|
||||
cl_assert(fpga_buffer[i] == 0xff);
|
||||
}
|
||||
|
||||
// Write some data in
|
||||
mfg_info_set_rtc_freq(1);
|
||||
|
||||
// The first time we write something into mfg_info we'll actually write the boot fpga as a side
|
||||
// effect. Make sure it's there.
|
||||
flash_read_bytes(fpga_buffer, BOOT_FPGA_FLASH_ADDR, sizeof(fpga_buffer));
|
||||
cl_assert(memcmp(fpga_buffer + HEADER_SIZE, s_boot_fpga, sizeof(s_boot_fpga)) == 0);
|
||||
|
||||
mfg_info_set_disp_offsets((GPoint) { 2, 3 });
|
||||
|
||||
char model[MFG_INFO_MODEL_STRING_LENGTH] = "123456789012345";
|
||||
mfg_info_set_model(model);
|
||||
|
||||
// Now let's write in an fpga image
|
||||
mfg_info_update_constant_data();
|
||||
|
||||
// Let's make sure the mfg data is still persisted
|
||||
cl_assert_equal_i(mfg_info_get_rtc_freq(), 1);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().x, 2);
|
||||
cl_assert_equal_i(mfg_info_get_disp_offsets().y, 3);
|
||||
|
||||
char result_model[MFG_INFO_MODEL_STRING_LENGTH];
|
||||
mfg_info_get_model(result_model);
|
||||
cl_assert_equal_s(model, result_model);
|
||||
|
||||
// Make sure the boot fpga is still correct
|
||||
flash_read_bytes(fpga_buffer, BOOT_FPGA_FLASH_ADDR, sizeof(fpga_buffer));
|
||||
cl_assert(memcmp(fpga_buffer + HEADER_SIZE, s_boot_fpga, sizeof(s_boot_fpga)) == 0);
|
||||
|
||||
// Now invalidate the section and write it back. Make sure it comes back
|
||||
flash_write_bytes((const uint8_t*) "xxxx", BOOT_FPGA_FLASH_ADDR + HEADER_SIZE, 4);
|
||||
|
||||
// Make sure it's corrupted
|
||||
flash_read_bytes(fpga_buffer, BOOT_FPGA_FLASH_ADDR, sizeof(fpga_buffer));
|
||||
cl_assert(memcmp(fpga_buffer + HEADER_SIZE, s_boot_fpga, sizeof(s_boot_fpga)) != 0);
|
||||
|
||||
// Now update it and make sure we healed the corruption
|
||||
mfg_info_update_constant_data();
|
||||
|
||||
flash_read_bytes(fpga_buffer, BOOT_FPGA_FLASH_ADDR, sizeof(fpga_buffer));
|
||||
cl_assert(memcmp(fpga_buffer + HEADER_SIZE, s_boot_fpga, sizeof(s_boot_fpga)) == 0);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
from waftools.pebble_test import clar
|
||||
|
||||
def build(ctx):
|
||||
clar(ctx,
|
||||
sources_ant_glob = "src/fw/mfg/mfg_serials.c tests/fakes/fake_otp.c",
|
||||
test_sources_ant_glob = "test_mfg_serials.c",
|
||||
override_includes=['dummy_board', 'silk'])
|
||||
|
||||
clar(ctx,
|
||||
sources_ant_glob="src/fw/mfg/snowy/mfg_info.c",
|
||||
test_sources_ant_glob="test_snowy_mfg_info.c",
|
||||
override_includes=['dummy_board', 'snowy_mfg_board'],
|
||||
platforms=['snowy'])
|
||||
|
||||
clar(ctx,
|
||||
sources_ant_glob="src/fw/mfg/spalding/mfg_info.c "
|
||||
"src/fw/mfg/spalding/boot_fpga.c "
|
||||
"src/fw/util/legacy_checksum.c "
|
||||
"src/fw/drivers/flash/flash_crc.c",
|
||||
test_sources_ant_glob="test_spalding_mfg_info.c",
|
||||
override_includes=['dummy_board', 'snowy_mfg_board'],
|
||||
platforms=['spalding'])
|
||||
|
||||
# vim:filetype=python
|
||||
|
||||
Reference in New Issue
Block a user