forked from PAWPAW/lib_rgb
整合测试框架
- 整合了原有的功能用例与接口测试
This commit is contained in:
24
testcases/test_api/app_test_HSV_to_RGB/Makefile
Normal file
24
testcases/test_api/app_test_HSV_to_RGB/Makefile
Normal file
@@ -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
|
||||
22
testcases/test_api/app_test_HSV_to_RGB/src/main.xc
Normal file
22
testcases/test_api/app_test_HSV_to_RGB/src/main.xc
Normal file
@@ -0,0 +1,22 @@
|
||||
/** @brief 测试 HSV_to_RGB,以及饱和处理
|
||||
* @author Vergil Wong
|
||||
* @date 2023-11-25
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void test_hsv_to_rgb();
|
||||
}
|
||||
|
||||
int main() // 定义主函数
|
||||
{
|
||||
par
|
||||
{
|
||||
on tile[1]: test_hsv_to_rgb();
|
||||
}
|
||||
return 0; // 返回0,表示程序正常结束
|
||||
}
|
||||
17
testcases/test_api/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
Normal file
17
testcases/test_api/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
24
testcases/test_api/app_test_vol_to_level/Makefile
Normal file
24
testcases/test_api/app_test_vol_to_level/Makefile
Normal file
@@ -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
|
||||
22
testcases/test_api/app_test_vol_to_level/src/main.xc
Normal file
22
testcases/test_api/app_test_vol_to_level/src/main.xc
Normal file
@@ -0,0 +1,22 @@
|
||||
/** @brief 测试不同的响度值转化为音量等级
|
||||
* @author Vergil Wong
|
||||
* @date 2023-11-25
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void test_vol_to_level();
|
||||
}
|
||||
|
||||
int main() // 定义主函数
|
||||
{
|
||||
par
|
||||
{
|
||||
on tile[1]: test_vol_to_level();
|
||||
}
|
||||
return 0; // 返回0,表示程序正常结束
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#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]));
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user