diff --git a/.gitignore b/.gitignore index 3fad1a9..da61105 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/.build* **/bin** -.vscode \ No newline at end of file +.vscode +**/__pycache__ \ No newline at end of file diff --git a/testcases/conftest.py b/testcases/conftest.py new file mode 100755 index 0000000..c3f461a --- /dev/null +++ b/testcases/conftest.py @@ -0,0 +1,82 @@ +import time +from _pytest import terminal +import os +import pytest +import sys +from commons.check import Check +from commons.logger_ext import Logger + + +# 获取当前文件的绝对路径 +current_file_path = os.path.abspath(__file__) + +# 获取当前文件的上上上一级目录路径 +grandparent_directory = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path))).replace('\\', '/') + + + +# 测试结果路径 +test_result_file_path = os.path.join(grandparent_directory, "reports", "test_result", "test_result.txt") + + +def pytest_terminal_summary(terminalreporter, exitstatus, config): + # 收集测试结果 + passed = len([i for i in terminalreporter.stats.get('passed', []) if i.when != 'teardown']) + failed = len([i for i in terminalreporter.stats.get('failed', []) if i.when != 'teardown']) + error = len([i for i in terminalreporter.stats.get('error', []) if i.when != 'teardown']) + skipped = len([i for i in terminalreporter.stats.get('skipped', []) if i.when != 'teardown']) + # total = terminalreporter._numcollected + total = passed + failed + error + skipped + success_rate = passed / (total - skipped) * 100 + failure_rate = failed / (total - skipped) * 100 + error_rate = error / (total - skipped) * 100 + skip_rate = skipped / total * 100 + # terminalreporter._sessionstarttime 会话开始时间 + duration = time.time() - terminalreporter._sessionstarttime + # print('total times: %.2f' % duration, 'seconds') + + failure_case_list = [] + if failed == 0: + failure_case_list = [] + else: + for rep in terminalreporter.stats.get('failed', []): + file_path = rep.nodeid.split("::")[0] + failure_case_list.append(file_path) + + with open(test_result_file_path, "w") as fp: + fp.write("TOTAL=%s" % total + "\n") + fp.write("PASSED=%s" % passed + "\n") + fp.write("FAILED=%s" % failed + "\n") + fp.write("ERROR=%s" % error + "\n") + fp.write("SKIPPED=%s" % skipped + "\n") + fp.write("SUCCESS_RATE=%.2f%%" % success_rate + "\n") + fp.write("FAILURE_RATE=%.2f%%" % failure_rate + "\n") + fp.write("ERROR_RATE=%.2f%%" % error_rate + "\n") + fp.write("SKIP_RATE=%.2f%%" % skip_rate + "\n") + fp.write("TOTAL_TIMES=%.2fs" % duration + "\n") + fp.write("FAILURE_CASE_PATH=%s" % failure_case_list + "\n") + fp.close() + + +@pytest.fixture(scope='function') +def get_logger_check(request): + filename = request.node.name + logger = Logger(name=filename) + check = Check(logger) + request.cls.logger = logger + request.cls.check = check + + +# 添加命令行参数为功能测试 +def pytest_addoption(parser): + parser.addoption("--function", action="store_true") + +@pytest.fixture +def function(pytestconfig): + return pytestconfig.getoption("function") + +@pytest.fixture +def function(pytestconfig): + # 使用 pytestconfig.getoption 方法尝试获取 'function' 参数 + # 如果参数不存在,则返回一个默认值,例如 False + return pytestconfig.getoption("function", default=False) \ No newline at end of file diff --git a/testcases/main.py b/testcases/main.py new file mode 100644 index 0000000..d348c27 --- /dev/null +++ b/testcases/main.py @@ -0,0 +1,24 @@ +import os +import pytest +from commons.operate_log import OperateLog + + +if __name__ == "__main__": + # 获取当前脚本文件所在的目录路径 + current_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))).replace('\\', '/') + reports_path = os.path.join(current_path, 'reports') + allure_path = os.path.join(current_path, 'reports', 'allure') + test_result_path = os.path.join(current_path, 'reports', 'test_result') + if not os.path.exists(reports_path): + os.makedirs(reports_path) + if not os.path.exists(allure_path): + os.makedirs(allure_path) + if not os.path.exists(test_result_path): + os.makedirs(test_result_path) + + #每次执行全部用例之前删除logs下的日志文件 + OperateLog().delete_logs() + # 执行测试用例 + pytest.main(['-q', "--alluredir", allure_path, '--clean-alluredir']) + #合并生成的日志文件 + OperateLog().merge_logs('lib_rgb_test.log') \ No newline at end of file diff --git a/testcases/pytest.ini b/testcases/pytest.ini new file mode 100644 index 0000000..4e0eed2 --- /dev/null +++ b/testcases/pytest.ini @@ -0,0 +1,10 @@ +[pytest] + + +python_files = test_*.py +python_classes = Test* +python_functions = test_* + +addopts = -n 16 --dist=loadscope -p no:warnings + +log_cli = 0 \ No newline at end of file diff --git a/testcases/test_api/app_test_HSV_to_RGB/Makefile b/testcases/test_api/app_test_HSV_to_RGB/Makefile new file mode 100644 index 0000000..0053fc3 --- /dev/null +++ b/testcases/test_api/app_test_HSV_to_RGB/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_api/app_test_HSV_to_RGB/src/main.xc b/testcases/test_api/app_test_HSV_to_RGB/src/main.xc new file mode 100644 index 0000000..e7a1cca --- /dev/null +++ b/testcases/test_api/app_test_HSV_to_RGB/src/main.xc @@ -0,0 +1,22 @@ +/** @brief 测试 HSV_to_RGB,以及饱和处理 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void test_hsv_to_rgb(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: test_hsv_to_rgb(); + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_api/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c b/testcases/test_api/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c new file mode 100644 index 0000000..e0d9349 --- /dev/null +++ b/testcases/test_api/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c @@ -0,0 +1,17 @@ +#include +#include +#include "rgb_effect.h" +void test_hsv_to_rgb() +{ + uint32_t hue, sat, value; // HSV值 + uint32_t color; // RGB值 + + // 测试转换 + hue = 999; + sat = 999; + value = 999; + + color = HSV_to_RGB(&hue, &sat, &value); + + printf("GRB color is: 0x%06lX\n", color); +} \ No newline at end of file diff --git a/testcases/test_api/app_test_HSV_to_RGB/test_app_test_HSV_to_RGB.py b/testcases/test_api/app_test_HSV_to_RGB/test_app_test_HSV_to_RGB.py new file mode 100644 index 0000000..d622662 --- /dev/null +++ b/testcases/test_api/app_test_HSV_to_RGB/test_app_test_HSV_to_RGB.py @@ -0,0 +1,34 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_test_HSV_to_RGB(self, capfd, request): + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xsim {xrun_file_path}' + xmakerun.xsim_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "GRB color is: 0x00C700" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_api/app_test_vol_to_level/Makefile b/testcases/test_api/app_test_vol_to_level/Makefile new file mode 100644 index 0000000..0053fc3 --- /dev/null +++ b/testcases/test_api/app_test_vol_to_level/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_api/app_test_vol_to_level/src/main.xc b/testcases/test_api/app_test_vol_to_level/src/main.xc new file mode 100644 index 0000000..424a75b --- /dev/null +++ b/testcases/test_api/app_test_vol_to_level/src/main.xc @@ -0,0 +1,22 @@ +/** @brief 测试不同的响度值转化为音量等级 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void test_vol_to_level(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: test_vol_to_level(); + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_api/app_test_vol_to_level/src/test_vol_to_level.c b/testcases/test_api/app_test_vol_to_level/src/test_vol_to_level.c new file mode 100644 index 0000000..8adc97c --- /dev/null +++ b/testcases/test_api/app_test_vol_to_level/src/test_vol_to_level.c @@ -0,0 +1,15 @@ +#include +#include +#include "rgb_effect.h" +void test_vol_to_level() +{ + // 测试不同的响度值 + uint32_t test_loudness_values[] = {1, 0, -2, -5, -8, -20, -30, -40, -60, -62, -70, }; + int num_tests = sizeof(test_loudness_values) / sizeof(test_loudness_values[0]); + + for (int i = 0; i < num_tests; ++i) { + printf("Loudness: %lu dB, Volume Level: %u\n", + test_loudness_values[i], + get_volume_level((int)test_loudness_values[i])); + } +} \ No newline at end of file diff --git a/testcases/test_api/app_test_vol_to_level/test_app_test_vol_to_level.py b/testcases/test_api/app_test_vol_to_level/test_app_test_vol_to_level.py new file mode 100644 index 0000000..ded41c9 --- /dev/null +++ b/testcases/test_api/app_test_vol_to_level/test_app_test_vol_to_level.py @@ -0,0 +1,46 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_test_vol_to_level(self, capfd, request): + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xsim {xrun_file_path}' + xmakerun.xsim_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = """Loudness: 1 dB, Volume Level: 6 +Loudness: 0 dB, Volume Level: 6 +Loudness: 4294967294 dB, Volume Level: 5 +Loudness: 4294967291 dB, Volume Level: 4 +Loudness: 4294967288 dB, Volume Level: 4 +Loudness: 4294967276 dB, Volume Level: 2 +Loudness: 4294967266 dB, Volume Level: 2 +Loudness: 4294967256 dB, Volume Level: 1 +Loudness: 4294967236 dB, Volume Level: 1 +Loudness: 4294967234 dB, Volume Level: 1 +Loudness: 4294967226 dB, Volume Level: 0 + """ + + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_cycleHSV_vol_level_example/Makefile b/testcases/test_function/app_cycleHSV_vol_level_example/Makefile new file mode 100644 index 0000000..88b050d --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_example/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../../ +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c b/testcases/test_function/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c new file mode 100644 index 0000000..dea75ac --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c @@ -0,0 +1,38 @@ +#include +#include +#include // 包含基本的输入输出函数 +#include "samples_to_levels.h" +#include "rgb_effect.h" +#include "timer.h" +void cycleHSV_vol_level_example() +{ + uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定 + uint32_t current_hue = 0; // 从红色开始的当前色相值 + // uint32_t current_sat = 100; // 当前饱和度值,初始化为满饱和度 + // uint32_t current_val = 100; // 当前亮度值,初始化为最大亮度 + uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000}; + + srand(1); // 初始化随机数种子 + size_t random_levels[NUM_RGB_GROUPS]; + + while (1) + { + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + *(random_levels + i) = get_volume_level(rand() % 101 - 100); + } + + // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 + fill_gradient_with_groups(buf, current_color, random_levels); + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); + // 更改下一个颜色 + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + *(current_color + i) = cycleHSV(¤t_hue); + } + + // 打印出当前的GRB颜色值 + // printf("GRB color is: 0x%06X\n", current_color); + } +} \ No newline at end of file diff --git a/testcases/test_function/app_cycleHSV_vol_level_example/src/main.xc b/testcases/test_function/app_cycleHSV_vol_level_example/src/main.xc new file mode 100644 index 0000000..9e43de8 --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_example/src/main.xc @@ -0,0 +1,29 @@ +/** @brief 测试音量响应&HSV色彩循环 + * + * 此函数不断地循环通过HSV色彩空间,并根据音量水平来更新RGB条的颜色。 + * 每个颜色组都会根据音量水平的随机值来更新其亮度。当前色相值从红色开始, + * 并在每次循环中更新,以通过HSV色彩空间进行循环。每次循环后,将当前颜色 + * 应用到RGB条的相应组中。此函数旨在并发执行,以模拟实时音乐响应的灯光效果。 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C"{ + void cycleHSV_vol_level_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + cycleHSV_vol_level_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_cycleHSV_vol_level_example/test_app_cycleHSV_vol_level_example.py b/testcases/test_function/app_cycleHSV_vol_level_example/test_app_cycleHSV_vol_level_example.py new file mode 100644 index 0000000..95340f8 --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_example/test_app_cycleHSV_vol_level_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_cycleHSV_vol_level_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_cycleHSV_vol_level_smooth_example/Makefile b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/Makefile new file mode 100644 index 0000000..0053fc3 --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c new file mode 100644 index 0000000..a0fdbe7 --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c @@ -0,0 +1,56 @@ +#include +#include +#include // 包含基本的输入输出函数 +#include "rgb_effect.h" +#include "timer.h" +#define DELAY_DECREASE 40 // 降低亮度时的额外延迟 + +// 该函数用于平滑过渡HSV颜色和音量级别 +void cycleHSV_vol_level_smooth_example() +{ + uint32_t buf[NUM_RGBS]; // 存储RGB值的缓冲区 + uint32_t current_hue = 0; // 当前色调 + uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000}; // 当前颜色数组 + size_t random_levels[NUM_RGB_GROUPS]; // 随机音量级别数组 + size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别 + + srand(1); // 设置随机数种子 + + while (1) // 无限循环 + { + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) // 遍历RGB组 + { + // 获取新的随机音量级别 + random_levels[i] = get_volume_level(rand() % 101 - 100); + // 如果新的级别低于之前的级别,逐渐降低 + while (previous_levels[i] > random_levels[i]) + { + previous_levels[i]--; // 降低当前级别 + // 用当前颜色和级别填充渐变 + fill_gradient_with_groups(buf, current_color, previous_levels); + delay_milliseconds(DELAY_DECREASE); // 延迟 + // 更新每一步的RGB颜色 + for (size_t j = 0; j < NUM_RGB_GROUPS; j++) + { + current_color[j] = cycleHSV(¤t_hue); + } + } + } + + // 用随机颜色和级别填充渐变 + fill_gradient_with_groups(buf, current_color, random_levels); + delay_milliseconds(DELAY_TIME_RGB); // 延迟 + + // 更新当前颜色 + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + current_color[i] = cycleHSV(¤t_hue); + } + + // 更新先前的音量级别 + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + previous_levels[i] = random_levels[i]; + } + } +} diff --git a/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/main.xc b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/main.xc new file mode 100644 index 0000000..155ed3a --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/src/main.xc @@ -0,0 +1,24 @@ +/** @brief 平滑过渡&HSV循环&模拟音量响应 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C"{ + void cycleHSV_vol_level_smooth_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + cycleHSV_vol_level_smooth_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_cycleHSV_vol_level_smooth_example/test_app_cycleHSV_vol_level_smooth_example.py b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/test_app_cycleHSV_vol_level_smooth_example.py new file mode 100644 index 0000000..314a3db --- /dev/null +++ b/testcases/test_function/app_cycleHSV_vol_level_smooth_example/test_app_cycleHSV_vol_level_smooth_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_cycleHSV_vol_level_smooth_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_example/Makefile b/testcases/test_function/app_hsv_cycle_example/Makefile new file mode 100644 index 0000000..93f7215 --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_example/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb lib_xcore_math + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_example/src/hsv_cycle_example.c b/testcases/test_function/app_hsv_cycle_example/src/hsv_cycle_example.c new file mode 100644 index 0000000..a9cb75b --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_example/src/hsv_cycle_example.c @@ -0,0 +1,25 @@ +#include +#include // 包含基本的输入输出函数 +#include "rgb_effect.h" +#include "timer.h" +void hsv_cycle_example() +{ + uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定 + uint32_t current_hue = 0; // 从红色开始的当前色相值 + uint32_t current_sat = 100; // 当前饱和度值,初始化为满饱和度 + uint32_t current_val = 100; // 当前亮度值,初始化为最大亮度 + uint32_t current_color = HSV_to_RGB(¤t_hue, ¤t_sat, ¤t_val); + while (1) + { + // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 + fill_gradient(buf, current_color, NUM_RGBS); + + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); + // 更改下一个颜色 + current_color = cycleHSV(¤t_hue); + + // 打印出当前的GRB颜色值 + // printf("GRB color is: 0x%06X\n", current_color); + } +} \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_example/src/main.xc b/testcases/test_function/app_hsv_cycle_example/src/main.xc new file mode 100644 index 0000000..a5733f8 --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_example/src/main.xc @@ -0,0 +1,33 @@ +/** @brief RGB循环呼吸 + * + * 驱动HSV颜色空间中的颜色循环,以实现连续的颜色渐变效果。 + * + * 此函数初始化颜色值,并进入一个无限循环,不断地计算新的颜色值并更新LED阵列。 + * 使用并发执行关键字 'par' 来实现循环内部的并行处理。这个函数假定运行环境支持并行关键字 'par'。 + * + * 在此循环中,它首先使用当前颜色填充一个预定义大小的缓冲区,然后调用 `cycleHSV` 函数 + * 来更新当前色相值并获取新的颜色。最后,它打印出当前的GRB颜色值。 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void hsv_cycle_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + hsv_cycle_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_hsv_cycle_example/test_app_hsv_cycle_example.py b/testcases/test_function/app_hsv_cycle_example/test_app_hsv_cycle_example.py new file mode 100644 index 0000000..a79f856 --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_example/test_app_hsv_cycle_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_hsv_cycle_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_per_rgb_example/Makefile b/testcases/test_function/app_hsv_cycle_per_rgb_example/Makefile new file mode 100644 index 0000000..1090fb8 --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_per_rgb_example/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope -D_XUA_CONF_H_EXISTS_ + +USED_MODULES = lib_rgb lib_xcore_math + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h new file mode 100644 index 0000000..9cc6aae --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h @@ -0,0 +1,26 @@ +/** + * @file xua_conf.h + * @brief Defines relating to device configuration and customisation. + * For PXUA-XU316-MC-MAX + */ +#ifndef _XUA_CONF_H_ +#define _XUA_CONF_H_ + +/* Defines relating to feature placement regarding tiles */ +#ifndef RGB_TILE +#define RGB_TILE (1) +#endif + +#ifndef DELAY_TIME_RGB +#define DELAY_TIME_RGB (60) +#endif + +#ifndef RGB_MAX +#define RGB_MAX (20) +#endif + +#ifndef HUE_STEP +#define HUE_STEP (10) +#endif + +#endif diff --git a/testcases/test_function/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c new file mode 100644 index 0000000..4647318 --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c @@ -0,0 +1,44 @@ +#include +#include +#include // 包含基本的输入输出函数 +#include "rgb_effect.h" +#include "timer.h" +#include "xmath/xmath.h" +#include + +void init_colors(uint32_t *current_colors, uint32_t *previous_colors, uint32_t current_hue){ + for (size_t i = 0; i < NUM_RGBS; i++) + { + *(current_colors + i) = cycleHSV(¤t_hue); + } + xs3_memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t)); +} + +void hsv_cycle_per_rgb_example() +{ + uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定 + uint32_t current_hue = 0; // 从红色开始的当前色相值 + uint32_t WORD_ALIGNED current_colors[NUM_RGBS]; //用于存储当前颜色值的数组。 + uint32_t WORD_ALIGNED previous_colors[NUM_RGBS];//用于存储上一组颜色值的数组 + size_t levels[NUM_RGB_GROUPS]; //指定每个RGB组亮灯的个数 + init_colors(current_colors, previous_colors, current_hue); //初始化颜色 + while (1) + { + + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + *(levels + i) = (NUM_RGBS / NUM_RGB_GROUPS); + } + // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 + fill_gradient_with_groups_colorful(buf, current_colors, levels); + + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); + // 更改下一组颜色,其中每个灯继承上一个灯的颜色,第一个灯通过cycleHSV计算出新的颜色 + xs3_memcpy(current_colors+1, previous_colors, (NUM_RGBS-1) * sizeof(uint32_t)); + current_colors[0] = cycleHSV(¤t_hue); + + // 保留本轮颜色的记录 + xs3_memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t)); + } +} \ No newline at end of file diff --git a/testcases/test_function/app_hsv_cycle_per_rgb_example/src/main.xc b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/main.xc new file mode 100644 index 0000000..ce6eabb --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_per_rgb_example/src/main.xc @@ -0,0 +1,32 @@ +/** @brief RGB灯条HSV循环渐变 + * + * 此函数使用初始色相值初始化两个颜色数组current_colors和preview_colors。 + * 它通过调用'cycleHSV'函数为每个颜色位置生成一个基于当前色相的颜色值。 + * 然后,它在一个无限循环中,使用'fill_gradient_with_groups_colorful'函数 + * 将颜色渐变填充到一个RGB缓冲区,并通过'output_rgb_array'函数输出。 + * 在每次循环的末尾,颜色数组会更新,为下一次迭代准备新的颜色。 + * + * @author Vergil Wong + * @date 2023-11-26 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void hsv_cycle_per_rgb_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + hsv_cycle_per_rgb_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_hsv_cycle_per_rgb_example/test_app_hsv_cycle_per_rgb_example.py b/testcases/test_function/app_hsv_cycle_per_rgb_example/test_app_hsv_cycle_per_rgb_example.py new file mode 100644 index 0000000..46ccf3d --- /dev/null +++ b/testcases/test_function/app_hsv_cycle_per_rgb_example/test_app_hsv_cycle_per_rgb_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_hsv_cycle_per_rgb_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_rgb_cycle_breathing_example/Makefile b/testcases/test_function/app_rgb_cycle_breathing_example/Makefile new file mode 100644 index 0000000..627da31 --- /dev/null +++ b/testcases/test_function/app_rgb_cycle_breathing_example/Makefile @@ -0,0 +1,23 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_rgb_cycle_breathing_example/src/main.xc b/testcases/test_function/app_rgb_cycle_breathing_example/src/main.xc new file mode 100644 index 0000000..cfef7e3 --- /dev/null +++ b/testcases/test_function/app_rgb_cycle_breathing_example/src/main.xc @@ -0,0 +1,28 @@ +/** @brief 持续更新RGB灯条的颜色 + * 在tile[1]上启动一个永久循环,该循环会持续更新RGB灯条的颜色。 + * 它初始化一个颜色值,然后在一个无限循环中不断地调用fill_gradient和cycleRGB函数, + * 以实现RGB灯条颜色的渐变效果。颜色的变化方向会根据GradientDirection变量进行调整。 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void rgb_cycle_breathing_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + rgb_cycle_breathing_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c b/testcases/test_function/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c new file mode 100644 index 0000000..be1de2c --- /dev/null +++ b/testcases/test_function/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c @@ -0,0 +1,20 @@ +#include +#include // 包含基本的输入输出函数 +#include "rgb_effect.h" +#include "timer.h" +void rgb_cycle_breathing_example() +{ + uint32_t buf[NUM_RGBS]; + uint32_t current_color = 0x000000; // Start from black + GradientDirection direction = INCREMENTING; // 开始时设置为递增亮度 + + while (1) + { + // 用当前渐变颜色填充RGB数组 + fill_gradient(buf, current_color, NUM_RGBS); + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); + // 更改下一个渐变的基色 + current_color = cycleRGB(current_color, &direction); + } +} diff --git a/testcases/test_function/app_rgb_cycle_breathing_example/test_app_rgb_cycle_breathing_example.py b/testcases/test_function/app_rgb_cycle_breathing_example/test_app_rgb_cycle_breathing_example.py new file mode 100644 index 0000000..561c8e3 --- /dev/null +++ b/testcases/test_function/app_rgb_cycle_breathing_example/test_app_rgb_cycle_breathing_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_rgb_cycle_breathing_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_test_config_rgb_port/Makefile b/testcases/test_function/app_test_config_rgb_port/Makefile new file mode 100644 index 0000000..54f8baa --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/Makefile @@ -0,0 +1,25 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = PXUA-316-MC-MAX.xn + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +# _XUA_CONF_H_EXISTS_: 提示编译器,编译部分文件时包含xua_conf.h +BUILD_FLAGS = -O2 -g -report -fxscope -D_XUA_CONF_H_EXISTS_ + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn b/testcases/test_function/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn new file mode 100644 index 0000000..c7a918a --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn @@ -0,0 +1,106 @@ + + + Board + PXUA-316-MC-MAX + + tileref tile[2] + tileref usb_tile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testcases/test_function/app_test_config_rgb_port/src/core/xua_conf.h b/testcases/test_function/app_test_config_rgb_port/src/core/xua_conf.h new file mode 100644 index 0000000..dd936e1 --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/src/core/xua_conf.h @@ -0,0 +1,14 @@ +/** + * @file xua_conf.h + * @brief Defines relating to device configuration and customisation. + * For PXUA-XU316-MC-MAX + */ +#ifndef _XUA_CONF_H_ +#define _XUA_CONF_H_ + +/* Defines relating to feature placement regarding tiles */ +#ifndef RGB_TILE +#define RGB_TILE (1) +#endif + +#endif diff --git a/testcases/test_function/app_test_config_rgb_port/src/main.xc b/testcases/test_function/app_test_config_rgb_port/src/main.xc new file mode 100644 index 0000000..b4cc7e5 --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/src/main.xc @@ -0,0 +1,26 @@ +/** @brief 测试output_rgb_array + * + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void test_output_rgb_array_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + test_output_rgb_array_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_test_config_rgb_port/src/test_config_rgb_port.c b/testcases/test_function/app_test_config_rgb_port/src/test_config_rgb_port.c new file mode 100644 index 0000000..e9f8c64 --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/src/test_config_rgb_port.c @@ -0,0 +1,16 @@ +#include +#include +#include "rgb_effect.h" +void test_output_rgb_array_example() +{ + uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定 + uint32_t num_rgbs = 12; + + // Initialize the buffer with example RGB values + for (uint32_t i = 0; i < num_rgbs; ++i) { + buf[i] = (i << 16) | (i << 8) | i; // Just an example pattern for RGB values + } + + // Call the function with the test buffer and number of RGBs + output_rgb_array(buf, num_rgbs); +} \ No newline at end of file diff --git a/testcases/test_function/app_test_config_rgb_port/test_app_test_config_rgb_port.py b/testcases/test_function/app_test_config_rgb_port/test_app_test_config_rgb_port.py new file mode 100644 index 0000000..b7539fa --- /dev/null +++ b/testcases/test_function/app_test_config_rgb_port/test_app_test_config_rgb_port.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_test_config_rgb_port(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_test_fill_gradient_with_groups/Makefile b/testcases/test_function/app_test_fill_gradient_with_groups/Makefile new file mode 100644 index 0000000..0053fc3 --- /dev/null +++ b/testcases/test_function/app_test_fill_gradient_with_groups/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_test_fill_gradient_with_groups/src/main.xc b/testcases/test_function/app_test_fill_gradient_with_groups/src/main.xc new file mode 100644 index 0000000..7312d9a --- /dev/null +++ b/testcases/test_function/app_test_fill_gradient_with_groups/src/main.xc @@ -0,0 +1,26 @@ +/** @brief 测试 fill_gradient_with_groups 函数 + * 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用 + * fill_gradient_with_groups 函数来填充缓冲区,并渲染RGB。 + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C" +{ + void test_fill_gradient_with_groups(); +} +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + test_fill_gradient_with_groups(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c b/testcases/test_function/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c new file mode 100644 index 0000000..506ec16 --- /dev/null +++ b/testcases/test_function/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c @@ -0,0 +1,14 @@ +#include +#include // 包含基本的输入输出函数 +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +#include "rgb_effect.h" +#include "timer.h" +void test_fill_gradient_with_groups() +{ + uint32_t buffer[NUM_RGBS]; + uint32_t colors[] = {0x110000, 0x001100, 0x000011}; // 红,绿,蓝 + size_t num_filled_rgb[] = {4, 4, 4}; // 每组填充数量 + + fill_gradient_with_groups(buffer, colors, num_filled_rgb); +} \ No newline at end of file diff --git a/testcases/test_function/app_test_fill_gradient_with_groups/test_app_test_fill_gradient_with_groups.py b/testcases/test_function/app_test_fill_gradient_with_groups/test_app_test_fill_gradient_with_groups.py new file mode 100644 index 0000000..263fbc7 --- /dev/null +++ b/testcases/test_function/app_test_fill_gradient_with_groups/test_app_test_fill_gradient_with_groups.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_test_fill_gradient_with_groups(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file diff --git a/testcases/test_function/app_vol_level_smooth_example/Makefile b/testcases/test_function/app_vol_level_smooth_example/Makefile new file mode 100644 index 0000000..0053fc3 --- /dev/null +++ b/testcases/test_function/app_vol_level_smooth_example/Makefile @@ -0,0 +1,24 @@ +# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。 + +TARGET = XCORE-AI-EXPLORER + +# 编译选项 +# 构建应用程序时传递给 xcc 的参数 +# O2: xcc编译器优化等级2 +# report: 打开编译报告 +# g: 生成调试信息 +# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink) +BUILD_FLAGS = -O2 -g -report -fxscope + +USED_MODULES = lib_rgb + +XCC_FLAGS = $(BUILD_FLAGS) + +XMOS_MODULE_PATH = ../../../.. +XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1 + +#============================================================================= +# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。 + +XMOS_MAKE_PATH ?= ../.. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/testcases/test_function/app_vol_level_smooth_example/src/main.xc b/testcases/test_function/app_vol_level_smooth_example/src/main.xc new file mode 100644 index 0000000..07e63b7 --- /dev/null +++ b/testcases/test_function/app_vol_level_smooth_example/src/main.xc @@ -0,0 +1,28 @@ +/** @brief 音量响应&平滑过渡 + * + * 每个颜色组都会根据音量水平的随机值来更新其亮度。每次循环后,将当前颜色 + * 应用到RGB条的相应组中。此函数旨在模拟实时音乐响应的灯光效果,并实现平滑过渡下降 + * 与app_cy + * @author Vergil Wong + * @date 2023-11-25 + * @param + * @return + */ + +#include // 包含对封装的定义,引用以使用 on tile[] 语法 + +extern "C"{ + void vol_level_smooth_example(); +} + +int main() // 定义主函数 +{ + par + { + on tile[1]: + { + vol_level_smooth_example(); + } + } + return 0; // 返回0,表示程序正常结束 +} diff --git a/testcases/test_function/app_vol_level_smooth_example/src/vol_level_smooth_example.c b/testcases/test_function/app_vol_level_smooth_example/src/vol_level_smooth_example.c new file mode 100644 index 0000000..5448a51 --- /dev/null +++ b/testcases/test_function/app_vol_level_smooth_example/src/vol_level_smooth_example.c @@ -0,0 +1,42 @@ +#include +#include +#include // 包含基本的输入输出函数 +#include "rgb_effect.h" +#include "timer.h" + +#define DELAY_DECREASE 40 // 降低亮度时的额外延迟 +void vol_level_smooth_example() +{ + uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定 + uint32_t current_color[NUM_RGB_GROUPS] = {0xFF0000, 0xFF0000}; + + srand(1); // 初始化随机数种子 + size_t random_levels[NUM_RGB_GROUPS]; + size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别 + while (1) + { + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + *(random_levels + i) = get_volume_level(rand() % 101 - 100); + // 如果新的级别低于之前的级别,逐渐降低 + while (previous_levels[i] > random_levels[i]) + { + previous_levels[i]--; // 降低当前级别 + // 用当前颜色和级别填充渐变 + fill_gradient_with_groups(buf, current_color, previous_levels); + delay_milliseconds(DELAY_DECREASE); // 延迟 + } + } + + // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 + fill_gradient_with_groups(buf, current_color, random_levels); + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); + + // 更新先前的音量级别 + for (size_t i = 0; i < NUM_RGB_GROUPS; i++) + { + previous_levels[i] = random_levels[i]; + } + } +} \ No newline at end of file diff --git a/testcases/test_function/app_vol_level_smooth_example/test_app_vol_level_smooth_example.py b/testcases/test_function/app_vol_level_smooth_example/test_app_vol_level_smooth_example.py new file mode 100644 index 0000000..7adb659 --- /dev/null +++ b/testcases/test_function/app_vol_level_smooth_example/test_app_vol_level_smooth_example.py @@ -0,0 +1,37 @@ +from pathlib import Path +import pytest +import os +from commons.pyxrun import XMakeRun + + +@pytest.mark.usefixtures("get_logger_check") +class TestClass: + def test_app_vol_level_smooth_example(self, capfd, request, function): + if not function: + self.logger.info("Skipping test because it's functional testing.") + pytest.skip("Skipping test because it's functional testing.") + + file_path = Path(request.fspath).parent + xmakerun = XMakeRun(self.logger, file_path) + # xmake的命令 + xmake_cmd = 'xmake -j' + # 执行xmake命令 + xmakerun.xmake_cmd(xmake_cmd) + + # app_cycleHSV_vol_level_example + xe_basename = os.path.basename(file_path) + + # app_cycleHSV_vol_level_example.xe + xe_name = "{}.xe".format(xe_basename) + + # bin/app_cycleHSV_vol_level_example.xe + xrun_file_path = "bin/{}".format(xe_name) + + xrun_cmd = f'xrun {xrun_file_path}' + xmakerun.xrun_cmd(xrun_cmd) + + out, _ = capfd.readouterr() + + expect = "xrun successful!" + self.check.check_equal(out, expect) + \ No newline at end of file