From da66b838e4792338bd066d78261d70c80ea029a5 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Wed, 1 Jan 2025 19:27:05 +0100 Subject: [PATCH] support/testing: new gstreamer1 runtime test Signed-off-by: Julien Olivain Signed-off-by: Peter Korsgaard --- DEVELOPERS | 1 + .../testing/tests/package/test_gstreamer1.py | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 support/testing/tests/package/test_gstreamer1.py diff --git a/DEVELOPERS b/DEVELOPERS index 3992a82351..2da5d178b2 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1897,6 +1897,7 @@ F: support/testing/tests/package/test_gnuradio.py F: support/testing/tests/package/test_gnuradio/ F: support/testing/tests/package/test_gpsd.py F: support/testing/tests/package/test_gpsd/ +F: support/testing/tests/package/test_gstreamer1.py F: support/testing/tests/package/test_gzip.py F: support/testing/tests/package/test_highway.py F: support/testing/tests/package/test_hwloc.py diff --git a/support/testing/tests/package/test_gstreamer1.py b/support/testing/tests/package/test_gstreamer1.py new file mode 100644 index 0000000000..aa4b67d1a6 --- /dev/null +++ b/support/testing/tests/package/test_gstreamer1.py @@ -0,0 +1,82 @@ +import os + +import infra.basetest + + +class TestGstreamer1(infra.basetest.BRTest): + # This test creates a full, yet simple, Gstreamer pipeline which + # encodes/decodes a video, using only plugins from Base and Good + # packages. It will use Tesseract OCR to validate the final + # output. The DejaVu font package is also installed, in order to + # have few fonts for the Pango plugin. + config = \ + """ + BR2_arm=y + BR2_cortex_a9=y + BR2_ARM_ENABLE_VFP=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_PACKAGE_DEJAVU=y + BR2_PACKAGE_GSTREAMER1=y + BR2_PACKAGE_GST1_PLUGINS_BASE=y + BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_OGG=y + BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_PANGO=y + BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_THEORA=y + BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEOTESTSRC=y + BR2_PACKAGE_GST1_PLUGINS_GOOD=y + BR2_PACKAGE_GST1_PLUGINS_GOOD_PNG=y + BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIFILE=y + BR2_PACKAGE_TESSERACT_OCR=y + BR2_PACKAGE_TESSERACT_OCR_LANG_ENG=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="armv7", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + video_file = "videotest.ogg" + num_frames = 10 + msg_prefix = "Hello Buildroot:" + + # We check the main program can execute. + self.assertRunOk("gst-launch-1.0 --version") + + # We check we can list installed plugins. + self.assertRunOk("gst-inspect-1.0") + + # We check we can query one of the plugin we requested. + self.assertRunOk("gst-inspect-1.0 theoraenc") + + # We create a Ogg/Theora video file. We use the "videotestsrc" + # with the ball animation which will create a small file. We + # add a time overlay with a message. We encode with the Theora + # codec and store everything in an Ogg container file. + enc_pipeline = \ + f"videotestsrc num-buffers={num_frames} pattern=ball ! " \ + f"timeoverlay text=\"{msg_prefix}\" font-desc=\"Sans, 24\" ! " \ + f"theoraenc ! oggmux ! filesink location={video_file}" + cmd = f"gst-launch-1.0 -v {enc_pipeline}" + self.assertRunOk(cmd) + + # We decode our previous video file and store each frame in a + # PNG image file. + dec_pipeline = \ + f"filesrc location={video_file} ! " \ + "decodebin ! videoconvert ! pngenc ! " \ + "multifilesink index=1 location=frame%02d.png" + cmd = f"gst-launch-1.0 -v {dec_pipeline}" + self.assertRunOk(cmd) + + # We extract the text from our last image. + img_file = f"frame{num_frames}.png" + cmd = f"tesseract {img_file} output" + self.assertRunOk(cmd) + + # We check we have our initial message. + out, ret = self.emulator.run("cat output.txt") + self.assertEqual(ret, 0) + self.assertTrue(out[0].startswith(msg_prefix))