HsacExamples.SlimTests.ExecuteProgramTest


This page demonstrates the usage of ExecuteProgramTest, which allows you to run a program and inspect its output.

The program will be executed on the machine which hosts the Slim process.


We can run a program with some arguments, check its exit code and show its output.

script execute program test
set -c as argument 0
set ls -l / as argument 1
execute /bin/bash
check exit code 0
show standard out
total 200184
drwxr-xr-x   2 root   root        4096 Feb 18 10:29 bin
drwxr-xr-x   3 root   root        4096 Feb 18 10:45 boot
drwxr-xr-x  16 root   root        3580 Mar 16 07:44 dev
drwxr-xr-x 113 root   root        4096 Mar 16 07:44 etc
drwxr-xr-x   8 root   root        4096 Mar 16 07:44 home
lrwxrwxrwx   1 root   root          31 Feb 18 10:45 initrd.img -> boot/initrd.img-4.15.0-1055-gcp
lrwxrwxrwx   1 root   root          33 Feb 18 10:45 initrd.img.old -> boot/initrd.img-4.4.0-174-generic
-rw-r--r--   1 root   root   204892533 Jun 28  2018 jdk.tar.gz
drwxr-xr-x  22 root   root        4096 Feb 18 10:47 lib
drwxr-xr-x   2 root   root        4096 Feb 18 10:22 lib64
drwx------   2 root   root       16384 Oct 23  2018 lost+found
drwxr-xr-x   2 root   root        4096 Oct 23  2018 media
drwxr-xr-x   2 root   root        4096 Oct 23  2018 mnt
drwxr-xr-x   5 travis travis      4096 Feb 18 10:47 opt
dr-xr-xr-x 115 root   root           0 Mar 16 07:44 proc
drwx------   5 root   root        4096 Feb 18 10:44 root
drwxr-xr-x  26 root   root        1000 Mar 16 07:44 run
drwxr-xr-x   2 root   root       12288 Feb 18 10:29 sbin
drwxr-xr-x   2 root   root        4096 Feb 18 10:20 snap
drwxr-xr-x   2 root   root        4096 Oct 23  2018 srv
dr-xr-xr-x  13 root   root           0 Mar 16 08:20 sys
drwxrwxrwt  12 root   root        4096 Mar 16 08:31 tmp
drwxr-xr-x  12 root   root        4096 Feb 18 10:27 usr
drwxr-xr-x  14 root   root        4096 Feb 18 10:39 var
lrwxrwxrwx   1 root   root          28 Feb 18 10:45 vmlinuz -> boot/vmlinuz-4.15.0-1055-gcp
lrwxrwxrwx   1 root   root          30 Feb 18 10:45 vmlinuz.old -> boot/vmlinuz-4.4.0-174-generic
check standard error BLANK

The default timeout for program execution is one minute, but we can set a custom timeout. Furthermore we can control the directory it is invoked from, set all arguments using a list and get its output 'unformatted'.

script execute program test
check timeout 60000
set timeout of 100 milliseconds
set working directory /
set -c, ls -l as arguments
execute /bin/bash
check exit code 0
show raw standard out total 200184 drwxr-xr-x 2 root root 4096 Feb 18 10:29 bin drwxr-xr-x 3 root root 4096 Feb 18 10:45 boot drwxr-xr-x 16 root root 3580 Mar 16 07:44 dev drwxr-xr-x 113 root root 4096 Mar 16 07:44 etc drwxr-xr-x 8 root root 4096 Mar 16 07:44 home lrwxrwxrwx 1 root root 31 Feb 18 10:45 initrd.img -> boot/initrd.img-4.15.0-1055-gcp lrwxrwxrwx 1 root root 33 Feb 18 10:45 initrd.img.old -> boot/initrd.img-4.4.0-174-generic -rw-r--r-- 1 root root 204892533 Jun 28 2018 jdk.tar.gz drwxr-xr-x 22 root root 4096 Feb 18 10:47 lib drwxr-xr-x 2 root root 4096 Feb 18 10:22 lib64 drwx------ 2 root root 16384 Oct 23 2018 lost+found drwxr-xr-x 2 root root 4096 Oct 23 2018 media drwxr-xr-x 2 root root 4096 Oct 23 2018 mnt drwxr-xr-x 5 travis travis 4096 Feb 18 10:47 opt dr-xr-xr-x 115 root root 0 Mar 16 07:44 proc drwx------ 5 root root 4096 Feb 18 10:44 root drwxr-xr-x 26 root root 1000 Mar 16 07:44 run drwxr-xr-x 2 root root 12288 Feb 18 10:29 sbin drwxr-xr-x 2 root root 4096 Feb 18 10:20 snap drwxr-xr-x 2 root root 4096 Oct 23 2018 srv dr-xr-xr-x 13 root root 0 Mar 16 08:20 sys drwxrwxrwt 12 root root 4096 Mar 16 08:31 tmp drwxr-xr-x 12 root root 4096 Feb 18 10:27 usr drwxr-xr-x 14 root root 4096 Feb 18 10:39 var lrwxrwxrwx 1 root root 28 Feb 18 10:45 vmlinuz -> boot/vmlinuz-4.15.0-1055-gcp lrwxrwxrwx 1 root root 30 Feb 18 10:45 vmlinuz.old -> boot/vmlinuz-4.4.0-174-generic
check raw standard error BLANK

The timeout can also be set in seconds, and pass environment variables (and the process's output is escaped to ensure it is displayed properly).

script execute program test
set timeout of 1 seconds
set value Hi for BLA
set -c as argument 0
set echo ${BLA} as argument 1
execute /bin/bash
check exit code 0
check raw standard out Hi <there>
check standard out
Hi <there>