Skip to content

Commit

Permalink
tests/log_color: add test application
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Sep 9, 2019
1 parent 9ea3b2e commit f6ba779
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/log_color/Makefile
@@ -0,0 +1,8 @@
include ../Makefile.tests_common

USEMODULE += log_color

# Enable debug log level
CFLAGS += -DLOG_LEVEL=4

include $(RIOTBASE)/Makefile.include
33 changes: 33 additions & 0 deletions tests/log_color/main.c
@@ -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;
}
32 changes: 32 additions & 0 deletions tests/log_color/tests/01-run.py
@@ -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))

0 comments on commit f6ba779

Please sign in to comment.