Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: new bc runtime test
@ 2024-01-16 18:20 Julien Olivain
  2024-01-21 10:22 ` Yann E. MORIN
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2024-01-16 18:20 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Tested on branch master at commit e07402a with commands:

    make check-package
    ...
    0 warnings generated

    support/testing/run-tests \
        -d dl -o output_folder \
        tests.package.test_bc
    ...
    OK
---
 DEVELOPERS                               |  1 +
 support/testing/tests/package/test_bc.py | 62 ++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 support/testing/tests/package/test_bc.py

diff --git a/DEVELOPERS b/DEVELOPERS
index f5b04937b6..b30923f3ba 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1759,6 +1759,7 @@ F:	support/testing/tests/package/sample_python_pyalsa.py
 F:	support/testing/tests/package/sample_python_spake2.py
 F:	support/testing/tests/package/test_acpica.py
 F:	support/testing/tests/package/test_acpica/
+F:	support/testing/tests/package/test_bc.py
 F:	support/testing/tests/package/test_brotli.py
 F:	support/testing/tests/package/test_bzip2.py
 F:	support/testing/tests/package/test_compressor_base.py
diff --git a/support/testing/tests/package/test_bc.py b/support/testing/tests/package/test_bc.py
new file mode 100644
index 0000000000..c31e871339
--- /dev/null
+++ b/support/testing/tests/package/test_bc.py
@@ -0,0 +1,62 @@
+import math
+import os
+
+import infra.basetest
+
+
+class TestBc(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_BC=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()
+
+        # Check the program executes.
+        self.assertRunOk("bc --version")
+
+        # We check a square root function of a number slightly larger
+        # than 32 bits.
+        value = 123456
+        squared_value = value ** 2
+        bc_expr = f"sqrt({squared_value})"
+        cmd = f"echo '{bc_expr}' | bc"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(int(output[0]), value)
+
+        # Perform an integer exponentiation producing a large number.
+        base = 3
+        exponent = 4567
+        expected_value = base ** exponent
+        bc_expr = f"{base} ^ {exponent}"
+        cmd = f"echo '{bc_expr}' | BC_LINE_LENGTH=0 bc"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(int(output[0]), expected_value)
+
+        # Test a basic output base conversion of a large number.
+        hex_str = "DEADBEEF0000ABADC0DE0000CAFEBABE"
+        hex_base = 16
+        value = int(hex_str, base=hex_base)
+        bc_expr = f"obase={hex_base} ; {value}"
+        cmd = f"echo '{bc_expr}' | bc"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], hex_str)
+
+        # Test a floating point computation by estimating Pi. Since we
+        # use the bc arc-tangent a() function, we need the '-l'
+        # option.
+        bc_expr = "4 * a(1)"
+        cmd = f"echo '{bc_expr}' | bc -l"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        self.assertAlmostEqual(float(output[0]), math.pi, places=16)
-- 
2.43.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Buildroot] [PATCH 1/1] support/testing: new bc runtime test
  2024-01-16 18:20 [Buildroot] [PATCH 1/1] support/testing: new bc runtime test Julien Olivain
@ 2024-01-21 10:22 ` Yann E. MORIN
  0 siblings, 0 replies; 2+ messages in thread
From: Yann E. MORIN @ 2024-01-21 10:22 UTC (permalink / raw)
  To: Julien Olivain; +Cc: buildroot

Julien, All,

On 2024-01-16 19:20 +0100, Julien Olivain spake thusly:
> Signed-off-by: Julien Olivain <ju.o@free.fr>
> ---
[--SNIP--]
> +        # Test a basic output base conversion of a large number.
> +        hex_str = "DEADBEEF0000ABADC0DE0000CAFEBABE"
                                              ^^^^^^^^
I've changed that to 8BADF00D.

Applied to master, thanks.

Regards,
Yann E. MORIN.

> +        hex_base = 16
> +        value = int(hex_str, base=hex_base)
> +        bc_expr = f"obase={hex_base} ; {value}"
> +        cmd = f"echo '{bc_expr}' | bc"
> +        output, exit_code = self.emulator.run(cmd)
> +        self.assertEqual(exit_code, 0)
> +        self.assertEqual(output[0], hex_str)
> +
> +        # Test a floating point computation by estimating Pi. Since we
> +        # use the bc arc-tangent a() function, we need the '-l'
> +        # option.
> +        bc_expr = "4 * a(1)"
> +        cmd = f"echo '{bc_expr}' | bc -l"
> +        output, exit_code = self.emulator.run(cmd)
> +        self.assertEqual(exit_code, 0)
> +        self.assertAlmostEqual(float(output[0]), math.pi, places=16)
> -- 
> 2.43.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-21 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16 18:20 [Buildroot] [PATCH 1/1] support/testing: new bc runtime test Julien Olivain
2024-01-21 10:22 ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox