summaryrefslogtreecommitdiffstats
path: root/testutil
diff options
context:
space:
mode:
Diffstat (limited to 'testutil')
-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
13 files changed, 134 insertions, 8 deletions
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;
}