summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtest71
-rw-r--r--tests/default-integers8
-rw-r--r--tests/endians175
-rw-r--r--tests/errors1
-rw-r--r--tests/fixed-array-types9
-rw-r--r--tests/load-archinfo2
-rw-r--r--tests/load-functions24
-rw-r--r--tests/preamble41
-rw-r--r--tests/sections90
-rw-r--r--tests/signals6
-rw-r--r--tests/signness296
-rw-r--r--tests/syscall-errors6
-rw-r--r--tests/test-self-check7
-rw-r--r--testutil/get-integer-alignment.c2
-rw-r--r--testutil/make-signed.c56
-rw-r--r--testutil/parse-signed.c56
-rw-r--r--testutil/section-value.c52
-rw-r--r--testutil/to-tracee-endian.c111
-rw-r--r--testutil/to-tracer-endian.c83
-rw-r--r--testutil/unsection-value.c52
20 files changed, 1094 insertions, 54 deletions
diff --git a/test b/test
index 185d915..4af52c8 100755
--- a/test
+++ b/test
@@ -1,68 +1,49 @@
#!/bin/sh
# See LICENSE file for copyright and license details.
-if test $# = 0; then
- if "$0" fail for me; then
- printf 'Testing is broken!\n' >&2
- exit 2
- fi
- set +e
- "$0" $$
- r=$?
- rm -f -- .?-$$.tmp
- exit $r
-fi
+. tests/preamble
-
-set -e
-test $# = 1
-pid=$1
-a=.a-$pid.tmp
-b=.b-$pid.tmp
-PATH="$(dirname -- "$0")/testutil:$PATH"
-export PATH
-
-. tests/load-functions
-
-alias t=.
+t=.
# this is for test development; set to : to skip tests
# have already been written and passed, set to . otherwise
-
-if ! env | grep '^SUPPORTED_OSES=' >/dev/null; then
- printf '%s\n' \
- "The test's environment has not been set up;" \
- 'you should run the test via `make check`'
- exit 1
-fi
+# t is used to synchronous tests,
+# p is used for asynchronous tests, and use t to determine whether to run
+# If you want to force all tests to run synchronous, uncomment the next line
+#alias p=t
set -v
-(. tests/test-self-check) >/dev/null 2>/dev/null
t tests/enums
. tests/load-types
-t tests/errors
-t tests/syscall-ranges
-t tests/syscall-errors
-t tests/signals
-t tests/split-register-classes
+p tests/errors
+p tests/syscall-ranges
+p tests/syscall-errors
+p tests/signals
+p tests/split-register-classes
+p tests/signness
+p tests/endians
+p tests/sections
+await
. tests/load-archinfo
t tests/archinfo
-t tests/fundamental-primitives
-t tests/is-struct
-t tests/array-types
-t tests/fixed-array-types
-t tests/split-register-types
-t tests/os-dependent-primitives
-t tests/os-dependent-arrays
-t tests/os-dependent-integers
-
+p tests/fundamental-primitives
+p tests/is-struct
+p tests/array-types
+p tests/fixed-array-types
+p tests/split-register-types
+p tests/os-dependent-primitives
+p tests/os-dependent-arrays
+p tests/os-dependent-integers
+await
+# TODO test libsyscalls_get_struct_description
+# TODO test libsyscalls_get_struct_display_info
# TODO test libsyscalls_get_syscall
# TODO test libsyscalls_get_syscall_display_info
diff --git a/tests/default-integers b/tests/default-integers
index 12faa5a..a33e51a 100644
--- a/tests/default-integers
+++ b/tests/default-integers
@@ -9,7 +9,13 @@ for arch in $(getnamelist ARCH); do
if test $arch = M68K; then
maxalign=16
- elif test $arch = I386; then
+ elif test $arch = I386 || \
+ test $arch = ARM_OABI_LE || \
+ test $arch = ARM_OABI_BE || \
+ test $arch = SH_LE || \
+ test $arch = SH_BE || \
+ test $arch = MICROBLAZE_32_LE || \
+ test $arch = MICROBLAZE_32_BE; then
maxalign=32
else
maxalign=64
diff --git a/tests/endians b/tests/endians
new file mode 100644
index 0000000..13f29f8
--- /dev/null
+++ b/tests/endians
@@ -0,0 +1,175 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+check_endian () {
+ xvalue="$1"
+ text0="$2"
+ text1="$3"
+ textoff="$4"
+ bits="$5"
+ shift 5
+
+ sxvalue="$(printf '%s\n' "$xvalue" | sed 's/^0*//' | sed 's/^$/0/')"
+
+ test "$(to-tracer-endian.tu $text0 $textoff $bits $@)" = "$sxvalue"
+ test "$(to-tracer-endian.tu $text1 $textoff $bits $@)" = "$sxvalue"
+ test "$(to-tracee-endian.tu $xvalue $textoff $bits $@)" = "$text0 $text1"
+}
+
+check_endian0 () {
+ xvalue="$1"
+ text="$2"
+ textoff="$3"
+ bits="$4"
+ shift 4
+ check_endian $xvalue $text $text $textoff $bits $@
+}
+
+check_endian 0 00 FE 0 1 0
+check_endian 0 00 FD 1 1 0
+check_endian 0 00 FB 2 1 0
+check_endian 0 00 F7 3 1 0
+check_endian 0 00 EF 4 1 0
+check_endian 0 00 DF 5 1 0
+check_endian 0 00 BF 6 1 0
+check_endian 0 00 7F 7 1 0
+check_endian 0 0000 FFFE 8 1 0
+
+check_endian 1 01 FF 0 1 0
+check_endian 1 02 FF 1 1 0
+check_endian 1 04 FF 2 1 0
+check_endian 1 08 FF 3 1 0
+check_endian 1 10 FF 4 1 0
+check_endian 1 20 FF 5 1 0
+check_endian 1 40 FF 6 1 0
+check_endian 1 80 FF 7 1 0
+check_endian 1 0001 FFFF 8 1 0
+
+check_endian 0 00 F0 0 4 0
+check_endian 1 01 F1 0 4 0
+check_endian 2 02 F2 0 4 0
+check_endian 3 03 F3 0 4 0
+check_endian 4 04 F4 0 4 0
+check_endian 8 08 F8 0 4 0
+check_endian A 0A FA 0 4 0
+check_endian F 0F FF 0 4 0
+
+check_endian 0 00 E1 1 4 0
+check_endian 0 00 C3 2 4 0
+check_endian 0 00 87 3 4 0
+check_endian 0 00 0F 4 4 0
+check_endian F 1E FF 1 4 0
+check_endian F 3C FF 2 4 0
+check_endian F 78 FF 3 4 0
+check_endian F F0 FF 4 4 0
+check_endian 0 0000 1FFE 5 4 0
+check_endian F E001 FFFF 5 4 0
+check_endian 0 0000 3FFC 6 4 0
+check_endian F C003 FFFF 6 4 0
+
+check_endian0 00 00 0 8 0
+check_endian0 10 10 0 8 0
+check_endian0 01 01 0 8 0
+check_endian0 80 80 0 8 0
+check_endian0 08 08 0 8 0
+check_endian0 FF FF 0 8 0
+
+check_endian 00 0000 01FE 1 8 0
+check_endian FF FE01 FFFF 1 8 0
+
+check_endian 000 0000 00FE 0 9 0
+check_endian 1FF FF01 FFFF 0 9 0
+
+check_endian 000 0000 00FC 0 10 0
+check_endian 3FF FF03 FFFF 0 10 0
+
+check_endian 000 0000 01FC 1 9 0
+check_endian 1FF FE03 FFFF 1 9 0
+
+check_endian 000 0000 01F8 1 10 0
+check_endian 3FF FE07 FFFF 1 10 0
+
+check_endian0 0000 0000 0 16 8 0
+check_endian0 FFFF FFFF 0 16 8 0
+check_endian0 1234 1234 0 16 8 0
+check_endian0 0800 0800 0 16 8 0
+
+check_endian0 0000 0000 0 16 0 8
+check_endian0 FFFF FFFF 0 16 0 8
+check_endian0 1234 3412 0 16 0 8
+check_endian0 0800 0008 0 16 0 8
+
+check_endian0 0000 0000 0 16 0
+check_endian0 FFFF FFFF 0 16 0
+check_endian0 1234 3412 0 16 0
+check_endian0 0800 0008 0 16 0
+
+check_endian0 000000 000000 0 24 16 8 0
+check_endian0 FFFFFF FFFFFF 0 24 16 8 0
+check_endian0 160800 160800 0 24 16 8 0
+
+check_endian0 000000 000000 0 24 16 0 8
+check_endian0 FFFFFF FFFFFF 0 24 16 0 8
+check_endian0 160800 160008 0 24 16 0 8
+
+check_endian0 000000 000000 0 24 0 8 16
+check_endian0 FFFFFF FFFFFF 0 24 0 8 16
+check_endian0 160800 000816 0 24 0 8 16
+
+check_endian0 000000 000000 0 24 8 0 16
+check_endian0 FFFFFF FFFFFF 0 24 8 0 16
+check_endian0 160800 080016 0 24 8 0 16
+
+check_endian0 000000 000000 0 24 0 16 8
+check_endian0 FFFFFF FFFFFF 0 24 0 16 8
+check_endian0 160800 001608 0 24 0 16 8
+
+check_endian0 000000 000000 0 24 8 16 0
+check_endian0 FFFFFF FFFFFF 0 24 8 16 0
+check_endian0 160800 081600 0 24 8 16 0
+
+check_endian0 00000000 00000000 0 32 24 16 8 0
+check_endian0 FFFFFFFF FFFFFFFF 0 32 24 16 8 0
+check_endian0 12345678 12345678 0 32 24 16 8 0
+check_endian0 24160800 24160800 0 32 24 16 8 0
+
+check_endian0 00000000 00000000 0 32 8 0 24 16
+check_endian0 FFFFFFFF FFFFFFFF 0 32 8 0 24 16
+check_endian0 12345678 56781234 0 32 8 0 24 16
+check_endian0 24160800 08002416 0 32 8 0 24 16
+
+check_endian0 00000000 00000000 0 32 0 8 16 24
+check_endian0 FFFFFFFF FFFFFFFF 0 32 0 8 16 24
+check_endian0 12345678 78563412 0 32 0 8 16 24
+check_endian0 24160800 00081624 0 32 0 8 16 24
+
+check_endian0 00000000 00000000 0 32 0 16 8 24
+check_endian0 FFFFFFFF FFFFFFFF 0 32 0 16 8 24
+check_endian0 12345678 78345612 0 32 0 16 8 24
+check_endian0 24160800 00160824 0 32 0 16 8 24
+
+check_endian0 0000000000000000 0000000000000000 0 64 56 48 40 32 24 16 8 0
+check_endian0 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 0 64 56 48 40 32 24 16 8 0
+check_endian0 0123456789ABCDEF 0123456789ABCDEF 0 64 56 48 40 32 24 16 8 0
+check_endian0 5648403224160800 5648403224160800 0 64 56 48 40 32 24 16 8 0
+
+check_endian0 0000000000000000 0000000000000000 0 64 24 16 8 0 56 48 40 32
+check_endian0 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 0 64 24 16 8 0 56 48 40 32
+check_endian0 0123456789ABCDEF 89ABCDEF01234567 0 64 24 16 8 0 56 48 40 32
+check_endian0 5648403224160800 2416080056484032 0 64 24 16 8 0 56 48 40 32
+
+check_endian0 0000000000000000 0000000000000000 0 64 8 0 24 16 40 32 56 48
+check_endian0 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 0 64 8 0 24 16 40 32 56 48
+check_endian0 0123456789ABCDEF CDEF89AB45670123 0 64 8 0 24 16 40 32 56 48
+check_endian0 5648403224160800 0800241640325648 0 64 8 0 24 16 40 32 56 48
+
+check_endian0 0000000000000000 0000000000000000 0 64 0 8 16 24 32 40 48 56
+check_endian0 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 0 64 0 8 16 24 32 40 48 56
+check_endian0 0123456789ABCDEF EFCDAB8967452301 0 64 0 8 16 24 32 40 48 56
+check_endian0 5648403224160800 0008162432404856 0 64 0 8 16 24 32 40 48 56
+
+check_endian 000 0000 00FE 0 9 0 8
+check_endian 1FF FF01 FFFF 0 9 0 8
+
+check_endian 000 0000 FE00 0 9 8 0
+check_endian 1FF 01FF FFFF 0 9 8 0
diff --git a/tests/errors b/tests/errors
index 8c74731..9e098d1 100644
--- a/tests/errors
+++ b/tests/errors
@@ -55,5 +55,6 @@ cat > $a <<.
7 LIBSYSCALLS_E_INVAL Invalid arguments passed to function
8 LIBSYSCALLS_E_NOSUCHTYPE Type does not exist on the selected operating system or architecture
9 LIBSYSCALLS_E_ISSTRUCT Type is a structure or union
+10 LIBSYSCALLS_E_ISNOTSTRUCT Type is not a structure or union
.
list-errors.tu | diff -u $a -
diff --git a/tests/fixed-array-types b/tests/fixed-array-types
index 070920e..06dcbb5 100644
--- a/tests/fixed-array-types
+++ b/tests/fixed-array-types
@@ -29,5 +29,14 @@ for os in $(getnamelist OS); do
| sed 's/^\(array_size\) = 1$/\1 = 2/' > $a
get-datatype-description.tu $osn $archn $(lookupnum "$types" $atype) $os $arch $atype > $b
diff -u $a $b
+
+ for n in 9 65; do
+ ptype=CHAR
+ atype=BUFFER_$n
+ get-datatype-description.tu $osn $archn $(lookupnum "$types" $ptype) $os $arch $ptype \
+ | sed 's/^\(array_size\) = 1$/\1 = '$n/ > $a
+ get-datatype-description.tu $osn $archn $(lookupnum "$types" $atype) $os $arch $atype > $b
+ diff -u $a $b
+ done
done
done
diff --git a/tests/load-archinfo b/tests/load-archinfo
index 09d472b..e5413b4 100644
--- a/tests/load-archinfo
+++ b/tests/load-archinfo
@@ -18,7 +18,7 @@ getbyteorder () {
printf '%s\n' "$byteorders" | grep "^$1$2 " | cut -d ' ' -f 2-
}
-sed '1,/LIST_ARCH_SPECS/d' < libsyscalls_get_datatype_description.c \
+sed '1,/LIST_ARCH_SPECS/d' < common.h \
| sed '/#include/q' \
| sed 's/\(TO''DO\)[[:space:]]*([^)]*)/\1/g' \
| sed -n 's/^[[:space:]]*[A-Z_]\{1,\}(LIBSYSCALLS_ARCH_\([^)]*\)).*$/\1/p' \
diff --git a/tests/load-functions b/tests/load-functions
index 2e9ddda..3436158 100644
--- a/tests/load-functions
+++ b/tests/load-functions
@@ -1,6 +1,30 @@
# -*- sh -*-
# See LICENSE file for copyright and license details.
+parallelindex=0
+p () {
+ (
+ set +ev
+ pid=$$-$parallelindex
+ a=.a-$pid.tmp
+ b=.b-$pid.tmp
+ log=.x-$pid.tmp
+ ( set -ev ; $t "$@" ) > $log 2>&1
+ r=$?
+ test $r = 0 || cat -- $log >&2
+ rm -f -- .?-$pid.tmp
+ exit $r
+ ) &
+ eval parallelpid$(( ++parallelindex ))=$!
+}
+await () {
+ while (( parallelindex )); do
+ parallelvar=parallelpid$(( parallelindex-- ))
+ eval wait '$'$parallelvar
+ done
+}
+
+
stderr () {
("$@") 2>&1 >/dev/null
}
diff --git a/tests/preamble b/tests/preamble
new file mode 100644
index 0000000..527a098
--- /dev/null
+++ b/tests/preamble
@@ -0,0 +1,41 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+if test $# = 0; then
+ if "$0" fail for me; then
+ printf 'Testing is broken!\n' >&2
+ exit 2
+ fi
+ set +e
+ "$0" $$
+ r=$?
+ rm -f -- .?-$$.tmp
+ exit $r
+fi
+
+
+set -e
+test $# = 1
+pid=$1
+a=.a-$pid.tmp
+b=.b-$pid.tmp
+PATH="$(dirname -- "$0")/testutil:$PATH"
+export PATH
+
+
+if ! env | grep '^SUPPORTED_OSES=' >/dev/null; then
+ printf '%s\n' \
+ "The test's environment has not been set up;" \
+ 'you should run the test via `make check`'
+ exit 1
+fi
+
+. tests/load-functions
+
+alias t='$t'
+
+if ! (. tests/test-self-check) >/dev/null 2>/dev/null; then
+ printf '%s\n' \
+ "The test's self-check failed"
+ exit 1
+fi
diff --git a/tests/sections b/tests/sections
new file mode 100644
index 0000000..1574b8d
--- /dev/null
+++ b/tests/sections
@@ -0,0 +1,90 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+check_section () {
+ sectionn=$1
+ whole=$2
+ splitinwhole=$3
+ split=$(printf '%s\n' $splitinwhole | tr -d -- -)
+ wholebits=$(( ( $(printf '%s\n' $whole | sed 's/./+1/g') ) * 4 ))
+ splitbits=$(( ( $(printf '%s\n' $split | sed 's/./+1/g') ) * 4 ))
+ ssplit=$(printf '%s\n' $split | sed 's/^0*//' | sed 's/^$/0/' )
+ ssplitinwhole=$(printf '%s\n' $splitinwhole | tr -- - 0 | sed 's/^0*//' | sed 's/^$/0/' )
+
+ test $(section-value.tu $sectionn $whole $wholebits) = $ssplit
+ test $(unsection-value.tu $sectionn $split $splitbits) = $ssplitinwhole
+}
+
+test $(section-value.tu 32767 0 8) = inval
+test $(unsection-value.tu 32767 0 8) = inval
+
+for section in $(getnamelist SECTION); do
+ sectionn=$(getnum SECTION $section)
+ if test $section = UNDETERMINED || test $section = WHOLE; then
+ check_section $sectionn 12 12
+ check_section $sectionn 1234 1234
+ check_section $sectionn 12345678 12345678
+ check_section $sectionn 123456789ABC 123456789ABC
+ check_section $sectionn 0123456789ABCDEF 0123456789ABCDEF
+
+ elif test $section = UPPER_HALF; then
+ check_section $sectionn 1234 12--
+ check_section $sectionn 12345678 1234----
+ check_section $sectionn 123456789ABC 123456------
+ check_section $sectionn 0123456789ABCDEF 01234567--------
+
+ elif test $section = LOWER_HALF; then
+ check_section $sectionn 1234 --34
+ check_section $sectionn 12345678 ----5678
+ check_section $sectionn 123456789ABC ------789ABC
+ check_section $sectionn 0123456789ABCDEF --------89ABCDEF
+
+ elif test $section = INNER_HALF; then
+ check_section $sectionn 12345678 --3456--
+ check_section $sectionn 0123456789ABCDEF ----456789AB----
+
+ elif test $section = OUTER_HALF; then
+ check_section $sectionn 12345678 12----78
+ check_section $sectionn 0123456789ABCDEF 0123--------CDEF
+
+ elif test $section = EVEN_QUARTERS_AS_HALF; then
+ check_section $sectionn 12345678 --34--78
+ check_section $sectionn 0123456789ABCDEF ----4567----CDEF
+
+ elif test $section = ODD_QUARTERS_AS_HALF; then
+ check_section $sectionn 12345678 12--56--
+ check_section $sectionn 0123456789ABCDEF 0123----89AB----
+
+ elif test $section = EVEN_BYTES_AS_HALF; then
+ check_section $sectionn 1234 --34
+ check_section $sectionn 12345678 --34--78
+ check_section $sectionn 123456789ABC --34--78--BC
+ check_section $sectionn 0123456789ABCDEF --23--67--AB--EF
+
+ elif test $section = ODD_BYTES_AS_HALF; then
+ check_section $sectionn 1234 12--
+ check_section $sectionn 12345678 12--56--
+ check_section $sectionn 123456789ABC 12--56--9A--
+ check_section $sectionn 0123456789ABCDEF 01--45--89--CD--
+
+ elif test $section = UPPER_QUARTER; then
+ check_section $sectionn 12345678 12------
+ check_section $sectionn 0123456789ABCDEF 0123------------
+
+ elif test $section = UPPER_MID_QUARTER; then
+ check_section $sectionn 12345678 --34----
+ check_section $sectionn 0123456789ABCDEF ----4567--------
+
+ elif test $section = LOWER_MID_QUARTER; then
+ check_section $sectionn 12345678 ----56--
+ check_section $sectionn 0123456789ABCDEF --------89AB----
+
+ elif test $section = LOWER_QUARTER; then
+ check_section $sectionn 12345678 ------78
+ check_section $sectionn 0123456789ABCDEF ------------CDEF
+
+ else
+ printf 'Missing test for LIBSYSCALLS_SECTION_%s in tests/sections\n' "$section" >&2
+ false
+ fi
+done
diff --git a/tests/signals b/tests/signals
index 4052402..733baa4 100644
--- a/tests/signals
+++ b/tests/signals
@@ -6,11 +6,11 @@ for os in $(getnamelist OS); do
for arch in $(getnamelist ARCH); do
archn=$(getnum ARCH $arch)
get-signals.tu $osn $archn $os $arch > $a
- grep -v '^[0-9]\{1,\} -' >/dev/null < $a
- grep -v '^-' < $a > $b
- grep '^\([0-9]\{1,\}\) \1 ' < $a | diff -u $a -
if issupported $os $arch; then
(! test "$(cat $a)" = x)
+ grep -v '^[0-9]\{1,\} -' >/dev/null < $a
+ grep -v '^-' < $a > $b
+ grep '^\([0-9]\{1,\}\) \1 ' < $a | diff -u $a -
if test "$os" = LINUX; then
signed=1
grep '^[0-9]\{1,\} [0-9]\{1,\} [A-Z0-9_+]\{1,\}$' >/dev/null < $a
diff --git a/tests/signness b/tests/signness
new file mode 100644
index 0000000..8c29fe4
--- /dev/null
+++ b/tests/signness
@@ -0,0 +1,296 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+test $(parse-signed.tu 32767 32 0) = inval
+test $(make-signed.tu 32767 32 0) = inval
+
+check_signed () {
+ test $(parse-signed.tu $1 $2 $3) = $4
+ test $(make-signed.tu $1 $2 $4) = $3
+}
+
+ucheck_signed () {
+ check_signed "$@"
+ test $(make-signed.tu $1 $2 -$4) = $3
+}
+
+for sign in $(getnamelist SIGN); do
+ signn=$(getnum SIGN $sign)
+ if test $sign = UNDETERMINED; then
+ ucheck_signed $signn 1 0 0
+ ucheck_signed $signn 1 1 1
+ ucheck_signed $signn 2 0 0
+ ucheck_signed $signn 2 1 1
+ ucheck_signed $signn 2 2 2
+ ucheck_signed $signn 2 3 3
+ ucheck_signed $signn 4 4 4
+ ucheck_signed $signn 4 9 9
+ ucheck_signed $signn 4 A A
+ ucheck_signed $signn 4 C C
+ ucheck_signed $signn 4 F F
+ ucheck_signed $signn 7 00 00
+ ucheck_signed $signn 7 08 08
+ ucheck_signed $signn 7 70 70
+ ucheck_signed $signn 7 7F 7F
+ ucheck_signed $signn 8 00 00
+ ucheck_signed $signn 8 08 08
+ ucheck_signed $signn 8 80 80
+ ucheck_signed $signn 8 FF FF
+ ucheck_signed $signn 16 0001 0001
+ ucheck_signed $signn 16 0020 0020
+ ucheck_signed $signn 16 0300 0300
+ ucheck_signed $signn 16 4000 4000
+ ucheck_signed $signn 16 0008 0008
+ ucheck_signed $signn 16 0090 0090
+ ucheck_signed $signn 16 0A00 0A00
+ ucheck_signed $signn 16 B000 B000
+ ucheck_signed $signn 17 08100 08100
+ ucheck_signed $signn 17 00820 00820
+ ucheck_signed $signn 17 00083 00083
+ ucheck_signed $signn 17 04008 04008
+ ucheck_signed $signn 17 11008 11008
+ ucheck_signed $signn 17 10280 10280
+ ucheck_signed $signn 17 10830 10830
+ ucheck_signed $signn 17 18004 18004
+ ucheck_signed $signn 32 12345678 12345678
+ ucheck_signed $signn 32 9ABCDEF0 9ABCDEF0
+ ucheck_signed $signn 32 87654321 87654321
+ ucheck_signed $signn 32 0FEDCBA9 0FEDCBA9
+ ucheck_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
+ ucheck_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
+ ucheck_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
+ ucheck_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
+ ucheck_signed $signn 64 89ABCDEF01234567 89ABCDEF01234567
+ ucheck_signed $signn 64 9ABCDEF012345678 9ABCDEF012345678
+ ucheck_signed $signn 64 ABCDEF0123456789 ABCDEF0123456789
+ ucheck_signed $signn 64 BCDEF0123456789A BCDEF0123456789A
+ ucheck_signed $signn 64 0000000000000000 0000000000000000
+ ucheck_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
+ ucheck_signed $signn 64 8000000000000000 8000000000000000
+ ucheck_signed $signn 64 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
+
+ elif test $sign = SIGN_MAGNITUDE; then
+ check_signed $signn 1 0 0
+ check_signed $signn 1 1 -0
+ check_signed $signn 2 0 0
+ check_signed $signn 2 1 1
+ check_signed $signn 2 2 -0
+ check_signed $signn 2 3 -1
+ check_signed $signn 4 4 4
+ check_signed $signn 4 9 -1
+ check_signed $signn 4 A -2
+ check_signed $signn 4 C -4
+ check_signed $signn 4 F -7
+ check_signed $signn 7 00 00
+ check_signed $signn 7 08 08
+ check_signed $signn 7 70 -30
+ check_signed $signn 7 7F -3F
+ check_signed $signn 8 00 00
+ check_signed $signn 8 08 08
+ check_signed $signn 8 80 -00
+ check_signed $signn 8 FF -7F
+ check_signed $signn 16 0001 0001
+ check_signed $signn 16 0020 0020
+ check_signed $signn 16 0300 0300
+ check_signed $signn 16 4000 4000
+ check_signed $signn 16 0008 0008
+ check_signed $signn 16 0090 0090
+ check_signed $signn 16 0A00 0A00
+ check_signed $signn 16 B000 -3000
+ check_signed $signn 17 08100 08100
+ check_signed $signn 17 00820 00820
+ check_signed $signn 17 00083 00083
+ check_signed $signn 17 04008 04008
+ check_signed $signn 17 11008 -01008
+ check_signed $signn 17 10280 -00280
+ check_signed $signn 17 10830 -00830
+ check_signed $signn 17 18004 -08004
+ check_signed $signn 32 12345678 12345678
+ check_signed $signn 32 9ABCDEF0 -1ABCDEF0
+ check_signed $signn 32 87654321 -07654321
+ check_signed $signn 32 0FEDCBA9 0FEDCBA9
+ check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
+ check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
+ check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
+ check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
+ check_signed $signn 64 89ABCDEF01234567 -09ABCDEF01234567
+ check_signed $signn 64 9ABCDEF012345678 -1ABCDEF012345678
+ check_signed $signn 64 ABCDEF0123456789 -2BCDEF0123456789
+ check_signed $signn 64 BCDEF0123456789A -3CDEF0123456789A
+ check_signed $signn 64 0000000000000000 0000000000000000
+ check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
+ check_signed $signn 64 8000000000000000 -0000000000000000
+ check_signed $signn 64 FFFFFFFFFFFFFFFF -7FFFFFFFFFFFFFFF
+
+ elif test $sign = ONES_COMPLEMENT; then
+ check_signed $signn 1 0 0
+ check_signed $signn 1 1 -0
+ check_signed $signn 2 0 0
+ check_signed $signn 2 1 1
+ check_signed $signn 2 2 -1
+ check_signed $signn 2 3 -0
+ check_signed $signn 4 4 4
+ check_signed $signn 4 9 -6
+ check_signed $signn 4 A -5
+ check_signed $signn 4 C -3
+ check_signed $signn 4 F -0
+ check_signed $signn 7 00 00
+ check_signed $signn 7 08 08
+ check_signed $signn 7 70 -0F
+ check_signed $signn 7 7F -00
+ check_signed $signn 8 00 00
+ check_signed $signn 8 08 08
+ check_signed $signn 8 80 -7F
+ check_signed $signn 8 FF -00
+ check_signed $signn 16 0001 0001
+ check_signed $signn 16 0020 0020
+ check_signed $signn 16 0300 0300
+ check_signed $signn 16 4000 4000
+ check_signed $signn 16 0008 0008
+ check_signed $signn 16 0090 0090
+ check_signed $signn 16 0A00 0A00
+ check_signed $signn 16 B000 -4FFF
+ check_signed $signn 17 08100 08100
+ check_signed $signn 17 00820 00820
+ check_signed $signn 17 00083 00083
+ check_signed $signn 17 04008 04008
+ check_signed $signn 17 11008 -0EFF7
+ check_signed $signn 17 10280 -0FD7F
+ check_signed $signn 17 10830 -0F7CF
+ check_signed $signn 17 18004 -07FFB
+ check_signed $signn 32 12345678 12345678
+ check_signed $signn 32 9ABCDEF0 -6543210F
+ check_signed $signn 32 87654321 -789ABCDE
+ check_signed $signn 32 0FEDCBA9 0FEDCBA9
+ check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
+ check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
+ check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
+ check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
+ check_signed $signn 64 89ABCDEF01234567 -76543210FEDCBA98
+ check_signed $signn 64 9ABCDEF012345678 -6543210FEDCBA987
+ check_signed $signn 64 ABCDEF0123456789 -543210FEDCBA9876
+ check_signed $signn 64 BCDEF0123456789A -43210FEDCBA98765
+ check_signed $signn 64 0000000000000000 0000000000000000
+ check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
+ check_signed $signn 64 8000000000000000 -7FFFFFFFFFFFFFFF
+ check_signed $signn 64 FFFFFFFFFFFFFFFF -0000000000000000
+
+ elif test $sign = TWOS_COMPLEMENT; then
+ check_signed $signn 1 0 0
+ check_signed $signn 1 1 -1
+ check_signed $signn 2 0 0
+ check_signed $signn 2 1 1
+ check_signed $signn 2 2 -2
+ check_signed $signn 2 3 -1
+ check_signed $signn 4 4 4
+ check_signed $signn 4 9 -7
+ check_signed $signn 4 A -6
+ check_signed $signn 4 C -4
+ check_signed $signn 4 F -1
+ check_signed $signn 7 00 00
+ check_signed $signn 7 08 08
+ check_signed $signn 7 70 -10
+ check_signed $signn 7 7F -01
+ check_signed $signn 8 00 00
+ check_signed $signn 8 08 08
+ check_signed $signn 8 80 -80
+ check_signed $signn 8 FF -01
+ check_signed $signn 16 0001 0001
+ check_signed $signn 16 0020 0020
+ check_signed $signn 16 0300 0300
+ check_signed $signn 16 4000 4000
+ check_signed $signn 16 0008 0008
+ check_signed $signn 16 0090 0090
+ check_signed $signn 16 0A00 0A00
+ check_signed $signn 16 B000 -5000
+ check_signed $signn 17 08100 08100
+ check_signed $signn 17 00820 00820
+ check_signed $signn 17 00083 00083
+ check_signed $signn 17 04008 04008
+ check_signed $signn 17 11008 -0EFF8
+ check_signed $signn 17 10280 -0FD80
+ check_signed $signn 17 10830 -0F7D0
+ check_signed $signn 17 18004 -07FFC
+ check_signed $signn 32 12345678 12345678
+ check_signed $signn 32 9ABCDEF0 -65432110
+ check_signed $signn 32 87654321 -789ABCDF
+ check_signed $signn 32 0FEDCBA9 0FEDCBA9
+ check_signed $signn 64 0123456789ABCDEF 0123456789ABCDEF
+ check_signed $signn 64 123456789ABCDEF0 123456789ABCDEF0
+ check_signed $signn 64 23456789ABCDEF01 23456789ABCDEF01
+ check_signed $signn 64 3456789ABCDEF012 3456789ABCDEF012
+ check_signed $signn 64 89ABCDEF01234567 -76543210FEDCBA99
+ check_signed $signn 64 9ABCDEF012345678 -6543210FEDCBA988
+ check_signed $signn 64 ABCDEF0123456789 -543210FEDCBA9877
+ check_signed $signn 64 BCDEF0123456789A -43210FEDCBA98766
+ check_signed $signn 64 0000000000000000 0000000000000000
+ check_signed $signn 64 7FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
+ check_signed $signn 64 8000000000000000 -8000000000000000
+ check_signed $signn 64 FFFFFFFFFFFFFFFF -0000000000000001
+ test $(make-signed.tu $signn 1 -0) = 0
+ test $(make-signed.tu $signn 4 -0) = 0
+
+ elif test $sign = EXCESS_HALF; then
+ check_signed $signn 1 0 -1
+ check_signed $signn 1 1 0
+ check_signed $signn 2 0 -2
+ check_signed $signn 2 1 -1
+ check_signed $signn 2 2 0
+ check_signed $signn 2 3 1
+ check_signed $signn 4 4 -4
+ check_signed $signn 4 9 1
+ check_signed $signn 4 A 2
+ check_signed $signn 4 C 4
+ check_signed $signn 4 F 7
+ check_signed $signn 7 00 -40
+ check_signed $signn 7 08 -38
+ check_signed $signn 7 70 30
+ check_signed $signn 7 7F 3F
+ check_signed $signn 8 00 -80
+ check_signed $signn 8 08 -78
+ check_signed $signn 8 80 00
+ check_signed $signn 8 FF 7F
+ check_signed $signn 16 0001 -7FFF
+ check_signed $signn 16 0020 -7FE0
+ check_signed $signn 16 0300 -7D00
+ check_signed $signn 16 4000 -4000
+ check_signed $signn 16 0008 -7FF8
+ check_signed $signn 16 0090 -7F70
+ check_signed $signn 16 0A00 -7600
+ check_signed $signn 16 B000 3000
+ check_signed $signn 17 08100 -07F00
+ check_signed $signn 17 00820 -0F7E0
+ check_signed $signn 17 00083 -0FF7D
+ check_signed $signn 17 04008 -0BFF8
+ check_signed $signn 17 11008 01008
+ check_signed $signn 17 10280 00280
+ check_signed $signn 17 10830 00830
+ check_signed $signn 17 18004 08004
+ check_signed $signn 32 12345678 -6DCBA988
+ check_signed $signn 32 9ABCDEF0 1ABCDEF0
+ check_signed $signn 32 87654321 07654321
+ check_signed $signn 32 0FEDCBA9 -70123457
+ check_signed $signn 64 0123456789ABCDEF -7EDCBA9876543211
+ check_signed $signn 64 123456789ABCDEF0 -6DCBA98765432110
+ check_signed $signn 64 23456789ABCDEF01 -5CBA9876543210FF
+ check_signed $signn 64 3456789ABCDEF012 -4BA9876543210FEE
+ check_signed $signn 64 89ABCDEF01234567 09ABCDEF01234567
+ check_signed $signn 64 9ABCDEF012345678 1ABCDEF012345678
+ check_signed $signn 64 ABCDEF0123456789 2BCDEF0123456789
+ check_signed $signn 64 BCDEF0123456789A 3CDEF0123456789A
+ check_signed $signn 64 0000000000000000 -8000000000000000
+ check_signed $signn 64 7FFFFFFFFFFFFFFF -0000000000000001
+ check_signed $signn 64 8000000000000000 0000000000000000
+ check_signed $signn 64 FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF
+ test $(make-signed.tu $signn 1 -0) = 1
+ test $(make-signed.tu $signn 4 -0) = 8
+
+ else
+ printf 'Missing test for LIBSYSCALLS_SIGN_%s in tests/signness\n' "$sign" >&2
+ false
+ fi
+ test $(parse-signed.tu $signn 0 0) = inval
+ test $(parse-signed.tu $signn 32767 0) = inval
+ test $(make-signed.tu $signn 0 0) = inval
+ test $(make-signed.tu $signn 32767 0) = inval
+done
diff --git a/tests/syscall-errors b/tests/syscall-errors
index 8d85ded..4608fe7 100644
--- a/tests/syscall-errors
+++ b/tests/syscall-errors
@@ -6,11 +6,11 @@ for os in $(getnamelist OS); do
for arch in $(getnamelist ARCH); do
archn=$(getnum ARCH $arch)
get-syscall-errors.tu $osn $archn $os $arch > $a
- grep -v '^[0-9]\{1,\} -' >/dev/null < $a
- grep -v '^-' < $a > $b
- grep '^\([0-9]\{1,\}\) \1 ' < $a | diff -u $a -
if issupported $os $arch; then
(! test "$(cat $a)" = x)
+ grep -v '^[0-9]\{1,\} -' >/dev/null < $a
+ grep -v '^-' < $a > $b
+ grep '^\([0-9]\{1,\}\) \1 ' < $a | diff -u $a -
if test "$os" = LINUX; then
signed=1
grep '^[0-9]\{1,\} [0-9]\{1,\} [A-Z0-9_]\{1,\}$' >/dev/null < $a
diff --git a/tests/test-self-check b/tests/test-self-check
index 8e42f18..c0e1d0d 100644
--- a/tests/test-self-check
+++ b/tests/test-self-check
@@ -9,6 +9,9 @@ stderr_printf () {
test "$(stderr_printf 'hello\n')" = ''
test "$(stderr stderr_printf 'hello\n' 2>&1)" = 'hello'
+failing_function () { false; true; } # use of { } rather than ( ) is important
+( ! failing_function )
+
(! (false > $a) )
getname OS 0
@@ -39,6 +42,10 @@ printf 'a\n' > $a
printf 'a\n' > $b
diff -u $a $b
+true & wait $!
+( false & ! wait $! )
+await
+
for os in ${SUPPORTED_OSES}; do
issupported $os
for arch in $(env | sed -n 's/^SUPPORTED_'"$os"'_ARCHES=//p' | xargs printf '%s\n'); do
diff --git a/testutil/get-integer-alignment.c b/testutil/get-integer-alignment.c
index 6c91824..7d0fcc3 100644
--- a/testutil/get-integer-alignment.c
+++ b/testutil/get-integer-alignment.c
@@ -15,7 +15,7 @@ int
main(int argc, char **argv)
{
int os, arch, width;
- unsigned alignment = -1;
+ unsigned alignment = 0;
enum libsyscalls_error err;
if (argc != 6) {
diff --git a/testutil/make-signed.c b/testutil/make-signed.c
new file mode 100644
index 0000000..7cd0134
--- /dev/null
+++ b/testutil/make-signed.c
@@ -0,0 +1,56 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ int sign, neg = -1;
+ size_t bits;
+ const char *xval;
+ enum libsyscalls_error err;
+ unsigned long long int value;
+ char *end;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ sign = atoi(argv[1]);
+ bits = (unsigned long long int)atoll(argv[2]);
+ xval = argv[3];
+ neg = *xval == '-';
+ xval = &xval[neg];
+ errno = 0;
+ value = strtoull(xval, &end, 16);
+ if (errno || *end)
+ goto usage;
+
+ err = libsyscalls_make_signed_integer(value, neg, (enum libsyscalls_datatype_sign_representation)sign, bits, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ printf("%0*llX\n", (int)strlen(xval), value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/parse-signed.c b/testutil/parse-signed.c
new file mode 100644
index 0000000..0fea405
--- /dev/null
+++ b/testutil/parse-signed.c
@@ -0,0 +1,56 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ int sign, neg = -1;
+ size_t bits;
+ const char *xval;
+ enum libsyscalls_error err;
+ unsigned long long int value;
+ char *end;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ sign = atoi(argv[1]);
+ bits = (unsigned long long int)atoll(argv[2]);
+ xval = argv[3];
+ errno = 0;
+ value = strtoull(xval, &end, 16);
+ if (errno || *end)
+ goto usage;
+
+ err = libsyscalls_parse_signed_integer(value, (enum libsyscalls_datatype_sign_representation)sign, bits, &value, &neg);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ if (neg != 0 && neg != 1)
+ abort();
+ printf("%.*s%0*llX\n", neg, "-", (int)strlen(xval), value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/section-value.c b/testutil/section-value.c
new file mode 100644
index 0000000..b4c0304
--- /dev/null
+++ b/testutil/section-value.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ enum libsyscalls_datatype_section section;
+ unsigned long long int value;
+ size_t bits;
+ char *end;
+ enum libsyscalls_error err;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ section = (enum libsyscalls_datatype_section)atoi(argv[1]);
+ errno = 0;
+ value = strtoull(argv[2], &end, 16);
+ if (errno || *end)
+ goto usage;
+ bits = (size_t)atol(argv[3]);
+
+ err = libsyscalls_section_value(value, bits, section, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/to-tracee-endian.c b/testutil/to-tracee-endian.c
new file mode 100644
index 0000000..4346883
--- /dev/null
+++ b/testutil/to-tracee-endian.c
@@ -0,0 +1,111 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+static void
+make_hex(char *out, const char *in, size_t n)
+{
+ for (; n--; in++) {
+ *out++ = "0123456789ABCDEF"[((unsigned)*in >> 4) & 0xFU];
+ *out++ = "0123456789ABCDEF"[((unsigned)*in >> 0) & 0xFU];
+ }
+ *out = '\0';
+}
+
+
+int
+main(int argc, char **argv)
+{
+ struct libsyscalls_datatype_description type;
+ char *data, *end, *text0, *text1;
+ size_t dataoff, i, datasize;
+ unsigned long long int value;
+ enum libsyscalls_error err;
+
+ _Static_assert(CHAR_BIT, "We only support 8-bit char at the moment in testutil/to-tracee-endian.c");
+
+ if (argc < 5) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
+ errno = 0;
+ value = strtoull(argv[1], &end, 16);
+ if (errno || *end)
+ goto usage;
+ dataoff = (size_t)atol(argv[2]);
+ type.width_in_bits = (unsigned short int)atoi(argv[3]);
+ argv = &argv[4];
+ i = 0;
+ for (; argv[i] && i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++)
+ type.byteorder[i] = (unsigned)atoi(argv[i]);
+ if (argv[i])
+ goto usage;
+ for (; i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++) {
+ type.byteorder[i] = 0U;
+ type.byteorder[i] = ~type.byteorder[i];
+ }
+
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+ datasize = ((size_t)type.width_in_bits + dataoff + 7UL) / 8UL;
+ data = malloc(datasize);
+ text0 = malloc(datasize * 2UL + 1UL);
+ text1 = malloc(datasize * 2UL + 1UL);
+
+ memset(data, 0, datasize);
+ err = libsyscalls_to_tracee_endian(value, &type, data, dataoff);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ free(data);
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ make_hex(text0, data, datasize);
+
+ memset(data, ~0, datasize);
+ err = libsyscalls_to_tracee_endian(value, &type, data, dataoff);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ free(data);
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ make_hex(text1, data, datasize);
+
+ free(data);
+
+ printf("%s %s\n", text0, text1);
+
+ free(text0);
+ free(text1);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/to-tracer-endian.c b/testutil/to-tracer-endian.c
new file mode 100644
index 0000000..53cb380
--- /dev/null
+++ b/testutil/to-tracer-endian.c
@@ -0,0 +1,83 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ struct libsyscalls_datatype_description type;
+ const char *text;
+ char *data;
+ size_t dataoff, i;
+ unsigned long long int value;
+ unsigned char high, low;
+ enum libsyscalls_error err;
+
+ _Static_assert(CHAR_BIT, "We only support 8-bit char at the moment in testutil/to-tracer-endian.c");
+
+ if (argc < 5) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
+ text = argv[1];
+ dataoff = (size_t)atol(argv[2]);
+ type.width_in_bits = (unsigned short int)atoi(argv[3]);
+ argv = &argv[4];
+ i = 0;
+ for (; argv[i] && i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++)
+ type.byteorder[i] = (unsigned)atoi(argv[i]);
+ if (argv[i])
+ goto usage;
+ for (; i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++) {
+ type.byteorder[i] = 0U;
+ type.byteorder[i] = ~type.byteorder[i];
+ }
+
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+ if (strlen(text) & 1 || !strlen(text))
+ goto usage;
+ data = malloc(strlen(text) / 2);
+ for (i = 0; *text; i++) {
+ high = (unsigned char)*text++;
+ low = (unsigned char)*text++;
+ high = (unsigned char)((high & 15U) + (high > '9' ? 9U : 0U));
+ low = (unsigned char)((low & 15U) + (low > '9' ? 9U : 0U));
+ data[i] = (char)((high << 4) | low);
+ }
+
+ err = libsyscalls_to_tracer_endian(data, dataoff, &type, &value);
+ free(data);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/unsection-value.c b/testutil/unsection-value.c
new file mode 100644
index 0000000..9c85b3b
--- /dev/null
+++ b/testutil/unsection-value.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ enum libsyscalls_datatype_section section;
+ unsigned long long int value;
+ size_t bits;
+ char *end;
+ enum libsyscalls_error err;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ section = (enum libsyscalls_datatype_section)atoi(argv[1]);
+ errno = 0;
+ value = strtoull(argv[2], &end, 16);
+ if (errno || *end)
+ goto usage;
+ bits = (size_t)atol(argv[3]);
+
+ err = libsyscalls_unsection_value(value, bits, section, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}