diff options
| author | Michael Ellerman <michael@ellerman.id.au> | 2013-08-06 03:42:36 -0400 |
|---|---|---|
| committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-08-14 00:57:07 -0400 |
| commit | 2fae0d7ced53ef2e7b4d87d84986ec3ff7cf798f (patch) | |
| tree | e8ed1accab4920d9e2256f7c9d96f52989d897b3 /tools/testing | |
| parent | 0e56dacdda49940ff6e24e504f11468a27922416 (diff) | |
selftests: Add support files for powerpc tests
This commit adds support code used by upcoming powerpc tests.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/powerpc/harness.c | 105 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/subunit.h | 47 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/utils.h | 34 |
3 files changed, 186 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/harness.c b/tools/testing/selftests/powerpc/harness.c new file mode 100644 index 000000000000..e80c42a584fe --- /dev/null +++ b/tools/testing/selftests/powerpc/harness.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2013, Michael Ellerman, IBM Corp. | ||
| 3 | * Licensed under GPLv2. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <errno.h> | ||
| 7 | #include <signal.h> | ||
| 8 | #include <stdbool.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/wait.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | #include "subunit.h" | ||
| 16 | #include "utils.h" | ||
| 17 | |||
| 18 | #define TIMEOUT 120 | ||
| 19 | #define KILL_TIMEOUT 5 | ||
| 20 | |||
| 21 | |||
| 22 | int run_test(int (test_function)(void), char *name) | ||
| 23 | { | ||
| 24 | bool terminated; | ||
| 25 | int rc, status; | ||
| 26 | pid_t pid; | ||
| 27 | |||
| 28 | /* Make sure output is flushed before forking */ | ||
| 29 | fflush(stdout); | ||
| 30 | |||
| 31 | pid = fork(); | ||
| 32 | if (pid == 0) { | ||
| 33 | exit(test_function()); | ||
| 34 | } else if (pid == -1) { | ||
| 35 | perror("fork"); | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | /* Wake us up in timeout seconds */ | ||
| 40 | alarm(TIMEOUT); | ||
| 41 | terminated = false; | ||
| 42 | |||
| 43 | wait: | ||
| 44 | rc = waitpid(pid, &status, 0); | ||
| 45 | if (rc == -1) { | ||
| 46 | if (errno != EINTR) { | ||
| 47 | printf("unknown error from waitpid\n"); | ||
| 48 | return 1; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (terminated) { | ||
| 52 | printf("!! force killing %s\n", name); | ||
| 53 | kill(pid, SIGKILL); | ||
| 54 | return 1; | ||
| 55 | } else { | ||
| 56 | printf("!! killing %s\n", name); | ||
| 57 | kill(pid, SIGTERM); | ||
| 58 | terminated = true; | ||
| 59 | alarm(KILL_TIMEOUT); | ||
| 60 | goto wait; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | if (WIFEXITED(status)) | ||
| 65 | status = WEXITSTATUS(status); | ||
| 66 | else { | ||
| 67 | if (WIFSIGNALED(status)) | ||
| 68 | printf("!! child died by signal %d\n", WTERMSIG(status)); | ||
| 69 | else | ||
| 70 | printf("!! child died by unknown cause\n"); | ||
| 71 | |||
| 72 | status = 1; /* Signal or other */ | ||
| 73 | } | ||
| 74 | |||
| 75 | return status; | ||
| 76 | } | ||
| 77 | |||
| 78 | static void alarm_handler(int signum) | ||
| 79 | { | ||
| 80 | /* Jut wake us up from waitpid */ | ||
| 81 | } | ||
| 82 | |||
| 83 | static struct sigaction alarm_action = { | ||
| 84 | .sa_handler = alarm_handler, | ||
| 85 | }; | ||
| 86 | |||
| 87 | int test_harness(int (test_function)(void), char *name) | ||
| 88 | { | ||
| 89 | int rc; | ||
| 90 | |||
| 91 | test_start(name); | ||
| 92 | test_set_git_version(GIT_VERSION); | ||
| 93 | |||
| 94 | if (sigaction(SIGALRM, &alarm_action, NULL)) { | ||
| 95 | perror("sigaction"); | ||
| 96 | test_error(name); | ||
| 97 | return 1; | ||
| 98 | } | ||
| 99 | |||
| 100 | rc = run_test(test_function, name); | ||
| 101 | |||
| 102 | test_finish(name, rc); | ||
| 103 | |||
| 104 | return rc; | ||
| 105 | } | ||
diff --git a/tools/testing/selftests/powerpc/subunit.h b/tools/testing/selftests/powerpc/subunit.h new file mode 100644 index 000000000000..98a22920792d --- /dev/null +++ b/tools/testing/selftests/powerpc/subunit.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2013, Michael Ellerman, IBM Corp. | ||
| 3 | * Licensed under GPLv2. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _SELFTESTS_POWERPC_SUBUNIT_H | ||
| 7 | #define _SELFTESTS_POWERPC_SUBUNIT_H | ||
| 8 | |||
| 9 | static inline void test_start(char *name) | ||
| 10 | { | ||
| 11 | printf("test: %s\n", name); | ||
| 12 | } | ||
| 13 | |||
| 14 | static inline void test_failure_detail(char *name, char *detail) | ||
| 15 | { | ||
| 16 | printf("failure: %s [%s]\n", name, detail); | ||
| 17 | } | ||
| 18 | |||
| 19 | static inline void test_failure(char *name) | ||
| 20 | { | ||
| 21 | printf("failure: %s\n", name); | ||
| 22 | } | ||
| 23 | |||
| 24 | static inline void test_error(char *name) | ||
| 25 | { | ||
| 26 | printf("error: %s\n", name); | ||
| 27 | } | ||
| 28 | |||
| 29 | static inline void test_success(char *name) | ||
| 30 | { | ||
| 31 | printf("success: %s\n", name); | ||
| 32 | } | ||
| 33 | |||
| 34 | static inline void test_finish(char *name, int status) | ||
| 35 | { | ||
| 36 | if (status) | ||
| 37 | test_failure(name); | ||
| 38 | else | ||
| 39 | test_success(name); | ||
| 40 | } | ||
| 41 | |||
| 42 | static inline void test_set_git_version(char *value) | ||
| 43 | { | ||
| 44 | printf("tags: git_version:%s\n", value); | ||
| 45 | } | ||
| 46 | |||
| 47 | #endif /* _SELFTESTS_POWERPC_SUBUNIT_H */ | ||
diff --git a/tools/testing/selftests/powerpc/utils.h b/tools/testing/selftests/powerpc/utils.h new file mode 100644 index 000000000000..5851c4b0f553 --- /dev/null +++ b/tools/testing/selftests/powerpc/utils.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2013, Michael Ellerman, IBM Corp. | ||
| 3 | * Licensed under GPLv2. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _SELFTESTS_POWERPC_UTILS_H | ||
| 7 | #define _SELFTESTS_POWERPC_UTILS_H | ||
| 8 | |||
| 9 | #include <stdint.h> | ||
| 10 | #include <stdbool.h> | ||
| 11 | |||
| 12 | /* Avoid headaches with PRI?64 - just use %ll? always */ | ||
| 13 | typedef unsigned long long u64; | ||
| 14 | typedef signed long long s64; | ||
| 15 | |||
| 16 | /* Just for familiarity */ | ||
| 17 | typedef uint32_t u32; | ||
| 18 | typedef uint8_t u8; | ||
| 19 | |||
| 20 | |||
| 21 | int test_harness(int (test_function)(void), char *name); | ||
| 22 | |||
| 23 | |||
| 24 | /* Yes, this is evil */ | ||
| 25 | #define FAIL_IF(x) \ | ||
| 26 | do { \ | ||
| 27 | if ((x)) { \ | ||
| 28 | fprintf(stderr, \ | ||
| 29 | "[FAIL] Test FAILED on line %d\n", __LINE__); \ | ||
| 30 | return 1; \ | ||
| 31 | } \ | ||
| 32 | } while (0) | ||
| 33 | |||
| 34 | #endif /* _SELFTESTS_POWERPC_UTILS_H */ | ||
