Running LTP on musl based systems

Introduction

LTP is freely available testsuite used for validating the reliability and stability of Linux systems. It has functionality, stress as well as regression tests. Thus far it has been mainly run on Linux systems running glibc for C library, and its natural that there will be areas in the project which would have assumptions on glibc coded in. We have ported LTP to run on MUSL based systems. The patches are still being upstreamed. A recent series is ported to LTP mailing list

http://lists.linux.it/pipermail/ltp/2016-July/002259.html

Patches

LTP patches are currently residing on a branch ‘oe/master’ on git://github.com/kraj/ltp repository, There still are few more patches in addition to above patchset ported to mailing list.

Building and Running LTP

Prerequisites

LTP depends on ftw library and we need to install external ftw on musl based systems

On OpenEmbedded based systems just add “libfts-dev” to IMAGE_INSTALL

Building

git clone git://github.com/kraj/ltp -b oe/master
cd ltp
make autotools
./configure --without-numa --without-tirpc --with-power-management-testsuite --with-realtime-testsuite

make LIBC=musl -j8 all
make LIBC=musl install
rm /opt/ltp/testcases/bin/getdents01

getdents01 runs into infinite loop and fills the disk. This would install the ltp test suite under /opt/ltp

Running

hst=`hostname`
/opt/ltp/runltp -p -l "${hst}-$(date +%FT%T).log" -o "${hst}-$(date +%FT%T).out"

Conclusion

We can build and execute the testsuite on raspberryPI3, however the results dont look good. Many tests fail. Here are results of a run on raspberrypi3 running OpenEmbedded/Yocto

https://uclibc.org/~kraj/LTP_RUN_ON-2016_07_22-04h_19m_30s.log

 

 

 

Multilib GCC on ArchLinux

Some packages like LuaJIT uses native compiler to generate source files which are then used during cross compiling it for another architecture. Now if the target architecture has 32bit word length ( which most of them in embedded space are ) then it expects a matching bitness in compiler on build host. So we need to to use HOST_CC = “gcc -m32” on 64-bit ArchLinux build hosts. This requires multilib to be enabled on ArchLinux

 sudo vim /etc/pacman.conf

add or uncomment

[multilib]
Include = /etc/pacman.d/mirrorlist

Now update and install multilib gcc

sudo pacman -Syu gcc-multilib gcc-libs-multilib

To check the install is done correctly create hello.c with following content

 

#include <stdio.h>
int main() {
  printf("Voila!!\n");
  return 0;
}
$ gcc -m32 ~/hello.c

$ ./a.out

should say

“Voila!!”

Clang based Cross SDK with OpenEmbedded Framework

Introduction

Clang based toolchain can be used to compile large portions of packages in OpenEmbedded Framework, in this article we will cover the generating and using OpenEmbedded SDKs based on Clang, This SDK will also have the original cross gcc based compilers cohabiting with clang

Generating SDK

Building image base SDK in OpenEmbedded Framework is a simple process like its building any other image or component. One can generate a SDK corresponding to final image that will be shipped on target. This gets development headers and libraries from all the dependencies packaged into the SDK installer, this SDK then can be installed and used for stand alone application development.

Preparing OpenEmbedded Workspace

$ git clone https://github.com/openembedded/openembedded-core.git
$ cd openembedded-core
$ git clone https://github.com/openembedded/bitbake.git
$ git clone https://github.com/kraj/meta-clang.git
$ . ./oe-init-build-env

Add meta-clang to conf/bblayers.conf e.g.

# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
 /home/kraj/openembedded-core/meta-clang \
 /home/kraj/openembedded-core/meta \
 "
BBLAYERS_NON_REMOVABLE ?= " \
 /home/kraj/openembedded-core/meta \
 "

Select qemuarm64 for MACHINE in conf/local.conf, you need to uncomment the line marked in red

#
# Machine Selection
#
# You need to select a specific machine to target the build with. There are a selection
# of emulated machines available which can boot and run in the QEMU emulator:
#
#MACHINE ?= "qemuarm"
MACHINE ?= "qemuarm64"
#MACHINE ?= "qemumips"
#MACHINE ?= "qemuppc"
#MACHINE ?= "qemux86"
#MACHINE ?= "qemux86-64"
#

Build SDK

$ bitbake -cpopulate_sdk core-image-minimal

Install SDK

SDK self-installer will be in deploy are under e.g. tmp-glibc/deploy/sdk/

$ ./tmp-glibc/deploy/sdk/oecore-x86_64-aarch64-toolchain-nodistro.0.sh

OpenEmbedded SDK installer version nodistro.0
===========================================================
Enter target directory for SDK (default: /usr/local/oecore-x86_64):
You are about to install the SDK to “/usr/local/oecore-x86_64”. Proceed[Y/n]?
Extracting SDK…………………………….done
Setting it up…done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /usr/local/oecore-x86_64/environment-setup-aarch64-oe-linux

Using SDK

The environment setup needs to be done in every shell where the SDK is to be used

$ . /usr/local/oecore-x86_64/environment-setup-aarch64-oe-linux

At this point the SDK is ready to be used for compiling applications as well as kernel. Since the SDK has both gcc and clang in it a new set of variables is introduced to make it easy to use clang

CLANGCC – C cross compiler

CLANGCXX – C++ cross compiler

Example 1 – Build musl C library

The example lists compiling musl C library using the cross SDK but this can be used for anything including kernel and application

$ git clone git://git.musl-libc.org/musl
$ cd musl
$ ./configure --host=aarch64-oe-linux CC=${CLANGCC}
$ make -j

Example 2 – Building llvmlinux kernel

$ git clone git://git.linuxfoundation.org/llvmlinux/kernel.git llvmlinux
$ cd llvmlinux
$ make ARCH=arm64 CC=${CLANGCC} LDFLAGS="" defconfig
$ make ARCH=arm64 CC=${CLANGCC} LDFLAGS="" -j vmlinux

If the kernel for aarch64 won’t build, then hey what have you been waiting for ? you have everything go fix it !!!

Notes

I have not provided prebuilt SDKs, if there is enough intrest for such SDKs, I would consider building the SDK self-installs and host them somewhere, contact me if you are interested.

Example is covering aarch64 but the SDKs are not limited to aarch64, one can build for x86,x86_64, ppc, mips, arm in same fashion. All one would need is to changes is MACHINE selection in conf/local.conf