Skip to content

Commit dd2c84d

Browse files
committed
feat(log): Add test function
1 parent 7c8e414 commit dd2c84d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

components/log/test/component.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
#Component Makefile
3+
#
4+
5+
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <assert.h>
16+
#include <stdint.h>
17+
#include <stdio.h>
18+
#include <string.h>
19+
#include <sys/param.h>
20+
21+
#include <unity.h>
22+
#include <esp_spi_flash.h>
23+
#include "esp_attr.h"
24+
#include "esp_log.h"
25+
26+
27+
TEST_CASE("Test set tag level", "[log]")
28+
{
29+
esp_log_level_t level;
30+
size_t tag_off;
31+
const char *TAG[] = {"TAG-0", "TAG-1", "TAG-2", "TAG-3"};
32+
const char tag_max = sizeof(TAG) / sizeof(TAG[0]);
33+
34+
esp_log_level_set("*", ESP_LOG_NONE);
35+
36+
for (tag_off = 0; tag_off < tag_max; tag_off++) {
37+
esp_log_level_set(TAG[tag_off], ESP_LOG_MAX);
38+
}
39+
40+
for (level = ESP_LOG_VERBOSE; level > ESP_LOG_NONE; level--) {
41+
for (tag_off = 0; tag_off < tag_max; tag_off++) {
42+
ESP_LOGE(TAG[tag_off], "Test TAG ERROR with level %d", level);
43+
ESP_LOGW(TAG[tag_off], "Test TAG WARN with level %d", level);
44+
ESP_LOGI(TAG[tag_off], "Test TAG INFO with level %d", level);
45+
ESP_LOGD(TAG[tag_off], "Test TAG DEBUG with level %d", level);
46+
ESP_LOGV(TAG[tag_off], "Test TAG VERBOSE with level %d", level);
47+
48+
esp_log_level_set(TAG[tag_off], level - 1);
49+
}
50+
}
51+
52+
printf("\n\n");
53+
54+
esp_log_level_set("*", ESP_LOG_MAX);
55+
level = ESP_LOG_MAX;
56+
57+
for (tag_off = 0; tag_off < tag_max; tag_off++) {
58+
ESP_LOGE(TAG[tag_off], "Test TAG ERROR with global level %d", level);
59+
ESP_LOGW(TAG[tag_off], "Test TAG WARN with global level %d", level);
60+
ESP_LOGI(TAG[tag_off], "Test TAG INFO with global level %d", level);
61+
ESP_LOGD(TAG[tag_off], "Test TAG DEBUG with global level %d", level);
62+
ESP_LOGV(TAG[tag_off], "Test TAG VERBOSE with global level %d", level);
63+
}
64+
}

0 commit comments

Comments
 (0)