diff mbox series

[meta-oe] cjson: Add ptest

Message ID 20231016123725.10725-1-david.pierret@smile.fr
State Under Review
Headers show
Series [meta-oe] cjson: Add ptest | expand

Commit Message

David Pierret Oct. 16, 2023, 12:37 p.m. UTC
cjson use pure CMake test framework named CTest.
CMake generate CTestTestfile.cmake containing fully defined path.
This path need to be altered on install step to match the ptest directory.

The json_patch_tests doesn't works because of file access and is skip.

Signed-off-by: David Pierret <david.pierret@smile.fr>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
---
 .../include/ptest-packagelists-meta-oe.inc    |  1 +
 .../recipes-devtools/cjson/cjson/run-ptest    |  8 +++++++
 .../recipes-devtools/cjson/cjson_1.7.15.bb    | 24 +++++++++++++++++--
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 meta-oe/recipes-devtools/cjson/cjson/run-ptest
diff mbox series

Patch

diff --git a/meta-oe/conf/include/ptest-packagelists-meta-oe.inc b/meta-oe/conf/include/ptest-packagelists-meta-oe.inc
index a2b2ce4bc..212b90c86 100644
--- a/meta-oe/conf/include/ptest-packagelists-meta-oe.inc
+++ b/meta-oe/conf/include/ptest-packagelists-meta-oe.inc
@@ -36,6 +36,7 @@  PTESTS_FAST_META_OE = "\
     uthash \
     xmlsec1 \
     zeromq \
+    cjson \
 "
 PTESTS_FAST_META_OE:append:x86 = " mcelog"
 PTESTS_FAST_META_OE:append:x86-64 = " mcelog"
diff --git a/meta-oe/recipes-devtools/cjson/cjson/run-ptest b/meta-oe/recipes-devtools/cjson/cjson/run-ptest
new file mode 100644
index 000000000..f061e9466
--- /dev/null
+++ b/meta-oe/recipes-devtools/cjson/cjson/run-ptest
@@ -0,0 +1,8 @@ 
+#!/bin/sh
+
+# exclude json_patch_tests
+if ctest -E 'json_patch_tests' ; then
+    echo "PASS: cjson"
+else
+    echo "FAIL: cjson"
+fi
diff --git a/meta-oe/recipes-devtools/cjson/cjson_1.7.15.bb b/meta-oe/recipes-devtools/cjson/cjson_1.7.15.bb
index 8bf7981ab..1841aeffc 100644
--- a/meta-oe/recipes-devtools/cjson/cjson_1.7.15.bb
+++ b/meta-oe/recipes-devtools/cjson/cjson_1.7.15.bb
@@ -4,12 +4,32 @@  SECTION = "libs"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=218947f77e8cb8e2fa02918dc41c50d0"
 
-SRC_URI = "git://github.com/DaveGamble/cJSON.git;branch=master;protocol=https"
+SRC_URI = "git://github.com/DaveGamble/cJSON.git;branch=master;protocol=https \
+           file://run-ptest \
+         "
 SRCREV = "d348621ca93571343a56862df7de4ff3bc9b5667"
 
 S = "${WORKDIR}/git"
 
-inherit cmake pkgconfig
+inherit cmake pkgconfig ptest
+
+RDEPENDS:${PN}-ptest += "cmake"
+
+do_install_ptest() {
+        # create directories
+        install -d ${D}${PTEST_PATH} ${D}${PTEST_PATH}/tests ${D}${PTEST_PATH}/fuzzing
+        install -d ${D}${PTEST_PATH}/tests/inputs ${D}${PTEST_PATH}/tests/json-patch-tests
+        # CTestTestfiles.cmake contain fully defined path generated by cmake.
+        # Change the fully defined path to ptest path on the target
+        sed s#${B}#${PTEST_PATH}# ${B}/CTestTestfile.cmake > ${D}${PTEST_PATH}/CTestTestfile.cmake
+        sed s#${B}#${PTEST_PATH}# ${B}/tests/CTestTestfile.cmake > ${D}${PTEST_PATH}/tests/CTestTestfile.cmake
+        sed s#${B}#${PTEST_PATH}# ${B}/fuzzing/CTestTestfile.cmake > ${D}${PTEST_PATH}/fuzzing/CTestTestfile.cmake
+        # install test artifacts
+        install ${B}/cJSON_test ${D}${PTEST_PATH}
+        install ${B}/tests/cjson_add ${B}/tests/*_tests ${B}/tests/parse_*  ${B}/tests/print_*  ${B}/tests/readme_examples ${D}${PTEST_PATH}/tests/
+        install ${B}/tests/inputs/* ${D}${PTEST_PATH}/tests/inputs
+        install ${B}/fuzzing/fuzz_main ${D}${PTEST_PATH}/fuzzing
+}
 
 EXTRA_OECMAKE += "\
     -DENABLE_CJSON_UTILS=On \