1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

tests/progress_bar: add test application

This commit is contained in:
Alexandre Abadie 2019-10-06 15:34:46 +02:00
parent 9f1b84b51d
commit 3f1ac65b95
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,26 @@
include ../Makefile.tests_common
USEMODULE += xtimer
USEMODULE += progress_bar
PROGRESS_BAR_LENGTH ?= 50
PROGRESS_BAR_FULL_CHARACTER ?= "█"
PROGRESS_BAR_EMPTY_CHARACTER ?= " "
# Other nice progress bar characters:
#PROGRESS_BAR_FULL_CHARACTER ?= "◉"
#PROGRESS_BAR_EMPTY_CHARACTER ?= "◯"
#PROGRESS_BAR_FULL_CHARACTER ?= "▣"
#PROGRESS_BAR_EMPTY_CHARACTER ?= "▢"
CFLAGS += -DPROGRESS_BAR_FULL_CHARACTER=\"$(PROGRESS_BAR_FULL_CHARACTER)\"
CFLAGS += -DPROGRESS_BAR_EMPTY_CHARACTER=\"$(PROGRESS_BAR_EMPTY_CHARACTER)\"
CFLAGS += -DPROGRESS_BAR_LENGTH=$(PROGRESS_BAR_LENGTH)
include $(RIOTBASE)/Makefile.include
# Make custom progress bar characters available in Python test script via
# environment variables
export PROGRESS_BAR_FULL_CHARACTER
export PROGRESS_BAR_EMPTY_CHARACTER
export PROGRESS_BAR_LENGTH

73
tests/progress_bar/main.c Normal file
View File

@ -0,0 +1,73 @@
/*
* 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.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief progress_bar test application
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#include <stdio.h>
#include <string.h>
#include "xtimer.h"
#include "progress_bar.h"
#define PROGRESS_BAR_LIST_NUMOF (5U)
/* Test single progress bar */
static progress_bar_t progress_bar;
/* Test multiple progress bars */
static progress_bar_t progress_bar_list[PROGRESS_BAR_LIST_NUMOF];
int main(void)
{
puts("Progress bar test application.");
/* Test a single progress bar */
sprintf(progress_bar.prefix, "%s ", "Progress bar 0");
for (uint8_t i = 0; i < 101; ++i) {
progress_bar.value = i;
sprintf(progress_bar.suffix, " %3d%%", i);
progress_bar_update(&progress_bar);
xtimer_usleep(50 * US_PER_MS);
}
puts("\nDone!");
/* Prepare enough space for the progress bars */
progress_bar_prepare_multi(PROGRESS_BAR_LIST_NUMOF);
for (uint8_t i = 0; i < PROGRESS_BAR_LIST_NUMOF; ++i) {
sprintf(progress_bar_list[i].prefix, "%s %d ", "Progress bar", i + 1);
}
for (uint8_t i = 0; i < 101; ++i) {
for (uint8_t p = PROGRESS_BAR_LIST_NUMOF; p > 0 ; --p) {
(p * i < 101) ? progress_bar_list[PROGRESS_BAR_LIST_NUMOF - p].value = i * p : 100;
}
progress_bar_update_multi(progress_bar_list, PROGRESS_BAR_LIST_NUMOF);
xtimer_usleep(50 * US_PER_MS);
}
puts("Done!");
return 0;
}

View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
# 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.
import os
import sys
from testrunner import run
TIMEOUT = 60
LENGTH = int(os.getenv('PROGRESS_BAR_LENGTH'))
FULL_CHARACTER = os.getenv('PROGRESS_BAR_FULL_CHARACTER')[1:-1]
EMPTY_CHARACTER = os.getenv('PROGRESS_BAR_EMPTY_CHARACTER')[1:-1]
def testfunc(child):
for i in range(0, 100, 10):
ratio = int(i * LENGTH / 100.0)
progress_str = FULL_CHARACTER * ratio
progress_str += EMPTY_CHARACTER * (LENGTH - ratio)
check_str = 'Progress bar 0 |{}| {:3}%'.format(
progress_str, i)
child.expect_exact(check_str)
child.expect_exact("Done!")
for i in range(2, 6): # 5 parallel progress bars
check_str = 'Progress bar {} |{}|'.format(
i, LENGTH * FULL_CHARACTER)
child.expect_exact(check_str, timeout=TIMEOUT)
child.expect_exact('Done!')
if __name__ == "__main__":
sys.exit(run(testfunc))