@@ -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
new file mode 100644
@@ -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)
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