support/testing: sqlitecpp: new runtime test

build and run an SQLiteCpp example to check database writes and queries.

Assisted-by: GitHub Copilot:GPT-6 Sol
Signed-off-by: Michael Nosthoff <buildroot@heine.tech>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(cherry picked from commit 93c6c91955)
Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
This commit is contained in:
Michael Nosthoff
2026-10-02 09:56:30 +02:00
committed by Raphaël Mélotte
parent 95f448c511
commit 9d96d396ec
8 changed files with 81 additions and 0 deletions

View File

@@ -2459,6 +2459,8 @@ F: package/protobuf/
F: package/sdbus-cpp/
F: package/spdlog/
F: package/sqlitecpp/
F: support/testing/tests/package/br2-external/sqlitecpp/
F: support/testing/tests/package/test_sqlitecpp.py
N: Michael Trimarchi <michael@amarulasolutions.com>
F: board/bsh/

View File

@@ -0,0 +1 @@
source "$BR2_EXTERNAL_SQLITECPP_PATH/package/sqlitecpp-test/Config.in"

View File

@@ -0,0 +1 @@
name: SQLITECPP

View File

@@ -0,0 +1 @@
include $(sort $(wildcard $(BR2_EXTERNAL_SQLITECPP_PATH)/package/*/*.mk))

View File

@@ -0,0 +1,5 @@
config BR2_PACKAGE_SQLITECPP_TEST
bool "sqlitecpp-test"
depends on BR2_PACKAGE_SQLITECPP
help
Test program for the SQLiteCpp library.

View File

@@ -0,0 +1,27 @@
#include <SQLiteCpp/SQLiteCpp.h>
#include <iostream>
#include <string>
int main()
{
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
db.exec("CREATE TABLE fruits (name TEXT, color TEXT)");
SQLite::Statement insert(db, "INSERT INTO fruits VALUES (?, ?)");
insert.bind(1, "Banana");
insert.bind(2, "Yellow");
insert.exec();
SQLite::Statement query(db, "SELECT name, color FROM fruits");
if (!query.executeStep()) {
return 1;
}
const std::string name = query.getColumn(0).getString();
const std::string color = query.getColumn(1).getString();
if (name != "Banana" || color != "Yellow" || query.executeStep()) {
return 1;
}
std::cout << name << ": " << color << std::endl;
return 0;
}

View File

@@ -0,0 +1,19 @@
################################################################################
#
# sqlitecpp-test
#
################################################################################
SQLITECPP_TEST_DEPENDENCIES = sqlitecpp
define SQLITECPP_TEST_BUILD_CMDS
$(TARGET_CXX) $(TARGET_CXXFLAGS) -o $(@D)/sqlitecpp-test \
$(SQLITECPP_TEST_PKGDIR)/sqlitecpp-test.cpp \
$(TARGET_LDFLAGS) -lSQLiteCpp -lsqlite3
endef
define SQLITECPP_TEST_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/sqlitecpp-test $(TARGET_DIR)/usr/bin/sqlitecpp-test
endef
$(eval $(generic-package))

View File

@@ -0,0 +1,25 @@
import os
import infra.basetest
class TestSQLiteCpp(infra.basetest.BRTest):
br2_external = [infra.filepath("tests/package/br2-external/sqlitecpp")]
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_PACKAGE_SQLITECPP=y
BR2_PACKAGE_SQLITECPP_TEST=y
BR2_TARGET_ROOTFS_CPIO=y
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
self.emulator.boot(arch="armv5",
kernel="builtin",
options=["-initrd", cpio_file])
self.emulator.login()
output, exit_code = self.emulator.run("/usr/bin/sqlitecpp-test")
self.assertEqual(exit_code, 0, output)
self.assertIn("Banana: Yellow", output)