mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-12 23:09:45 +03:00
libcamera: test: Add a failing test for the log level parser
Log level parsing doesn't always work as expected. Add a failing test for that. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
c19047dfdf
commit
8ea3ef083f
2 changed files with 41 additions and 3 deletions
|
@ -26,6 +26,11 @@ using namespace std;
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
LOG_DEFINE_CATEGORY(LogAPITest)
|
LOG_DEFINE_CATEGORY(LogAPITest)
|
||||||
|
LOG_DEFINE_CATEGORY(Cat0)
|
||||||
|
LOG_DEFINE_CATEGORY(Cat1)
|
||||||
|
LOG_DEFINE_CATEGORY(Cat2)
|
||||||
|
LOG_DEFINE_CATEGORY(Cat3)
|
||||||
|
LOG_DEFINE_CATEGORY(Cat4)
|
||||||
|
|
||||||
class LogAPITest : public Test
|
class LogAPITest : public Test
|
||||||
{
|
{
|
||||||
|
@ -74,6 +79,34 @@ protected:
|
||||||
return TestPass;
|
return TestPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int testEnvLevels()
|
||||||
|
{
|
||||||
|
setenv("LIBCAMERA_LOG_LEVELS",
|
||||||
|
"Cat0:0,Cat0:9999,Cat1:INFO,Cat1:INVALID,Cat2:2,Cat2:-1,"
|
||||||
|
"Cat3:ERROR,Cat3:{[]},Cat4:4,Cat4:rubbish",
|
||||||
|
true);
|
||||||
|
logSetTarget(libcamera::LoggingTargetNone);
|
||||||
|
|
||||||
|
const std::pair<const LogCategory &, libcamera::LogSeverity> expected[] = {
|
||||||
|
{ _LOG_CATEGORY(Cat0)(), libcamera::LogDebug },
|
||||||
|
{ _LOG_CATEGORY(Cat1)(), libcamera::LogInfo },
|
||||||
|
{ _LOG_CATEGORY(Cat2)(), libcamera::LogWarning },
|
||||||
|
{ _LOG_CATEGORY(Cat3)(), libcamera::LogError },
|
||||||
|
{ _LOG_CATEGORY(Cat4)(), libcamera::LogFatal },
|
||||||
|
};
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
for (const auto &[c, s] : expected) {
|
||||||
|
if (c.severity() != s) {
|
||||||
|
ok = false;
|
||||||
|
cerr << "Severity of " << c.name() << " (" << c.severity() << ") "
|
||||||
|
<< "does not equal " << s << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok ? TestPass : TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
int testFile()
|
int testFile()
|
||||||
{
|
{
|
||||||
int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
|
int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
|
||||||
|
@ -135,7 +168,11 @@ protected:
|
||||||
|
|
||||||
int run() override
|
int run() override
|
||||||
{
|
{
|
||||||
int ret = testFile();
|
int ret = testEnvLevels();
|
||||||
|
if (ret != TestPass)
|
||||||
|
return TestFail;
|
||||||
|
|
||||||
|
ret = testFile();
|
||||||
if (ret != TestPass)
|
if (ret != TestPass)
|
||||||
return TestFail;
|
return TestFail;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
log_test = [
|
log_test = [
|
||||||
{'name': 'log_api', 'sources': ['log_api.cpp']},
|
{'name': 'log_api', 'sources': ['log_api.cpp'], 'should_fail': true},
|
||||||
{'name': 'log_process', 'sources': ['log_process.cpp']},
|
{'name': 'log_process', 'sources': ['log_process.cpp']},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -11,5 +11,6 @@ foreach test : log_test
|
||||||
link_with : test_libraries,
|
link_with : test_libraries,
|
||||||
include_directories : test_includes_internal)
|
include_directories : test_includes_internal)
|
||||||
|
|
||||||
test(test['name'], exe, suite : 'log')
|
test(test['name'], exe, suite : 'log',
|
||||||
|
should_fail : test.get('should_fail', false))
|
||||||
endforeach
|
endforeach
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue