diff mbox series

[meta-oe,V2] bc: add ptest

Message ID 1666686311-4123-1-git-send-email-yanxk.fnst@fujitsu.com
State New
Headers show
Series [meta-oe,V2] bc: add ptest | expand

Commit Message

yanxk.fnst@fujitsu.com Oct. 25, 2022, 8:25 a.m. UTC
From: Yan Xinkuan <yanxk.fnst@fujitsu.com>

add ptest for bc, modified the original 'timetest' script, only
using bc in the system to run package test.

Signed-off-by: Yan Xinkuan <yanxk.fnst@fujitsu.com>
---
 .../distro/include/ptest-packagelists.inc     |  1 +
 ...0001-ptest-only-use-bc-in-the-system.patch | 34 +++++++++++++++++++
 meta/recipes-extended/bc/bc/run-ptest         |  8 +++++
 meta/recipes-extended/bc/bc_1.07.1.bb         | 23 +++++++++++--
 4 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-extended/bc/bc/0001-ptest-only-use-bc-in-the-system.patch
 create mode 100644 meta/recipes-extended/bc/bc/run-ptest

Comments

Ross Burton Oct. 28, 2022, 12:23 p.m. UTC | #1
On 25 Oct 2022, at 09:25, Yan Xin Kuan via lists.openembedded.org <yanxk.fnst=fujitsu.com@lists.openembedded.org> wrote:
> @@ -100,6 +100,7 @@ PTESTS_SLOW = "\
>     tcl-ptest \
>     util-linux-ptest \
>     valgrind-ptest \
> +    bc-ptest \
> "

Is this really a slow test?

> +++ b/meta/recipes-extended/bc/bc/0001-ptest-only-use-bc-in-the-system.patch
> @@ -0,0 +1,34 @@
> +From a7a19baf07cde3eaf8f0c007fea47f2c45475874 Mon Sep 17 00:00:00 2001
> +From: Yan Xinkuan <yanxk.fnst@fujitsu.com>
> +Date: Mon, 24 Oct 2022 16:08:37 +0800
> +Subject: [PATCH] ptest: only use bc in the system
> +
> +use bc in the system to do ptest.
> +
> +Upstream-Status: Pending

This is very Inappropriate, as we don’t want to send it upstream.

> diff --git a/meta/recipes-extended/bc/bc/run-ptest b/meta/recipes-extended/bc/bc/run-ptest
> new file mode 100644
> index 0000000000..7e37e9ef01
> --- /dev/null
> +++ b/meta/recipes-extended/bc/bc/run-ptest
> @@ -0,0 +1,8 @@
> +#!/bin/bash
> +cd ./bc_test
> +if ./timetest; then
> +	echo "PASS: bc/timetest"
> +else
> +	echo "FAIL: bc/timetest"
> +fi

This won’t do what you think.  timetest.sh just runs bc, doesn’t look at $?, and doesn’t use set -e. This means it will *always* return 0.  Even if bc crashed on startup, this test case would “pass”.

timetest.sh is a tool that runs ‘bc -l’ on some bc scripts, with the bulk of the logic around timing those operations (we don’t care about that) and running against multiple bc implementations (we also don’t care about that).  This tells me that timetest.sh is redundant and we can ignore it.  

My suggestion is to install the Test/*.b files into PTEST_PATH directly, and then a run-ptest can do something like:

#! /bin/sh

for TEST in *.b; do
	if bc -l $TEST </dev/null; then
		echo “PASS: bc/$TEST”
        else
		echo “FAIL: bc/$TEST”
        fi
done

(you need to connect /dev/null to stdin otherwise bc will wait for interactive input)

Note that some of the tests actually announce that they’re failing, but don’t exit with an error code.

> PACKAGECONFIG ??= "readline"
> PACKAGECONFIG[readline] = "--with-readline,--without-readline,readline"
> @@ -29,6 +31,23 @@ do_compile:prepend() {
>     cp -f ${WORKDIR}/libmath.h ${B}/bc/libmath.h
> }
> 
> +RDEPENDS:${PN}-ptest += "bash"

Don’t use bash unless you need to.  There’s no need to use bash here.

> +do_install_ptest() {
> +        install -d ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/atan.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/div.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/exp.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/fact.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/jn.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/ln.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/mul.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/raise.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/sine.b ${D}${PTEST_PATH}/bc_test/
> +        install ${S}/Test/sqrt.b ${D}${PTEST_PATH}/bc_test/

Use a glob instead of installing them one-by-one.

Ross
diff mbox series

Patch

diff --git a/meta/conf/distro/include/ptest-packagelists.inc b/meta/conf/distro/include/ptest-packagelists.inc
index 56088e4e66..5cbed54cc5 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -100,6 +100,7 @@  PTESTS_SLOW = "\
     tcl-ptest \
     util-linux-ptest \
     valgrind-ptest \
+    bc-ptest \
 "
 
 PTESTS_SLOW:remove:riscv64 = "valgrind-ptest"
diff --git a/meta/recipes-extended/bc/bc/0001-ptest-only-use-bc-in-the-system.patch b/meta/recipes-extended/bc/bc/0001-ptest-only-use-bc-in-the-system.patch
new file mode 100644
index 0000000000..191db358e3
--- /dev/null
+++ b/meta/recipes-extended/bc/bc/0001-ptest-only-use-bc-in-the-system.patch
@@ -0,0 +1,34 @@ 
+From a7a19baf07cde3eaf8f0c007fea47f2c45475874 Mon Sep 17 00:00:00 2001
+From: Yan Xinkuan <yanxk.fnst@fujitsu.com>
+Date: Mon, 24 Oct 2022 16:08:37 +0800
+Subject: [PATCH] ptest: only use bc in the system
+
+use bc in the system to do ptest.
+
+Upstream-Status: Pending
+
+Signed-off-by: Yan Xinkuan <yanxk.fnst@fujitsu.com>
+---
+ timetest | 3 ---
+ 1 file changed, 3 deletions(-)
+
+diff --git a/Test/timetest b/Test/timetest
+index 36d8d8e..313250a 100755
+--- a/Test/timetest
++++ b/Test/timetest
+@@ -3,12 +3,9 @@
+ # Time the functions.
+ #
+ SYSBC=/usr/bin/bc
+-if [ x$BC = x ] ; then
+-  BC=../bc/bc
+-fi
+ for file in exp.b ln.b sine.b atan.b jn.b mul.b div.b raise.b sqrt.b fact.b
+ do
+ for prog in $SYSBC $BC $OTHERBC
+ do
+ echo Timing $file with $prog
+ time $prog -l $file
+--
+2.25.1
+
diff --git a/meta/recipes-extended/bc/bc/run-ptest b/meta/recipes-extended/bc/bc/run-ptest
new file mode 100644
index 0000000000..7e37e9ef01
--- /dev/null
+++ b/meta/recipes-extended/bc/bc/run-ptest
@@ -0,0 +1,8 @@ 
+#!/bin/bash
+cd ./bc_test
+if ./timetest; then
+	echo "PASS: bc/timetest"
+else
+	echo "FAIL: bc/timetest"
+fi
+
diff --git a/meta/recipes-extended/bc/bc_1.07.1.bb b/meta/recipes-extended/bc/bc_1.07.1.bb
index 1bec76bb2a..d931690d7d 100644
--- a/meta/recipes-extended/bc/bc_1.07.1.bb
+++ b/meta/recipes-extended/bc/bc_1.07.1.bb
@@ -15,11 +15,13 @@  DEPENDS = "flex-native"
 SRC_URI = "${GNU_MIRROR}/${BPN}/${BP}.tar.gz \
            file://no-gen-libmath.patch \
            file://libmath.h \
-           file://0001-dc-fix-exit-code-of-q-command.patch"
+           file://0001-dc-fix-exit-code-of-q-command.patch \
+           file://0001-ptest-only-use-bc-in-the-system.patch \
+           file://run-ptest"
 SRC_URI[md5sum] = "cda93857418655ea43590736fc3ca9fc"
 SRC_URI[sha256sum] = "62adfca89b0a1c0164c2cdca59ca210c1d44c3ffc46daf9931cf4942664cb02a"
 
-inherit autotools texinfo update-alternatives
+inherit autotools texinfo update-alternatives ptest
 
 PACKAGECONFIG ??= "readline"
 PACKAGECONFIG[readline] = "--with-readline,--without-readline,readline"
@@ -29,6 +31,23 @@  do_compile:prepend() {
     cp -f ${WORKDIR}/libmath.h ${B}/bc/libmath.h
 }
 
+RDEPENDS:${PN}-ptest += "bash"
+
+do_install_ptest() {
+        install -d ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/atan.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/div.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/exp.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/fact.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/jn.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/ln.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/mul.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/raise.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/sine.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/sqrt.b ${D}${PTEST_PATH}/bc_test/
+        install ${S}/Test/timetest ${D}${PTEST_PATH}/bc_test/
+}
+
 ALTERNATIVE:${PN} = "bc dc"
 ALTERNATIVE_PRIORITY = "100"