also looking at this
test: qualify partial host image writes and recovery
#57
9 files
+311
-7
| @@ -0,0 +1,28 @@ | ||
| 1 | // Test-only inherited POSIX file-size limit. No application or board linkage. | |
| 2 | #include <cerrno> | |
| 3 | #include <csignal> | |
| 4 | #include <cstdio> | |
| 5 | #include <cstdlib> | |
| 6 | #include <cstring> | |
| 7 | #include <sys/resource.h> | |
| 8 | #include <unistd.h> | |
| 9 | ||
| 10 | int main(int argc, char** argv) { | |
| 11 | if (argc < 3 || !argv[1][0] || std::strlen(argv[1]) > 8 | |
| 12 | || std::strspn(argv[1], "0123456789") != std::strlen(argv[1])) return 125; | |
| 13 | errno = 0; | |
| 14 | char* end = nullptr; | |
| 15 | const auto requested = std::strtoull(argv[1], &end, 10); | |
| 16 | if (errno || !end || *end || requested < 1 || requested > 16777216) return 125; | |
| 17 | const rlim_t bytes = static_cast<rlim_t>(requested); | |
| 18 | const rlimit limit{bytes, bytes}; | |
| 19 | if (setrlimit(RLIMIT_FSIZE, &limit) != 0 || std::signal(SIGXFSZ, SIG_IGN) == SIG_ERR) return 125; | |
| 20 | rlimit observed{}; | |
| 21 | if (getrlimit(RLIMIT_FSIZE, &observed) != 0 || observed.rlim_cur != bytes || observed.rlim_max != bytes) return 125; | |
| 22 | if (setenv("DRONE_TEST_FILE_LIMIT", argv[1], 1) != 0) return 125; | |
| 23 | std::fprintf(stderr, "FILE_LIMIT_ACTIVE %llu\n", requested); | |
| 24 | std::fflush(stderr); | |
| 25 | execvp(argv[2], argv + 2); | |
| 26 | std::perror("File-limit test exec"); | |
| 27 | return 127; | |
| 28 | } | |