Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Microcontainers for Unit Testing

November 16, 2018
DJ Delorie
Related topics:
LinuxContainers
Related products:
Red Hat Enterprise Linux

Share:

    When you write a program, you have to test it. Run, program, run! Did it do what you expected? Yay! Maybe you'll even set up a testsuite to run it many times, just to be sure. You might even create some sample files for it to work with.

    What do you do when your "program" is your whole system? You can't just change your /etc config files just to test your new program, but that's exactly what you have to do when your "program" is the core C library, glibc. You can't even update the library easily, as the commands you use to update it (cp, mv) themselves rely on the library!

    One option for this is to have a separate machine (real or virtual) set aside for testing. Still, installing a newly built glibc and automating tests on a remote machine is not a trivial task. Currently, most glibc testing is done in the "build directory" - an uninstalled glibc is tested, with options and hacks to force it to use its own support files and configuration. This, however, has some drawbacks. Consider this code flow:

    When testing a non-installed glibc, you can test the "User API" portion of glibc's code, but you can't test the "System API" portion because it's bypassed - you end up only testing the "Test API" code, which is a waste of time as it will never get used by a real application. Ideally, we'd use the "System API" code for testing as well, but how?

    Enter the Microcontainer

    Linux Containers allow you to have a "system" that's just a subdirectory in your filesystem. Normally this subdirectory would be its own block device, with a full OS on it, managed by some high level software like Kubernetes or Docker. In our case, though, we only need "just enough" of a container to test glibc. Conveniently, glibc is at the core of the operating system, and has almost no dependencies. So, we can "install" glibc into an empty directory and consider that directory to be a container. We also only need the smallest amount of "containerizing" code as possible, making this the smallest implementation of a container. Hence, a microcontainer.

    In glibc 2.28 I extended the testsuite's infrastructure to support such a microcontainer via a support program called test-container. The build system pre-installs a copy of glibc into an empty subdirectory, and test-container runs each test within that container. There are a few dummy programs we include that aren't part of glibc, like /bin/sh and /bin/echo, but since the container has its own filesystem the test now looks like this:

    As you can see, the code path is simpler, and is the same path that real applications will use. The test-container program is able to isolate the test by giving it its own PID, UID, and filesystem namespaces. Each test that needs to run in a container may provide a skeleton set of files to install (like /etc/hosts) and/or commands to run (i.e. to chmod /etc/hosts) and the container is cleaned up between tests. Thus, the test may run as root, install "system" files, corrupt the environment, or whatever else it needs to do to test glibc.

    The Benefits

    Besides the obvious "more tests", this new feature also allows tests that would normally be run outside of glibc's testsuite to be migrated into it. A test that might have been run, say, by a QA department just prior to shipping a product with glibc in it, can now be run months if not years earlier by the glibc developers themselves. Tests also become less expensive to run if they previously required manual intervention, or the provisioning of an entire virtual machine. All this means that problems get found quickly, typically by the upstream developer working on that code, when the new code is fresh in their mind. This leads to a better upstream, which benefits all glibc users.

    OSZAR »
    Last updated: September 3, 2019

    Recent Posts

    • How to integrate vLLM inference into your macOS and iOS apps

    • How Insights events enhance system life cycle management

    • Meet the Red Hat Node.js team at PowerUP 2025

    • How to use pipelines for AI/ML automation at the edge

    • What's new in network observability 1.8

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue

    OSZAR »