summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtest3
-rw-r--r--tests/archinfo17
-rw-r--r--tests/error-search13
-rw-r--r--tests/load-archinfo7
-rw-r--r--tests/run4
-rw-r--r--tests/signal-search13
-rw-r--r--testutil/get-datatype-description.c2
-rw-r--r--testutil/get-integer-alignment.c2
-rw-r--r--testutil/get-signals.c2
-rw-r--r--testutil/get-syscall-errors.c2
-rw-r--r--testutil/get-syscall-range.c2
-rw-r--r--testutil/is-datatype-struct.c2
-rw-r--r--testutil/make-signed.c1
-rw-r--r--testutil/parse-signed.c1
-rw-r--r--testutil/section-value.c1
-rw-r--r--testutil/test-search.c114
-rw-r--r--testutil/to-tracee-endian.c8
-rw-r--r--testutil/to-tracer-endian.c4
-rw-r--r--testutil/unsection-value.c1
19 files changed, 182 insertions, 17 deletions
diff --git a/test b/test
index 4af52c8..28ce256 100755
--- a/test
+++ b/test
@@ -42,6 +42,9 @@ p tests/os-dependent-arrays
p tests/os-dependent-integers
await
+t tests/error-search
+t tests/signal-search
+
# TODO test libsyscalls_get_struct_description
# TODO test libsyscalls_get_struct_display_info
diff --git a/tests/archinfo b/tests/archinfo
index 5034766..334571e 100644
--- a/tests/archinfo
+++ b/tests/archinfo
@@ -1,19 +1,22 @@
# -*- sh -*-
# See LICENSE file for copyright and license details.
-printf '%s\n' "$archinfo" | grep '^AMD64 8 64 64 Little TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^AMD64_X32 8 32 32 Little TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^M68K 8 32 32 Big TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^PARISC_32 8 32 32 Big TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^PARISC_64 8 64 64 Big TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^SPARC_32 8 32 32 Big TWOS_COMPLEMENT' >/dev/null
-printf '%s\n' "$archinfo" | grep '^I386 8 32 32 Little TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^AMD64 8 64 64 64 Little TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^AMD64_X32 8 32 32 64 Little TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^M68K 8 32 32 16 Big TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^PARISC_32 8 32 32 64 Big TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^PARISC_64 8 64 64 64 Big TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^SPARC_32 8 32 32 64 Big TWOS_COMPLEMENT' >/dev/null
+printf '%s\n' "$archinfo" | grep '^I386 8 32 32 32 Little TWOS_COMPLEMENT' >/dev/null
test $(getbytesize AMD64) = 8
test $(getbytesize I386) = 8
test $(getaddrsize I386) = 32
test $(getaddrsize AMD64) = 64
test $(getsizesize AMD64) = 64
test $(getsizesize I386) = 32
+test $(getintalign I386) = 32
+test $(getintalign AMD64) = 64
+test $(getintalign M68K) = 16
test $(getendian I386) = Little
test $(getendian AMD64) = Little
test $(getendian M68K) = Big
diff --git a/tests/error-search b/tests/error-search
new file mode 100644
index 0000000..dd71bd9
--- /dev/null
+++ b/tests/error-search
@@ -0,0 +1,13 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+for os in $(getnamelist OS); do
+ osn=$(getnum OS $os)
+ for arch in $(getnamelist ARCH); do
+ archn=$(getnum ARCH $arch)
+ if issupported $os $arch; then
+ p tests/run test-search.tu errors $osn $archn $os $arch
+ fi
+ done
+ await
+done
diff --git a/tests/load-archinfo b/tests/load-archinfo
index e5413b4..8e6b2a6 100644
--- a/tests/load-archinfo
+++ b/tests/load-archinfo
@@ -33,9 +33,12 @@ getaddrsize () {
getsizesize () {
printf '%s\n' "$archinfo" | grep "^$1 " | cut -d ' ' -f 4
}
-getendian () {
+getintalign () {
printf '%s\n' "$archinfo" | grep "^$1 " | cut -d ' ' -f 5
}
-getsign () {
+getendian () {
printf '%s\n' "$archinfo" | grep "^$1 " | cut -d ' ' -f 6
}
+getsign () {
+ printf '%s\n' "$archinfo" | grep "^$1 " | cut -d ' ' -f 7
+}
diff --git a/tests/run b/tests/run
new file mode 100644
index 0000000..c9bd4b6
--- /dev/null
+++ b/tests/run
@@ -0,0 +1,4 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+"$@"
diff --git a/tests/signal-search b/tests/signal-search
new file mode 100644
index 0000000..b4afc49
--- /dev/null
+++ b/tests/signal-search
@@ -0,0 +1,13 @@
+# -*- sh -*-
+# See LICENSE file for copyright and license details.
+
+for os in $(getnamelist OS); do
+ osn=$(getnum OS $os)
+ for arch in $(getnamelist ARCH); do
+ archn=$(getnum ARCH $arch)
+ if issupported $os $arch; then
+ p tests/run test-search.tu signals $osn $archn $os $arch
+ fi
+ done
+ await
+done
diff --git a/testutil/get-datatype-description.c b/testutil/get-datatype-description.c
index 9c26626..b3d2637 100644
--- a/testutil/get-datatype-description.c
+++ b/testutil/get-datatype-description.c
@@ -31,7 +31,7 @@ main(int argc, char **argv)
err = libsyscalls_get_datatype_description((enum libsyscalls_os)os, (enum libsyscalls_arch)arch,
(enum libsyscalls_datatype)type, &desc);
if (err) {
- fprintf(stderr, "libsyscalls_get_datatype_description %s %s %s: ", argv[4], argv[5], argv[6]);
+ fprintf(stderr, "get-datatype-description %s %s %s: ", argv[4], argv[5], argv[6]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/get-integer-alignment.c b/testutil/get-integer-alignment.c
index 7d0fcc3..cb67eef 100644
--- a/testutil/get-integer-alignment.c
+++ b/testutil/get-integer-alignment.c
@@ -30,7 +30,7 @@ main(int argc, char **argv)
err = libsyscalls_get_integer_alignment((enum libsyscalls_os)os, (enum libsyscalls_arch)arch,
(unsigned)width, &alignment);
if (err) {
- fprintf(stderr, "libsyscalls_get_integer_alignment %s %s %s: ", argv[4], argv[5], argv[3]);
+ fprintf(stderr, "get-integer-alignment %s %s %s: ", argv[4], argv[5], argv[3]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/get-signals.c b/testutil/get-signals.c
index 54fcac4..2a2ea03 100644
--- a/testutil/get-signals.c
+++ b/testutil/get-signals.c
@@ -34,7 +34,7 @@ main(int argc, char **argv)
} else if (err == LIBSYSCALLS_E_NOSIGNALS) {
return 0;
} else if (err) {
- fprintf(stderr, "test-get-syscall-signals %s %s: ", argv[3], argv[4]);
+ fprintf(stderr, "get-signals %s %s: ", argv[3], argv[4]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/get-syscall-errors.c b/testutil/get-syscall-errors.c
index a5923f4..0870e07 100644
--- a/testutil/get-syscall-errors.c
+++ b/testutil/get-syscall-errors.c
@@ -34,7 +34,7 @@ main(int argc, char **argv)
} else if (err == LIBSYSCALLS_E_NOERRORS) {
return 0;
} else if (err) {
- fprintf(stderr, "test-get-syscall-errors %s %s: ", argv[3], argv[4]);
+ fprintf(stderr, "get-syscall-errors %s %s: ", argv[3], argv[4]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/get-syscall-range.c b/testutil/get-syscall-range.c
index 2c40b71..a199091 100644
--- a/testutil/get-syscall-range.c
+++ b/testutil/get-syscall-range.c
@@ -31,7 +31,7 @@ main(int argc, char **argv)
printf("max: x\n");
return 0;
} else if (err) {
- fprintf(stderr, "test-get-syscall-range %s %s: ", argv[3], argv[4]);
+ fprintf(stderr, "get-syscall-range %s %s: ", argv[3], argv[4]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/is-datatype-struct.c b/testutil/is-datatype-struct.c
index e9eb2ef..ffaff5f 100644
--- a/testutil/is-datatype-struct.c
+++ b/testutil/is-datatype-struct.c
@@ -32,7 +32,7 @@ main(int argc, char **argv)
if (err == LIBSYSCALLS_E_ISSTRUCT) {
return 0;
} else if (err) {
- fprintf(stderr, "libsyscalls_get_datatype_description %s %s %s: ", argv[4], argv[5], argv[6]);
+ fprintf(stderr, "is-datatype-struct %s %s %s: ", argv[4], argv[5], argv[6]);
libsyscalls_perror(NULL, err);
return 2;
}
diff --git a/testutil/make-signed.c b/testutil/make-signed.c
index 7cd0134..5ac7338 100644
--- a/testutil/make-signed.c
+++ b/testutil/make-signed.c
@@ -42,6 +42,7 @@ main(int argc, char **argv)
printf("inval\n");
goto out;
} else if (err) {
+ fprintf(stderr, "make-signed %s %s %s: ", argv[1], argv[2], argv[3]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/parse-signed.c b/testutil/parse-signed.c
index 0fea405..f5e6d35 100644
--- a/testutil/parse-signed.c
+++ b/testutil/parse-signed.c
@@ -40,6 +40,7 @@ main(int argc, char **argv)
printf("inval\n");
goto out;
} else if (err) {
+ fprintf(stderr, "parse-signed %s %s %s: ", argv[1], argv[2], argv[3]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/section-value.c b/testutil/section-value.c
index b4c0304..bb86b8d 100644
--- a/testutil/section-value.c
+++ b/testutil/section-value.c
@@ -37,6 +37,7 @@ main(int argc, char **argv)
printf("inval\n");
goto out;
} else if (err) {
+ fprintf(stderr, "section-value %s %s %s: ", argv[1], argv[2], argv[3]);
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/test-search.c b/testutil/test-search.c
new file mode 100644
index 0000000..93d6d03
--- /dev/null
+++ b/testutil/test-search.c
@@ -0,0 +1,114 @@
+/* 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
+
+
+static struct libsyscalls_named_number not_found;
+static size_t not_found_count = 0;
+static char **argv;
+
+static void
+check(unsigned long long int key, const struct libsyscalls_named_number *base, size_t n, int is_signed)
+{
+ static int first = 1;
+
+ const struct libsyscalls_named_number *found;
+ found = libsyscalls_find_named_number(key, is_signed, base, n);
+ if (found) {
+ if (first)
+ not_found.number.u = key + 1;
+ if (found->number.u != key) {
+ fprintf(stderr, "test-search %s %s %s: found incorrect element: %llu instead of %llu\n",
+ argv[1], argv[4], argv[5], found->number.u, key);
+ exit(1);
+ }
+ } else {
+ if (first) {
+ fprintf(stderr, "test-search %s %s %s: did not find first element\n", argv[1], argv[4], argv[5]);
+ exit(1);
+ }
+ not_found.number.u = key;
+ not_found_count += 1;
+ }
+
+ first = 0;
+}
+
+
+int
+main(int argc, char **argv_)
+{
+ int os, arch, search_singals, is_signed;
+ enum libsyscalls_error err;
+ const struct libsyscalls_named_number *base, *min, *max;
+ unsigned long long int ukey;
+ signed long long int skey;
+ size_t n, expected_not_found_count;
+
+ argv = argv_;
+
+ if (argc != 6) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ if (!strcmp(argv[1], "signals"))
+ search_singals = 1;
+ else if (!strcmp(argv[1], "errors"))
+ search_singals = 0;
+ else
+ goto usage;
+ os = atoi(argv[2]);
+ arch = atoi(argv[3]);
+
+ if (search_singals)
+ err = libsyscalls_get_signals((enum libsyscalls_os)os, (enum libsyscalls_arch)arch, &base, &n, &is_signed);
+ else
+ err = libsyscalls_get_syscall_errors((enum libsyscalls_os)os, (enum libsyscalls_arch)arch, &base, &n, &is_signed);
+ if (err) {
+ fprintf(stderr, "test-search %s %s %s: ", argv[1], argv[4], argv[5]);
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ if (!n)
+ return 0;
+
+ min = &base[0];
+ max = &base[n - 1];
+
+ if (is_signed) {
+ skey = min->number.s;
+ do {
+ check(*(unsigned long long int *)&skey, base, n, is_signed);
+ } while (skey++ != max->number.s);
+ expected_not_found_count = (size_t)((unsigned long long int)max->number.s -
+ (unsigned long long int)min->number.s -
+ (unsigned long long int)n + 1);
+ } else {
+ ukey = min->number.u;
+ do {
+ check(ukey, base, n, is_signed);
+ } while (ukey++ != max->number.u);
+ expected_not_found_count = (size_t)(max->number.u - min->number.u - (unsigned long long int)n + 1);
+ }
+
+ if (not_found.number.u == max->number.u) {
+ fprintf(stderr, "test-search %s %s %s: did not find last element\n", argv[1], argv[4], argv[5]);
+ return 1;
+ }
+ if (not_found_count != expected_not_found_count) {
+ fprintf(stderr, "test-search %s %s %s: did not find all elements\n", argv[1], argv[4], argv[5]);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/testutil/to-tracee-endian.c b/testutil/to-tracee-endian.c
index 4346883..ba97a95 100644
--- a/testutil/to-tracee-endian.c
+++ b/testutil/to-tracee-endian.c
@@ -78,6 +78,11 @@ main(int argc, char **argv)
free(data);
goto out;
} else if (err) {
+ fail:
+ fprintf(stderr, "to-tracee-endian");
+ for (argv = &argv[1 - argc]; *argv; argv++)
+ fprintf(stderr, " %s", *argv);
+ fprintf(stderr, ": ");
libsyscalls_perror(NULL, err);
return 1;
}
@@ -90,8 +95,7 @@ main(int argc, char **argv)
free(data);
goto out;
} else if (err) {
- libsyscalls_perror(NULL, err);
- return 1;
+ goto fail;
}
make_hex(text1, data, datasize);
diff --git a/testutil/to-tracer-endian.c b/testutil/to-tracer-endian.c
index 53cb380..668499f 100644
--- a/testutil/to-tracer-endian.c
+++ b/testutil/to-tracer-endian.c
@@ -69,6 +69,10 @@ main(int argc, char **argv)
printf("inval\n");
goto out;
} else if (err) {
+ fprintf(stderr, "to-tracer-endian");
+ for (argv = &argv[1 - argc]; *argv; argv++)
+ fprintf(stderr, " %s", *argv);
+ fprintf(stderr, ": ");
libsyscalls_perror(NULL, err);
return 1;
}
diff --git a/testutil/unsection-value.c b/testutil/unsection-value.c
index 9c85b3b..9c7e68a 100644
--- a/testutil/unsection-value.c
+++ b/testutil/unsection-value.c
@@ -37,6 +37,7 @@ main(int argc, char **argv)
printf("inval\n");
goto out;
} else if (err) {
+ fprintf(stderr, "unsection-value %s %s %s: ", argv[1], argv[2], argv[3]);
libsyscalls_perror(NULL, err);
return 1;
}