Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/log_color: add test application
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += log_color | ||
|
||
# Enable debug log level | ||
CFLAGS += -DLOG_LEVEL=4 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2019 Inria | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief Test logging with colors gives the expected output | ||
* | ||
* @author Alexandre Abadie <alexandre.abadie@inria.fr> | ||
* | ||
*/ | ||
|
||
#include <inttypes.h> | ||
|
||
#include "log.h" | ||
|
||
int main(void) | ||
{ | ||
const uint8_t value = 42; | ||
const char *string = "test"; | ||
const char *format = "Logging value '%d' and string '%s'\n"; | ||
|
||
LOG_ERROR(format, value, string); | ||
LOG_WARNING(format, value, string); | ||
LOG_INFO(format, value, string); | ||
LOG_DEBUG(format, value, string); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2019 Alexandre Abadie <alexandre.abadie@inria.fr> | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
|
||
VALUE = 42 | ||
STRING = 'test' | ||
|
||
STRING_FORMAT = '{}{}Logging value \'{}\' and string \'{}\'' | ||
ERROR = '\033[1;31m' | ||
WARNING = '\033[1;33m' | ||
INFO = '\033[1m' | ||
DEBUG = '\033[0;32m' | ||
RESET = '\033[0m' | ||
|
||
LEVELS = [ERROR, WARNING, INFO, DEBUG] | ||
|
||
|
||
def testfunc(child): | ||
for level in LEVELS: | ||
child.expect_exact(STRING_FORMAT.format(RESET, level, VALUE, STRING)) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run(testfunc)) |