From 58dd684c4e86944301959a140dbed9746df35779 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 5 Dec 2023 00:03:04 +0100 Subject: Second commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- testutil/get-datatype-description.c | 52 +++++++++++++++++++++++++++++++++++++ testutil/get-error.c | 27 +++++++++++++++++++ testutil/get-section-fraction.c | 24 +++++++++++++++++ testutil/get-signals.c | 43 ++++++++++++++++++++++++++++++ testutil/get-syscall-errors.c | 43 ++++++++++++++++++++++++++++++ testutil/get-syscall-range.c | 41 +++++++++++++++++++++++++++++ testutil/is-datatype-struct.c | 29 +++++++++++++++++++++ testutil/is-section-half.c | 14 ++++++++++ testutil/is-section-quarter.c | 14 ++++++++++ testutil/list-errors.c | 21 +++++++++++++++ testutil/perror-all.c | 23 ++++++++++++++++ testutil/perror-bad.c | 23 ++++++++++++++++ testutil/strerror-all.c | 25 ++++++++++++++++++ testutil/strerror-bad.c | 25 ++++++++++++++++++ 14 files changed, 404 insertions(+) create mode 100644 testutil/get-datatype-description.c create mode 100644 testutil/get-error.c create mode 100644 testutil/get-section-fraction.c create mode 100644 testutil/get-signals.c create mode 100644 testutil/get-syscall-errors.c create mode 100644 testutil/get-syscall-range.c create mode 100644 testutil/is-datatype-struct.c create mode 100644 testutil/is-section-half.c create mode 100644 testutil/is-section-quarter.c create mode 100644 testutil/list-errors.c create mode 100644 testutil/perror-all.c create mode 100644 testutil/perror-bad.c create mode 100644 testutil/strerror-all.c create mode 100644 testutil/strerror-bad.c (limited to 'testutil') diff --git a/testutil/get-datatype-description.c b/testutil/get-datatype-description.c new file mode 100644 index 0000000..0bec618 --- /dev/null +++ b/testutil/get-datatype-description.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_os os = (enum libsyscalls_os)atoi(argv[1]); + enum libsyscalls_arch arch = (enum libsyscalls_arch)atoi(argv[2]); + enum libsyscalls_datatype type = (enum libsyscalls_datatype)atoi(argv[3]); + struct libsyscalls_datatype_description desc; + enum libsyscalls_error err; + size_t i; + + err = libsyscalls_get_datatype_description(os, arch, type, &desc); + if (err) { + fprintf(stderr, "libsyscalls_get_datatype_description %s %s %s: ", argv[4], argv[5], argv[6]); + libsyscalls_perror(NULL, err); + return 1; + } + + printf("width_in_bits = %u\n", desc.width_in_bits); + printf("array_size = %u\n", desc.array_size); + printf("relative_position_of_array_size = %i\n", desc.relative_position_of_array_size); + printf("absolute_position_of_array_size = %i\n", desc.absolute_position_of_array_size); + printf("fill_is_known = %u\n", desc.fill_is_known); + printf("is_signed = %u\n", desc.is_signed); + printf("is_unsigned = %u\n", desc.is_unsigned); + printf("min_is_minus_max = %u\n", desc.min_is_minus_max); + printf("sign_representation = %lli\n", (long long int)desc.sign_representation); + printf("annotation = %lli\n", (long long int)desc.annotation); + printf("section = %lli\n", (long long int)desc.section); + printf("byteorder ="); + for (i = 0; i < sizeof(desc.byteorder) / sizeof(*desc.byteorder); i++) { + if (LIBSYSCALLS_IS_BYTEORDER_END(desc.byteorder[i])) + goto end_of_byteorder; + printf(" %u", desc.byteorder[i]); + } +end_of_byteorder: + printf("\n"); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/get-error.c b/testutil/get-error.c new file mode 100644 index 0000000..8f066d7 --- /dev/null +++ b/testutil/get-error.c @@ -0,0 +1,27 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) { +#define X(N, S)\ + if (!strcmp(argv[i], #N))\ + printf("%s\n", S) + LIBSYSCALLS_LIST_ERRORS(X, ;); +#undef X + } + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/get-section-fraction.c b/testutil/get-section-fraction.c new file mode 100644 index 0000000..cdb1530 --- /dev/null +++ b/testutil/get-section-fraction.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_datatype_section sec; + + (void) argc; + + sec = (enum libsyscalls_datatype_section)atoi(argv[1]); + printf("%u\n", LIBSYSCALLS_GET_SECTION_FRACTION(sec)); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/get-signals.c b/testutil/get-signals.c new file mode 100644 index 0000000..846a0c1 --- /dev/null +++ b/testutil/get-signals.c @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_os os; + enum libsyscalls_arch arch; + const struct libsyscalls_named_number *signals; + size_t i, nsignals; + enum libsyscalls_error err; + + (void) argc; + + os = (enum libsyscalls_os)atoi(argv[1]); + arch = (enum libsyscalls_arch)atoi(argv[2]); + + libsyscalls_get_signals(os, arch, &signals, &nsignals); + if (err == LIBSYSCALLS_E_OSNOSUP || err == LIBSYSCALLS_E_ARCHNOSUP) { + printf("x\n"); + return 0; + } else if (err == LIBSYSCALLS_E_NOSIGNALS) { + return 0; + } else if (err) { + fprintf(stderr, "test-get-syscall-signals %s %s: ", argv[3], argv[4]); + libsyscalls_perror(NULL, err); + return 1; + } + + for (i = 0; i < nsignals; i++) + printf("%lli %llu %s\n", signals[i].number.s, signals[i].number.u, signals[i].name); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/get-syscall-errors.c b/testutil/get-syscall-errors.c new file mode 100644 index 0000000..c97e556 --- /dev/null +++ b/testutil/get-syscall-errors.c @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_os os; + enum libsyscalls_arch arch; + const struct libsyscalls_named_number *errors; + size_t i, nerrors; + enum libsyscalls_error err; + + (void) argc; + + os = (enum libsyscalls_os)atoi(argv[1]); + arch = (enum libsyscalls_arch)atoi(argv[2]); + + libsyscalls_get_syscall_errors(os, arch, &errors, &nerrors); + if (err == LIBSYSCALLS_E_OSNOSUP || err == LIBSYSCALLS_E_ARCHNOSUP) { + printf("x\n"); + return 0; + } else if (err == LIBSYSCALLS_E_NOERRORS) { + return 0; + } else if (err) { + fprintf(stderr, "test-get-syscall-errors %s %s: ", argv[3], argv[4]); + libsyscalls_perror(NULL, err); + return 1; + } + + for (i = 0; i < nerrors; i++) + printf("%lli %llu %s\n", errors[i].number.s, errors[i].number.u, errors[i].name); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/get-syscall-range.c b/testutil/get-syscall-range.c new file mode 100644 index 0000000..9f26b8e --- /dev/null +++ b/testutil/get-syscall-range.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_os os; + enum libsyscalls_arch arch; + long long int min, max; + enum libsyscalls_error err; + + (void) argc; + + os = (enum libsyscalls_os)atoi(argv[1]); + arch = (enum libsyscalls_arch)atoi(argv[2]); + + err = libsyscalls_get_syscall_range(os, arch, &min, &max); + if (err == LIBSYSCALLS_E_OSNOSUP || err == LIBSYSCALLS_E_ARCHNOSUP) { + printf("min: x\n"); + printf("max: x\n"); + return 0; + } else if (err) { + fprintf(stderr, "test-get-syscall-range %s %s: ", argv[3], argv[4]); + libsyscalls_perror(NULL, err); + return 1; + } + + printf("min: %lli\n", min); + printf("max: %lli\n", max); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/is-datatype-struct.c b/testutil/is-datatype-struct.c new file mode 100644 index 0000000..f1c7675 --- /dev/null +++ b/testutil/is-datatype-struct.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_os os = (enum libsyscalls_os)atoi(argv[1]); + enum libsyscalls_arch arch = (enum libsyscalls_arch)atoi(argv[2]); + enum libsyscalls_datatype type = (enum libsyscalls_datatype)atoi(argv[3]); + struct libsyscalls_datatype_description desc; + enum libsyscalls_error err; + size_t i; + + err = libsyscalls_get_datatype_description(os, arch, type, &desc); + 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]); + libsyscalls_perror(NULL, err); + return 2; + } + return 1; +} diff --git a/testutil/is-section-half.c b/testutil/is-section-half.c new file mode 100644 index 0000000..ee6ef50 --- /dev/null +++ b/testutil/is-section-half.c @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_datatype_section sec; + (void) argc; + sec = (enum libsyscalls_datatype_section)atoi(argv[1]); + return !LIBSYSCALLS_IS_SECTION_HALF(sec); +} diff --git a/testutil/is-section-quarter.c b/testutil/is-section-quarter.c new file mode 100644 index 0000000..1fe28d2 --- /dev/null +++ b/testutil/is-section-quarter.c @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include + + +int +main(int argc, char *argv[]) +{ + enum libsyscalls_datatype_section sec; + (void) argc; + sec = (enum libsyscalls_datatype_section)atoi(argv[1]); + return !LIBSYSCALLS_IS_SECTION_QUARTER(sec); +} diff --git a/testutil/list-errors.c b/testutil/list-errors.c new file mode 100644 index 0000000..5738b06 --- /dev/null +++ b/testutil/list-errors.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include + + +int +main(void) +{ +#define X(N, S)\ + printf("%li %s %s\n", (long int)N, #N, S) + LIBSYSCALLS_LIST_ERRORS(X, ;); +#undef X + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/perror-all.c b/testutil/perror-all.c new file mode 100644 index 0000000..2b37cff --- /dev/null +++ b/testutil/perror-all.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include + + +int +main(int argc, char *argv[]) +{ + size_t i, count; + + (void) argc; + +#define X(...) 1 + count = (LIBSYSCALLS_LIST_ERRORS(X, +)); +#undef X + + for (i = 0; i < count; i++) + libsyscalls_perror(argv[1], (enum libsyscalls_error)i); + + return fflush(stderr) || fclose(stderr); +} diff --git a/testutil/perror-bad.c b/testutil/perror-bad.c new file mode 100644 index 0000000..55d36d3 --- /dev/null +++ b/testutil/perror-bad.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include + + +int +main(int argc, char *argv[]) +{ + size_t count; + + (void) argc; + +#define X(...) 1 + count = (LIBSYSCALLS_LIST_ERRORS(X, +)); +#undef X + + libsyscalls_perror(argv[1], (enum libsyscalls_error)-1); + libsyscalls_perror(argv[1], (enum libsyscalls_error)count); + + return fflush(stderr) || fclose(stderr); +} diff --git a/testutil/strerror-all.c b/testutil/strerror-all.c new file mode 100644 index 0000000..b875392 --- /dev/null +++ b/testutil/strerror-all.c @@ -0,0 +1,25 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include + + +int +main(void) +{ + size_t i, count; + +#define X(...) 1 + count = (LIBSYSCALLS_LIST_ERRORS(X, +)); +#undef X + + for (i = 0; i < count; i++) + printf("%s\n", libsyscalls_strerror((enum libsyscalls_error)i)); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} diff --git a/testutil/strerror-bad.c b/testutil/strerror-bad.c new file mode 100644 index 0000000..23d8836 --- /dev/null +++ b/testutil/strerror-bad.c @@ -0,0 +1,25 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include +#include + + +int +main(void) +{ + size_t count; + +#define X(...) 1 + count = (LIBSYSCALLS_LIST_ERRORS(X, +)); +#undef X + + printf("%s\n", libsyscalls_strerror((enum libsyscalls_error)-1)); + printf("%s\n", libsyscalls_strerror((enum libsyscalls_error)count)); + + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} -- cgit v1.2.3-70-g09d2