[esp_rom]: Partially buildable for linux

The following files have been ported:
* esp_rom_crc.h
* esp_rom_sys.h
* esp_rom_efuse.h (mostly no-ops)
* esp_rom_md5.h

Integrated Linux-based rom implementation into log
and NVS component.

Added brief host tests for ROM to ensure basic
consistency on Linux.

Added ROM printf host unit tests.

Temporarily added reset reason for Linux in ROM.
This commit is contained in:
Jakob Hasse
2021-06-03 11:59:00 +08:00
parent b8c2825b21
commit 4dd88329c1
25 changed files with 1192 additions and 138 deletions

View File

@@ -3,9 +3,7 @@
# Simple log test on Linux target
This unit test tests basic functionality of the log component. The test does not use mocks. Instead, it runs the whole implementation of the component on the Linux host. The test framework is CATCH.
*Note that the early log (ESP_EARLY_LOG<X>) functionality has not been ported to Linux since it depends on the ROM component.*
This unit test tests basic functionality of the log component. The test does not use mocks. Instead, it runs the whole implementation of the component on the Linux host. The test framework is CATCH. For early log, we only perform a compile time test since there's nothing to test on Linux except for the log macros themselves (all the implementation will be in chip ROM).
## Requirements

View File

@@ -18,29 +18,19 @@ using namespace std;
static const char *TEST_TAG = "test";
struct PrintFixture {
class BasicLogFixture {
public:
static const size_t BUFFER_SIZE = 4096;
PrintFixture(esp_log_level_t log_level = ESP_LOG_VERBOSE)
BasicLogFixture(esp_log_level_t log_level = ESP_LOG_VERBOSE)
{
if (instance != nullptr) {
throw exception();
}
std::memset(print_buffer, 0, BUFFER_SIZE);
instance = this;
old_vprintf = esp_log_set_vprintf(print_callback);
esp_log_level_set(TEST_TAG, log_level);
esp_log_level_set("*", log_level);
}
~PrintFixture()
virtual ~BasicLogFixture()
{
esp_log_level_set(TEST_TAG, ESP_LOG_INFO);
esp_log_set_vprintf(old_vprintf);
instance = nullptr;
esp_log_level_set("*", ESP_LOG_INFO);
}
string get_print_buffer_string() const
@@ -51,10 +41,33 @@ struct PrintFixture {
void reset_buffer()
{
std::memset(print_buffer, 0, BUFFER_SIZE);
additional_reset();
}
protected:
char print_buffer [BUFFER_SIZE];
virtual void additional_reset() { }
};
struct PrintFixture : BasicLogFixture {
PrintFixture(esp_log_level_t log_level = ESP_LOG_VERBOSE) : BasicLogFixture(log_level)
{
if (instance != nullptr) {
throw exception();
}
instance = this;
old_vprintf = esp_log_set_vprintf(print_callback);
}
virtual ~PrintFixture()
{
esp_log_set_vprintf(old_vprintf);
instance = nullptr;
}
private:
static int print_callback(const char *format, va_list args)
{
@@ -72,7 +85,47 @@ private:
vprintf_like_t old_vprintf;
};
struct PutcFixture : BasicLogFixture {
PutcFixture(esp_log_level_t log_level = ESP_LOG_VERBOSE) : BasicLogFixture(log_level), counter(0)
{
if (instance != nullptr) {
throw exception();
}
esp_rom_install_channel_putc(0, putc_callback);
instance = this;
}
~PutcFixture()
{
esp_rom_install_uart_printf();
instance = nullptr;
}
void additional_reset() override
{
counter = 0;
}
size_t counter;
private:
static void putc_callback(char c)
{
return instance->putc_to_buffer(c);
}
void putc_to_buffer(char c)
{
print_buffer[counter++] = c;
}
static PutcFixture *instance;
};
PrintFixture *PrintFixture::instance = nullptr;
PutcFixture *PutcFixture::instance = nullptr;
TEST_CASE("verbose log level")
{
@@ -139,3 +192,78 @@ TEST_CASE("changing log level")
ESP_LOGI(TEST_TAG, "must indeed be printed");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("rom printf")
{
PutcFixture fix;
int printed_chars = esp_rom_printf("info");
CHECK(printed_chars == 4);
CHECK(fix.get_print_buffer_string() == "info");
}
TEST_CASE("early verbose log level")
{
PutcFixture fix;
const std::regex test_print("V \\([0-9]*\\) test: verbose", std::regex::ECMAScript);
ESP_EARLY_LOGV(TEST_TAG, "verbose");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("early debug log level")
{
PutcFixture fix;
const std::regex test_print("D \\([0-9]*\\) test: debug", std::regex::ECMAScript);
ESP_EARLY_LOGD(TEST_TAG, "debug");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("early info log level")
{
PutcFixture fix;
const std::regex test_print("I \\([0-9]*\\) test: info", std::regex::ECMAScript);
ESP_EARLY_LOGI(TEST_TAG, "info");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("early warn log level")
{
PutcFixture fix;
const std::regex test_print("W \\([0-9]*\\) test: warn", std::regex::ECMAScript);
ESP_EARLY_LOGW(TEST_TAG, "warn");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("early error log level")
{
PutcFixture fix;
const std::regex test_print("E \\([0-9]*\\) test: error", std::regex::ECMAScript);
ESP_EARLY_LOGE(TEST_TAG, "error");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}
TEST_CASE("changing early log level")
{
PutcFixture fix(ESP_LOG_INFO);
const std::regex test_print("I \\([0-9]*\\) test: must indeed be printed", std::regex::ECMAScript);
ESP_EARLY_LOGI(TEST_TAG, "must indeed be printed");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
fix.reset_buffer();
esp_log_level_set("*", ESP_LOG_WARN);
ESP_EARLY_LOGI(TEST_TAG, "must not be printed");
CHECK(fix.get_print_buffer_string().size() == 0);
fix.reset_buffer();
esp_log_level_set("*", ESP_LOG_INFO);
ESP_EARLY_LOGI(TEST_TAG, "must indeed be printed");
CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true);
}