-
-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write more tests attempting to break windows
This time I haven't succeeded in breaking anything which is a good sign.
- Loading branch information
Showing
7 changed files
with
331 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2024 Justine Alexandra Roberts Tunney | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for | ||
// any purpose with or without fee is hereby granted, provided that the | ||
// above copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | ||
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
// PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#include <errno.h> | ||
#include <poll.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
/** | ||
* @fileoverview Tests that EAGAIN won't corrupt pipe. | ||
* | ||
* This is a real bug when using CancelIoEx() on winsock writes, so we | ||
* need to make sure it doesn't happen on pipes too. | ||
*/ | ||
|
||
#define ITERATIONS 100000 | ||
#define ASYMMETRY 3 | ||
|
||
int fds[2]; | ||
int got_read_eagains; | ||
int got_write_eagains; | ||
|
||
void *worker(void *arg) { | ||
for (int expect = 0; expect < ITERATIONS;) { | ||
int number; | ||
ssize_t rc = read(fds[0], &number, sizeof(number)); | ||
if (rc == -1) { | ||
if (errno == EAGAIN) { | ||
++got_read_eagains; | ||
if (poll(&(struct pollfd){fds[0], POLLIN}, 1, -1) == -1) | ||
exit(11); | ||
continue; | ||
} | ||
perror("read"); | ||
exit(8); | ||
} | ||
size_t got = rc; | ||
if (got != sizeof(int)) | ||
exit(9); | ||
if (expect != number) | ||
exit(10); | ||
++expect; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
if (pipe2(fds, O_NONBLOCK)) | ||
return 1; | ||
|
||
pthread_t th; | ||
if (pthread_create(&th, 0, worker, 0)) | ||
return 2; | ||
|
||
int number = 0; | ||
for (;;) { | ||
int chunk = 0; | ||
int numbers[ASYMMETRY]; | ||
for (;;) { | ||
numbers[chunk] = number + chunk; | ||
if (++chunk == ASYMMETRY) | ||
break; | ||
if (number + chunk == ITERATIONS) | ||
break; | ||
} | ||
for (;;) { | ||
ssize_t rc = write(fds[1], numbers, chunk * sizeof(int)); | ||
if (rc == -1) { | ||
if (errno == EAGAIN) { | ||
++got_write_eagains; | ||
if (poll(&(struct pollfd){fds[1], POLLOUT}, 1, -1) == -1) | ||
return 10; | ||
continue; | ||
} | ||
return 3; | ||
} | ||
if (rc % sizeof(int)) | ||
return 4; | ||
chunk = rc / sizeof(int); | ||
number += chunk; | ||
break; | ||
} | ||
if (number == ITERATIONS) | ||
break; | ||
} | ||
|
||
if (pthread_join(th, 0)) | ||
return 5; | ||
|
||
if (!got_read_eagains && !got_write_eagains) | ||
return 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,90 @@ | ||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ | ||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ Copyright 2023 Justine Alexandra Roberts Tunney │ | ||
│ │ | ||
│ Permission to use, copy, modify, and/or distribute this software for │ | ||
│ any purpose with or without fee is hereby granted, provided that the │ | ||
│ above copyright notice and this permission notice appear in all copies. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ | ||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ | ||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ | ||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ | ||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ | ||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ | ||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ | ||
│ PERFORMANCE OF THIS SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
// Copyright 2024 Justine Alexandra Roberts Tunney | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for | ||
// any purpose with or without fee is hereby granted, provided that the | ||
// above copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | ||
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
// PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#include <errno.h> | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
|
||
volatile int gotsig; | ||
|
||
void OnSig(int sig) { | ||
gotsig = sig; | ||
} | ||
|
||
int main() { | ||
void test_sa_resethand_raise(void) { | ||
struct sigaction sa; | ||
sa.sa_handler = OnSig; | ||
sa.sa_flags = SA_RESETHAND; | ||
sigemptyset(&sa.sa_mask); | ||
if (sigaction(SIGUSR1, &sa, 0)) | ||
return 1; | ||
exit(1); | ||
if (sigaction(SIGUSR1, 0, &sa)) | ||
return 2; | ||
exit(2); | ||
if (sa.sa_handler != OnSig) | ||
return 3; | ||
exit(3); | ||
if (raise(SIGUSR1)) | ||
return 4; | ||
exit(4); | ||
if (gotsig != SIGUSR1) | ||
return 5; | ||
exit(5); | ||
if (sigaction(SIGUSR1, 0, &sa)) | ||
return 6; | ||
exit(6); | ||
if (sa.sa_handler != SIG_DFL) | ||
exit(7); | ||
} | ||
|
||
void test_sa_resethand_pause(void) { | ||
struct sigaction sa; | ||
sa.sa_handler = OnSig; | ||
sa.sa_flags = SA_RESETHAND; | ||
sigemptyset(&sa.sa_mask); | ||
if (sigaction(SIGALRM, &sa, 0)) | ||
exit(10); | ||
ualarm(10000, 0); | ||
if (pause() != -1 || errno != EINTR) | ||
exit(11); | ||
if (gotsig != SIGALRM) | ||
exit(12); | ||
if (sigaction(SIGALRM, 0, &sa)) | ||
exit(13); | ||
if (sa.sa_handler != SIG_DFL) | ||
return 7; | ||
exit(14); | ||
} | ||
|
||
void test_sa_resethand_read(void) { | ||
struct sigaction sa; | ||
sa.sa_handler = OnSig; | ||
sa.sa_flags = SA_RESETHAND; | ||
sigemptyset(&sa.sa_mask); | ||
if (sigaction(SIGALRM, &sa, 0)) | ||
exit(20); | ||
int fds[2]; | ||
if (pipe(fds)) | ||
exit(21); | ||
ualarm(10000, 0); | ||
if (read(fds[0], (char[]){0}, 1) != -1 || errno != EINTR) | ||
exit(22); | ||
if (gotsig != SIGALRM) | ||
exit(23); | ||
if (sigaction(SIGALRM, 0, &sa)) | ||
exit(24); | ||
if (sa.sa_handler != SIG_DFL) | ||
exit(25); | ||
} | ||
|
||
int main() { | ||
test_sa_resethand_raise(); | ||
test_sa_resethand_pause(); | ||
test_sa_resethand_read(); | ||
} |
Oops, something went wrong.